Skip to content

Commit 0c416c8

Browse files
committed
Remove ban check from /ess cleanup, no longer required.
Fix ban upgrade script.
1 parent 51be213 commit 0c416c8

File tree

6 files changed

+65
-39
lines changed

6 files changed

+65
-39
lines changed

Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ public class EssentialsUpgrade
2525
private final static Logger LOGGER = Logger.getLogger("Essentials");
2626
private final transient IEssentials ess;
2727
private final transient EssentialsConf doneFile;
28-
private String banReason;
29-
private Long banTimeout;
3028

3129
EssentialsUpgrade(final IEssentials essentials)
3230
{
@@ -676,36 +674,62 @@ public void banFormatChange()
676674
{
677675
return;
678676
}
679-
File[] playerFiles = userdir.listFiles();
680677

681-
for (File pFile : playerFiles)
678+
int countFiles = 0;
679+
680+
ess.getLogger().info("Found " + userdir.list().length + " files to convert...");
681+
682+
for (String string : userdir.list())
682683
{
683-
EssentialsConf conf = new EssentialsConf(pFile);
684+
if (!string.endsWith(".yml") || string.length() < 5)
685+
{
686+
continue;
687+
}
688+
689+
final int showProgress = countFiles % 250;
690+
691+
if (showProgress == 0)
692+
{
693+
ess.getLogger().info("Converted " + countFiles + "/" + userdir.list().length);
694+
}
695+
696+
countFiles++;
697+
final File pFile = new File(userdir, string);
698+
final EssentialsConf conf = new EssentialsConf(pFile);
684699
conf.load();
700+
701+
String banReason;
702+
Long banTimeout;
703+
685704
try
686705
{
687706
banReason = conf.getConfigurationSection("ban").getString("reason");
688707
}
689708
catch (NullPointerException n)
690709
{
691-
//No ban in userfile
692-
banReason = "";
710+
banReason = null;
693711
}
694712

695-
String playerName = conf.getString("lastAccountName");
696-
if (!banReason.equals(""))
713+
final String playerName = conf.getString("lastAccountName");
714+
if (playerName != null && playerName.length() > 1 && banReason != null && banReason.length() > 1)
697715
{
698716
try
699717
{
700-
banTimeout = Long.parseLong(conf.getConfigurationSection("ban").getString("timeout"));
718+
if (conf.getConfigurationSection("ban").contains("timeout"))
719+
{
720+
banTimeout = Long.parseLong(conf.getConfigurationSection("ban").getString("timeout"));
721+
}
722+
else
723+
{
724+
banTimeout = 0L;
725+
}
701726
}
702727
catch (NumberFormatException n)
703728
{
704-
//No ban timeout set, or malformed timeout.
705729
banTimeout = 0L;
706730
}
707-
org.bukkit.OfflinePlayer player = ess.getServer().getOfflinePlayer(playerName);
708-
if (player.isBanned())
731+
732+
if (ess.getServer().getBanList(BanList.Type.NAME).isBanned(playerName))
709733
{
710734
updateBan(playerName, banReason, banTimeout);
711735
}

Essentials/src/com/earth2me/essentials/commands/Commandban.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ public void run(final Server server, final CommandSource sender, final String co
6262
{
6363
banReason = tl("defaultBanReason");
6464
}
65-
65+
6666
Bukkit.getBanList(BanList.Type.NAME).addBan(user.getName(), banReason, null, senderName);
67-
user.getBase().kickPlayer(tl("banFormat", banReason, senderName));
6867

69-
server.getLogger().log(Level.INFO, tl("playerBanned", senderName, user.getName(), banReason));
68+
String banDisplay = tl("banFormat", banReason, senderName);
69+
70+
user.getBase().kickPlayer(banDisplay);
71+
server.getLogger().log(Level.INFO, tl("playerBanned", senderName, user.getName(), banDisplay));
7072

7173
if (nomatch)
7274
{

Essentials/src/com/earth2me/essentials/commands/Commandessentials.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,14 @@ private void run_cleanup(final Server server, final CommandSource sender, final
264264
{
265265
sender.sendMessage("This sub-command will delete users who havent logged in in the last <days> days.");
266266
sender.sendMessage("Optional parameters define the minium amount required to prevent deletion.");
267-
sender.sendMessage("Unless you define larger default values, this command wil ignore people who have more than 0 money/homes/bans.");
268-
throw new Exception("/<command> cleanup <days> [money] [homes] [ban count]");
267+
sender.sendMessage("Unless you define larger default values, this command wil ignore people who have more than 0 money/homes.");
268+
throw new Exception("/<command> cleanup <days> [money] [homes]");
269269
}
270270
sender.sendMessage(tl("cleaning"));
271271

272272
final long daysArg = Long.parseLong(args[1]);
273273
final double moneyArg = args.length >= 3 ? Double.parseDouble(args[2].replaceAll("[^0-9\\.]", "")) : 0;
274274
final int homesArg = args.length >= 4 && NumberUtil.isInt(args[3]) ? Integer.parseInt(args[3]) : 0;
275-
final int bansArg = args.length >= 5 && NumberUtil.isInt(args[4]) ? Integer.parseInt(args[4]) : 0;
276275
final UserMap userMap = ess.getUserMap();
277276

278277
ess.runTaskAsynchronously(new Runnable()
@@ -289,8 +288,6 @@ public void run()
289288
continue;
290289
}
291290

292-
int ban = user.getBase().isBanned() ? 0 : 1;
293-
294291
long lastLog = user.getLastLogout();
295292
if (lastLog == 0)
296293
{
@@ -311,7 +308,7 @@ public void run()
311308
int homeCount = user.getHomes().size();
312309
double moneyCount = user.getMoney().doubleValue();
313310

314-
if ((lastLog == 0) || (ban > bansArg) || (timeDiff < milliDays)
311+
if ((lastLog == 0) || (timeDiff < milliDays)
315312
|| (homeCount > homesArg) || (moneyCount > moneyArg))
316313
{
317314
continue;

Essentials/src/com/earth2me/essentials/commands/Commandseen.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@ protected void seen(final Server server, final CommandSource sender, final Strin
5656
seenIP(server, sender, args[0]);
5757
return;
5858
}
59-
else if (FormatUtil.validIP(args[0]) && (server.getIPBans().contains(args[0])))
59+
else if (Bukkit.getBanList(BanList.Type.IP).isBanned(args[0]))
6060
{
6161
sender.sendMessage(tl("isIpBanned", args[0]));
6262
return;
6363
}
64-
else if (Bukkit.getBannedPlayers().contains(Bukkit.getOfflinePlayer(args[0]))) {
65-
sender.sendMessage(tl("whoisBanned", showBan ? Bukkit.getBanList(BanList.Type.NAME).getBanEntry(Bukkit.getOfflinePlayer(args[0]).getName()).getReason() : tl("true")));
64+
65+
else if (Bukkit.getBanList(BanList.Type.NAME).isBanned(args[0]))
66+
{
67+
sender.sendMessage(tl("whoisBanned", showBan ? Bukkit.getBanList(BanList.Type.NAME).getBanEntry(args[0]).getReason() : tl("true")));
6668
return;
6769
}
6870
else
@@ -168,7 +170,7 @@ private void seenIP(final Server server, final CommandSource sender, final Strin
168170
{
169171
final UserMap userMap = ess.getUserMap();
170172

171-
if (server.getIPBans().contains(ipAddress))
173+
if (Bukkit.getBanList(BanList.Type.IP).isBanned(ipAddress))
172174
{
173175
sender.sendMessage(tl("isIpBanned", ipAddress));
174176
}

Essentials/src/com/earth2me/essentials/commands/Commandtempban.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,27 @@ public void run(final Server server, final CommandSource sender, final String co
4747
}
4848
final String time = getFinalArg(args, 1);
4949
final long banTimestamp = DateUtil.parseDateDiff(time, true);
50-
String stringDregs = DateUtil.removeTimePattern(time);
51-
50+
String banReason = DateUtil.removeTimePattern(time);
51+
5252
final long maxBanLength = ess.getSettings().getMaxTempban() * 1000;
5353
if (maxBanLength > 0 && ((banTimestamp - GregorianCalendar.getInstance().getTimeInMillis()) > maxBanLength)
5454
&& sender.isPlayer() && !(ess.getUser(sender.getPlayer()).isAuthorized("essentials.tempban.unlimited")))
5555
{
5656
sender.sendMessage(tl("oversizedTempban"));
5757
throw new NoChargeException();
5858
}
59-
60-
if (stringDregs.length() < 2)
59+
60+
if (banReason.length() < 2)
6161
{
62-
stringDregs = tl("defaultBanReason");
62+
banReason = tl("defaultBanReason");
6363
}
6464

6565
final String senderName = sender.isPlayer() ? sender.getPlayer().getDisplayName() : Console.NAME;
66-
final String banReason = tl("tempBanned", DateUtil.formatDateDiff(banTimestamp), senderName, stringDregs);
67-
6866
Bukkit.getBanList(BanList.Type.NAME).addBan(user.getName(), banReason, new Date(banTimestamp), senderName);
69-
user.getBase().kickPlayer(banReason);
67+
68+
String banDisplay = tl("tempBanned", DateUtil.formatDateDiff(banTimestamp), senderName, banReason);
69+
user.getBase().kickPlayer(banDisplay);
70+
server.getLogger().log(Level.INFO, tl("playerBanned", senderName, user.getName(), banDisplay));
7071

7172
final String message = tl("playerBanned", senderName, user.getName(), banReason, DateUtil.formatDateDiff(banTimestamp));
7273
server.getLogger().log(Level.INFO, message);

Essentials/src/messages_en.properties

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ balance=\u00a7aBalance\:\u00a7c {0}
2727
balanceOther=\u00a7aBalance of {0}\u00a7a\:\u00a7c {1}
2828
balanceTop=\u00a76Top balances ({0})
2929
banExempt=\u00a74You cannot ban that player.
30-
banFormat=\u00a74Banned\:\n\u00a7r{0}
30+
banFormat=\u00a7cYou have been banned\:\n\u00a7r{0}
3131
bed=\u00a7obed\u00a7r
3232
bedMissing=\u00a74Your bed is either unset, missing or blocked.
3333
bedNull=\u00a7mbed\u00a7r
@@ -155,7 +155,7 @@ holdBook=\u00a74You are not holding a writable book.
155155
holdFirework=\u00a74You must be holding a firework to add effects.
156156
holdPotion=\u00a74You must be holding a potion to apply effects to it.
157157
holeInFloor=\u00a74Hole in floor\!
158-
homeSet=\u00a76Home set.
158+
homeSet=\u00a76Home set to current location.
159159
homes=\u00a76Homes\:\u00a7r {0}
160160
hour=hour
161161
hours=hours
@@ -321,8 +321,8 @@ pWeatherPlayers=\u00a76These players have their own weather\:\u00a7r
321321
pWeatherReset=\u00a76Player weather has been reset for\: \u00a7c{0}
322322
pWeatherSet=\u00a76Player weather is set to \u00a7c{0}\u00a76 for\: \u00a7c{1}.
323323
pendingTeleportCancelled=\u00a74Pending teleportation request cancelled.
324-
playerBanIpAddress=\u00a76Player\u00a7c {0} \u00a76banned IP address\:\u00a7c {1}\u00a76.
325-
playerBanned=\u00a76Player\u00a7c {0} \u00a76banned\u00a7c {1} \u00a76for \u00a7c{2}\u00a76.
324+
playerBanIpAddress=\u00a76Player\u00a7c {0} \u00a76banned IP address\u00a7c {1} \u00a76for\: \u00a7c{2}\u00a76.
325+
playerBanned=\u00a76Player\u00a7c {0} \u00a76banned\u00a7c {1} \u00a76for\: \u00a7c{2}\u00a76.
326326
playerInJail=\u00a74Player is already in jail\u00a7c {0}\u00a74.
327327
playerJailed=\u00a76Player\u00a7c {0} \u00a76jailed.
328328
playerJailedFor=\u00a76Player\u00a7c {0} \u00a76jailed for {1}.
@@ -426,7 +426,7 @@ teleportationEnabled=\u00a76Teleportation \u00a7cenabled\u00a76.
426426
teleportationEnabledFor=\u00a76Teleportation \u00a7cenabled \u00a76for \u00a7c{0}\u00a76.
427427
teleporting=\u00a76Teleporting...
428428
teleportToPlayer=\u00a76Teleporting to \u00a7c{0}\u00a76.
429-
tempBanned=Temporarily banned from server for {0}.
429+
tempBanned=\u00a7cYou have been temporarily banned for {0}\:\n\u00a7r{2}
430430
tempbanExempt=\u00a74You may not tempban that player.
431431
thunder=\u00a76You\u00a7c {0} \u00a76thunder in your world.
432432
thunderDuration=\u00a76You\u00a7c {0} \u00a76thunder in your world for\u00a7c {1} \u00a76seconds.

0 commit comments

Comments
 (0)