Fixed dmodradius command having the wrong implementation
This commit is contained in:
parent
3c812b7fd7
commit
59a73ffcd2
@ -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()) {
|
||||
|
@ -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()) {
|
||||
|
@ -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()) {
|
||||
|
@ -24,15 +24,9 @@ import java.util.*;
|
||||
|
||||
public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements TabCompleter {
|
||||
private int maxRadius = 30;
|
||||
private ArrayList<Class<? extends Entity>> 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<Entity> 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<String> classes = new ArrayList<>();
|
||||
|
||||
for (Class c : validClasses) {
|
||||
classes.add(c.getSimpleName());
|
||||
for (DisguiseType type : DisguiseType.values()) {
|
||||
classes.add(type.toReadable());
|
||||
}
|
||||
|
||||
Collections.sort(classes);
|
||||
@ -80,32 +75,23 @@ 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) {
|
||||
if (baseType == null) {
|
||||
sender.sendMessage(LibsMsg.DMODRADIUS_UNRECOGNIZED.get(args[0]));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length == starting + 1) {
|
||||
sender.sendMessage(
|
||||
@ -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,29 +186,33 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
|
||||
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> perms = getPermissions(sender);
|
||||
|
||||
if (args.length == 0) {
|
||||
for (Class<? extends Entity> 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;
|
||||
|
||||
for (DisguiseType t : DisguiseType.values()) {
|
||||
if (t.toReadable().replaceAll(" ", "").equalsIgnoreCase(args[0].replaceAll("_", ""))) {
|
||||
starting = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Not a valid radius
|
||||
if (starting == 1 || args.length == 1 || !isNumeric(args[1]))
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
@ -61,24 +61,18 @@ public enum LibsMsg {
|
||||
DCLONE_SNEAKSPRINT("doSneakSprint"),
|
||||
DCLONE_SNEAK("doSneak"),
|
||||
DCLONE_SPRINT("doSprint"),
|
||||
DMODRADIUS_HELP2(
|
||||
(ChatColor.DARK_GREEN + "/disguisemodifyradius <DisguiseType" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")> <Radius> <Disguise Options>")
|
||||
.replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")),
|
||||
DMODRADIUS_HELP3(
|
||||
(ChatColor.DARK_GREEN + "/disguisemodifyradius <EntityType" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")> <Radius> player <Name>")
|
||||
.replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")),
|
||||
DMODRADIUS_HELP4(
|
||||
(ChatColor.DARK_GREEN + "/disguisemodifyradius <EntityType" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")> <Radius> <DisguiseType> <Baby" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")>")
|
||||
.replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")),
|
||||
DMODRADIUS_HELP5(
|
||||
(ChatColor.DARK_GREEN + "/disguisemodifyradius <EntityType" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")> <Radius> <Dropped_Item/Falling_Block> <Id> <Durability" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")>")
|
||||
.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!"),
|
||||
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user