Skip to content

Commit

Permalink
improve skull checking
Browse files Browse the repository at this point in the history
  • Loading branch information
ds58 committed Oct 5, 2019
1 parent e2bf8e2 commit ab6d41c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
import com.ruinscraft.panilla.api.nbt.NbtDataType;

import java.util.Base64;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class NbtCheck_SkullOwner extends NbtCheck {

private static final Pattern URL_MATCHER = Pattern.compile("url");

public NbtCheck_SkullOwner() {
super("SkullOwner", PStrictness.AVERAGE);
}
Expand All @@ -30,28 +34,37 @@ public boolean check(INbtTagCompound tag, String nmsItemClassName, IPanilla pani

if (entry.hasKey("Value")) {
String b64 = entry.getString("Value");
String decoded;

try {
String decoded = new String(Base64.getDecoder().decode(b64));
decoded = decoded.trim()
.replace(" ", "")
.replace("\"", "");

// example: {textures:{SKIN:{url:https://education.minecraft.net/wp-content/uploads/deezcord.png}}}
String url = decoded.substring(21);

if (url.startsWith("http")) {
if (url.startsWith("http://textures.minecraft.net")
|| url.startsWith("https://textures.minecraft.net")) {
return true;
} else {
return false;
}
}
decoded = new String(Base64.getDecoder().decode(b64));
} catch (IllegalArgumentException e) {
panilla.getPlatform().getLogger().info("Invalid head texture");
return false;
}

// all lowercase, no parentheses or spaces
decoded = decoded.trim()
.replace(" ", "")
.replace("\"", "")
.toLowerCase();

Matcher matcher = URL_MATCHER.matcher(decoded);

// example: {textures:{SKIN:{url:https://education.minecraft.net/wp-content/uploads/deezcord.png}}}
// may contain multiple url tags
while (matcher.find()) {
String url = decoded.substring(matcher.end() + 1);

if (url.startsWith("http://textures.minecraft.net") ||
url.startsWith("https://textures.minecraft.net")) {
continue;
} else {
return false;
}
}

return true;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
allprojects {
group = 'com.ruinscraft'
version = '1.3.7'
version = '1.3.8'
}

subprojects {
Expand Down

0 comments on commit ab6d41c

Please sign in to comment.