mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-08-10 22:35:35 +00:00
Merge remove and killall command, thanks to @Evonuts and @Iaccidentally.
This commit is contained in:
parent
b3bad6a35a
commit
dde8cd8f72
3 changed files with 182 additions and 306 deletions
|
@ -2,15 +2,19 @@ package com.earth2me.essentials.commands;
|
|||
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.Mob;
|
||||
import com.earth2me.essentials.User;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.*;
|
||||
|
||||
//Todo: Fix this up
|
||||
//Todo: now overlaps some functions of killall, which should be deprecated and removed once all functions are covered
|
||||
// This could be rewritten in a simpler form if we made a mapping of all Entity names to their types (which would also provide possible mod support)
|
||||
|
||||
public class Commandremove extends EssentialsCommand
|
||||
{
|
||||
public Commandremove()
|
||||
|
@ -21,14 +25,9 @@ public class Commandremove extends EssentialsCommand
|
|||
@Override
|
||||
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
ToRemove toRemove;
|
||||
World world = user.getWorld();
|
||||
int radius = 0;
|
||||
|
||||
Bukkit.broadcastMessage("len: " + args.length);
|
||||
if (args.length >= 2)
|
||||
{
|
||||
try
|
||||
|
@ -40,28 +39,12 @@ public class Commandremove extends EssentialsCommand
|
|||
throw new Exception(_("numberRequired"), e);
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length >= 3)
|
||||
{
|
||||
world = ess.getWorld(args[2]);
|
||||
}
|
||||
parseCommand(server, user.getSource(), args, world, radius);
|
||||
|
||||
try
|
||||
{
|
||||
toRemove = ToRemove.valueOf(args[0].toUpperCase(Locale.ENGLISH));
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
try
|
||||
{
|
||||
toRemove = ToRemove.valueOf(args[0].concat("S").toUpperCase(Locale.ENGLISH));
|
||||
}
|
||||
catch (IllegalArgumentException ee)
|
||||
{
|
||||
throw new NotEnoughArgumentsException(ee); //TODO: translate and list types
|
||||
}
|
||||
}
|
||||
removeEntities(user.getSource(), world, toRemove, radius);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -72,33 +55,60 @@ public class Commandremove extends EssentialsCommand
|
|||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
World world = ess.getWorld(args[1]);
|
||||
|
||||
ToRemove toRemove;
|
||||
try
|
||||
{
|
||||
toRemove = ToRemove.valueOf(args[0].toUpperCase(Locale.ENGLISH));
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
try
|
||||
{
|
||||
toRemove = ToRemove.valueOf(args[0].concat("S").toUpperCase(Locale.ENGLISH));
|
||||
}
|
||||
catch (IllegalArgumentException ee)
|
||||
{
|
||||
throw new NotEnoughArgumentsException(ee); //TODO: translate and list types
|
||||
}
|
||||
}
|
||||
removeEntities(sender, world, toRemove, 0);
|
||||
parseCommand(server, sender, args, world, 0);
|
||||
}
|
||||
|
||||
private void removeEntities(final CommandSource sender, final World world, final ToRemove toRemove, int radius) throws Exception
|
||||
private void parseCommand(Server server, CommandSource sender, String[] args, World world, int radius) throws Exception
|
||||
{
|
||||
List<String> types = new ArrayList<String>();
|
||||
List<String> customTypes = new ArrayList<String>();
|
||||
|
||||
if (args.length > 0 && (args[0].contentEquals("*") || args[0].contentEquals("all")))
|
||||
{
|
||||
types.add(0, "ALL");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (String s : args[0].split(","))
|
||||
{
|
||||
ToRemove toRemove;
|
||||
try
|
||||
{
|
||||
toRemove = ToRemove.valueOf(s.toUpperCase(Locale.ENGLISH));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
try
|
||||
{
|
||||
toRemove = ToRemove.valueOf(s.concat("S").toUpperCase(Locale.ENGLISH));
|
||||
}
|
||||
catch (Exception ee)
|
||||
{
|
||||
toRemove = ToRemove.CUSTOM;
|
||||
customTypes.add(s);
|
||||
}
|
||||
}
|
||||
types.add(toRemove.toString());
|
||||
}
|
||||
}
|
||||
removeHandler(sender, types, customTypes, world, radius);
|
||||
}
|
||||
|
||||
private void removeHandler(CommandSource sender, List<String> types, List<String> customTypes, World world, int radius)
|
||||
{
|
||||
int removed = 0;
|
||||
if (radius > 0)
|
||||
{
|
||||
radius *= radius;
|
||||
}
|
||||
|
||||
ArrayList<ToRemove> removeTypes = new ArrayList<ToRemove>();
|
||||
|
||||
for (String s : types)
|
||||
{
|
||||
removeTypes.add(ToRemove.valueOf(s));
|
||||
}
|
||||
|
||||
for (Chunk chunk : world.getLoadedChunks())
|
||||
{
|
||||
for (Entity e : chunk.getEntities())
|
||||
|
@ -110,114 +120,136 @@ public class Commandremove extends EssentialsCommand
|
|||
continue;
|
||||
}
|
||||
}
|
||||
if (e instanceof Tameable)
|
||||
if (e instanceof HumanEntity)
|
||||
{
|
||||
if (((Tameable)e).isTamed())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
switch (toRemove)
|
||||
|
||||
for (ToRemove toRemove : removeTypes)
|
||||
{
|
||||
case DROPS:
|
||||
if (e instanceof Item)
|
||||
|
||||
if (e instanceof Tameable && ((Tameable)e).isTamed())
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
;
|
||||
break;
|
||||
case ARROWS:
|
||||
if (e instanceof Projectile)
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
break;
|
||||
case BOATS:
|
||||
if (e instanceof Boat)
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
break;
|
||||
case MINECARTS:
|
||||
if (e instanceof Minecart)
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
break;
|
||||
case XP:
|
||||
if (e instanceof ExperienceOrb)
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
break;
|
||||
case PAINTINGS:
|
||||
if (e instanceof Painting)
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
break;
|
||||
case ITEMFRAMES:
|
||||
if (e instanceof ItemFrame)
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
break;
|
||||
case ENDERCRYSTALS:
|
||||
if (e instanceof EnderCrystal)
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
break;
|
||||
case AMBIENT:
|
||||
if (e instanceof Flying)
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
break;
|
||||
case HOSTILE:
|
||||
case MONSTERS:
|
||||
if (e instanceof Monster || e instanceof ComplexLivingEntity || e instanceof Flying || e instanceof Slime)
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
break;
|
||||
case PASSIVE:
|
||||
case ANIMALS:
|
||||
if (e instanceof Animals || e instanceof NPC || e instanceof Snowman || e instanceof WaterMob)
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
break;
|
||||
case MOBS:
|
||||
if (e instanceof Animals || e instanceof NPC || e instanceof Snowman || e instanceof WaterMob
|
||||
|| e instanceof Monster || e instanceof ComplexLivingEntity || e instanceof Flying || e instanceof Slime)
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
break;
|
||||
case ENTITIES:
|
||||
if (e instanceof Entity)
|
||||
{
|
||||
if (e instanceof HumanEntity)
|
||||
if (toRemove == ToRemove.TAMED)
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
break;
|
||||
|
||||
switch (toRemove)
|
||||
{
|
||||
case DROPS:
|
||||
if (e instanceof Item)
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
;
|
||||
break;
|
||||
case ARROWS:
|
||||
if (e instanceof Projectile)
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
break;
|
||||
case BOATS:
|
||||
if (e instanceof Boat)
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
break;
|
||||
case MINECARTS:
|
||||
if (e instanceof Minecart)
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
break;
|
||||
case XP:
|
||||
if (e instanceof ExperienceOrb)
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
break;
|
||||
case PAINTINGS:
|
||||
if (e instanceof Painting)
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
break;
|
||||
case ITEMFRAMES:
|
||||
if (e instanceof ItemFrame)
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
break;
|
||||
case ENDERCRYSTALS:
|
||||
if (e instanceof EnderCrystal)
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
break;
|
||||
case AMBIENT:
|
||||
if (e instanceof Flying)
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
break;
|
||||
case HOSTILE:
|
||||
case MONSTERS:
|
||||
if (e instanceof Monster || e instanceof ComplexLivingEntity || e instanceof Flying || e instanceof Slime)
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
break;
|
||||
case PASSIVE:
|
||||
case ANIMALS:
|
||||
if (e instanceof Animals || e instanceof NPC || e instanceof Snowman || e instanceof WaterMob || e instanceof Ambient)
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
break;
|
||||
case MOBS:
|
||||
if (e instanceof Animals || e instanceof NPC || e instanceof Snowman || e instanceof WaterMob
|
||||
|| e instanceof Monster || e instanceof ComplexLivingEntity || e instanceof Flying || e instanceof Slime || e instanceof Ambient)
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
break;
|
||||
case ENTITIES:
|
||||
case ALL:
|
||||
if (e instanceof Entity)
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
break;
|
||||
case CUSTOM:
|
||||
for (String type : customTypes)
|
||||
{
|
||||
if (e.getType() == Mob.fromName(type).getType())
|
||||
{
|
||||
e.remove();
|
||||
removed++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -241,6 +273,9 @@ public class Commandremove extends EssentialsCommand
|
|||
ANIMALS,
|
||||
AMBIENT,
|
||||
MOBS,
|
||||
ENTITIES
|
||||
ENTITIES,
|
||||
ALL,
|
||||
CUSTOM,
|
||||
TAMED
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue