Skip to content

Commit

Permalink
Fix #6
Browse files Browse the repository at this point in the history
  • Loading branch information
Elikill58 committed Dec 27, 2023
1 parent 3c7609d commit 5c1fe7f
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.elikill58.negativity.fabric.listeners;

import java.net.InetAddress;

import com.elikill58.negativity.api.NegativityPlayer;
import com.elikill58.negativity.api.events.EventManager;
import com.elikill58.negativity.api.events.player.LoginEvent;
Expand All @@ -12,6 +14,7 @@
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;

public class PlayersListeners {
Expand All @@ -23,11 +26,15 @@ public static void register() {
}

public static void onPreLogin(ServerPlayNetworkHandler e, MinecraftServer srv) {
LoginEvent event = new LoginEvent(e.getPlayer().getUuid(), e.getPlayer().getName().getString(), Result.ALLOWED,
null, "");
EventManager.callEvent(event);
if (!event.getLoginResult().equals(Result.ALLOWED))
e.disconnect(Text.of(event.getKickMessage()));
try {
ServerPlayerEntity p = e.getPlayer();
LoginEvent event = new LoginEvent(p.getUuid(), p.getName().getString(), Result.ALLOWED, InetAddress.getByName(p.getIp()), "");
EventManager.callEvent(event);
if (!event.getLoginResult().equals(Result.ALLOWED))
e.disconnect(Text.of(event.getKickMessage()));
} catch (Exception exc) {
exc.printStackTrace();
}
}

public static void onPlayerJoin(ServerPlayNetworkHandler e, PacketSender sender, MinecraftServer srv) {
Expand All @@ -38,8 +45,7 @@ public static void onPlayerJoin(ServerPlayNetworkHandler e, PacketSender sender,
}

public static void onLeave(ServerPlayNetworkHandler e, MinecraftServer srv) {
NegativityPlayer np = NegativityPlayer.getNegativityPlayer(e.getPlayer().getUuid(),
() -> new FabricPlayer(e.getPlayer()));
NegativityPlayer np = NegativityPlayer.getNegativityPlayer(e.getPlayer().getUuid(), () -> new FabricPlayer(e.getPlayer()));
PlayerLeaveEvent event = new PlayerLeaveEvent(np.getPlayer(), np, "");
EventManager.callEvent(event);
// TODO add again e.setMessage(Text.of(event.getQuitMessage()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.elikill58.negativity.fabric.listeners;

import java.net.InetAddress;

import com.elikill58.negativity.api.NegativityPlayer;
import com.elikill58.negativity.api.events.EventManager;
import com.elikill58.negativity.api.events.player.LoginEvent;
Expand All @@ -12,6 +14,7 @@
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;

public class PlayersListeners {
Expand All @@ -23,11 +26,15 @@ public static void register() {
}

public static void onPreLogin(ServerPlayNetworkHandler e, MinecraftServer srv) {
LoginEvent event = new LoginEvent(e.getPlayer().getUuid(), e.getPlayer().getName().getString(), Result.ALLOWED,
null, "");
EventManager.callEvent(event);
if (!event.getLoginResult().equals(Result.ALLOWED))
e.disconnect(Text.of(event.getKickMessage()));
try {
ServerPlayerEntity p = e.getPlayer();
LoginEvent event = new LoginEvent(p.getUuid(), p.getName().getString(), Result.ALLOWED, InetAddress.getByName(p.getIp()), "");
EventManager.callEvent(event);
if (!event.getLoginResult().equals(Result.ALLOWED))
e.disconnect(Text.of(event.getKickMessage()));
} catch (Exception exc) {
exc.printStackTrace();
}
}

public static void onPlayerJoin(ServerPlayNetworkHandler e, PacketSender sender, MinecraftServer srv) {
Expand All @@ -38,8 +45,7 @@ public static void onPlayerJoin(ServerPlayNetworkHandler e, PacketSender sender,
}

public static void onLeave(ServerPlayNetworkHandler e, MinecraftServer srv) {
NegativityPlayer np = NegativityPlayer.getNegativityPlayer(e.getPlayer().getUuid(),
() -> new FabricPlayer(e.getPlayer()));
NegativityPlayer np = NegativityPlayer.getNegativityPlayer(e.getPlayer().getUuid(), () -> new FabricPlayer(e.getPlayer()));
PlayerLeaveEvent event = new PlayerLeaveEvent(np.getPlayer(), np, "");
EventManager.callEvent(event);
// TODO add again e.setMessage(Text.of(event.getQuitMessage()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.elikill58.negativity.fabric.listeners;

import java.net.InetAddress;

import com.elikill58.negativity.api.NegativityPlayer;
import com.elikill58.negativity.api.events.EventManager;
import com.elikill58.negativity.api.events.player.LoginEvent;
Expand All @@ -12,6 +14,7 @@
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;

public class PlayersListeners {
Expand All @@ -23,11 +26,15 @@ public static void register() {
}

public static void onPreLogin(ServerPlayNetworkHandler e, MinecraftServer srv) {
LoginEvent event = new LoginEvent(e.getPlayer().getUuid(), e.getPlayer().getName().getString(), Result.ALLOWED,
null, "");
EventManager.callEvent(event);
if (!event.getLoginResult().equals(Result.ALLOWED))
e.disconnect(Text.of(event.getKickMessage()));
try {
ServerPlayerEntity p = e.getPlayer();
LoginEvent event = new LoginEvent(p.getUuid(), p.getName().getString(), Result.ALLOWED, InetAddress.getByName(p.getIp()), "");
EventManager.callEvent(event);
if (!event.getLoginResult().equals(Result.ALLOWED))
e.disconnect(Text.of(event.getKickMessage()));
} catch (Exception exc) {
exc.printStackTrace();
}
}

public static void onPlayerJoin(ServerPlayNetworkHandler e, PacketSender sender, MinecraftServer srv) {
Expand All @@ -38,8 +45,7 @@ public static void onPlayerJoin(ServerPlayNetworkHandler e, PacketSender sender,
}

public static void onLeave(ServerPlayNetworkHandler e, MinecraftServer srv) {
NegativityPlayer np = NegativityPlayer.getNegativityPlayer(e.getPlayer().getUuid(),
() -> new FabricPlayer(e.getPlayer()));
NegativityPlayer np = NegativityPlayer.getNegativityPlayer(e.getPlayer().getUuid(), () -> new FabricPlayer(e.getPlayer()));
PlayerLeaveEvent event = new PlayerLeaveEvent(np.getPlayer(), np, "");
EventManager.callEvent(event);
// TODO add again e.setMessage(Text.of(event.getQuitMessage()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.elikill58.negativity.fabric.listeners;

import java.net.InetAddress;

import com.elikill58.negativity.api.NegativityPlayer;
import com.elikill58.negativity.api.events.EventManager;
import com.elikill58.negativity.api.events.player.LoginEvent;
Expand All @@ -12,6 +14,7 @@
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;

public class PlayersListeners {
Expand All @@ -23,11 +26,15 @@ public static void register() {
}

public static void onPreLogin(ServerPlayNetworkHandler e, MinecraftServer srv) {
LoginEvent event = new LoginEvent(e.getPlayer().getUuid(), e.getPlayer().getName().getString(), Result.ALLOWED,
null, "");
EventManager.callEvent(event);
if (!event.getLoginResult().equals(Result.ALLOWED))
e.disconnect(Text.of(event.getKickMessage()));
try {
ServerPlayerEntity p = e.getPlayer();
LoginEvent event = new LoginEvent(p.getUuid(), p.getName().getString(), Result.ALLOWED, InetAddress.getByName(p.getIp()), "");
EventManager.callEvent(event);
if (!event.getLoginResult().equals(Result.ALLOWED))
e.disconnect(Text.of(event.getKickMessage()));
} catch (Exception exc) {
exc.printStackTrace();
}
}

public static void onPlayerJoin(ServerPlayNetworkHandler e, PacketSender sender, MinecraftServer srv) {
Expand All @@ -38,8 +45,7 @@ public static void onPlayerJoin(ServerPlayNetworkHandler e, PacketSender sender,
}

public static void onLeave(ServerPlayNetworkHandler e, MinecraftServer srv) {
NegativityPlayer np = NegativityPlayer.getNegativityPlayer(e.getPlayer().getUuid(),
() -> new FabricPlayer(e.getPlayer()));
NegativityPlayer np = NegativityPlayer.getNegativityPlayer(e.getPlayer().getUuid(), () -> new FabricPlayer(e.getPlayer()));
PlayerLeaveEvent event = new PlayerLeaveEvent(np.getPlayer(), np, "");
EventManager.callEvent(event);
// TODO add again e.setMessage(Text.of(event.getQuitMessage()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.elikill58.negativity.fabric.listeners;

import java.net.InetAddress;

import com.elikill58.negativity.api.NegativityPlayer;
import com.elikill58.negativity.api.events.EventManager;
import com.elikill58.negativity.api.events.player.LoginEvent;
Expand All @@ -12,6 +14,7 @@
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;

public class PlayersListeners {
Expand All @@ -23,11 +26,15 @@ public static void register() {
}

public static void onPreLogin(ServerPlayNetworkHandler e, MinecraftServer srv) {
LoginEvent event = new LoginEvent(e.getPlayer().getUuid(), e.getPlayer().getName().getString(), Result.ALLOWED,
null, "");
EventManager.callEvent(event);
if (!event.getLoginResult().equals(Result.ALLOWED))
e.disconnect(Text.of(event.getKickMessage()));
try {
ServerPlayerEntity p = e.getPlayer();
LoginEvent event = new LoginEvent(p.getUuid(), p.getName().getString(), Result.ALLOWED, InetAddress.getByName(p.getIp()), "");
EventManager.callEvent(event);
if (!event.getLoginResult().equals(Result.ALLOWED))
e.disconnect(Text.of(event.getKickMessage()));
} catch (Exception exc) {
exc.printStackTrace();
}
}

public static void onPlayerJoin(ServerPlayNetworkHandler e, PacketSender sender, MinecraftServer srv) {
Expand All @@ -38,8 +45,7 @@ public static void onPlayerJoin(ServerPlayNetworkHandler e, PacketSender sender,
}

public static void onLeave(ServerPlayNetworkHandler e, MinecraftServer srv) {
NegativityPlayer np = NegativityPlayer.getNegativityPlayer(e.getPlayer().getUuid(),
() -> new FabricPlayer(e.getPlayer()));
NegativityPlayer np = NegativityPlayer.getNegativityPlayer(e.getPlayer().getUuid(), () -> new FabricPlayer(e.getPlayer()));
PlayerLeaveEvent event = new PlayerLeaveEvent(np.getPlayer(), np, "");
EventManager.callEvent(event);
// TODO add again e.setMessage(Text.of(event.getQuitMessage()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.elikill58.negativity.fabric.listeners;

import java.net.InetAddress;

import com.elikill58.negativity.api.NegativityPlayer;
import com.elikill58.negativity.api.events.EventManager;
import com.elikill58.negativity.api.events.player.LoginEvent;
Expand All @@ -12,6 +14,7 @@
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;

public class PlayersListeners {
Expand All @@ -23,11 +26,15 @@ public static void register() {
}

public static void onPreLogin(ServerPlayNetworkHandler e, MinecraftServer srv) {
LoginEvent event = new LoginEvent(e.getPlayer().getUuid(), e.getPlayer().getName().getString(), Result.ALLOWED,
null, "");
EventManager.callEvent(event);
if (!event.getLoginResult().equals(Result.ALLOWED))
e.disconnect(Text.of(event.getKickMessage()));
try {
ServerPlayerEntity p = e.getPlayer();
LoginEvent event = new LoginEvent(p.getUuid(), p.getName().getString(), Result.ALLOWED, InetAddress.getByName(p.getIp()), "");
EventManager.callEvent(event);
if (!event.getLoginResult().equals(Result.ALLOWED))
e.disconnect(Text.of(event.getKickMessage()));
} catch (Exception exc) {
exc.printStackTrace();
}
}

public static void onPlayerJoin(ServerPlayNetworkHandler e, PacketSender sender, MinecraftServer srv) {
Expand All @@ -38,8 +45,7 @@ public static void onPlayerJoin(ServerPlayNetworkHandler e, PacketSender sender,
}

public static void onLeave(ServerPlayNetworkHandler e, MinecraftServer srv) {
NegativityPlayer np = NegativityPlayer.getNegativityPlayer(e.getPlayer().getUuid(),
() -> new FabricPlayer(e.getPlayer()));
NegativityPlayer np = NegativityPlayer.getNegativityPlayer(e.getPlayer().getUuid(), () -> new FabricPlayer(e.getPlayer()));
PlayerLeaveEvent event = new PlayerLeaveEvent(np.getPlayer(), np, "");
EventManager.callEvent(event);
// TODO add again e.setMessage(Text.of(event.getQuitMessage()));
Expand Down

0 comments on commit 5c1fe7f

Please sign in to comment.