From 70bd9bd1f35edf6eadb5238c11b5e74294ed2381 Mon Sep 17 00:00:00 2001 From: snowleo Date: Tue, 13 Dec 2011 10:28:15 +0100 Subject: Renamed /butcher to /killall and fixes to the code. --- .../essentials/commands/Commandbutcher.java | 150 ------------------- .../essentials/commands/Commandkillall.java | 162 +++++++++++++++++++++ Essentials/src/plugin.yml | 8 +- 3 files changed, 166 insertions(+), 154 deletions(-) delete mode 100644 Essentials/src/com/earth2me/essentials/commands/Commandbutcher.java create mode 100644 Essentials/src/com/earth2me/essentials/commands/Commandkillall.java diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbutcher.java b/Essentials/src/com/earth2me/essentials/commands/Commandbutcher.java deleted file mode 100644 index fa628f8e0..000000000 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbutcher.java +++ /dev/null @@ -1,150 +0,0 @@ -package com.earth2me.essentials.commands; - -import com.earth2me.essentials.Mob; -import static com.earth2me.essentials.I18n._; -import java.util.Collections; -import org.bukkit.Chunk; -import org.bukkit.Server; -import org.bukkit.World; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Animals; -import org.bukkit.entity.ComplexLivingEntity; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Flying; -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Monster; -import org.bukkit.entity.NPC; -import org.bukkit.entity.Player; -import org.bukkit.entity.Slime; -import org.bukkit.entity.Snowman; -import org.bukkit.entity.WaterMob; -import org.bukkit.entity.Wolf; -import org.bukkit.event.entity.EntityDeathEvent; - -public class Commandbutcher extends EssentialsCommand -{ - public Commandbutcher() - { - super("butcher"); - } - - //TODO: Tidy - missed this during command cleanup - @Override - public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception - { - String type = "all"; - int radius = -1; - World world; - if (sender instanceof Player) - { - world = ((Player)sender).getWorld(); - if (args.length == 1) - { - try - { - radius = Integer.parseInt(args[0]); - } - catch (NumberFormatException e1) - { - type = args[0]; - } - } - else if (args.length > 1) - { - type = args[0]; - try - { - radius = Integer.parseInt(args[1]); - } - catch (NumberFormatException e) - { - throw new Exception(_("numberRequired")); - } - } - } - else - { - if (args.length == 0) - { - throw new NotEnoughArgumentsException(); - } - else if (args.length == 1) - { - world = ess.getWorld(args[0]); - } - else - { - type = args[0]; - world = ess.getWorld(args[1]); - } - } - if (radius >=0) { - radius *= radius; - } - String killType = type.toLowerCase(); - int numKills = 0; - for (Chunk chunk : world.getLoadedChunks()) - { - for (Entity entity : chunk.getEntities()) - { - if (sender instanceof Player) - { - if (((Player)sender).getLocation().distanceSquared(entity.getLocation()) > radius && radius >= 0) - { - continue; - } - } - if (entity instanceof LivingEntity == false || entity instanceof HumanEntity) - { - continue; - } - if (entity instanceof Wolf) - { - if (((Wolf)entity).isTamed()) - { - continue; - } - } - if (killType.contains("animal")) - { - if (entity instanceof Animals || entity instanceof NPC || entity instanceof Snowman || entity instanceof WaterMob) - { - EntityDeathEvent event = new EntityDeathEvent(entity, Collections.EMPTY_LIST); - ess.getServer().getPluginManager().callEvent(event); - entity.remove(); - numKills++; - } - } - else if (killType.contains("monster")) - { - if (entity instanceof Monster || entity instanceof ComplexLivingEntity || entity instanceof Flying || entity instanceof Slime) - { - EntityDeathEvent event = new EntityDeathEvent(entity, Collections.EMPTY_LIST); - ess.getServer().getPluginManager().callEvent(event); - entity.remove(); - numKills++; - } - } - else if (killType.contains("all")) - { - EntityDeathEvent event = new EntityDeathEvent(entity, Collections.EMPTY_LIST); - ess.getServer().getPluginManager().callEvent(event); - entity.remove(); - numKills++; - } - else - { - if (Mob.fromName(killType).getType().getEntityClass().isAssignableFrom(entity.getClass())) - { - EntityDeathEvent event = new EntityDeathEvent(entity, Collections.EMPTY_LIST); - ess.getServer().getPluginManager().callEvent(event); - entity.remove(); - numKills++; - } - } - } - } - sender.sendMessage(_("kill", numKills)); - } -} \ No newline at end of file diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkillall.java b/Essentials/src/com/earth2me/essentials/commands/Commandkillall.java new file mode 100644 index 000000000..b9679e8b9 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkillall.java @@ -0,0 +1,162 @@ +package com.earth2me.essentials.commands; + +import com.earth2me.essentials.Mob; +import static com.earth2me.essentials.I18n._; +import java.util.Collections; +import java.util.Locale; +import org.bukkit.Chunk; +import org.bukkit.Server; +import org.bukkit.World; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Animals; +import org.bukkit.entity.ComplexLivingEntity; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Flying; +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Monster; +import org.bukkit.entity.NPC; +import org.bukkit.entity.Player; +import org.bukkit.entity.Slime; +import org.bukkit.entity.Snowman; +import org.bukkit.entity.WaterMob; +import org.bukkit.entity.Wolf; +import org.bukkit.event.entity.EntityDeathEvent; + + +public class Commandkillall extends EssentialsCommand +{ + public Commandkillall() + { + super("killall"); + } + + //TODO: Tidy - missed this during command cleanup + @Override + public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception + { + String type = "all"; + int radius = -1; + World world; + if (sender instanceof Player) + { + world = ((Player)sender).getWorld(); + if (args.length == 1) + { + try + { + radius = Integer.parseInt(args[0]); + } + catch (NumberFormatException e1) + { + type = args[0]; + } + } + else if (args.length > 1) + { + type = args[0]; + try + { + radius = Integer.parseInt(args[1]); + } + catch (NumberFormatException e) + { + throw new Exception(_("numberRequired")); + } + } + } + else + { + if (args.length == 0) + { + throw new NotEnoughArgumentsException(); + } + else if (args.length == 1) + { + world = ess.getWorld(args[0]); + } + else + { + type = args[0]; + world = ess.getWorld(args[1]); + } + } + if (radius >= 0) + { + radius *= radius; + } + String killType = type.toLowerCase(Locale.ENGLISH); + boolean animals = killType.startsWith("animal"); + boolean monster = killType.startsWith("monster") || killType.startsWith("mob"); + boolean all = killType.equals("all"); + Class entityClass = null; + if (!animals && !monster && !all) + { + if (Mob.fromName(killType) == null) + { + throw new Exception(_("invalidMob")); + } + entityClass = Mob.fromName(killType).getType().getEntityClass(); + } + int numKills = 0; + for (Chunk chunk : world.getLoadedChunks()) + { + for (Entity entity : chunk.getEntities()) + { + if (sender instanceof Player) + { + if (radius >= 0 && ((Player)sender).getLocation().distanceSquared(entity.getLocation()) > radius) + { + continue; + } + } + if (entity instanceof LivingEntity == false || entity instanceof HumanEntity) + { + continue; + } + if (entity instanceof Wolf) + { + if (((Wolf)entity).isTamed()) + { + continue; + } + } + if (animals) + { + if (entity instanceof Animals || entity instanceof NPC || entity instanceof Snowman || entity instanceof WaterMob) + { + EntityDeathEvent event = new EntityDeathEvent(entity, Collections.EMPTY_LIST); + ess.getServer().getPluginManager().callEvent(event); + entity.remove(); + numKills++; + } + } + else if (monster) + { + if (entity instanceof Monster || entity instanceof ComplexLivingEntity || entity instanceof Flying || entity instanceof Slime) + { + EntityDeathEvent event = new EntityDeathEvent(entity, Collections.EMPTY_LIST); + ess.getServer().getPluginManager().callEvent(event); + entity.remove(); + numKills++; + } + } + else if (all) + { + EntityDeathEvent event = new EntityDeathEvent(entity, Collections.EMPTY_LIST); + ess.getServer().getPluginManager().callEvent(event); + entity.remove(); + numKills++; + } + else if (entityClass != null && entityClass.isAssignableFrom(entity.getClass())) + { + EntityDeathEvent event = new EntityDeathEvent(entity, Collections.EMPTY_LIST); + ess.getServer().getPluginManager().callEvent(event); + entity.remove(); + numKills++; + } + } + } + sender.sendMessage(_("kill", numKills)); + } +} \ No newline at end of file diff --git a/Essentials/src/plugin.yml b/Essentials/src/plugin.yml index c3ed49ad1..a92210d69 100644 --- a/Essentials/src/plugin.yml +++ b/Essentials/src/plugin.yml @@ -55,10 +55,6 @@ commands: description: Set a player on fire. usage: / aliases: [eburn] - butcher: - description: Kill all mobs in a world. - usage: / - aliases: [ebutcher] clearinventory: description: Clear all items in your inventory. usage: / @@ -186,6 +182,10 @@ commands: description: Kills specified player. usage: / aliases: [ekill] + killall: + description: Kill all mobs in a world. + usage: / + aliases: [ekillall,butcher] list: description: List all online players. usage: / -- cgit v1.2.3