Fix serializing of more complex items such as player heads, don't include setArmor in disguise string but instead rely on sethelmet etc

This commit is contained in:
libraryaddict 2020-10-09 10:09:37 +13:00
parent be34a2c84a
commit 1ed3a149ea
3 changed files with 33 additions and 11 deletions

View File

@ -2735,10 +2735,24 @@ public class DisguiseUtilities {
String[] str = new String[Array.getLength(base.getValue())];
for (int i = 0; i < str.length; i++) {
str[i] = Array.get(base.getValue(),i).toString();//+ getChar(base.getType());
str[i] = Array.get(base.getValue(), i).toString();//+ getChar(base.getType());
}
return "[" + StringUtils.join(str, ",") + "]";
String c = "";
switch (base.getType()) {
case TAG_BYTE_ARRAY:
c = "B;";
break;
case TAG_INT_ARRAY:
c = "I;";
break;
case TAG_LONG_ARRAY:
c = "L;";
break;
}
return "[" + c + StringUtils.join(str, ",") + "]";
case TAG_BYTE:
case TAG_INT:
case TAG_LONG:

View File

@ -114,11 +114,11 @@ public class ParamInfoItemStack extends ParamInfoEnum {
String[] split;
// If it matches /give @p stone {data}
if (string.matches("[^{]+?[ -]\\{.+?}")) {
if (string.matches("^[^{]+?[ -]\\{[.].+?}$")) {
split = string.substring(0, string.indexOf("{") - 1).split("[ -]");
split = Arrays.copyOf(split, split.length + 1);
split[split.length - 1] = string.substring(string.indexOf("{"));
} else if (string.matches("[^{ ]+?\\{.+?}( [0-9]+)?")) { // /give @p stone[data] <amount?>
} else if (string.matches("^[^{ -]+?\\{.+?}([ -][0-9]+)?$")) { // /give @p stone[data] <amount?>
split = new String[string.endsWith("}") ? 2 : 3];
split[0] = string.substring(0, string.indexOf("{"));
split[string.endsWith("}") ? 1 : 2] = string

View File

@ -63,12 +63,19 @@ public class DisguiseParser {
for (Method setMethod : methods) {
// Invalidate methods that can't be handled normally
if (setMethod.getName().equals("addPotionEffect") || (setMethod.getName().equals("setSkin") &&
setMethod.getParameterTypes()[0] == String.class) ||
(setMethod.getName().equals("setTarget") &&
setMethod.getParameterTypes()[0] != int.class) ||
(setMethod.getName().equals("setItemInMainHand") &&
setMethod.getParameterTypes()[0] == Material.class)) {
if (setMethod.getName().equals("addPotionEffect")) {
continue;
} else if (setMethod.getName().equals("setSkin") &&
setMethod.getParameterTypes()[0] == String.class) {
continue;
} else if (setMethod.getName().equals("setTarget") &&
setMethod.getParameterTypes()[0] != int.class) {
continue;
} else if (setMethod.getName().equals("setItemInMainHand") &&
setMethod.getParameterTypes()[0] == Material.class) {
continue;
} else if (setMethod.getName().matches("setArmor") &&
setMethod.getParameterTypes()[0] == ItemStack[].class) {
continue;
}
@ -829,7 +836,8 @@ public class DisguiseParser {
usedOptions.add(optionName);
doCheck(sender, permissions, disguisePerm, usedOptions);
String itemName = itemStack == null ? "null" : itemStack.getType().name().toLowerCase(Locale.ENGLISH);
String itemName = itemStack == null ? "null" :
itemStack.getType().name().toLowerCase(Locale.ENGLISH);
if (!hasPermissionOption(disguiseOptions, optionName, itemName)) {
throw new DisguiseParseException(LibsMsg.PARSE_NO_PERM_PARAM, itemName,