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.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -126,9 +127,7 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter
|
|||||||
addMethods = false;
|
addMethods = false;
|
||||||
|
|
||||||
if (info.isEnums()) {
|
if (info.isEnums()) {
|
||||||
for (String e : info.getEnums(origArgs[origArgs.length - 1])) {
|
tabs.addAll(Arrays.asList(info.getEnums(origArgs[origArgs.length - 1])));
|
||||||
tabs.add(e);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (info.getParamClass() == String.class) {
|
if (info.getParamClass() == String.class) {
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
@ -21,6 +21,7 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -112,19 +113,18 @@ public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCom
|
|||||||
if (passesCheck(sender, perms.get(disguiseType), usedOptions)) {
|
if (passesCheck(sender, perms.get(disguiseType), usedOptions)) {
|
||||||
boolean addMethods = true;
|
boolean addMethods = true;
|
||||||
|
|
||||||
if (args.length > 1) {
|
if (args.length > 0) {
|
||||||
String prevArg = args[args.length - 1];
|
String prevArg = args[args.length - 1];
|
||||||
|
|
||||||
ParamInfo info = ReflectionFlagWatchers.getParamInfo(disguiseType, prevArg);
|
ParamInfo info = ReflectionFlagWatchers.getParamInfo(disguiseType, prevArg);
|
||||||
|
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
if (info.getParamClass() != boolean.class)
|
if (info.getParamClass() != boolean.class) {
|
||||||
addMethods = false;
|
addMethods = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (info.isEnums()) {
|
if (info.isEnums()) {
|
||||||
for (String e : info.getEnums(origArgs[origArgs.length - 1])) {
|
tabs.addAll(Arrays.asList(info.getEnums(origArgs[origArgs.length - 1])));
|
||||||
tabs.add(e);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (info.getParamClass() == String.class) {
|
if (info.getParamClass() == String.class) {
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
@ -17,6 +17,7 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -62,19 +63,18 @@ public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements
|
|||||||
for (DisguisePerm perm : perms.keySet()) {
|
for (DisguisePerm perm : perms.keySet()) {
|
||||||
boolean addMethods = true;
|
boolean addMethods = true;
|
||||||
|
|
||||||
if (args.length > 1) {
|
if (args.length > 0) {
|
||||||
String prevArg = args[args.length - 1];
|
String prevArg = args[args.length - 1];
|
||||||
|
|
||||||
ParamInfo info = ReflectionFlagWatchers.getParamInfo(perm.getType(), prevArg);
|
ParamInfo info = ReflectionFlagWatchers.getParamInfo(perm.getType(), prevArg);
|
||||||
|
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
if (info.getParamClass() != boolean.class)
|
if (info.getParamClass() != boolean.class) {
|
||||||
addMethods = false;
|
addMethods = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (info.isEnums()) {
|
if (info.isEnums()) {
|
||||||
for (String e : info.getEnums(origArgs[origArgs.length - 1])) {
|
tabs.addAll(Arrays.asList(info.getEnums(origArgs[origArgs.length - 1])));
|
||||||
tabs.add(e);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (info.getParamClass() == String.class) {
|
if (info.getParamClass() == String.class) {
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
@ -24,15 +24,9 @@ import java.util.*;
|
|||||||
|
|
||||||
public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements TabCompleter {
|
public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements TabCompleter {
|
||||||
private int maxRadius = 30;
|
private int maxRadius = 30;
|
||||||
private ArrayList<Class<? extends Entity>> validClasses = new ArrayList<>();
|
|
||||||
|
|
||||||
public DisguiseModifyRadiusCommand(int maxRadius) {
|
public DisguiseModifyRadiusCommand(int maxRadius) {
|
||||||
this.maxRadius = 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) {
|
private Collection<Entity> getNearbyEntities(CommandSender sender, int radius) {
|
||||||
@ -66,11 +60,12 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
|
|||||||
return true;
|
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<>();
|
ArrayList<String> classes = new ArrayList<>();
|
||||||
|
|
||||||
for (Class c : validClasses) {
|
for (DisguiseType type : DisguiseType.values()) {
|
||||||
classes.add(c.getSimpleName());
|
classes.add(type.toReadable());
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(classes);
|
Collections.sort(classes);
|
||||||
@ -80,32 +75,23 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Class entityClass = Entity.class;
|
DisguiseType baseType = null;
|
||||||
EntityType type = null;
|
|
||||||
int starting = 0;
|
int starting = 0;
|
||||||
|
|
||||||
if (!isNumeric(args[0])) {
|
if (!isNumeric(args[0])) {
|
||||||
for (Class c : validClasses) {
|
for (DisguiseType t : DisguiseType.values()) {
|
||||||
if (c.getSimpleName().equalsIgnoreCase(args[0])) {
|
if (t.toReadable().replaceAll(" ", "").equalsIgnoreCase(args[0].replaceAll("_", ""))) {
|
||||||
entityClass = c;
|
baseType = t;
|
||||||
starting = 1;
|
starting = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (starting == 0) {
|
if (baseType == null) {
|
||||||
try {
|
|
||||||
type = EntityType.valueOf(args[0].toUpperCase());
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == null) {
|
|
||||||
sender.sendMessage(LibsMsg.DMODRADIUS_UNRECOGNIZED.get(args[0]));
|
sender.sendMessage(LibsMsg.DMODRADIUS_UNRECOGNIZED.get(args[0]));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (args.length == starting + 1) {
|
if (args.length == starting + 1) {
|
||||||
sender.sendMessage(
|
sender.sendMessage(
|
||||||
@ -145,7 +131,7 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type != null ? entity.getType() != type : !entityClass.isAssignableFrom(entity.getClass())) {
|
if (baseType != null && !baseType.name().equalsIgnoreCase(entity.getType().name())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,29 +186,33 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
|
|||||||
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> perms = getPermissions(sender);
|
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> perms = getPermissions(sender);
|
||||||
|
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
for (Class<? extends Entity> entityClass : validClasses) {
|
for (DisguiseType type : DisguiseType.values()) {
|
||||||
tabs.add(entityClass.getSimpleName());
|
tabs.add(type.toReadable().replaceAll(" ", "_"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return filterTabs(tabs, origArgs);
|
return filterTabs(tabs, origArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
int starting = 1;
|
int starting = 0;
|
||||||
|
|
||||||
if (!isNumeric(args[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;
|
starting = 2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Not a valid radius
|
// Not a valid radius
|
||||||
if (starting == 1 || args.length == 1 || !isNumeric(args[1]))
|
if (starting == 1 || args.length == 1 || !isNumeric(args[1]))
|
||||||
return filterTabs(tabs, origArgs);
|
return filterTabs(tabs, origArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isNumeric(args[starting])) {
|
||||||
|
return filterTabs(tabs, origArgs);
|
||||||
|
}
|
||||||
|
|
||||||
int radius = Integer.parseInt(args[starting]);
|
int radius = Integer.parseInt(args[starting]);
|
||||||
|
|
||||||
if (radius > maxRadius) {
|
if (radius > maxRadius) {
|
||||||
@ -242,7 +232,7 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
|
|||||||
|
|
||||||
for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) {
|
for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) {
|
||||||
for (String arg : args) {
|
for (String arg : args) {
|
||||||
if (!method.getName().equalsIgnoreCase(arg))
|
if (!method.getName().equalsIgnoreCase(arg) || usedOptions.contains(arg))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
usedOptions.add(arg);
|
usedOptions.add(arg);
|
||||||
@ -262,9 +252,7 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
|
|||||||
addMethods = false;
|
addMethods = false;
|
||||||
|
|
||||||
if (info.isEnums()) {
|
if (info.isEnums()) {
|
||||||
for (String e : info.getEnums(origArgs[origArgs.length - 1])) {
|
tabs.addAll(Arrays.asList(info.getEnums(origArgs[origArgs.length - 1])));
|
||||||
tabs.add(e);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (info.getParamClass() == String.class) {
|
if (info.getParamClass() == String.class) {
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
@ -300,18 +288,7 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
|
|||||||
sender.sendMessage(LibsMsg.DMODIFY_HELP3
|
sender.sendMessage(LibsMsg.DMODIFY_HELP3
|
||||||
.get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)));
|
.get(ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)));
|
||||||
|
|
||||||
String optional = ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")";
|
sender.sendMessage(LibsMsg.DMODRADIUS_HELP2.get());
|
||||||
|
sender.sendMessage(LibsMsg.DMODRADIUS_HELP3.get());
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,24 +61,18 @@ public enum LibsMsg {
|
|||||||
DCLONE_SNEAKSPRINT("doSneakSprint"),
|
DCLONE_SNEAKSPRINT("doSneakSprint"),
|
||||||
DCLONE_SNEAK("doSneak"),
|
DCLONE_SNEAK("doSneak"),
|
||||||
DCLONE_SPRINT("doSprint"),
|
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(
|
DMODRADIUS_HELP3(
|
||||||
(ChatColor.DARK_GREEN + "/disguisemodifyradius <EntityType" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")> <Radius> player <Name>")
|
ChatColor.DARK_GREEN + "See the DisguiseType's usable by " + ChatColor.GREEN + "/disguisemodifyradius DisguiseType"),
|
||||||
.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"),
|
|
||||||
DMODRADIUS_NEEDOPTIONS(ChatColor.RED + "You need to supply the disguise options as well as the radius"),
|
DMODRADIUS_NEEDOPTIONS(ChatColor.RED + "You need to supply the disguise options as well as the radius"),
|
||||||
DMODRADIUS_NEEDOPTIONS_ENTITY(
|
DMODRADIUS_NEEDOPTIONS_ENTITY(
|
||||||
ChatColor.RED + "You need to supply the disguise options as well as the radius and EntityType"),
|
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_NOENTS(ChatColor.RED + "Couldn't find any disguised entities!"),
|
||||||
DMODRADIUS_NOPERM(ChatColor.RED + "No permission to modify %s disguises!"),
|
DMODRADIUS_NOPERM(ChatColor.RED + "No permission to modify %s disguises!"),
|
||||||
DMODRADIUS_UNRECOGNIZED(ChatColor.RED + "Unrecognised EntityType %s"),
|
DMODRADIUS_UNRECOGNIZED(ChatColor.RED + "Unrecognised DisguiseType %s"),
|
||||||
DMODRADIUS_USABLE(ChatColor.DARK_GREEN + "EntityTypes usable are: %s" + ChatColor.DARK_GREEN + "."),
|
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"),
|
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_ENTITIES(ChatColor.DARK_GREEN + "EntityTypes usable are: %s"),
|
||||||
DRADIUS_HELP1(ChatColor.DARK_GREEN + "Disguise all entities in a radius! Caps at %s blocks!"),
|
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("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()) {
|
for (LibsMsg msg : LibsMsg.values()) {
|
||||||
TranslateType.MESSAGES.save(msg.getRaw());
|
TranslateType.MESSAGES.save(msg.getRaw());
|
||||||
|
Loading…
Reference in New Issue
Block a user