Don't include entity class in usable params, allow people to use a EntityType as well

This commit is contained in:
libraryaddict 2014-06-12 18:15:41 +12:00
parent 014c34ce0e
commit cddfbafb3d

View File

@ -15,6 +15,7 @@ import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -29,6 +30,7 @@ public class DisguiseRadiusCommand extends BaseDisguiseCommand {
validClasses.add(c); validClasses.add(c);
} }
} }
validClasses.remove(Entity.class);
} }
@Override @Override
@ -57,6 +59,7 @@ public class DisguiseRadiusCommand extends BaseDisguiseCommand {
return true; return true;
} }
Class entityClass = Entity.class; Class entityClass = Entity.class;
EntityType type = null;
int starting = 0; int starting = 0;
if (!isNumeric(args[0])) { if (!isNumeric(args[0])) {
for (Class c : validClasses) { for (Class c : validClasses) {
@ -67,10 +70,16 @@ public class DisguiseRadiusCommand extends BaseDisguiseCommand {
} }
} }
if (starting == 0) { if (starting == 0) {
try {
type = EntityType.valueOf(args[0].toUpperCase());
} catch (Exception ex) {
}
if (type == null) {
sender.sendMessage(ChatColor.RED + "Unrecognised EntityType " + args[0]); sender.sendMessage(ChatColor.RED + "Unrecognised EntityType " + args[0]);
return true; return true;
} }
} }
}
if (args.length == starting + 1) { if (args.length == starting + 1) {
sender.sendMessage(ChatColor.RED + "You need to supply a disguise as well as the radius" sender.sendMessage(ChatColor.RED + "You need to supply a disguise as well as the radius"
+ (starting != 0 ? " and EntityType" : "")); + (starting != 0 ? " and EntityType" : ""));
@ -103,7 +112,7 @@ public class DisguiseRadiusCommand extends BaseDisguiseCommand {
for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) { for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) {
if (entity == sender) if (entity == sender)
continue; continue;
if (entityClass.isAssignableFrom(entity.getClass())) { if (type != null ? entity.getType() == type : entityClass.isAssignableFrom(entity.getClass())) {
if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled()
&& entity instanceof LivingEntity) { && entity instanceof LivingEntity) {
miscDisguises++; miscDisguises++;