001 package org.bukkit.command.defaults; 002 003 import java.util.List; 004 005 import org.apache.commons.lang.Validate; 006 import org.bukkit.Bukkit; 007 import org.bukkit.command.CommandSender; 008 import org.bukkit.entity.Player; 009 import org.bukkit.event.entity.EntityDamageEvent; 010 011 import com.google.common.collect.ImmutableList; 012 013 public class KillCommand extends VanillaCommand { 014 public KillCommand() { 015 super("kill"); 016 this.description = "Commits suicide, only usable as a player"; 017 this.usageMessage = "/kill"; 018 this.setPermission("bukkit.command.kill"); 019 } 020 021 @Override 022 public boolean execute(CommandSender sender, String currentAlias, String[] args) { 023 if (!testPermission(sender)) return true; 024 025 if (sender instanceof Player) { 026 Player player = (Player) sender; 027 028 EntityDamageEvent ede = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.SUICIDE, 1000); 029 Bukkit.getPluginManager().callEvent(ede); 030 if (ede.isCancelled()) return true; 031 032 ede.getEntity().setLastDamageCause(ede); 033 player.setHealth(0); 034 sender.sendMessage("Ouch. That look like it hurt."); 035 } else { 036 sender.sendMessage("You can only perform this command as a player"); 037 } 038 039 return true; 040 } 041 042 @Override 043 public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException { 044 Validate.notNull(sender, "Sender cannot be null"); 045 Validate.notNull(args, "Arguments cannot be null"); 046 Validate.notNull(alias, "Alias cannot be null"); 047 048 return ImmutableList.of(); 049 } 050 }