From ae7c64619c173bf4a9e7ab9e8c68241369af0d41 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sun, 14 Oct 2012 13:04:00 +0100 Subject: [PATCH] Allow kicking of hidden players --- .../essentials/commands/Commandkick.java | 20 ++++++++++++------- .../commands/EssentialsCommand.java | 6 +++--- .../commands/PlayerNotFoundException.java | 11 ++++++++++ 3 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 Essentials/src/com/earth2me/essentials/commands/PlayerNotFoundException.java diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java index 287a3cc62..c05c66ad0 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java @@ -24,23 +24,29 @@ public class Commandkick extends EssentialsCommand throw new NotEnoughArgumentsException(); } - final User user = getPlayer(server, args, 0); - if (sender instanceof Player && user.isAuthorized("essentials.kick.exempt")) - { - throw new Exception(_("kickExempt")); + final User target = getPlayer(server, args, 0, true); + if (sender instanceof Player) { + User user = ess.getUser(sender); + if (target.isHidden() && !user.isAuthorized("essentials.list.hidden")) { + throw new PlayerNotFoundException(); + } + if (target.isAuthorized("essentials.kick.exempt")) + { + throw new Exception(_("kickExempt")); + } } final String kickReason = args.length > 1 ? getFinalArg(args, 1) : _("kickDefault"); - user.kickPlayer(kickReason); + target.kickPlayer(kickReason); final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME; - server.getLogger().log(Level.INFO, _("playerKicked", senderName, user.getName(), kickReason)); + server.getLogger().log(Level.INFO, _("playerKicked", senderName, target.getName(), kickReason)); for (Player onlinePlayer : server.getOnlinePlayers()) { User player = ess.getUser(onlinePlayer); if (player.isAuthorized("essentials.kick.notify")) { - onlinePlayer.sendMessage(_("playerKicked", senderName, user.getName(), kickReason)); + onlinePlayer.sendMessage(_("playerKicked", senderName, target.getName(), kickReason)); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java index 6bc0649e9..5287016eb 100644 --- a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java @@ -56,14 +56,14 @@ public abstract class EssentialsCommand implements IEssentialsCommand } if (args[pos].isEmpty()) { - throw new NoSuchFieldException(_("playerNotFound")); + throw new PlayerNotFoundException(); } final User user = ess.getUser(args[pos]); if (user != null) { if (!getOffline && (!user.isOnline() || user.isHidden())) { - throw new NoSuchFieldException(_("playerNotFound")); + throw new PlayerNotFoundException(); } return user; } @@ -85,7 +85,7 @@ public abstract class EssentialsCommand implements IEssentialsCommand return userMatch; } } - throw new NoSuchFieldException(_("playerNotFound")); + throw new PlayerNotFoundException(); } @Override diff --git a/Essentials/src/com/earth2me/essentials/commands/PlayerNotFoundException.java b/Essentials/src/com/earth2me/essentials/commands/PlayerNotFoundException.java new file mode 100644 index 000000000..c33e87522 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/commands/PlayerNotFoundException.java @@ -0,0 +1,11 @@ +package com.earth2me.essentials.commands; + +import static com.earth2me.essentials.I18n._; + +public class PlayerNotFoundException extends NoSuchFieldException +{ + public PlayerNotFoundException() + { + super(_("playerNotFound")); + } +}