From 7ae8d6908a77d05d2464a1e894151d2b493bc13d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Pani=C4=87?= Date: Sun, 7 Apr 2019 22:23:38 +0200 Subject: Added IP banning support --- .../bungeeBans/listeners/BanJoinListener.java | 38 +++++++++++++++------- 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'src/main/java/com/redstoner/bungeeBans/listeners/BanJoinListener.java') diff --git a/src/main/java/com/redstoner/bungeeBans/listeners/BanJoinListener.java b/src/main/java/com/redstoner/bungeeBans/listeners/BanJoinListener.java index f288447..4ef297b 100644 --- a/src/main/java/com/redstoner/bungeeBans/listeners/BanJoinListener.java +++ b/src/main/java/com/redstoner/bungeeBans/listeners/BanJoinListener.java @@ -25,26 +25,40 @@ public class BanJoinListener implements Listener { public void onJoin(PreLoginEvent event) { event.setCancelled(true); + T ban; + PendingConnection conn = event.getConnection(); - String name = conn.getName(); - Profile[] profiles = Util.findProfilesByNames(name); + switch (this.name) { + case "player": + String name = conn.getName(); - if (profiles.length != 1) { - event.setCancelReason( - new ComponentBuilder(ChatColor.RED + "Server error occured while joining: ") - .append(ChatColor.AQUA + "The mojang API does not know your UUID!") - .create() - ); + Profile[] profiles = Util.findProfilesByNames(name); - return; - } + if (profiles.length != 1) { + event.setCancelReason( + new ComponentBuilder(ChatColor.RED + "Server error occured while joining: ") + .append(ChatColor.AQUA + "The mojang API does not know your UUID!") + .create() + ); + + return; + } - T ban = bm.getBan(Util.dashUUID(profiles[0].getId())); + ban = bm.getBan(Util.dashUUID(profiles[0].getId())); + break; + case "IP": + String address = conn.getAddress().getAddress().getHostAddress(); + System.out.println("IP connection: " + address); + ban = bm.getBan(address); + break; + default: + throw new UnsupportedOperationException(); + } if (ban != null) { event.setCancelReason( - new ComponentBuilder(ChatColor.RED + "You were " + name + " banned by ") + new ComponentBuilder(ChatColor.RED + "You were " + this.name + " banned by ") .append(ChatColor.AQUA + ban.getSource()) .append(ChatColor.RED + " for ") .append(ChatColor.AQUA + ban.getReason()) -- cgit v1.2.3