From a44275af7d094ef9cf08ec7115248742d2b15dd7 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sat, 12 Jul 2014 17:47:39 +0100 Subject: Remove ban check from /ess cleanup, no longer required. Fix ban upgrade script. --- .../com/earth2me/essentials/EssentialsUpgrade.java | 50 ++++++++++++++++------ .../earth2me/essentials/commands/Commandban.java | 8 ++-- .../essentials/commands/Commandessentials.java | 9 ++-- .../earth2me/essentials/commands/Commandseen.java | 10 +++-- .../essentials/commands/Commandtempban.java | 17 ++++---- Essentials/src/messages_en.properties | 10 ++--- 6 files changed, 65 insertions(+), 39 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java index ba93f09c2..991abab34 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java @@ -25,8 +25,6 @@ public class EssentialsUpgrade private final static Logger LOGGER = Logger.getLogger("Essentials"); private final transient IEssentials ess; private final transient EssentialsConf doneFile; - private String banReason; - private Long banTimeout; EssentialsUpgrade(final IEssentials essentials) { @@ -676,36 +674,62 @@ public class EssentialsUpgrade { return; } - File[] playerFiles = userdir.listFiles(); - for (File pFile : playerFiles) + int countFiles = 0; + + ess.getLogger().info("Found " + userdir.list().length + " files to convert..."); + + for (String string : userdir.list()) { - EssentialsConf conf = new EssentialsConf(pFile); + if (!string.endsWith(".yml") || string.length() < 5) + { + continue; + } + + final int showProgress = countFiles % 250; + + if (showProgress == 0) + { + ess.getLogger().info("Converted " + countFiles + "/" + userdir.list().length); + } + + countFiles++; + final File pFile = new File(userdir, string); + final EssentialsConf conf = new EssentialsConf(pFile); conf.load(); + + String banReason; + Long banTimeout; + try { banReason = conf.getConfigurationSection("ban").getString("reason"); } catch (NullPointerException n) { - //No ban in userfile - banReason = ""; + banReason = null; } - String playerName = conf.getString("lastAccountName"); - if (!banReason.equals("")) + final String playerName = conf.getString("lastAccountName"); + if (playerName != null && playerName.length() > 1 && banReason != null && banReason.length() > 1) { try { - banTimeout = Long.parseLong(conf.getConfigurationSection("ban").getString("timeout")); + if (conf.getConfigurationSection("ban").contains("timeout")) + { + banTimeout = Long.parseLong(conf.getConfigurationSection("ban").getString("timeout")); + } + else + { + banTimeout = 0L; + } } catch (NumberFormatException n) { - //No ban timeout set, or malformed timeout. banTimeout = 0L; } - org.bukkit.OfflinePlayer player = ess.getServer().getOfflinePlayer(playerName); - if (player.isBanned()) + + if (ess.getServer().getBanList(BanList.Type.NAME).isBanned(playerName)) { updateBan(playerName, banReason, banTimeout); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandban.java b/Essentials/src/com/earth2me/essentials/commands/Commandban.java index 7480864d7..50b459a06 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandban.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandban.java @@ -62,11 +62,13 @@ public class Commandban extends EssentialsCommand { banReason = tl("defaultBanReason"); } - + Bukkit.getBanList(BanList.Type.NAME).addBan(user.getName(), banReason, null, senderName); - user.getBase().kickPlayer(tl("banFormat", banReason, senderName)); - server.getLogger().log(Level.INFO, tl("playerBanned", senderName, user.getName(), banReason)); + String banDisplay = tl("banFormat", banReason, senderName); + + user.getBase().kickPlayer(banDisplay); + server.getLogger().log(Level.INFO, tl("playerBanned", senderName, user.getName(), banDisplay)); if (nomatch) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java index 4c6c8f230..23173661e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java @@ -264,15 +264,14 @@ public class Commandessentials extends EssentialsCommand { sender.sendMessage("This sub-command will delete users who havent logged in in the last days."); sender.sendMessage("Optional parameters define the minium amount required to prevent deletion."); - sender.sendMessage("Unless you define larger default values, this command wil ignore people who have more than 0 money/homes/bans."); - throw new Exception("/ cleanup [money] [homes] [ban count]"); + sender.sendMessage("Unless you define larger default values, this command wil ignore people who have more than 0 money/homes."); + throw new Exception("/ cleanup [money] [homes]"); } sender.sendMessage(tl("cleaning")); final long daysArg = Long.parseLong(args[1]); final double moneyArg = args.length >= 3 ? Double.parseDouble(args[2].replaceAll("[^0-9\\.]", "")) : 0; final int homesArg = args.length >= 4 && NumberUtil.isInt(args[3]) ? Integer.parseInt(args[3]) : 0; - final int bansArg = args.length >= 5 && NumberUtil.isInt(args[4]) ? Integer.parseInt(args[4]) : 0; final UserMap userMap = ess.getUserMap(); ess.runTaskAsynchronously(new Runnable() @@ -289,8 +288,6 @@ public class Commandessentials extends EssentialsCommand continue; } - int ban = user.getBase().isBanned() ? 0 : 1; - long lastLog = user.getLastLogout(); if (lastLog == 0) { @@ -311,7 +308,7 @@ public class Commandessentials extends EssentialsCommand int homeCount = user.getHomes().size(); double moneyCount = user.getMoney().doubleValue(); - if ((lastLog == 0) || (ban > bansArg) || (timeDiff < milliDays) + if ((lastLog == 0) || (timeDiff < milliDays) || (homeCount > homesArg) || (moneyCount > moneyArg)) { continue; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandseen.java b/Essentials/src/com/earth2me/essentials/commands/Commandseen.java index 08d6cf4b3..f82342c30 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandseen.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandseen.java @@ -56,13 +56,15 @@ public class Commandseen extends EssentialsCommand seenIP(server, sender, args[0]); return; } - else if (FormatUtil.validIP(args[0]) && (server.getIPBans().contains(args[0]))) + else if (Bukkit.getBanList(BanList.Type.IP).isBanned(args[0])) { sender.sendMessage(tl("isIpBanned", args[0])); return; } - else if (Bukkit.getBannedPlayers().contains(Bukkit.getOfflinePlayer(args[0]))) { - sender.sendMessage(tl("whoisBanned", showBan ? Bukkit.getBanList(BanList.Type.NAME).getBanEntry(Bukkit.getOfflinePlayer(args[0]).getName()).getReason() : tl("true"))); + + else if (Bukkit.getBanList(BanList.Type.NAME).isBanned(args[0])) + { + sender.sendMessage(tl("whoisBanned", showBan ? Bukkit.getBanList(BanList.Type.NAME).getBanEntry(args[0]).getReason() : tl("true"))); return; } else @@ -168,7 +170,7 @@ public class Commandseen extends EssentialsCommand { final UserMap userMap = ess.getUserMap(); - if (server.getIPBans().contains(ipAddress)) + if (Bukkit.getBanList(BanList.Type.IP).isBanned(ipAddress)) { sender.sendMessage(tl("isIpBanned", ipAddress)); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java b/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java index aeaf4dbd8..dfb0139f1 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java @@ -47,8 +47,8 @@ public class Commandtempban extends EssentialsCommand } final String time = getFinalArg(args, 1); final long banTimestamp = DateUtil.parseDateDiff(time, true); - String stringDregs = DateUtil.removeTimePattern(time); - + String banReason = DateUtil.removeTimePattern(time); + final long maxBanLength = ess.getSettings().getMaxTempban() * 1000; if (maxBanLength > 0 && ((banTimestamp - GregorianCalendar.getInstance().getTimeInMillis()) > maxBanLength) && sender.isPlayer() && !(ess.getUser(sender.getPlayer()).isAuthorized("essentials.tempban.unlimited"))) @@ -56,17 +56,18 @@ public class Commandtempban extends EssentialsCommand sender.sendMessage(tl("oversizedTempban")); throw new NoChargeException(); } - - if (stringDregs.length() < 2) + + if (banReason.length() < 2) { - stringDregs = tl("defaultBanReason"); + banReason = tl("defaultBanReason"); } final String senderName = sender.isPlayer() ? sender.getPlayer().getDisplayName() : Console.NAME; - final String banReason = tl("tempBanned", DateUtil.formatDateDiff(banTimestamp), senderName, stringDregs); - Bukkit.getBanList(BanList.Type.NAME).addBan(user.getName(), banReason, new Date(banTimestamp), senderName); - user.getBase().kickPlayer(banReason); + + String banDisplay = tl("tempBanned", DateUtil.formatDateDiff(banTimestamp), senderName, banReason); + user.getBase().kickPlayer(banDisplay); + server.getLogger().log(Level.INFO, tl("playerBanned", senderName, user.getName(), banDisplay)); final String message = tl("playerBanned", senderName, user.getName(), banReason, DateUtil.formatDateDiff(banTimestamp)); server.getLogger().log(Level.INFO, message); diff --git a/Essentials/src/messages_en.properties b/Essentials/src/messages_en.properties index 14aaea799..18dfaecab 100644 --- a/Essentials/src/messages_en.properties +++ b/Essentials/src/messages_en.properties @@ -27,7 +27,7 @@ balance=\u00a7aBalance\:\u00a7c {0} balanceOther=\u00a7aBalance of {0}\u00a7a\:\u00a7c {1} balanceTop=\u00a76Top balances ({0}) banExempt=\u00a74You cannot ban that player. -banFormat=\u00a74Banned\:\n\u00a7r{0} +banFormat=\u00a7cYou have been banned\:\n\u00a7r{0} bed=\u00a7obed\u00a7r bedMissing=\u00a74Your bed is either unset, missing or blocked. bedNull=\u00a7mbed\u00a7r @@ -155,7 +155,7 @@ holdBook=\u00a74You are not holding a writable book. holdFirework=\u00a74You must be holding a firework to add effects. holdPotion=\u00a74You must be holding a potion to apply effects to it. holeInFloor=\u00a74Hole in floor\! -homeSet=\u00a76Home set. +homeSet=\u00a76Home set to current location. homes=\u00a76Homes\:\u00a7r {0} hour=hour hours=hours @@ -321,8 +321,8 @@ pWeatherPlayers=\u00a76These players have their own weather\:\u00a7r pWeatherReset=\u00a76Player weather has been reset for\: \u00a7c{0} pWeatherSet=\u00a76Player weather is set to \u00a7c{0}\u00a76 for\: \u00a7c{1}. pendingTeleportCancelled=\u00a74Pending teleportation request cancelled. -playerBanIpAddress=\u00a76Player\u00a7c {0} \u00a76banned IP address\:\u00a7c {1}\u00a76. -playerBanned=\u00a76Player\u00a7c {0} \u00a76banned\u00a7c {1} \u00a76for \u00a7c{2}\u00a76. +playerBanIpAddress=\u00a76Player\u00a7c {0} \u00a76banned IP address\u00a7c {1} \u00a76for\: \u00a7c{2}\u00a76. +playerBanned=\u00a76Player\u00a7c {0} \u00a76banned\u00a7c {1} \u00a76for\: \u00a7c{2}\u00a76. playerInJail=\u00a74Player is already in jail\u00a7c {0}\u00a74. playerJailed=\u00a76Player\u00a7c {0} \u00a76jailed. playerJailedFor=\u00a76Player\u00a7c {0} \u00a76jailed for {1}. @@ -426,7 +426,7 @@ teleportationEnabled=\u00a76Teleportation \u00a7cenabled\u00a76. teleportationEnabledFor=\u00a76Teleportation \u00a7cenabled \u00a76for \u00a7c{0}\u00a76. teleporting=\u00a76Teleporting... teleportToPlayer=\u00a76Teleporting to \u00a7c{0}\u00a76. -tempBanned=Temporarily banned from server for {0}. +tempBanned=\u00a7cYou have been temporarily banned for {0}\:\n\u00a7r{2} tempbanExempt=\u00a74You may not tempban that player. thunder=\u00a76You\u00a7c {0} \u00a76thunder in your world. thunderDuration=\u00a76You\u00a7c {0} \u00a76thunder in your world for\u00a7c {1} \u00a76seconds. -- cgit v1.2.3