diff options
author | David Panić <david@panic.tk> | 2019-04-07 22:23:38 +0200 |
---|---|---|
committer | David Panić <david@panic.tk> | 2019-04-07 22:23:38 +0200 |
commit | 7ae8d6908a77d05d2464a1e894151d2b493bc13d (patch) | |
tree | 3e3c7f7e3d982314337dba60f42820fc534001d7 /src/main/java/com/redstoner/bungeeBans/listeners/BanJoinListener.java | |
parent | ecc4b6d999ffc5dd482fec4a76b5c63a8d0143ce (diff) |
Added IP banning support
Diffstat (limited to 'src/main/java/com/redstoner/bungeeBans/listeners/BanJoinListener.java')
-rw-r--r-- | src/main/java/com/redstoner/bungeeBans/listeners/BanJoinListener.java | 38 |
1 files changed, 26 insertions, 12 deletions
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<T extends Ban> 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()) |