mirror of
https://github.com/libraryaddict/LibsDisguises.git
synced 2024-09-11 01:38:07 +02:00
Always have an entry for every DisguisePerm
This commit is contained in:
parent
d9c5a5f29e
commit
49f24c14b2
@ -127,17 +127,15 @@ public class DisguiseParser {
|
|||||||
if (permName == null) {
|
if (permName == null) {
|
||||||
if (other.permName != null)
|
if (other.permName != null)
|
||||||
return false;
|
return false;
|
||||||
}
|
} else if (!permName.equals(other.permName))
|
||||||
|
|
||||||
else if (!permName.equals(other.permName))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Object callValueOf(Class<?> param, String valueString, String methodName, String description)
|
private static Object callValueOf(Class<?> param, String valueString, String methodName,
|
||||||
throws DisguiseParseException {
|
String description) throws DisguiseParseException {
|
||||||
Object value;
|
Object value;
|
||||||
try {
|
try {
|
||||||
value = param.getMethod("valueOf", String.class).invoke(null, valueString.toUpperCase());
|
value = param.getMethod("valueOf", String.class).invoke(null, valueString.toUpperCase());
|
||||||
@ -153,41 +151,43 @@ public class DisguiseParser {
|
|||||||
|
|
||||||
if (!passesCheck(sender, optionPermissions, usedOptions)) {
|
if (!passesCheck(sender, optionPermissions, usedOptions)) {
|
||||||
throw new DisguiseParseException(
|
throw new DisguiseParseException(
|
||||||
ChatColor.RED + "You do not have permission to use the option " + usedOptions.get(usedOptions.size() - 1));
|
ChatColor.RED + "You do not have permission to use the option " + usedOptions.get(
|
||||||
|
usedOptions.size() - 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HashMap<String, Boolean> getDisguiseOptions(CommandSender sender, String permNode, DisguisePerm type) {
|
private static HashMap<String, Boolean> getDisguiseOptions(CommandSender sender, String permNode,
|
||||||
|
DisguisePerm type) {
|
||||||
switch (type.getType()) {
|
switch (type.getType()) {
|
||||||
case PLAYER:
|
case PLAYER:
|
||||||
case FALLING_BLOCK:
|
case FALLING_BLOCK:
|
||||||
case PAINTING:
|
case PAINTING:
|
||||||
case SPLASH_POTION:
|
case SPLASH_POTION:
|
||||||
case FISHING_HOOK:
|
case FISHING_HOOK:
|
||||||
case DROPPED_ITEM:
|
case DROPPED_ITEM:
|
||||||
HashMap<String, Boolean> returns = new HashMap<>();
|
HashMap<String, Boolean> returns = new HashMap<>();
|
||||||
|
|
||||||
String beginning = "libsdisguises.options." + permNode + ".";
|
String beginning = "libsdisguises.options." + permNode + ".";
|
||||||
|
|
||||||
for (PermissionAttachmentInfo permission : sender.getEffectivePermissions()) {
|
for (PermissionAttachmentInfo permission : sender.getEffectivePermissions()) {
|
||||||
String lowerPerm = permission.getPermission().toLowerCase();
|
String lowerPerm = permission.getPermission().toLowerCase();
|
||||||
|
|
||||||
if (lowerPerm.startsWith(beginning)) {
|
if (lowerPerm.startsWith(beginning)) {
|
||||||
String[] split = lowerPerm.substring(beginning.length()).split("\\.");
|
String[] split = lowerPerm.substring(beginning.length()).split("\\.");
|
||||||
|
|
||||||
if (split.length > 1) {
|
if (split.length > 1) {
|
||||||
if (split[0].replace("_", "").equals(type.name().toLowerCase().replace("_", ""))) {
|
if (split[0].replace("_", "").equals(type.name().toLowerCase().replace("_", ""))) {
|
||||||
for (int i = 1; i < split.length; i++) {
|
for (int i = 1; i < split.length; i++) {
|
||||||
returns.put(split[i], permission.getValue());
|
returns.put(split[i], permission.getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return returns;
|
return returns;
|
||||||
default:
|
default:
|
||||||
return new HashMap<>();
|
return new HashMap<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,16 +297,14 @@ public class DisguiseParser {
|
|||||||
|
|
||||||
if (singleDisguises.containsKey(dPerm)) {
|
if (singleDisguises.containsKey(dPerm)) {
|
||||||
list = singleDisguises.get(dPerm);
|
list = singleDisguises.get(dPerm);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
list = new HashMap<>();
|
list = new HashMap<>();
|
||||||
singleDisguises.put(dPerm, list);
|
singleDisguises.put(dPerm, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
HashMap<ArrayList<String>, Boolean> map1 = getOptions(perm);
|
HashMap<ArrayList<String>, Boolean> map1 = getOptions(perm);
|
||||||
list.put(map1.keySet().iterator().next(), map1.values().iterator().next());
|
list.put(map1.keySet().iterator().next(), map1.values().iterator().next());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
for (DisguisePerm type : getDisguisePerms()) {
|
for (DisguisePerm type : getDisguisePerms()) {
|
||||||
HashMap<ArrayList<String>, Boolean> options = null;
|
HashMap<ArrayList<String>, Boolean> options = null;
|
||||||
Class entityClass = type.getEntityClass();
|
Class entityClass = type.getEntityClass();
|
||||||
@ -315,28 +313,23 @@ public class DisguiseParser {
|
|||||||
if (type.isMob()) {
|
if (type.isMob()) {
|
||||||
options = getOptions(perm);
|
options = getOptions(perm);
|
||||||
}
|
}
|
||||||
}
|
} else if (disguiseType.equals("animal") || disguiseType.equals("animals")) {
|
||||||
else if (disguiseType.equals("animal") || disguiseType.equals("animals")) {
|
|
||||||
if (Animals.class.isAssignableFrom(entityClass)) {
|
if (Animals.class.isAssignableFrom(entityClass)) {
|
||||||
options = getOptions(perm);
|
options = getOptions(perm);
|
||||||
}
|
}
|
||||||
}
|
} else if (disguiseType.equals("monster") || disguiseType.equals("monsters")) {
|
||||||
else if (disguiseType.equals("monster") || disguiseType.equals("monsters")) {
|
|
||||||
if (Monster.class.isAssignableFrom(entityClass)) {
|
if (Monster.class.isAssignableFrom(entityClass)) {
|
||||||
options = getOptions(perm);
|
options = getOptions(perm);
|
||||||
}
|
}
|
||||||
}
|
} else if (disguiseType.equals("misc")) {
|
||||||
else if (disguiseType.equals("misc")) {
|
|
||||||
if (type.isMisc()) {
|
if (type.isMisc()) {
|
||||||
options = getOptions(perm);
|
options = getOptions(perm);
|
||||||
}
|
}
|
||||||
}
|
} else if (disguiseType.equals("ageable")) {
|
||||||
else if (disguiseType.equals("ageable")) {
|
|
||||||
if (Ageable.class.isAssignableFrom(entityClass)) {
|
if (Ageable.class.isAssignableFrom(entityClass)) {
|
||||||
options = getOptions(perm);
|
options = getOptions(perm);
|
||||||
}
|
}
|
||||||
}
|
} else if (disguiseType.equals("*")) {
|
||||||
else if (disguiseType.equals("*")) {
|
|
||||||
options = getOptions(perm);
|
options = getOptions(perm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -345,8 +338,7 @@ public class DisguiseParser {
|
|||||||
|
|
||||||
if (rangeDisguises.containsKey(type)) {
|
if (rangeDisguises.containsKey(type)) {
|
||||||
list = rangeDisguises.get(type);
|
list = rangeDisguises.get(type);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
list = new HashMap<>();
|
list = new HashMap<>();
|
||||||
rangeDisguises.put(type, list);
|
rangeDisguises.put(type, list);
|
||||||
}
|
}
|
||||||
@ -370,48 +362,47 @@ public class DisguiseParser {
|
|||||||
if (dType != null) {
|
if (dType != null) {
|
||||||
singleDisguises.remove(dType);
|
singleDisguises.remove(dType);
|
||||||
rangeDisguises.remove(dType);
|
rangeDisguises.remove(dType);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
for (DisguisePerm type : getDisguisePerms()) {
|
for (DisguisePerm type : getDisguisePerms()) {
|
||||||
boolean foundHim = false;
|
boolean foundHim = false;
|
||||||
Class entityClass = type.getEntityClass();
|
Class entityClass = type.getEntityClass();
|
||||||
|
|
||||||
switch (disguiseType) {
|
switch (disguiseType) {
|
||||||
case "mob":
|
case "mob":
|
||||||
if (type.isMob()) {
|
if (type.isMob()) {
|
||||||
foundHim = true;
|
foundHim = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "animal":
|
case "animal":
|
||||||
case "animals":
|
case "animals":
|
||||||
if (Animals.class.isAssignableFrom(entityClass)) {
|
if (Animals.class.isAssignableFrom(entityClass)) {
|
||||||
foundHim = true;
|
foundHim = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "monster":
|
case "monster":
|
||||||
case "monsters":
|
case "monsters":
|
||||||
if (Monster.class.isAssignableFrom(entityClass)) {
|
if (Monster.class.isAssignableFrom(entityClass)) {
|
||||||
foundHim = true;
|
foundHim = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "misc":
|
case "misc":
|
||||||
if (type.isMisc()) {
|
if (type.isMisc()) {
|
||||||
foundHim = true;
|
foundHim = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "ageable":
|
case "ageable":
|
||||||
if (Ageable.class.isAssignableFrom(entityClass)) {
|
if (Ageable.class.isAssignableFrom(entityClass)) {
|
||||||
foundHim = true;
|
foundHim = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "*":
|
case "*":
|
||||||
foundHim = true;
|
foundHim = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foundHim) {
|
if (foundHim) {
|
||||||
@ -435,9 +426,7 @@ public class DisguiseParser {
|
|||||||
temp.putAll(rangeDisguises.get(type));
|
temp.putAll(rangeDisguises.get(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!temp.isEmpty()) {
|
map.put(type, temp);
|
||||||
map.put(type, temp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
@ -477,8 +466,7 @@ public class DisguiseParser {
|
|||||||
* @throws java.lang.reflect.InvocationTargetException
|
* @throws java.lang.reflect.InvocationTargetException
|
||||||
*/
|
*/
|
||||||
public static Disguise parseDisguise(CommandSender sender, String permNode, String[] args,
|
public static Disguise parseDisguise(CommandSender sender, String permNode, String[] args,
|
||||||
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> permissionMap)
|
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> permissionMap) throws DisguiseParseException, IllegalAccessException, InvocationTargetException {
|
||||||
throws DisguiseParseException, IllegalAccessException, InvocationTargetException {
|
|
||||||
if (permissionMap.isEmpty()) {
|
if (permissionMap.isEmpty()) {
|
||||||
throw new DisguiseParseException(ChatColor.RED + "You are forbidden to use this command.");
|
throw new DisguiseParseException(ChatColor.RED + "You are forbidden to use this command.");
|
||||||
}
|
}
|
||||||
@ -500,24 +488,23 @@ public class DisguiseParser {
|
|||||||
disguise = DisguiseUtilities.getClonedDisguise(args[0].toLowerCase());
|
disguise = DisguiseUtilities.getClonedDisguise(args[0].toLowerCase());
|
||||||
|
|
||||||
if (disguise == null) {
|
if (disguise == null) {
|
||||||
throw new DisguiseParseException(ChatColor.RED + "Cannot find a disguise under the reference " + args[0]);
|
throw new DisguiseParseException(
|
||||||
|
ChatColor.RED + "Cannot find a disguise under the reference " + args[0]);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
throw new DisguiseParseException(
|
||||||
throw new DisguiseParseException(ChatColor.RED + "You do not have perimssion to use disguise references!");
|
ChatColor.RED + "You do not have perimssion to use disguise references!");
|
||||||
}
|
}
|
||||||
|
|
||||||
optionPermissions = (permissionMap.containsKey(disguise.getType()) ? permissionMap.get(disguise.getType())
|
optionPermissions = (permissionMap.containsKey(disguise.getType()) ? permissionMap.get(disguise.getType()) :
|
||||||
: new HashMap<ArrayList<String>, Boolean>());
|
new HashMap<ArrayList<String>, Boolean>());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
DisguisePerm disguisePerm = getDisguisePerm(args[0]);
|
DisguisePerm disguisePerm = getDisguisePerm(args[0]);
|
||||||
Entry<String, Disguise> customDisguise = DisguiseConfig.getCustomDisguise(args[0]);
|
Entry<String, Disguise> customDisguise = DisguiseConfig.getCustomDisguise(args[0]);
|
||||||
|
|
||||||
if (customDisguise != null) {
|
if (customDisguise != null) {
|
||||||
disguise = customDisguise.getValue().clone();
|
disguise = customDisguise.getValue().clone();
|
||||||
}
|
} else if (args[0].equalsIgnoreCase("p")) {
|
||||||
else if (args[0].equalsIgnoreCase("p")) {
|
|
||||||
disguisePerm = new DisguisePerm(DisguiseType.PLAYER);
|
disguisePerm = new DisguisePerm(DisguiseType.PLAYER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -527,7 +514,8 @@ public class DisguiseParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (disguisePerm.isUnknown()) {
|
if (disguisePerm.isUnknown()) {
|
||||||
throw new DisguiseParseException(ChatColor.RED + "Error! You cannot disguise as " + ChatColor.GREEN + "Unknown!");
|
throw new DisguiseParseException(
|
||||||
|
ChatColor.RED + "Error! You cannot disguise as " + ChatColor.GREEN + "Unknown!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (disguisePerm.getEntityType() == null) {
|
if (disguisePerm.getEntityType() == null) {
|
||||||
@ -548,10 +536,9 @@ public class DisguiseParser {
|
|||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
// He needs to give the player name
|
// He needs to give the player name
|
||||||
throw new DisguiseParseException(ChatColor.RED + "Error! You need to give a player name!");
|
throw new DisguiseParseException(ChatColor.RED + "Error! You need to give a player name!");
|
||||||
}
|
} else {
|
||||||
else {
|
if (!disguiseOptions.isEmpty() && (!disguiseOptions.containsKey(
|
||||||
if (!disguiseOptions.isEmpty() && (!disguiseOptions.containsKey(args[1].toLowerCase())
|
args[1].toLowerCase()) || !disguiseOptions.get(args[1].toLowerCase()))) {
|
||||||
|| !disguiseOptions.get(args[1].toLowerCase()))) {
|
|
||||||
throw new DisguiseParseException(
|
throw new DisguiseParseException(
|
||||||
ChatColor.RED + "Error! You don't have permission to use that name!");
|
ChatColor.RED + "Error! You don't have permission to use that name!");
|
||||||
}
|
}
|
||||||
@ -562,8 +549,7 @@ public class DisguiseParser {
|
|||||||
disguise = new PlayerDisguise(ChatColor.translateAlternateColorCodes('&', args[1]));
|
disguise = new PlayerDisguise(ChatColor.translateAlternateColorCodes('&', args[1]));
|
||||||
toSkip++;
|
toSkip++;
|
||||||
}
|
}
|
||||||
}
|
} else if (disguisePerm.isMob()) { // Its a mob, use the mob constructor
|
||||||
else if (disguisePerm.isMob()) { // Its a mob, use the mob constructor
|
|
||||||
boolean adult = true;
|
boolean adult = true;
|
||||||
|
|
||||||
if (args.length > 1) {
|
if (args.length > 1) {
|
||||||
@ -577,8 +563,7 @@ public class DisguiseParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
disguise = new MobDisguise(disguisePerm.getType(), adult);
|
disguise = new MobDisguise(disguisePerm.getType(), adult);
|
||||||
}
|
} else if (disguisePerm.isMisc()) {
|
||||||
else if (disguisePerm.isMisc()) {
|
|
||||||
// Its a misc, we are going to use the MiscDisguise constructor.
|
// Its a misc, we are going to use the MiscDisguise constructor.
|
||||||
int miscId = -1;
|
int miscId = -1;
|
||||||
int miscData = -1;
|
int miscData = -1;
|
||||||
@ -597,10 +582,8 @@ public class DisguiseParser {
|
|||||||
|
|
||||||
if (isNumeric(args[1])) {
|
if (isNumeric(args[1])) {
|
||||||
miscId = Integer.parseInt(args[1]);
|
miscId = Integer.parseInt(args[1]);
|
||||||
}
|
} else {
|
||||||
else {
|
if (disguisePerm.getType() == DisguiseType.FALLING_BLOCK || disguisePerm.getType() == DisguiseType.DROPPED_ITEM) {
|
||||||
if (disguisePerm.getType() == DisguiseType.FALLING_BLOCK
|
|
||||||
|| disguisePerm.getType() == DisguiseType.DROPPED_ITEM) {
|
|
||||||
for (Material mat : Material.values()) {
|
for (Material mat : Material.values()) {
|
||||||
if (mat.name().replace("_", "").equalsIgnoreCase(args[1].replace("_", ""))) {
|
if (mat.name().replace("_", "").equalsIgnoreCase(args[1].replace("_", ""))) {
|
||||||
miscId = mat.getId();
|
miscId = mat.getId();
|
||||||
@ -611,21 +594,21 @@ public class DisguiseParser {
|
|||||||
}
|
}
|
||||||
if (miscId != -1) {
|
if (miscId != -1) {
|
||||||
switch (disguisePerm.getType()) {
|
switch (disguisePerm.getType()) {
|
||||||
case PAINTING:
|
case PAINTING:
|
||||||
case FALLING_BLOCK:
|
case FALLING_BLOCK:
|
||||||
case SPLASH_POTION:
|
case SPLASH_POTION:
|
||||||
case DROPPED_ITEM:
|
case DROPPED_ITEM:
|
||||||
case FISHING_HOOK:
|
case FISHING_HOOK:
|
||||||
case ARROW:
|
case ARROW:
|
||||||
case TIPPED_ARROW:
|
case TIPPED_ARROW:
|
||||||
case SPECTRAL_ARROW:
|
case SPECTRAL_ARROW:
|
||||||
case SMALL_FIREBALL:
|
case SMALL_FIREBALL:
|
||||||
case FIREBALL:
|
case FIREBALL:
|
||||||
case WITHER_SKULL:
|
case WITHER_SKULL:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new DisguiseParseException(ChatColor.RED + "Error! " + disguisePerm.toReadable()
|
throw new DisguiseParseException(
|
||||||
+ " doesn't know what to do with " + args[1] + "!");
|
ChatColor.RED + "Error! " + disguisePerm.toReadable() + " doesn't know what to do with " + args[1] + "!");
|
||||||
}
|
}
|
||||||
toSkip++;
|
toSkip++;
|
||||||
// If they also defined a data value
|
// If they also defined a data value
|
||||||
@ -634,11 +617,9 @@ public class DisguiseParser {
|
|||||||
toSkip++;
|
toSkip++;
|
||||||
}
|
}
|
||||||
if (secondArg != null) {
|
if (secondArg != null) {
|
||||||
if (disguisePerm.getType() != DisguiseType.FALLING_BLOCK
|
if (disguisePerm.getType() != DisguiseType.FALLING_BLOCK && disguisePerm.getType() != DisguiseType.DROPPED_ITEM) {
|
||||||
&& disguisePerm.getType() != DisguiseType.DROPPED_ITEM) {
|
throw new DisguiseParseException(
|
||||||
throw new DisguiseParseException(ChatColor.RED + "Error! Only the disguises "
|
ChatColor.RED + "Error! Only the disguises " + DisguiseType.FALLING_BLOCK.toReadable() + " and " + DisguiseType.DROPPED_ITEM.toReadable() + " uses a second number!");
|
||||||
+ DisguiseType.FALLING_BLOCK.toReadable() + " and "
|
|
||||||
+ DisguiseType.DROPPED_ITEM.toReadable() + " uses a second number!");
|
|
||||||
}
|
}
|
||||||
miscData = Integer.parseInt(secondArg);
|
miscData = Integer.parseInt(secondArg);
|
||||||
}
|
}
|
||||||
@ -652,15 +633,13 @@ public class DisguiseParser {
|
|||||||
if (!disguiseOptions.containsKey(toCheck) || !disguiseOptions.get(toCheck)) {
|
if (!disguiseOptions.containsKey(toCheck) || !disguiseOptions.get(toCheck)) {
|
||||||
toCheck += ":0";
|
toCheck += ":0";
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
toCheck += ":" + miscData;
|
toCheck += ":" + miscData;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!disguiseOptions.containsKey(toCheck) || !disguiseOptions.get(toCheck)) {
|
if (!disguiseOptions.containsKey(toCheck) || !disguiseOptions.get(toCheck)) {
|
||||||
throw new DisguiseParseException(
|
throw new DisguiseParseException(
|
||||||
ChatColor.RED + "Error! You do not have permission to use the parameter " + toCheck
|
ChatColor.RED + "Error! You do not have permission to use the parameter " + toCheck + " on the " + disguisePerm.toReadable() + " disguise!");
|
||||||
+ " on the " + disguisePerm.toReadable() + " disguise!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -669,13 +648,11 @@ public class DisguiseParser {
|
|||||||
usedOptions.add("setblock");
|
usedOptions.add("setblock");
|
||||||
|
|
||||||
doCheck(sender, optionPermissions, usedOptions);
|
doCheck(sender, optionPermissions, usedOptions);
|
||||||
}
|
} else if (disguisePerm.getType() == DisguiseType.PAINTING) {
|
||||||
else if (disguisePerm.getType() == DisguiseType.PAINTING) {
|
|
||||||
usedOptions.add("setpainting");
|
usedOptions.add("setpainting");
|
||||||
|
|
||||||
doCheck(sender, optionPermissions, usedOptions);
|
doCheck(sender, optionPermissions, usedOptions);
|
||||||
}
|
} else if (disguisePerm.getType() == DisguiseType.SPLASH_POTION) {
|
||||||
else if (disguisePerm.getType() == DisguiseType.SPLASH_POTION) {
|
|
||||||
usedOptions.add("setpotionid");
|
usedOptions.add("setpotionid");
|
||||||
|
|
||||||
doCheck(sender, optionPermissions, usedOptions);
|
doCheck(sender, optionPermissions, usedOptions);
|
||||||
@ -697,9 +674,9 @@ public class DisguiseParser {
|
|||||||
return disguise;
|
return disguise;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void callMethods(CommandSender sender, Disguise disguise, HashMap<ArrayList<String>, Boolean> optionPermissions,
|
public static void callMethods(CommandSender sender, Disguise disguise,
|
||||||
ArrayList<String> usedOptions, String[] args)
|
HashMap<ArrayList<String>, Boolean> optionPermissions, ArrayList<String> usedOptions,
|
||||||
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, DisguiseParseException {
|
String[] args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, DisguiseParseException {
|
||||||
Method[] methods = ReflectionFlagWatchers.getDisguiseWatcherMethods(disguise.getWatcher().getClass());
|
Method[] methods = ReflectionFlagWatchers.getDisguiseWatcherMethods(disguise.getWatcher().getClass());
|
||||||
|
|
||||||
for (int i = 0; i < args.length; i += 2) {
|
for (int i = 0; i < args.length; i += 2) {
|
||||||
@ -729,44 +706,36 @@ public class DisguiseParser {
|
|||||||
// Parse to integer
|
// Parse to integer
|
||||||
if (isNumeric(valueString)) {
|
if (isNumeric(valueString)) {
|
||||||
value = Integer.parseInt(valueString);
|
value = Integer.parseInt(valueString);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
throw parseToException("number", valueString, methodName);
|
throw parseToException("number", valueString, methodName);
|
||||||
}
|
}
|
||||||
}
|
} else if (WrappedGameProfile.class == param && valueString.length() > 20) {
|
||||||
else if (WrappedGameProfile.class == param && valueString.length() > 20) {
|
|
||||||
try {
|
try {
|
||||||
value = ReflectionManager.parseGameProfile(valueString);
|
value = ReflectionManager.parseGameProfile(valueString);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
throw parseToException("gameprofile", valueString, methodName);
|
throw parseToException("gameprofile", valueString, methodName);
|
||||||
}
|
}
|
||||||
}
|
} else if (float.class == param || double.class == param) {
|
||||||
else if (float.class == param || double.class == param) {
|
|
||||||
// Parse to number
|
// Parse to number
|
||||||
if (isDouble(valueString)) {
|
if (isDouble(valueString)) {
|
||||||
float obj = Float.parseFloat(valueString);
|
float obj = Float.parseFloat(valueString);
|
||||||
if (param == float.class) {
|
if (param == float.class) {
|
||||||
value = obj;
|
value = obj;
|
||||||
}
|
} else if (param == double.class) {
|
||||||
else if (param == double.class) {
|
|
||||||
value = (double) obj;
|
value = (double) obj;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
throw parseToException("number.0", valueString, methodName);
|
throw parseToException("number.0", valueString, methodName);
|
||||||
}
|
}
|
||||||
}
|
} else if (param == String.class) {
|
||||||
else if (param == String.class) {
|
|
||||||
if (methodName.equalsIgnoreCase("setskin") && valueString.length() > 20) {
|
if (methodName.equalsIgnoreCase("setskin") && valueString.length() > 20) {
|
||||||
value = valueString;
|
value = valueString;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Parse to string
|
// Parse to string
|
||||||
value = ChatColor.translateAlternateColorCodes('&', valueString);
|
value = ChatColor.translateAlternateColorCodes('&', valueString);
|
||||||
}
|
}
|
||||||
}
|
} else if (param == AnimalColor.class) {
|
||||||
else if (param == AnimalColor.class) {
|
|
||||||
// Parse to animal color
|
// Parse to animal color
|
||||||
try {
|
try {
|
||||||
value = AnimalColor.valueOf(valueString.toUpperCase());
|
value = AnimalColor.valueOf(valueString.toUpperCase());
|
||||||
@ -774,16 +743,14 @@ public class DisguiseParser {
|
|||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
throw parseToException("animal color", valueString, methodName);
|
throw parseToException("animal color", valueString, methodName);
|
||||||
}
|
}
|
||||||
}
|
} else if (param == Llama.Color.class) {
|
||||||
else if (param == Llama.Color.class) {
|
|
||||||
try {
|
try {
|
||||||
value = Llama.Color.valueOf(valueString.toUpperCase());
|
value = Llama.Color.valueOf(valueString.toUpperCase());
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
throw parseToException("llama color", valueString, methodName);
|
throw parseToException("llama color", valueString, methodName);
|
||||||
}
|
}
|
||||||
}
|
} else if (param == ItemStack.class) {
|
||||||
else if (param == ItemStack.class) {
|
|
||||||
// Parse to itemstack
|
// Parse to itemstack
|
||||||
try {
|
try {
|
||||||
value = parseToItemstack(valueString);
|
value = parseToItemstack(valueString);
|
||||||
@ -791,8 +758,7 @@ public class DisguiseParser {
|
|||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
throw new DisguiseParseException(String.format(ex.getMessage(), methodName));
|
throw new DisguiseParseException(String.format(ex.getMessage(), methodName));
|
||||||
}
|
}
|
||||||
}
|
} else if (param == ItemStack[].class) {
|
||||||
else if (param == ItemStack[].class) {
|
|
||||||
// Parse to itemstack array
|
// Parse to itemstack array
|
||||||
ItemStack[] items = new ItemStack[4];
|
ItemStack[] items = new ItemStack[4];
|
||||||
|
|
||||||
@ -804,43 +770,37 @@ public class DisguiseParser {
|
|||||||
items[a] = parseToItemstack(split[a]);
|
items[a] = parseToItemstack(split[a]);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
throw parseToException("item ID,ID,ID,ID" + ChatColor.RED + " or " + ChatColor.GREEN
|
throw parseToException(
|
||||||
+ "ID:Data,ID:Data,ID:Data,ID:Data combo", valueString, methodName);
|
"item ID,ID,ID,ID" + ChatColor.RED + " or " + ChatColor.GREEN + "ID:Data,ID:Data,ID:Data,ID:Data combo",
|
||||||
|
valueString, methodName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
throw parseToException(
|
||||||
throw parseToException("item ID,ID,ID,ID" + ChatColor.RED + " or " + ChatColor.GREEN
|
"item ID,ID,ID,ID" + ChatColor.RED + " or " + ChatColor.GREEN + "ID:Data,ID:Data,ID:Data,ID:Data combo",
|
||||||
+ "ID:Data,ID:Data,ID:Data,ID:Data combo", valueString, methodName);
|
valueString, methodName);
|
||||||
}
|
}
|
||||||
|
|
||||||
value = items;
|
value = items;
|
||||||
}
|
} else if (param.getSimpleName().equals("Color")) {
|
||||||
else if (param.getSimpleName().equals("Color")) {
|
|
||||||
// Parse to horse color
|
// Parse to horse color
|
||||||
value = callValueOf(param, valueString, methodName, "a horse color");
|
value = callValueOf(param, valueString, methodName, "a horse color");
|
||||||
}
|
} else if (param.getSimpleName().equals("Style")) {
|
||||||
else if (param.getSimpleName().equals("Style")) {
|
|
||||||
// Parse to horse style
|
// Parse to horse style
|
||||||
value = callValueOf(param, valueString, methodName, "a horse style");
|
value = callValueOf(param, valueString, methodName, "a horse style");
|
||||||
}
|
} else if (param.getSimpleName().equals("Profession")) {
|
||||||
else if (param.getSimpleName().equals("Profession")) {
|
|
||||||
// Parse to villager profession
|
// Parse to villager profession
|
||||||
value = callValueOf(param, valueString, methodName, "a villager profession");
|
value = callValueOf(param, valueString, methodName, "a villager profession");
|
||||||
}
|
} else if (param.getSimpleName().equals("Art")) {
|
||||||
else if (param.getSimpleName().equals("Art")) {
|
|
||||||
// Parse to art type
|
// Parse to art type
|
||||||
value = callValueOf(param, valueString, methodName, "a painting art");
|
value = callValueOf(param, valueString, methodName, "a painting art");
|
||||||
}
|
} else if (param.getSimpleName().equals("Type")) {
|
||||||
else if (param.getSimpleName().equals("Type")) {
|
|
||||||
// Parse to ocelot type
|
// Parse to ocelot type
|
||||||
value = callValueOf(param, valueString, methodName, "a ocelot type");
|
value = callValueOf(param, valueString, methodName, "a ocelot type");
|
||||||
}
|
} else if (param.getSimpleName().equals("TreeSpecies")) {
|
||||||
else if (param.getSimpleName().equals("TreeSpecies")) {
|
|
||||||
// Parse to ocelot type
|
// Parse to ocelot type
|
||||||
value = callValueOf(param, valueString, methodName, "a tree species");
|
value = callValueOf(param, valueString, methodName, "a tree species");
|
||||||
}
|
} else if (param == PotionEffectType.class) {
|
||||||
else if (param == PotionEffectType.class) {
|
|
||||||
// Parse to potion effect
|
// Parse to potion effect
|
||||||
try {
|
try {
|
||||||
PotionEffectType potionType = PotionEffectType.getByName(valueString.toUpperCase());
|
PotionEffectType potionType = PotionEffectType.getByName(valueString.toUpperCase());
|
||||||
@ -857,8 +817,7 @@ public class DisguiseParser {
|
|||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
throw parseToException("a potioneffect type", valueString, methodName);
|
throw parseToException("a potioneffect type", valueString, methodName);
|
||||||
}
|
}
|
||||||
}
|
} else if (param == int[].class) {
|
||||||
else if (param == int[].class) {
|
|
||||||
String[] split = valueString.split(",");
|
String[] split = valueString.split(",");
|
||||||
|
|
||||||
int[] values = new int[split.length];
|
int[] values = new int[split.length];
|
||||||
@ -873,8 +832,7 @@ public class DisguiseParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
value = values;
|
value = values;
|
||||||
}
|
} else if (param == BlockFace.class) {
|
||||||
else if (param == BlockFace.class) {
|
|
||||||
try {
|
try {
|
||||||
BlockFace face = BlockFace.valueOf(valueString.toUpperCase());
|
BlockFace face = BlockFace.valueOf(valueString.toUpperCase());
|
||||||
|
|
||||||
@ -888,12 +846,11 @@ public class DisguiseParser {
|
|||||||
throw parseToException("a direction (north, east, south, west, up, down)", valueString,
|
throw parseToException("a direction (north, east, south, west, up, down)", valueString,
|
||||||
methodName);
|
methodName);
|
||||||
}
|
}
|
||||||
}
|
} else if (param == RabbitType.class) {
|
||||||
else if (param == RabbitType.class) {
|
|
||||||
try {
|
try {
|
||||||
for (RabbitType type : RabbitType.values()) {
|
for (RabbitType type : RabbitType.values()) {
|
||||||
if (type.name().replace("_", "")
|
if (type.name().replace("_", "").equalsIgnoreCase(
|
||||||
.equalsIgnoreCase(valueString.replace("_", "").replace(" ", ""))) {
|
valueString.replace("_", "").replace(" ", ""))) {
|
||||||
value = type;
|
value = type;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -904,10 +861,10 @@ public class DisguiseParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
throw parseToException("rabbit type (white, brown, patches...)", valueString, methodName);
|
throw parseToException("rabbit type (white, brown, patches...)", valueString,
|
||||||
|
methodName);
|
||||||
}
|
}
|
||||||
}
|
} else if (param == BlockPosition.class) {
|
||||||
else if (param == BlockPosition.class) {
|
|
||||||
try {
|
try {
|
||||||
String[] split = valueString.split(",");
|
String[] split = valueString.split(",");
|
||||||
|
|
||||||
@ -926,18 +883,14 @@ public class DisguiseParser {
|
|||||||
if (valueString == null) {
|
if (valueString == null) {
|
||||||
value = true;
|
value = true;
|
||||||
i--;
|
i--;
|
||||||
}
|
} else if (valueString.equalsIgnoreCase("true")) {
|
||||||
else if (valueString.equalsIgnoreCase("true")) {
|
|
||||||
value = true;
|
value = true;
|
||||||
}
|
} else if (valueString.equalsIgnoreCase("false")) {
|
||||||
else if (valueString.equalsIgnoreCase("false")) {
|
|
||||||
value = false;
|
value = false;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (getMethod(methods, valueString, 0) == null) {
|
if (getMethod(methods, valueString, 0) == null) {
|
||||||
throw parseToException("true/false", valueString, methodName);
|
throw parseToException("true/false", valueString, methodName);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
value = true;
|
value = true;
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
@ -977,17 +930,16 @@ public class DisguiseParser {
|
|||||||
|
|
||||||
if (FlagWatcher.class.isAssignableFrom(methodToUse.getDeclaringClass())) {
|
if (FlagWatcher.class.isAssignableFrom(methodToUse.getDeclaringClass())) {
|
||||||
methodToUse.invoke(disguise.getWatcher(), value);
|
methodToUse.invoke(disguise.getWatcher(), value);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
methodToUse.invoke(disguise, value);
|
methodToUse.invoke(disguise, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DisguiseParseException parseToException(String expectedValue, String receivedInstead, String methodName) {
|
private static DisguiseParseException parseToException(String expectedValue, String receivedInstead,
|
||||||
|
String methodName) {
|
||||||
return new DisguiseParseException(
|
return new DisguiseParseException(
|
||||||
ChatColor.RED + "Expected " + ChatColor.GREEN + expectedValue + ChatColor.RED + ", received " + ChatColor.GREEN
|
ChatColor.RED + "Expected " + ChatColor.GREEN + expectedValue + ChatColor.RED + ", received " + ChatColor.GREEN + receivedInstead + ChatColor.RED + " instead for " + ChatColor.GREEN + methodName);
|
||||||
+ receivedInstead + ChatColor.RED + " instead for " + ChatColor.GREEN + methodName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ItemStack parseToItemstack(String string) throws Exception {
|
private static ItemStack parseToItemstack(String string) throws Exception {
|
||||||
@ -997,8 +949,7 @@ public class DisguiseParser {
|
|||||||
|
|
||||||
if (isNumeric(split[0])) {
|
if (isNumeric(split[0])) {
|
||||||
itemId = Integer.parseInt(split[0]);
|
itemId = Integer.parseInt(split[0]);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
try {
|
try {
|
||||||
itemId = Material.valueOf(split[0].toUpperCase()).getId();
|
itemId = Material.valueOf(split[0].toUpperCase()).getId();
|
||||||
}
|
}
|
||||||
@ -1012,19 +963,16 @@ public class DisguiseParser {
|
|||||||
if (split.length > 1) {
|
if (split.length > 1) {
|
||||||
if (isNumeric(split[1])) {
|
if (isNumeric(split[1])) {
|
||||||
itemDura = Short.parseShort(split[1]);
|
itemDura = Short.parseShort(split[1]);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
throw parseToException("item ID:Durability combo", string, "%s");
|
throw parseToException("item ID:Durability combo", string, "%s");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ItemStack(itemId, 1, itemDura);
|
return new ItemStack(itemId, 1, itemDura);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (split.length == 1) {
|
if (split.length == 1) {
|
||||||
throw parseToException("item ID", string, "%s");
|
throw parseToException("item ID", string, "%s");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
throw parseToException("item ID:Durability combo", string, "%s");
|
throw parseToException("item ID:Durability combo", string, "%s");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1038,13 +986,13 @@ public class DisguiseParser {
|
|||||||
boolean myPerms = true;
|
boolean myPerms = true;
|
||||||
|
|
||||||
for (String option : usedOptions) {
|
for (String option : usedOptions) {
|
||||||
if (!sender.getName().equals("CONSOLE") && option.equalsIgnoreCase("setInvisible")
|
if (!sender.getName().equals("CONSOLE") && option.equalsIgnoreCase(
|
||||||
&& DisguiseConfig.isDisabledInvisibility()) {
|
"setInvisible") && DisguiseConfig.isDisabledInvisibility()) {
|
||||||
myPerms = false;
|
myPerms = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(theirPermissions.get(list) && list.contains("*"))
|
if (!(theirPermissions.get(list) && list.contains("*")) && (list.contains(
|
||||||
&& (list.contains(option) != theirPermissions.get(list))) {
|
option) != theirPermissions.get(list))) {
|
||||||
myPerms = false;
|
myPerms = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user