From f5c7f6e3b01b19b7280c056a92c461f6fb42eb2f Mon Sep 17 00:00:00 2001 From: Charlie Joseph Date: Sun, 1 Nov 2026 22:21:13 +0000 Subject: [PATCH] Fix has item comparisons with uppercase hex colors and malformed head textures - StringUtils#legacyColor kept the case of '&#RRGGBB' hex digits, while names and lore read back from items are always serialized lowercase, so strict has item name/lore checks failed whenever a menu used uppercase hex. - SkullUtils#decodeSkinUrl threw IllegalArgumentException / JsonSyntaxException on texture values that are not valid base64 or not the expected JSON shape. Since texture- and basehead- has item checks decode every head in the inventory, a single malformed head from another plugin broke the requirement. Malformed values are now treated as having no skin url. --- .../deluxemenus/utils/SkullUtils.java | 34 +++++++++++++------ .../deluxemenus/utils/StringUtils.java | 2 +- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/extendedclip/deluxemenus/utils/SkullUtils.java b/src/main/java/com/extendedclip/deluxemenus/utils/SkullUtils.java index 059bb5f5..9a2750ea 100644 --- a/src/main/java/com/extendedclip/deluxemenus/utils/SkullUtils.java +++ b/src/main/java/com/extendedclip/deluxemenus/utils/SkullUtils.java @@ -6,6 +6,7 @@ import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.inventory.ItemStack; @@ -153,22 +154,33 @@ public static String getSkullOwner(ItemStack skull) { */ @Nullable public static String decodeSkinUrl(@NotNull final String base64Texture) { - final String decoded = new String(Base64.getDecoder().decode(base64Texture)); - final JsonObject object = GSON.fromJson(decoded, JsonObject.class); + // Heads created by other plugins can carry texture values that are not valid base64 or not the expected + // JSON shape. Treat those as "no skin url" instead of throwing, so requirement checks that inspect a + // player's inventory keep working. + try { + final String decoded = new String(Base64.getDecoder().decode(base64Texture)); + final JsonObject object = GSON.fromJson(decoded, JsonObject.class); + + if (object == null) { + return null; + } - final JsonElement textures = object.get("textures"); + final JsonElement textures = object.get("textures"); - if (textures == null) { - return null; - } + if (textures == null || !textures.isJsonObject()) { + return null; + } - final JsonElement skin = textures.getAsJsonObject().get("SKIN"); + final JsonElement skin = textures.getAsJsonObject().get("SKIN"); - if (skin == null) { + if (skin == null || !skin.isJsonObject()) { + return null; + } + + final JsonElement url = skin.getAsJsonObject().get("url"); + return url == null || !url.isJsonPrimitive() ? null : url.getAsString(); + } catch (final IllegalArgumentException | JsonParseException exception) { return null; } - - final JsonElement url = skin.getAsJsonObject().get("url"); - return url == null ? null : url.getAsString(); } } diff --git a/src/main/java/com/extendedclip/deluxemenus/utils/StringUtils.java b/src/main/java/com/extendedclip/deluxemenus/utils/StringUtils.java index 9e8bb5a1..f37c39bb 100644 --- a/src/main/java/com/extendedclip/deluxemenus/utils/StringUtils.java +++ b/src/main/java/com/extendedclip/deluxemenus/utils/StringUtils.java @@ -44,7 +44,7 @@ public static String legacyColor(@NotNull String input) { while (matcher.find()) { final StringBuilder replacement = new StringBuilder().append(SECTION_CHAR).append('x'); for (final char character : matcher.group(1).substring(1).toCharArray()) { - replacement.append(SECTION_CHAR).append(character); + replacement.append(SECTION_CHAR).append(Character.toLowerCase(character)); } matcher.appendReplacement(builder, Matcher.quoteReplacement(replacement.toString())); }