Skip to content

Commit

Permalink
add check for mojang crash translations
Browse files Browse the repository at this point in the history
  • Loading branch information
ds58 committed May 6, 2019
1 parent a038cbd commit d5df3d7
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

public interface INbtTagList {

INbtTagCompound get(int index);
INbtTagCompound getCompound(int index);

String getString(int index);

int size();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolCons
private static boolean checkItems(INbtTagList items, String nmsItemClassName,
IProtocolConstants protocolConstants, PConfig config) {
for (int i = 0; i < items.size(); i++) {
INbtTagCompound item = items.get(i);
INbtTagCompound item = items.getCompound(i);

if (item.hasKey("tag")) {
String failedNbt = NbtChecks.checkAll(item.getCompound("tag"), nmsItemClassName, protocolConstants, config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolCons

private static boolean checkItems(INbtTagList items, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) {
for (int i = 0; i < items.size(); i++) {
INbtTagCompound item = items.get(i);
INbtTagCompound item = items.getCompound(i);

if (item.hasKey("tag")) {
String failedNbt = NbtChecks.checkAll(item.getCompound("tag"), nmsItemClassName, protocolConstants, config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolCons
INbtTagList enchantments = tag.getList(using, NbtDataType.COMPOUND);

for (int i = 0; i < enchantments.size(); i++) {
INbtTagCompound enchantment = enchantments.get(i);
INbtTagCompound enchantment = enchantments.getCompound(i);
Enchantment bukkitEnchantment = getEnchantment(enchantment);

if (bukkitEnchantment == null) {
continue;
}

int lvl = 0xFFFF & enchantments.get(i).getShort("lvl");
int lvl = 0xFFFF & enchantments.getCompound(i).getShort("lvl");

if (lvl > bukkitEnchantment.getMaxLevel()) {
return false;
Expand All @@ -51,7 +51,7 @@ public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolCons
}

for (int j = 0; j < enchantments.size(); j++) {
INbtTagCompound otherEnchantment = enchantments.get(j);
INbtTagCompound otherEnchantment = enchantments.getCompound(j);
Enchantment otherBukkitEnchantment = getEnchantment(otherEnchantment);

if (bukkitEnchantment != otherBukkitEnchantment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,42 @@
import com.ruinscraft.panilla.api.config.PConfig;
import com.ruinscraft.panilla.api.config.PStrictness;
import com.ruinscraft.panilla.api.nbt.INbtTagCompound;
import com.ruinscraft.panilla.api.nbt.INbtTagList;
import com.ruinscraft.panilla.api.nbt.NbtDataType;

public class NbtCheck_pages extends NbtCheck {

// translations in the game which (intentionally) crash the user
private static final String[] MOJANG_CRASH_TRANSLATIONS = new String[] {
"translation.test.invalid",
"translation.test.invalid2"
};

public NbtCheck_pages() {
super("pages", PStrictness.AVERAGE);
super("pages", PStrictness.LENIENT);
}

@Override
public boolean check(INbtTagCompound tag, String nmsItemClassName, IProtocolConstants protocolConstants, PConfig config) {
INbtTagList pages = tag.getList("pages", NbtDataType.STRING);

for (int i = 0; i < pages.size(); i++) {
final String page = pages.getString(i);
final String noSpaces = page.replace(" ", "");

if (!noSpaces.startsWith("{\"translate\"")) {
continue;
}

for (String crashTranslation : MOJANG_CRASH_TRANSLATIONS) {
String check = String.format("{\"translate\":\"%s\"}", crashTranslation);

if (page.equalsIgnoreCase(check)) {
return false;
}
}
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ public NbtTagList(NBTTagList handle) {
}

@Override
public INbtTagCompound get(int index) {
public INbtTagCompound getCompound(int index) {
return new NbtTagCompound(handle.get(index));
}

@Override
public String getString(int index) {
return handle.getString(index);
}

@Override
public int size() {
return handle.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ public NbtTagList(NBTTagList handle) {
}

@Override
public INbtTagCompound get(int index) {
public INbtTagCompound getCompound(int index) {
return new NbtTagCompound(handle.getCompound(index));
}

@Override
public String getString(int index) {
return handle.getString(index);
}

@Override
public int size() {
return handle.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ public NbtTagList(NBTTagList handle) {
}

@Override
public INbtTagCompound get(int index) {
public INbtTagCompound getCompound(int index) {
return new NbtTagCompound(handle.getCompound(index));
}

@Override
public String getString(int index) {
return handle.getString(index);
}

@Override
public int size() {
return handle.size();
Expand Down

0 comments on commit d5df3d7

Please sign in to comment.