diff --git a/src/me/libraryaddict/disguise/commands/DisguiseCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseCommand.java index 831cb990..5f28ddb7 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseCommand.java @@ -25,6 +25,7 @@ import org.bukkit.entity.Player; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -126,9 +127,7 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter addMethods = false; if (info.isEnums()) { - for (String e : info.getEnums(origArgs[origArgs.length - 1])) { - tabs.add(e); - } + tabs.addAll(Arrays.asList(info.getEnums(origArgs[origArgs.length - 1]))); } else { if (info.getParamClass() == String.class) { for (Player player : Bukkit.getOnlinePlayers()) { diff --git a/src/me/libraryaddict/disguise/commands/DisguiseModifyCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseModifyCommand.java index db33f34e..ae33c414 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseModifyCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseModifyCommand.java @@ -21,6 +21,7 @@ import org.bukkit.entity.Player; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -112,19 +113,18 @@ public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCom if (passesCheck(sender, perms.get(disguiseType), usedOptions)) { boolean addMethods = true; - if (args.length > 1) { + if (args.length > 0) { String prevArg = args[args.length - 1]; ParamInfo info = ReflectionFlagWatchers.getParamInfo(disguiseType, prevArg); if (info != null) { - if (info.getParamClass() != boolean.class) + if (info.getParamClass() != boolean.class) { addMethods = false; + } if (info.isEnums()) { - for (String e : info.getEnums(origArgs[origArgs.length - 1])) { - tabs.add(e); - } + tabs.addAll(Arrays.asList(info.getEnums(origArgs[origArgs.length - 1]))); } else { if (info.getParamClass() == String.class) { for (Player player : Bukkit.getOnlinePlayers()) { diff --git a/src/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java index d4cb0d43..6712b24f 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseModifyEntityCommand.java @@ -17,6 +17,7 @@ import org.bukkit.entity.Player; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -62,19 +63,18 @@ public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements for (DisguisePerm perm : perms.keySet()) { boolean addMethods = true; - if (args.length > 1) { + if (args.length > 0) { String prevArg = args[args.length - 1]; ParamInfo info = ReflectionFlagWatchers.getParamInfo(perm.getType(), prevArg); if (info != null) { - if (info.getParamClass() != boolean.class) + if (info.getParamClass() != boolean.class) { addMethods = false; + } if (info.isEnums()) { - for (String e : info.getEnums(origArgs[origArgs.length - 1])) { - tabs.add(e); - } + tabs.addAll(Arrays.asList(info.getEnums(origArgs[origArgs.length - 1]))); } else { if (info.getParamClass() == String.class) { for (Player player : Bukkit.getOnlinePlayers()) { diff --git a/src/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java index 6cc2462e..f0b4d9c8 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseModifyRadiusCommand.java @@ -24,15 +24,9 @@ import java.util.*; public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements TabCompleter { private int maxRadius = 30; - private ArrayList> validClasses = new ArrayList<>(); public DisguiseModifyRadiusCommand(int maxRadius) { this.maxRadius = maxRadius; - for (Class c : ClassGetter.getClassesForPackage("org.bukkit.entity")) { - if (c != Entity.class && Entity.class.isAssignableFrom(c) && c.getAnnotation(Deprecated.class) == null) { - validClasses.add(c); - } - } } private Collection getNearbyEntities(CommandSender sender, int radius) { @@ -66,11 +60,12 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements return true; } - if (args[0].equalsIgnoreCase("entitytype") || args[0].equalsIgnoreCase("entitytypes")) { + if (args[0].equalsIgnoreCase(TranslateType.DISGUISES.get("DisguiseType")) || args[0] + .equalsIgnoreCase(TranslateType.DISGUISES.get("DisguiseType") + "s")) { ArrayList classes = new ArrayList<>(); - for (Class c : validClasses) { - classes.add(c.getSimpleName()); + for (DisguiseType type : DisguiseType.values()) { + classes.add(type.toReadable()); } Collections.sort(classes); @@ -80,30 +75,21 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements return true; } - Class entityClass = Entity.class; - EntityType type = null; + DisguiseType baseType = null; int starting = 0; if (!isNumeric(args[0])) { - for (Class c : validClasses) { - if (c.getSimpleName().equalsIgnoreCase(args[0])) { - entityClass = c; + for (DisguiseType t : DisguiseType.values()) { + if (t.toReadable().replaceAll(" ", "").equalsIgnoreCase(args[0].replaceAll("_", ""))) { + baseType = t; starting = 1; break; } } - if (starting == 0) { - try { - type = EntityType.valueOf(args[0].toUpperCase()); - } - catch (Exception ex) { - } - - if (type == null) { - sender.sendMessage(LibsMsg.DMODRADIUS_UNRECOGNIZED.get(args[0])); - return true; - } + if (baseType == null) { + sender.sendMessage(LibsMsg.DMODRADIUS_UNRECOGNIZED.get(args[0])); + return true; } } @@ -145,7 +131,7 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements continue; } - if (type != null ? entity.getType() != type : !entityClass.isAssignableFrom(entity.getClass())) { + if (baseType != null && !baseType.name().equalsIgnoreCase(entity.getType().name())) { continue; } @@ -200,22 +186,22 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements HashMap, Boolean>> perms = getPermissions(sender); if (args.length == 0) { - for (Class entityClass : validClasses) { - tabs.add(entityClass.getSimpleName()); + for (DisguiseType type : DisguiseType.values()) { + tabs.add(type.toReadable().replaceAll(" ", "_")); } return filterTabs(tabs, origArgs); } - int starting = 1; + int starting = 0; if (!isNumeric(args[0])) { - for (Class c : validClasses) { - if (!c.getSimpleName().equalsIgnoreCase(args[0])) - continue; - starting = 2; - break; + for (DisguiseType t : DisguiseType.values()) { + if (t.toReadable().replaceAll(" ", "").equalsIgnoreCase(args[0].replaceAll("_", ""))) { + starting = 2; + break; + } } // Not a valid radius @@ -223,6 +209,10 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements return filterTabs(tabs, origArgs); } + if (!isNumeric(args[starting])) { + return filterTabs(tabs, origArgs); + } + int radius = Integer.parseInt(args[starting]); if (radius > maxRadius) { @@ -242,7 +232,7 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { for (String arg : args) { - if (!method.getName().equalsIgnoreCase(arg)) + if (!method.getName().equalsIgnoreCase(arg) || usedOptions.contains(arg)) continue; usedOptions.add(arg); @@ -262,9 +252,7 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements addMethods = false; if (info.isEnums()) { - for (String e : info.getEnums(origArgs[origArgs.length - 1])) { - tabs.add(e); - } + tabs.addAll(Arrays.asList(info.getEnums(origArgs[origArgs.length - 1]))); } else { if (info.getParamClass() == String.class) { for (Player player : Bukkit.getOnlinePlayers()) { @@ -300,18 +288,7 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements sender.sendMessage(LibsMsg.DMODIFY_HELP3 .get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN))); - String optional = ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")"; - - if (allowedDisguises.contains("player")) { - sender.sendMessage(LibsMsg.DRADIUS_HELP3.get()); - } - - sender.sendMessage(LibsMsg.DMODRADIUS_HELP4.get()); - - if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { - sender.sendMessage(LibsMsg.DMODRADIUS_HELP5.get()); - } - - sender.sendMessage(LibsMsg.DMODRADIUS_HELP6.get()); + sender.sendMessage(LibsMsg.DMODRADIUS_HELP2.get()); + sender.sendMessage(LibsMsg.DMODRADIUS_HELP3.get()); } } diff --git a/src/me/libraryaddict/disguise/utilities/LibsMsg.java b/src/me/libraryaddict/disguise/utilities/LibsMsg.java index 0eb905ea..1fdf200b 100644 --- a/src/me/libraryaddict/disguise/utilities/LibsMsg.java +++ b/src/me/libraryaddict/disguise/utilities/LibsMsg.java @@ -61,24 +61,18 @@ public enum LibsMsg { DCLONE_SNEAKSPRINT("doSneakSprint"), DCLONE_SNEAK("doSneak"), DCLONE_SPRINT("doSprint"), + DMODRADIUS_HELP2( + (ChatColor.DARK_GREEN + "/disguisemodifyradius ") + .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), DMODRADIUS_HELP3( - (ChatColor.DARK_GREEN + "/disguisemodifyradius player ") - .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), - DMODRADIUS_HELP4( - (ChatColor.DARK_GREEN + "/disguisemodifyradius ") - .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), - DMODRADIUS_HELP5( - (ChatColor.DARK_GREEN + "/disguisemodifyradius ") - .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), - DMODRADIUS_HELP6( - ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguisemodifyradius EntityTypes"), + ChatColor.DARK_GREEN + "See the DisguiseType's usable by " + ChatColor.GREEN + "/disguisemodifyradius DisguiseType"), DMODRADIUS_NEEDOPTIONS(ChatColor.RED + "You need to supply the disguise options as well as the radius"), DMODRADIUS_NEEDOPTIONS_ENTITY( ChatColor.RED + "You need to supply the disguise options as well as the radius and EntityType"), DMODRADIUS_NOENTS(ChatColor.RED + "Couldn't find any disguised entities!"), DMODRADIUS_NOPERM(ChatColor.RED + "No permission to modify %s disguises!"), - DMODRADIUS_UNRECOGNIZED(ChatColor.RED + "Unrecognised EntityType %s"), - DMODRADIUS_USABLE(ChatColor.DARK_GREEN + "EntityTypes usable are: %s" + ChatColor.DARK_GREEN + "."), + DMODRADIUS_UNRECOGNIZED(ChatColor.RED + "Unrecognised DisguiseType %s"), + DMODRADIUS_USABLE(ChatColor.DARK_GREEN + "DisguiseTypes usable are: %s" + ChatColor.DARK_GREEN + "."), DPLAYER_SUPPLY(ChatColor.RED + "You need to supply a disguise as well as the player"), DRADIUS_ENTITIES(ChatColor.DARK_GREEN + "EntityTypes usable are: %s"), DRADIUS_HELP1(ChatColor.DARK_GREEN + "Disguise all entities in a radius! Caps at %s blocks!"), diff --git a/src/me/libraryaddict/disguise/utilities/TranslateFiller.java b/src/me/libraryaddict/disguise/utilities/TranslateFiller.java index ec9b89a3..02ba6f51 100644 --- a/src/me/libraryaddict/disguise/utilities/TranslateFiller.java +++ b/src/me/libraryaddict/disguise/utilities/TranslateFiller.java @@ -69,6 +69,8 @@ public class TranslateFiller { } TranslateType.DISGUISES.save("EntityType", "Used for the disgiuse radius command to list all entitytypes"); + TranslateType.DISGUISES.save("DisgiseType", "Used for the disgiuse modify radius command to list all " + + "disguisetypes"); for (LibsMsg msg : LibsMsg.values()) { TranslateType.MESSAGES.save(msg.getRaw());