Allow kicking of hidden players

This commit is contained in:
KHobbits 2012-10-14 13:04:00 +01:00
parent bdef1780ac
commit ae7c64619c
3 changed files with 27 additions and 10 deletions

View File

@ -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));
}
}
}

View File

@ -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

View File

@ -0,0 +1,11 @@
package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
public class PlayerNotFoundException extends NoSuchFieldException
{
public PlayerNotFoundException()
{
super(_("playerNotFound"));
}
}