Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions src/main/java/com/extendedclip/deluxemenus/utils/SkullUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down