From 5c1fe7f6562db69d25a8afb6618057b8fcc82d2b Mon Sep 17 00:00:00 2001 From: Elikill58 Date: Wed, 27 Dec 2023 19:53:50 +0100 Subject: [PATCH] Fix #6 --- .../fabric/listeners/PlayersListeners.java | 20 ++++++++++++------- .../fabric/listeners/PlayersListeners.java | 20 ++++++++++++------- .../fabric/listeners/PlayersListeners.java | 20 ++++++++++++------- .../fabric/listeners/PlayersListeners.java | 20 ++++++++++++------- .../fabric/listeners/PlayersListeners.java | 20 ++++++++++++------- .../fabric/listeners/PlayersListeners.java | 20 ++++++++++++------- 6 files changed, 78 insertions(+), 42 deletions(-) diff --git a/fabric182/src/com/elikill58/negativity/fabric/listeners/PlayersListeners.java b/fabric182/src/com/elikill58/negativity/fabric/listeners/PlayersListeners.java index 1d1fa47..f40f18a 100644 --- a/fabric182/src/com/elikill58/negativity/fabric/listeners/PlayersListeners.java +++ b/fabric182/src/com/elikill58/negativity/fabric/listeners/PlayersListeners.java @@ -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; @@ -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 { @@ -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) { @@ -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())); diff --git a/fabric19/src/com/elikill58/negativity/fabric/listeners/PlayersListeners.java b/fabric19/src/com/elikill58/negativity/fabric/listeners/PlayersListeners.java index 1d1fa47..f40f18a 100644 --- a/fabric19/src/com/elikill58/negativity/fabric/listeners/PlayersListeners.java +++ b/fabric19/src/com/elikill58/negativity/fabric/listeners/PlayersListeners.java @@ -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; @@ -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 { @@ -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) { @@ -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())); diff --git a/fabric192/src/com/elikill58/negativity/fabric/listeners/PlayersListeners.java b/fabric192/src/com/elikill58/negativity/fabric/listeners/PlayersListeners.java index 1d1fa47..f40f18a 100644 --- a/fabric192/src/com/elikill58/negativity/fabric/listeners/PlayersListeners.java +++ b/fabric192/src/com/elikill58/negativity/fabric/listeners/PlayersListeners.java @@ -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; @@ -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 { @@ -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) { @@ -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())); diff --git a/fabric193/src/com/elikill58/negativity/fabric/listeners/PlayersListeners.java b/fabric193/src/com/elikill58/negativity/fabric/listeners/PlayersListeners.java index 1d1fa47..f40f18a 100644 --- a/fabric193/src/com/elikill58/negativity/fabric/listeners/PlayersListeners.java +++ b/fabric193/src/com/elikill58/negativity/fabric/listeners/PlayersListeners.java @@ -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; @@ -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 { @@ -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) { @@ -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())); diff --git a/fabric194/src/com/elikill58/negativity/fabric/listeners/PlayersListeners.java b/fabric194/src/com/elikill58/negativity/fabric/listeners/PlayersListeners.java index 1d1fa47..f40f18a 100644 --- a/fabric194/src/com/elikill58/negativity/fabric/listeners/PlayersListeners.java +++ b/fabric194/src/com/elikill58/negativity/fabric/listeners/PlayersListeners.java @@ -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; @@ -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 { @@ -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) { @@ -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())); diff --git a/fabric20/src/com/elikill58/negativity/fabric/listeners/PlayersListeners.java b/fabric20/src/com/elikill58/negativity/fabric/listeners/PlayersListeners.java index 1d1fa47..f40f18a 100644 --- a/fabric20/src/com/elikill58/negativity/fabric/listeners/PlayersListeners.java +++ b/fabric20/src/com/elikill58/negativity/fabric/listeners/PlayersListeners.java @@ -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; @@ -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 { @@ -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) { @@ -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()));