Skip to content

Commit

Permalink
fix base64 check
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Sep 18, 2024
1 parent ce2b2d0 commit 592d6f3
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/main/java/me/hsgamer/bettergui/modifier/SkullModifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ public class SkullModifier implements ItemMetaModifier {
/**
* <a href="https://github.com/CryptoMorin/XSeries/blob/b633d00608435701f1045a566b98a81edd5f923c/src/main/java/com/cryptomorin/xseries/profiles/objects/ProfileInputType.java#L29C35-L29C50">...</a>
*/
private static final Pattern MOJANG_SHA256_APPROX = Pattern.compile("[0-9a-z]{55,70}");
private static final Pattern MOJANG_SHA256_APPROX_PATTERN = Pattern.compile("[0-9a-z]{55,70}");
/**
* <a href="https://github.com/CryptoMorin/XSeries/blob/b11b176deca55da6d465e67a3d4be548c3ef06c6/src/main/java/com/cryptomorin/xseries/profiles/objects/ProfileInputType.java#L55C12-L55C57">...</a>
*/
private static final Pattern BASE64_PATTERN = Pattern.compile("[-A-Za-z0-9+/]{100,}={0,3}");
private static final SkullMeta delegateSkullMeta;
private static final SkullHandler skullHandler = getSkullHandler();

Expand All @@ -62,23 +66,23 @@ private static SkullHandler getSkullHandler() {
}

private static void setSkull(SkullMeta meta, String skull) {
Optional<byte[]> base64 = Validate.getBase64(skull);
if (base64.isPresent()) {
skullHandler.setSkullByBase64(meta, base64.get());
return;
}

Optional<URL> url = Validate.getURL(skull);
if (url.isPresent()) {
skullHandler.setSkullByURL(meta, url.get());
return;
}

if (MOJANG_SHA256_APPROX.matcher(skull).matches()) {
if (MOJANG_SHA256_APPROX_PATTERN.matcher(skull).matches()) {
skullHandler.setSkullByURL(meta, "https://textures.minecraft.net/texture/" + skull);
return;
}

if (BASE64_PATTERN.matcher(skull).matches()) {
Optional<byte[]> base64 = Validate.getBase64(skull);
base64.ifPresent(bytes -> skullHandler.setSkullByBase64(meta, bytes));
return;
}

Optional<UUID> uuid = Validate.getUUID(skull);
if (uuid.isPresent()) {
skullHandler.setSkullByUUID(meta, uuid.get());
Expand Down

0 comments on commit 592d6f3

Please sign in to comment.