From 15650b84cfd1a044589555ccb11bed2aea324789 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 26 Aug 2014 18:23:48 +0200 Subject: [PATCH] Fixed duplicate ban entries Bans are equal when: a) The ban-type matches b) The ban-subject matches Small changes --- buildnumber.properties | 4 +- .../Commands/Command_cake.java | 1 - .../Commands/Command_glist.java | 14 +++--- .../Commands/Command_nickclean.java | 1 - .../TotalFreedomMod/Commands/Command_tag.java | 13 +++--- .../TotalFreedomMod/Commands/TFM_Command.java | 1 - .../Listener/TFM_PlayerListener.java | 33 +++++++++----- .../StevenLawson/TotalFreedomMod/TFM_Ban.java | 43 +++++++++++++++++++ .../TotalFreedomMod/TFM_BanManager.java | 10 +++++ .../TotalFreedomMod/TFM_Heartbeat.java | 3 +- .../TotalFreedomMod/TFM_ServerInterface.java | 1 - 11 files changed, 91 insertions(+), 33 deletions(-) diff --git a/buildnumber.properties b/buildnumber.properties index 2ce3221a..eadcb68e 100644 --- a/buildnumber.properties +++ b/buildnumber.properties @@ -1,3 +1,3 @@ #Build Number for ANT. Do not edit! -#Mon Aug 25 14:06:59 CEST 2014 -build.number=924 +#Tue Aug 26 18:22:59 CEST 2014 +build.number=934 diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cake.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cake.java index d6366bfc..033b296b 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cake.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_cake.java @@ -16,7 +16,6 @@ import org.bukkit.inventory.meta.ItemMeta; public class Command_cake extends TFM_Command { public static final String CAKE_LYRICS = "But there's no sense crying over every mistake. You just keep on trying till you run out of cake."; - private final Random random = new Random(); @Override diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_glist.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_glist.java index 8165cb8b..239227f1 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_glist.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_glist.java @@ -68,15 +68,16 @@ public class Command_glist extends TFM_Command else { username = player.getName(); - ips.add(player.getAddress().getAddress().getHostAddress()); + final TFM_Player entry = TFM_PlayerList.getEntry(TFM_Util.getUniqueId(player)); + ips.addAll(entry.getIps()); } String mode = args[0].toLowerCase(); if (mode.equalsIgnoreCase("ban")) { - TFM_Util.adminAction(sender.getName(), "Banning " + username + " and IPs: " + StringUtils.join(ips, ","), true); + TFM_Util.adminAction(sender.getName(), "Banning " + username + " and IPs: " + StringUtils.join(ips, ", "), true); - Player target = getPlayer(username, true); + final Player target = getPlayer(username, true); if (target != null) { TFM_BanManager.addUuidBan(new TFM_Ban(TFM_Util.getUniqueId(target), target.getName())); @@ -90,13 +91,12 @@ public class Command_glist extends TFM_Command for (String ip : ips) { TFM_BanManager.addIpBan(new TFM_Ban(ip, username)); - String[] ip_address_parts = ip.split("\\."); - TFM_BanManager.addIpBan(new TFM_Ban(ip_address_parts[0] + "." + ip_address_parts[1] + ".*.*", username)); + TFM_BanManager.addIpBan(new TFM_Ban(TFM_Util.getFuzzyIp(ip), username)); } } - else if (mode.equalsIgnoreCase("unban") || mode.equalsIgnoreCase("pardon")) + else if (mode.equalsIgnoreCase("unban")) { - TFM_Util.adminAction(sender.getName(), "Unbanning " + username + " and IPs: " + StringUtils.join(ips, ","), true); + TFM_Util.adminAction(sender.getName(), "Unbanning " + username + " and IPs: " + StringUtils.join(ips, ", "), true); TFM_BanManager.unbanUuid(TFM_Util.getUniqueId(username)); for (String ip : ips) { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_nickclean.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_nickclean.java index 50780b7c..730615ec 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_nickclean.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_nickclean.java @@ -22,7 +22,6 @@ public class Command_nickclean extends TFM_Command ChatColor.UNDERLINE, ChatColor.BLACK }; - private static final Pattern REGEX = Pattern.compile("\\u00A7[" + StringUtils.join(BLOCKED, "") + "]"); @Override diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tag.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tag.java index 591f091c..b4d0e7e7 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tag.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tag.java @@ -112,14 +112,13 @@ public class Command_tag extends TFM_Command final String inputTag = StringUtils.join(args, " ", 1, args.length); final String outputTag = TFM_Util.colorize(StringUtils.replaceEachRepeatedly(StringUtils.strip(inputTag), new String[] - { - "" + ChatColor.COLOR_CHAR, "&k" - }, + { + "" + ChatColor.COLOR_CHAR, "&k" + }, new String[] - { - "", "" - } - )) + ChatColor.RESET; + { + "", "" + })) + ChatColor.RESET; if (!TFM_AdminList.isSuperAdmin(sender)) { diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_Command.java b/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_Command.java index 90f73ba3..a0611ada 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_Command.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_Command.java @@ -18,7 +18,6 @@ public abstract class TFM_Command public static final String YOU_ARE_NOT_OP = ChatColor.YELLOW + "You are no longer op!"; public static final String NOT_FROM_CONSOLE = "This command may not be used from the console."; public static final String PLAYER_NOT_FOUND = ChatColor.GRAY + "Player not found!"; - protected TotalFreedomMod plugin; protected Server server; private CommandSender commandSender; diff --git a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java index e674f39e..2095a945 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java @@ -733,7 +733,8 @@ public class TFM_PlayerListener implements Listener @EventHandler(priority = EventPriority.MONITOR) public void onPlayerKick(PlayerKickEvent event) { - Player player = event.getPlayer(); + final Player player = event.getPlayer(); + if (TotalFreedomMod.fuckoffEnabledFor.containsKey(player)) { TotalFreedomMod.fuckoffEnabledFor.remove(player); @@ -752,7 +753,8 @@ public class TFM_PlayerListener implements Listener @EventHandler(priority = EventPriority.MONITOR) public void onPlayerQuit(PlayerQuitEvent event) { - Player player = event.getPlayer(); + final Player player = event.getPlayer(); + if (TotalFreedomMod.fuckoffEnabledFor.containsKey(player)) { TotalFreedomMod.fuckoffEnabledFor.remove(player); @@ -774,36 +776,45 @@ public class TFM_PlayerListener implements Listener { final Player player = event.getPlayer(); final String ip = TFM_Util.getIp(player); + final TFM_Player playerEntry; + TFM_Log.info("[JOIN] " + TFM_Util.formatPlayer(player) + " joined the game with IP address: " + ip, true); + // Handle PlayerList entry (persistent) if (TFM_PlayerList.existsEntry(player)) { - final TFM_Player entry = TFM_PlayerList.getEntry(player); - entry.setLastLoginUnix(TFM_Util.getUnixTime()); - entry.setLastLoginName(player.getName()); - entry.save(); + playerEntry = TFM_PlayerList.getEntry(player); + playerEntry.setLastLoginUnix(TFM_Util.getUnixTime()); + playerEntry.setLastLoginName(player.getName()); + playerEntry.addIp(ip); + playerEntry.save(); } else { - TFM_PlayerList.getEntry(player); + playerEntry = TFM_PlayerList.getEntry(player); TFM_Log.info("Added new player: " + TFM_Util.formatPlayer(player)); } + // GGenerate PlayerData (non-persistent) final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); playerdata.setSuperadminIdVerified(false); - // Verify strict IP match if (TFM_AdminList.isSuperAdmin(player)) { - TFM_BanManager.unbanIp(ip); - TFM_BanManager.unbanIp(TFM_Util.getFuzzyIp(ip)); + for (String storedIp : playerEntry.getIps()) + { + TFM_BanManager.unbanIp(storedIp); + TFM_BanManager.unbanIp(TFM_Util.getFuzzyIp(storedIp)); + } + TFM_BanManager.unbanUuid(TFM_Util.getUniqueId(player)); + player.setOp(true); + // Verify strict IP match if (!TFM_AdminList.isIdentityMatched(player)) { playerdata.setSuperadminIdVerified(false); - TFM_Util.bcastMsg("Warning: " + player.getName() + " is an admin, but is using an account not registered to one of their ip-list.", ChatColor.RED); } else diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Ban.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Ban.java index 1692ef28..11d2ec81 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Ban.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_Ban.java @@ -166,4 +166,47 @@ public class TFM_Ban { return subject + ":" + lastLoginName + ":" + by + ":" + expireUnix + ":" + TFM_Util.decolorize(reason); } + + @Override + public boolean equals(Object object) + { + if (object == null) + { + return false; + } + + if (!(object instanceof TFM_Ban)) + { + return false; + } + + final TFM_Ban ban = (TFM_Ban) object; + + if (toString().equals(ban.toString())) + { + return true; + } + + if (getType() != ban.getType()) + { + return false; + } + + if (!getSubject().equals(ban.getSubject())) + { + return false; + } + + return true; + } + + @Override + public int hashCode() + { + final int prime = 37; + int result = 1; + result = prime * result + getType().hashCode(); + result = prime * result + getSubject().hashCode(); + return result; + } } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_BanManager.java b/src/me/StevenLawson/TotalFreedomMod/TFM_BanManager.java index 10bdd379..0d9c5a0e 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_BanManager.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_BanManager.java @@ -222,6 +222,11 @@ public class TFM_BanManager return; } + if (uuidBans.contains(ban)) + { + return; + } + if (unbannableUUIDs.contains(UUID.fromString(ban.getSubject()))) { return; @@ -248,6 +253,11 @@ public class TFM_BanManager return; } + if (ipBans.contains(ban)) + { + return; + } + ipBans.add(ban); save(); } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Heartbeat.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Heartbeat.java index 7afbce77..a3f93e86 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Heartbeat.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_Heartbeat.java @@ -31,8 +31,7 @@ public class TFM_Heartbeat extends BukkitRunnable { lastRan = System.currentTimeMillis(); - final boolean doAwayKickCheck - = TFM_ConfigEntry.AUTOKICK_ENABLED.getBoolean() + final boolean doAwayKickCheck = TFM_ConfigEntry.AUTOKICK_ENABLED.getBoolean() && TFM_EssentialsBridge.isEssentialsEnabled() && ((server.getOnlinePlayers().length / server.getMaxPlayers()) > TFM_ConfigEntry.AUTOKICK_THRESHOLD.getDouble()); diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_ServerInterface.java b/src/me/StevenLawson/TotalFreedomMod/TFM_ServerInterface.java index b34f3b1b..26a322cb 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_ServerInterface.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_ServerInterface.java @@ -1,6 +1,5 @@ package me.StevenLawson.TotalFreedomMod; -import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.List; import java.util.UUID;