Skip to content

Commit

Permalink
allow non Minecraft keys
Browse files Browse the repository at this point in the history
  • Loading branch information
ds58 committed Mar 17, 2019
1 parent 367b047 commit 8734ee8
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

public final class NbtChecks {

private static final int MAX_NON_MINECRAFT_KEYS = 16;
private static final Map<String, NbtCheck> checks = new HashMap<>();

static {
Expand Down Expand Up @@ -70,23 +71,26 @@ public static void checkPacketPlayOut(INbtTagCompound tag, String nmsItemClassNa
IProtocolConstants protocolConstants, PConfig config) throws NbtNotPermittedException {

String failedNbt = checkAll(tag, nmsItemClassName, protocolConstants, config);

if (failedNbt != null) {
throw new NbtNotPermittedException(nmsPacketClassName, false, failedNbt);
}
}

public static String checkAll(INbtTagCompound tag, String nmsItemClassName,
IProtocolConstants protocolConstants, PConfig config) {
int nonMinecraftKeys = 0;

for (String key : tag.getKeys()) {
if (config.nbtWhitelist.contains(key)) {
continue;
}

NbtCheck check = checks.get(key);

if (check == null) {
return key;
nonMinecraftKeys++;
continue;
}

if (check.getTolerance().lvl > config.strictness.lvl) {
Expand All @@ -98,6 +102,14 @@ public static String checkAll(INbtTagCompound tag, String nmsItemClassName,
}
}

if (nonMinecraftKeys > MAX_NON_MINECRAFT_KEYS) {
for (String key : tag.getKeys()) {
if (checks.get(key) == null) {
return key;
}
}
}

return null;
}

Expand Down

0 comments on commit 8734ee8

Please sign in to comment.