diff options
author | snowleo <schneeleo@gmail.com> | 2011-12-13 10:28:15 +0100 |
---|---|---|
committer | snowleo <schneeleo@gmail.com> | 2011-12-13 10:28:15 +0100 |
commit | 9579953f03db6ca2eea7af7c01a6e2e2f9d1b3ca (patch) | |
tree | 157aae0516922b6a3b84e474ada2044ec08e5c10 | |
parent | f3f8243de8a088238fe81ded53c4da16b799e350 (diff) | |
download | Essentials-9579953f03db6ca2eea7af7c01a6e2e2f9d1b3ca.tar Essentials-9579953f03db6ca2eea7af7c01a6e2e2f9d1b3ca.tar.gz Essentials-9579953f03db6ca2eea7af7c01a6e2e2f9d1b3ca.tar.lz Essentials-9579953f03db6ca2eea7af7c01a6e2e2f9d1b3ca.tar.xz Essentials-9579953f03db6ca2eea7af7c01a6e2e2f9d1b3ca.zip |
Renamed /butcher to /killall and fixes to the code.
-rw-r--r-- | Essentials/src/com/earth2me/essentials/commands/Commandkillall.java (renamed from Essentials/src/com/earth2me/essentials/commands/Commandbutcher.java) | 46 | ||||
-rw-r--r-- | Essentials/src/plugin.yml | 8 |
2 files changed, 33 insertions, 21 deletions
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbutcher.java b/Essentials/src/com/earth2me/essentials/commands/Commandkillall.java index fa628f8e0..b9679e8b9 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbutcher.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkillall.java @@ -3,6 +3,7 @@ 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; @@ -22,11 +23,12 @@ import org.bukkit.entity.WaterMob; import org.bukkit.entity.Wolf; import org.bukkit.event.entity.EntityDeathEvent; -public class Commandbutcher extends EssentialsCommand + +public class Commandkillall extends EssentialsCommand { - public Commandbutcher() + public Commandkillall() { - super("butcher"); + super("killall"); } //TODO: Tidy - missed this during command cleanup @@ -79,10 +81,23 @@ public class Commandbutcher extends EssentialsCommand world = ess.getWorld(args[1]); } } - if (radius >=0) { + if (radius >= 0) + { radius *= radius; } - String killType = type.toLowerCase(); + 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<? extends Entity> 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()) { @@ -90,7 +105,7 @@ public class Commandbutcher extends EssentialsCommand { if (sender instanceof Player) { - if (((Player)sender).getLocation().distanceSquared(entity.getLocation()) > radius && radius >= 0) + if (radius >= 0 && ((Player)sender).getLocation().distanceSquared(entity.getLocation()) > radius) { continue; } @@ -106,7 +121,7 @@ public class Commandbutcher extends EssentialsCommand continue; } } - if (killType.contains("animal")) + if (animals) { if (entity instanceof Animals || entity instanceof NPC || entity instanceof Snowman || entity instanceof WaterMob) { @@ -116,7 +131,7 @@ public class Commandbutcher extends EssentialsCommand numKills++; } } - else if (killType.contains("monster")) + else if (monster) { if (entity instanceof Monster || entity instanceof ComplexLivingEntity || entity instanceof Flying || entity instanceof Slime) { @@ -126,22 +141,19 @@ public class Commandbutcher extends EssentialsCommand numKills++; } } - else if (killType.contains("all")) + else if (all) { EntityDeathEvent event = new EntityDeathEvent(entity, Collections.EMPTY_LIST); ess.getServer().getPluginManager().callEvent(event); entity.remove(); numKills++; } - else + else if (entityClass != null && entityClass.isAssignableFrom(entity.getClass())) { - 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++; - } + EntityDeathEvent event = new EntityDeathEvent(entity, Collections.EMPTY_LIST); + ess.getServer().getPluginManager().callEvent(event); + entity.remove(); + numKills++; } } } 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: /<command> <player> <seconds> aliases: [eburn] - butcher: - description: Kill all mobs in a world. - usage: /<command> <mobType> <radius> - aliases: [ebutcher] clearinventory: description: Clear all items in your inventory. usage: /<command> @@ -186,6 +182,10 @@ commands: description: Kills specified player. usage: /<command> <player> aliases: [ekill] + killall: + description: Kill all mobs in a world. + usage: /<command> <mobType> <radius> + aliases: [ekillall,butcher] list: description: List all online players. usage: /<command> |