mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-03 13:17:38 +02:00
Show warning when invalid mob type is specified for /remove
This commit is contained in:
@@ -20,7 +20,7 @@ public class Commandremove extends EssentialsCommand
|
|||||||
{
|
{
|
||||||
super("remove");
|
super("remove");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
||||||
{
|
{
|
||||||
@@ -46,9 +46,9 @@ public class Commandremove extends EssentialsCommand
|
|||||||
world = ess.getWorld(args[2]);
|
world = ess.getWorld(args[2]);
|
||||||
}
|
}
|
||||||
parseCommand(server, user.getSource(), args, world, radius);
|
parseCommand(server, user.getSource(), args, world, radius);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception
|
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception
|
||||||
{
|
{
|
||||||
@@ -59,35 +59,35 @@ public class Commandremove extends EssentialsCommand
|
|||||||
World world = ess.getWorld(args[1]);
|
World world = ess.getWorld(args[1]);
|
||||||
parseCommand(server, sender, args, world, 0);
|
parseCommand(server, sender, args, world, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseCommand(Server server, CommandSource sender, String[] args, World world, 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> types = new ArrayList<String>();
|
||||||
List<String> customTypes = new ArrayList<String>();
|
List<String> customTypes = new ArrayList<String>();
|
||||||
|
|
||||||
if (args[0].contentEquals("*") || args[0].contentEquals("all"))
|
if (args[0].contentEquals("*") || args[0].contentEquals("all"))
|
||||||
{
|
{
|
||||||
types.add(0, "ALL");
|
types.add(0, "ALL");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (String s : args[0].split(","))
|
for (String entityType : args[0].split(","))
|
||||||
{
|
{
|
||||||
ToRemove toRemove;
|
ToRemove toRemove;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
toRemove = ToRemove.valueOf(s.toUpperCase(Locale.ENGLISH));
|
toRemove = ToRemove.valueOf(entityType.toUpperCase(Locale.ENGLISH));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
toRemove = ToRemove.valueOf(s.concat("S").toUpperCase(Locale.ENGLISH));
|
toRemove = ToRemove.valueOf(entityType.concat("S").toUpperCase(Locale.ENGLISH));
|
||||||
}
|
}
|
||||||
catch (Exception ee)
|
catch (Exception ee)
|
||||||
{
|
{
|
||||||
toRemove = ToRemove.CUSTOM;
|
toRemove = ToRemove.CUSTOM;
|
||||||
customTypes.add(s);
|
customTypes.add(entityType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
types.add(toRemove.toString());
|
types.add(toRemove.toString());
|
||||||
@@ -95,7 +95,7 @@ public class Commandremove extends EssentialsCommand
|
|||||||
}
|
}
|
||||||
removeHandler(sender, types, customTypes, world, radius);
|
removeHandler(sender, types, customTypes, world, radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeHandler(CommandSource sender, List<String> types, List<String> customTypes, World world, int radius)
|
private void removeHandler(CommandSource sender, List<String> types, List<String> customTypes, World world, int radius)
|
||||||
{
|
{
|
||||||
int removed = 0;
|
int removed = 0;
|
||||||
@@ -103,14 +103,35 @@ public class Commandremove extends EssentialsCommand
|
|||||||
{
|
{
|
||||||
radius *= radius;
|
radius *= radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<ToRemove> removeTypes = new ArrayList<ToRemove>();
|
ArrayList<ToRemove> removeTypes = new ArrayList<ToRemove>();
|
||||||
|
ArrayList<Mob> customRemoveTypes = new ArrayList<Mob>();
|
||||||
|
|
||||||
for (String s : types)
|
for (String s : types)
|
||||||
{
|
{
|
||||||
removeTypes.add(ToRemove.valueOf(s));
|
removeTypes.add(ToRemove.valueOf(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean warnUser = false;
|
||||||
|
|
||||||
|
for (String s : customTypes)
|
||||||
|
{
|
||||||
|
Mob mobType = Mob.fromName(s);
|
||||||
|
if (mobType == null)
|
||||||
|
{
|
||||||
|
warnUser = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
customRemoveTypes.add(mobType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (warnUser)
|
||||||
|
{
|
||||||
|
sender.sendMessage(_("invalidMob"));
|
||||||
|
}
|
||||||
|
|
||||||
for (Chunk chunk : world.getLoadedChunks())
|
for (Chunk chunk : world.getLoadedChunks())
|
||||||
{
|
{
|
||||||
for (Entity e : chunk.getEntities())
|
for (Entity e : chunk.getEntities())
|
||||||
@@ -126,10 +147,10 @@ public class Commandremove extends EssentialsCommand
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ToRemove toRemove : removeTypes)
|
for (ToRemove toRemove : removeTypes)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (e instanceof Tameable && ((Tameable)e).isTamed())
|
if (e instanceof Tameable && ((Tameable)e).isTamed())
|
||||||
{
|
{
|
||||||
if (toRemove == ToRemove.TAMED)
|
if (toRemove == ToRemove.TAMED)
|
||||||
@@ -142,7 +163,7 @@ public class Commandremove extends EssentialsCommand
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (toRemove)
|
switch (toRemove)
|
||||||
{
|
{
|
||||||
case DROPS:
|
case DROPS:
|
||||||
@@ -242,9 +263,9 @@ public class Commandremove extends EssentialsCommand
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CUSTOM:
|
case CUSTOM:
|
||||||
for (String type : customTypes)
|
for (Mob type : customRemoveTypes)
|
||||||
{
|
{
|
||||||
if (e.getType() == Mob.fromName(type).getType())
|
if (e.getType() == type.getType())
|
||||||
{
|
{
|
||||||
e.remove();
|
e.remove();
|
||||||
removed++;
|
removed++;
|
||||||
@@ -257,8 +278,8 @@ public class Commandremove extends EssentialsCommand
|
|||||||
}
|
}
|
||||||
sender.sendMessage(_("removed", removed));
|
sender.sendMessage(_("removed", removed));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private enum ToRemove
|
private enum ToRemove
|
||||||
{
|
{
|
||||||
DROPS,
|
DROPS,
|
||||||
|
@@ -171,7 +171,7 @@ invalidCharge=\u00a74Invalid charge.
|
|||||||
invalidFireworkFormat=\u00a76The option \u00a74{0} \u00a76is not a valid value for \u00a74{1}\u00a76.
|
invalidFireworkFormat=\u00a76The option \u00a74{0} \u00a76is not a valid value for \u00a74{1}\u00a76.
|
||||||
invalidHome=\u00a74Home\u00a7c {0} \u00a74doesn''t exist\!
|
invalidHome=\u00a74Home\u00a7c {0} \u00a74doesn''t exist\!
|
||||||
invalidHomeName=\u00a74Invalid home name\!
|
invalidHomeName=\u00a74Invalid home name\!
|
||||||
invalidMob=Invalid mob type.
|
invalidMob=\u00a74Invalid mob type.
|
||||||
invalidNumber=Invalid Number.
|
invalidNumber=Invalid Number.
|
||||||
invalidPotion=\u00a74Invalid Potion.
|
invalidPotion=\u00a74Invalid Potion.
|
||||||
invalidPotionMeta=\u00a74Invalid potion meta\: \u00a7c{0}\u00a74.
|
invalidPotionMeta=\u00a74Invalid potion meta\: \u00a7c{0}\u00a74.
|
||||||
|
@@ -171,7 +171,7 @@ invalidCharge=\u00a74Invalid charge.
|
|||||||
invalidFireworkFormat=\u00a76The option \u00a74{0} \u00a76is not a valid value for \u00a74{1}\u00a76.
|
invalidFireworkFormat=\u00a76The option \u00a74{0} \u00a76is not a valid value for \u00a74{1}\u00a76.
|
||||||
invalidHome=\u00a74Home\u00a7c {0} \u00a74doesn''t exist\!
|
invalidHome=\u00a74Home\u00a7c {0} \u00a74doesn''t exist\!
|
||||||
invalidHomeName=\u00a74Invalid home name\!
|
invalidHomeName=\u00a74Invalid home name\!
|
||||||
invalidMob=Invalid mob type.
|
invalidMob=\u00a74Invalid mob type.
|
||||||
invalidNumber=Invalid Number.
|
invalidNumber=Invalid Number.
|
||||||
invalidPotion=\u00a74Invalid Potion.
|
invalidPotion=\u00a74Invalid Potion.
|
||||||
invalidPotionMeta=\u00a74Invalid potion meta\: \u00a7c{0}\u00a74.
|
invalidPotionMeta=\u00a74Invalid potion meta\: \u00a7c{0}\u00a74.
|
||||||
|
Reference in New Issue
Block a user