From 7ea639399a2cf6b86c4c192c97e585e3a79ff9e3 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Wed, 9 Jan 2013 20:59:27 +0000 Subject: [PATCH] Multiline kick messages and tempban countdown. --- .../essentials/EssentialsPlayerListener.java | 14 +++++++++++--- .../earth2me/essentials/commands/Commandkick.java | 13 +++++++++---- .../essentials/commands/Commandkickall.java | 5 ++++- .../essentials/commands/Commandtempban.java | 3 +-- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index 9b4585112..93b793e49 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -6,7 +6,6 @@ import com.earth2me.essentials.textreader.KeywordReplacer; import com.earth2me.essentials.textreader.TextInput; import com.earth2me.essentials.textreader.TextPager; import java.io.IOException; -import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Locale; @@ -307,8 +306,17 @@ public class EssentialsPlayerListener implements Listener if (!banExpired && (user.isBanned() || event.getResult() == Result.KICK_BANNED)) { - final String banReason = user.getBanReason(); - event.disallow(Result.KICK_BANNED, banReason != null && !banReason.isEmpty() && !banReason.equalsIgnoreCase("ban") ? banReason : _("defaultBanReason")); + String banReason = user.getBanReason(); + if (banReason == null || banReason.isEmpty() || banReason.equalsIgnoreCase("ban")) + { + banReason = _("defaultBanReason"); + } + if (user.getBanTimeout() > 0) + { + //TODO: TL This + banReason += "\n\n" + "Expires in " + Util.formatDateDiff(user.getBanTimeout()); + } + event.disallow(Result.KICK_BANNED, banReason); return; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java index c05c66ad0..c84441ac4 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java @@ -25,9 +25,11 @@ public class Commandkick extends EssentialsCommand } final User target = getPlayer(server, args, 0, true); - if (sender instanceof Player) { + if (sender instanceof Player) + { User user = ess.getUser(sender); - if (target.isHidden() && !user.isAuthorized("essentials.list.hidden")) { + if (target.isHidden() && !user.isAuthorized("essentials.list.hidden")) + { throw new PlayerNotFoundException(); } if (target.isAuthorized("essentials.kick.exempt")) @@ -35,10 +37,13 @@ public class Commandkick extends EssentialsCommand throw new Exception(_("kickExempt")); } } - final String kickReason = args.length > 1 ? getFinalArg(args, 1) : _("kickDefault"); + + String kickReason = args.length > 1 ? getFinalArg(args, 1) : _("kickDefault"); + kickReason = kickReason.replace("\\n", "\n"); + target.kickPlayer(kickReason); final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME; - + server.getLogger().log(Level.INFO, _("playerKicked", senderName, target.getName(), kickReason)); for (Player onlinePlayer : server.getOnlinePlayers()) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java b/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java index 4722b7d68..36b2c7e15 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java @@ -16,6 +16,9 @@ public class Commandkickall extends EssentialsCommand @Override public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception { + String kickReason = args.length > 0 ? getFinalArg(args, 0) : _("kickDefault"); + kickReason = kickReason.replace("\\n", "\n"); + for (Player onlinePlayer : server.getOnlinePlayers()) { if (sender instanceof Player && onlinePlayer.getName().equalsIgnoreCase(((Player)sender).getName())) @@ -24,7 +27,7 @@ public class Commandkickall extends EssentialsCommand } else { - onlinePlayer.kickPlayer(args.length > 0 ? getFinalArg(args, 0) : _("kickDefault")); + onlinePlayer.kickPlayer(kickReason); } } sender.sendMessage(_("kickedAll")); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java b/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java index fd959472c..cf706aa8b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java @@ -4,7 +4,6 @@ import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.Util; -import java.util.Calendar; import java.util.GregorianCalendar; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -47,7 +46,7 @@ public class Commandtempban extends EssentialsCommand final long banTimestamp = Util.parseDateDiff(time, true); final long maxBanLength = ess.getSettings().getMaxTempban() * 1000; - if(maxBanLength > 0 && ((banTimestamp - GregorianCalendar.getInstance().getTimeInMillis()) > maxBanLength) && !(ess.getUser(sender).isAuthorized("essentials.tempban.unlimited"))) + if (maxBanLength > 0 && ((banTimestamp - GregorianCalendar.getInstance().getTimeInMillis()) > maxBanLength) && !(ess.getUser(sender).isAuthorized("essentials.tempban.unlimited"))) { sender.sendMessage(_("oversizedTempban")); throw new NoChargeException();