mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-11-19 00:55:32 +01:00
Renamed /butcher to /killall and fixes to the code.
This commit is contained in:
parent
32564fb4f7
commit
70bd9bd1f3
@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
|
|||||||
import com.earth2me.essentials.Mob;
|
import com.earth2me.essentials.Mob;
|
||||||
import static com.earth2me.essentials.I18n._;
|
import static com.earth2me.essentials.I18n._;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Locale;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -22,11 +23,12 @@ import org.bukkit.entity.WaterMob;
|
|||||||
import org.bukkit.entity.Wolf;
|
import org.bukkit.entity.Wolf;
|
||||||
import org.bukkit.event.entity.EntityDeathEvent;
|
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
|
//TODO: Tidy - missed this during command cleanup
|
||||||
@ -79,10 +81,23 @@ public class Commandbutcher extends EssentialsCommand
|
|||||||
world = ess.getWorld(args[1]);
|
world = ess.getWorld(args[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (radius >=0) {
|
if (radius >= 0)
|
||||||
|
{
|
||||||
radius *= radius;
|
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;
|
int numKills = 0;
|
||||||
for (Chunk chunk : world.getLoadedChunks())
|
for (Chunk chunk : world.getLoadedChunks())
|
||||||
{
|
{
|
||||||
@ -90,7 +105,7 @@ public class Commandbutcher extends EssentialsCommand
|
|||||||
{
|
{
|
||||||
if (sender instanceof Player)
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
@ -106,7 +121,7 @@ public class Commandbutcher extends EssentialsCommand
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (killType.contains("animal"))
|
if (animals)
|
||||||
{
|
{
|
||||||
if (entity instanceof Animals || entity instanceof NPC || entity instanceof Snowman || entity instanceof WaterMob)
|
if (entity instanceof Animals || entity instanceof NPC || entity instanceof Snowman || entity instanceof WaterMob)
|
||||||
{
|
{
|
||||||
@ -116,7 +131,7 @@ public class Commandbutcher extends EssentialsCommand
|
|||||||
numKills++;
|
numKills++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (killType.contains("monster"))
|
else if (monster)
|
||||||
{
|
{
|
||||||
if (entity instanceof Monster || entity instanceof ComplexLivingEntity || entity instanceof Flying || entity instanceof Slime)
|
if (entity instanceof Monster || entity instanceof ComplexLivingEntity || entity instanceof Flying || entity instanceof Slime)
|
||||||
{
|
{
|
||||||
@ -126,16 +141,14 @@ public class Commandbutcher extends EssentialsCommand
|
|||||||
numKills++;
|
numKills++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (killType.contains("all"))
|
else if (all)
|
||||||
{
|
{
|
||||||
EntityDeathEvent event = new EntityDeathEvent(entity, Collections.EMPTY_LIST);
|
EntityDeathEvent event = new EntityDeathEvent(entity, Collections.EMPTY_LIST);
|
||||||
ess.getServer().getPluginManager().callEvent(event);
|
ess.getServer().getPluginManager().callEvent(event);
|
||||||
entity.remove();
|
entity.remove();
|
||||||
numKills++;
|
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);
|
EntityDeathEvent event = new EntityDeathEvent(entity, Collections.EMPTY_LIST);
|
||||||
ess.getServer().getPluginManager().callEvent(event);
|
ess.getServer().getPluginManager().callEvent(event);
|
||||||
@ -144,7 +157,6 @@ public class Commandbutcher extends EssentialsCommand
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
sender.sendMessage(_("kill", numKills));
|
sender.sendMessage(_("kill", numKills));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -55,10 +55,6 @@ commands:
|
|||||||
description: Set a player on fire.
|
description: Set a player on fire.
|
||||||
usage: /<command> <player> <seconds>
|
usage: /<command> <player> <seconds>
|
||||||
aliases: [eburn]
|
aliases: [eburn]
|
||||||
butcher:
|
|
||||||
description: Kill all mobs in a world.
|
|
||||||
usage: /<command> <mobType> <radius>
|
|
||||||
aliases: [ebutcher]
|
|
||||||
clearinventory:
|
clearinventory:
|
||||||
description: Clear all items in your inventory.
|
description: Clear all items in your inventory.
|
||||||
usage: /<command>
|
usage: /<command>
|
||||||
@ -186,6 +182,10 @@ commands:
|
|||||||
description: Kills specified player.
|
description: Kills specified player.
|
||||||
usage: /<command> <player>
|
usage: /<command> <player>
|
||||||
aliases: [ekill]
|
aliases: [ekill]
|
||||||
|
killall:
|
||||||
|
description: Kill all mobs in a world.
|
||||||
|
usage: /<command> <mobType> <radius>
|
||||||
|
aliases: [ekillall,butcher]
|
||||||
list:
|
list:
|
||||||
description: List all online players.
|
description: List all online players.
|
||||||
usage: /<command>
|
usage: /<command>
|
||||||
|
Loading…
Reference in New Issue
Block a user