TF-EssentialsX/Essentials/src/com/earth2me/essentials/commands/Commandkill.java

53 lines
1.7 KiB
Java
Raw Normal View History

package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
2013-09-28 16:21:16 +00:00
import com.earth2me.essentials.User;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
2011-10-09 14:43:58 +00:00
import org.bukkit.event.entity.EntityDamageEvent;
2013-09-28 16:21:16 +00:00
public class Commandkill extends EssentialsLoopCommand
{
public Commandkill()
{
super("kill");
}
@Override
2011-11-18 13:48:31 +00:00
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
if (args.length < 1)
{
throw new NotEnoughArgumentsException();
}
2013-09-28 16:21:16 +00:00
loopOnlinePlayers(server, sender, true, args[0], null);
}
@Override
protected void updatePlayer(final Server server, final CommandSender sender, final User user, final String[] args) throws PlayerExemptException
{
final Player matchPlayer = user.getBase();
if (sender instanceof Player && user.isAuthorized("essentials.kill.exempt") && !ess.getUser(sender).isAuthorized("essentials.kill.force"))
{
2013-09-28 16:21:16 +00:00
throw new PlayerExemptException(_("killExempt", matchPlayer.getDisplayName()));
}
2013-09-28 16:21:16 +00:00
final EntityDamageEvent ede = new EntityDamageEvent(matchPlayer, sender instanceof Player && ((Player)sender).getName().equals(matchPlayer.getName()) ? EntityDamageEvent.DamageCause.SUICIDE : EntityDamageEvent.DamageCause.CUSTOM, Short.MAX_VALUE);
server.getPluginManager().callEvent(ede);
if (ede.isCancelled() && sender instanceof Player && !ess.getUser(sender).isAuthorized("essentials.kill.force"))
{
return;
}
matchPlayer.damage(Short.MAX_VALUE);
2013-09-28 16:21:16 +00:00
if (matchPlayer.getHealth() > 0)
{
2013-09-28 16:21:16 +00:00
matchPlayer.setHealth(0);
}
2013-09-28 16:21:16 +00:00
sender.sendMessage(_("kill", matchPlayer.getDisplayName()));
}
}