Check if LootTable exists, fix NPE and use Java 11

This commit is contained in:
Nathan Curran 2021-04-09 16:37:51 +10:00
parent 18eb36a8ba
commit ddcb6dc3c1
No known key found for this signature in database
GPG key ID: B3A964B30C2E56B8
11 changed files with 59 additions and 69 deletions

View file

@ -3,8 +3,8 @@ apply plugin: 'java'
group = pluginGroup
version = pluginVersion
sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceCompatibility = 11
targetCompatibility = 11
repositories {
mavenCentral()

View file

@ -1,2 +1,2 @@
pluginGroup=me.cooljwb.vulnerabilitypatcher
pluginVersion=v1.9.2
pluginVersion=v1.9.3.1

View file

@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip

View file

@ -40,7 +40,7 @@ public class NBTModifier
private NBTModifier_1_15 nbt_1_15 = new NBTModifier_1_15();
private NBTModifier_1_16 nbt_1_16 = new NBTModifier_1_16();
private NBTModifier_1_16_2 nbt_1_16_2 = new NBTModifier_1_16_2();
private NBTModifier_1_16_5 nbt_1_16_5 = new NBTModifier_1_16_5();
private NBTModifier_1_16_3 nbt_1_16_3 = new NBTModifier_1_16_3();
public static String getVersion()
{
@ -87,7 +87,7 @@ public class NBTModifier
case "1.16.2":
return nbt_1_16_2.itemToString(item);
case "1.16.5":
return nbt_1_16_5.itemToString(item);
return nbt_1_16_3.itemToString(item);
default:
return "";
}
@ -108,7 +108,7 @@ public class NBTModifier
case "1.16.2":
return nbt_1_16_2.removePlayerdata(player);
case "1.16.5":
return nbt_1_16_5.removePlayerdata(player);
return nbt_1_16_3.removePlayerdata(player);
}
return false;
}
@ -133,7 +133,7 @@ public class NBTModifier
nbt_1_16_2.resetMeta(player, item, mainhand);
break;
case "1.16.5":
nbt_1_16_5.resetMeta(player, item, mainhand);
nbt_1_16_3.resetMeta(player, item, mainhand);
break;
}
}
@ -153,7 +153,7 @@ public class NBTModifier
case "1.16.2":
return nbt_1_16_2.isPlayer(source);
case "1.16.5":
return nbt_1_16_5.isPlayer(source);
return nbt_1_16_3.isPlayer(source);
default:
return false;
}
@ -174,7 +174,7 @@ public class NBTModifier
case "1.16.2":
return nbt_1_16_2.getArrowDamage(arrow);
case "1.16.5":
return nbt_1_16_5.getArrowDamage(arrow);
return nbt_1_16_3.getArrowDamage(arrow);
default:
return 0;
}
@ -200,7 +200,7 @@ public class NBTModifier
nbt_1_16_2.setArrowDamage(arrow, amount);
break;
case "1.16.5":
nbt_1_16_5.setArrowDamage(arrow, amount);
nbt_1_16_3.setArrowDamage(arrow, amount);
break;
}
}
@ -220,7 +220,7 @@ public class NBTModifier
case "1.16.2":
return nbt_1_16_2.getFireworkEffectSize(firework);
case "1.16.5":
return nbt_1_16_5.getFireworkEffectSize(firework);
return nbt_1_16_3.getFireworkEffectSize(firework);
default:
return 0;
}
@ -241,7 +241,7 @@ public class NBTModifier
case "1.16.2":
return nbt_1_16_2.hasFireworkLargeEffect(firework);
case "1.16.5":
return nbt_1_16_5.hasFireworkLargeEffect(firework);
return nbt_1_16_3.hasFireworkLargeEffect(firework);
default:
return false;
}
@ -262,7 +262,7 @@ public class NBTModifier
case "1.16.2":
return nbt_1_16_2.isCrashItem(item);
case "1.16.5":
return nbt_1_16_5.isCrashItem(item);
return nbt_1_16_3.isCrashItem(item);
default:
return false;
}
@ -283,7 +283,7 @@ public class NBTModifier
case "1.16.2":
return nbt_1_16_2.containsCrashItem(item);
case "1.16.5":
return nbt_1_16_5.containsCrashItem(item);
return nbt_1_16_3.containsCrashItem(item);
default:
return false;
}
@ -304,7 +304,7 @@ public class NBTModifier
case "1.16.2":
return nbt_1_16_2.isDeathItem(item);
case "1.16.5":
return nbt_1_16_5.isDeathItem(item);
return nbt_1_16_3.isDeathItem(item);
default:
return false;
}
@ -325,7 +325,7 @@ public class NBTModifier
case "1.16.2":
return nbt_1_16_2.containsDeathItem(item);
case "1.16.5":
return nbt_1_16_5.containsDeathItem(item);
return nbt_1_16_3.containsDeathItem(item);
default:
return false;
}
@ -346,7 +346,7 @@ public class NBTModifier
case "1.16.2":
return nbt_1_16_2.isDisconnectItem(entity);
case "1.16.5":
return nbt_1_16_5.isDisconnectItem(entity);
return nbt_1_16_3.isDisconnectItem(entity);
default:
return false;
}
@ -367,7 +367,7 @@ public class NBTModifier
case "1.16.2":
return nbt_1_16_2.isDisconnectItem(item);
case "1.16.5":
return nbt_1_16_5.isDisconnectItem(item);
return nbt_1_16_3.isDisconnectItem(item);
default:
return false;
}
@ -388,7 +388,7 @@ public class NBTModifier
case "1.16.2":
return nbt_1_16_2.containsDisconnectItem(item);
case "1.16.5":
return nbt_1_16_5.containsDisconnectItem(item);
return nbt_1_16_3.containsDisconnectItem(item);
default:
return false;
}
@ -414,7 +414,7 @@ public class NBTModifier
nbt_1_16_2.removeInvalidValues(entity);
break;
case "1.16.5":
nbt_1_16_5.removeInvalidValues(entity);
nbt_1_16_3.removeInvalidValues(entity);
break;
}
}
@ -458,7 +458,7 @@ public class NBTModifier
{
return true;
}
return nbt_1_16_5.isDangerousEgg(item);
return nbt_1_16_3.isDangerousEgg(item);
default:
return false;
}
@ -484,7 +484,7 @@ public class NBTModifier
nbt_1_16_2.isDangerousSkull(item);
break;
case "1.16.5":
nbt_1_16_5.isDangerousSkull(item);
nbt_1_16_3.isDangerousSkull(item);
break;
}
return false;

View file

@ -224,15 +224,16 @@ public class NBTModifier_1_16
if (nmsItemStack.getTag() != null)
{
Pattern pattern = Pattern.compile("([^a-z0-9/._-])");
NBTTagCompound blockentitytag = nmsItemStack.getTag().getCompound("BlockEntityTag");
NBTTagList itemlist = blockentitytag.getList("Items", 10);
Pattern pattern = Pattern.compile("([a-z0-9/._-])");
NBTTagCompound blockEntityTag = nmsItemStack.getTag().getCompound("BlockEntityTag");
NBTTagList itemlist = blockEntityTag.getList("Items", 10);
for (int a = 0; a <= itemlist.size(); a++)
{
NBTTagCompound itemtag = itemlist.getCompound(a).getCompound("tag");
if (itemtag.toString().contains("translation.test.invalid") || pattern.matcher(blockentitytag.getString("LootTable")).find())
if (itemtag.toString().contains("translation.test.invalid")
|| (blockEntityTag.hasKey("LootTable") && !pattern.matcher(blockEntityTag.getString("LootTable")).find()))
{
fired_countermeasure("containsCrashItem");
return true;

View file

@ -244,15 +244,16 @@ public class NBTModifier_1_16_2
if (nmsItemStack.getTag() != null)
{
Pattern pattern = Pattern.compile("([^a-z0-9/._-])");
NBTTagCompound blockentitytag = nmsItemStack.getTag().getCompound("BlockEntityTag");
NBTTagList itemlist = blockentitytag.getList("Items", 10);
Pattern pattern = Pattern.compile("([a-z0-9/._-])");
NBTTagCompound blockEntityTag = nmsItemStack.getTag().getCompound("BlockEntityTag");
NBTTagList itemlist = blockEntityTag.getList("Items", 10);
for (int a = 0; a <= itemlist.size(); a++)
{
NBTTagCompound itemtag = itemlist.getCompound(a).getCompound("tag");
if (itemtag.toString().contains("translation.test.invalid") || pattern.matcher(blockentitytag.getString("LootTable")).find())
if (itemtag.toString().contains("translation.test.invalid")
|| (blockEntityTag.hasKey("LootTable") && !pattern.matcher(blockEntityTag.getString("LootTable")).find()))
{
fired_countermeasure("containsCrashItem");
return true;

View file

@ -30,7 +30,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
public class NBTModifier_1_16_5
public class NBTModifier_1_16_3
{
private Logger log = Logger.getLogger("Minecraft");
@ -221,15 +221,16 @@ public class NBTModifier_1_16_5
if (nmsItemStack.getTag() != null)
{
Pattern pattern = Pattern.compile("([^a-z0-9/._-])");
NBTTagCompound blockentitytag = nmsItemStack.getTag().getCompound("BlockEntityTag");
NBTTagList itemlist = blockentitytag.getList("Items", 10);
Pattern pattern = Pattern.compile("([a-z0-9/._-])");
NBTTagCompound blockEntityTag = nmsItemStack.getTag().getCompound("BlockEntityTag");
NBTTagList itemList = blockEntityTag.getList("Items", 10);
for (int a = 0; a <= itemlist.size(); a++)
for (int a = 0; a <= itemList.size(); a++)
{
NBTTagCompound itemtag = itemlist.getCompound(a).getCompound("tag");
NBTTagCompound itemtag = itemList.getCompound(a).getCompound("tag");
if (itemtag.toString().contains("translation.test.invalid") || pattern.matcher(blockentitytag.getString("LootTable")).find())
if (itemtag.toString().contains("translation.test.invalid")
|| (blockEntityTag.hasKey("LootTable") && !pattern.matcher(blockEntityTag.getString("LootTable")).find()))
{
fired_countermeasure("containsCrashItem");
return true;

View file

@ -62,7 +62,6 @@ public class Crash_Items extends Patches implements Listener
notifyViolation(event.getBlock().getType().toString(), "drop", "crash item", event.getBlock().getLocation());
}
else if (containsCrashItem(item))
{
event.setCancelled(true);
@ -111,7 +110,7 @@ public class Crash_Items extends Patches implements Listener
Container container = (Container) event.getBlockPlaced().getState();
for (ItemStack item : container.getInventory())
{
if (isCrashItem(item))
if (isCrashItem(item) || containsCrashItem(item))
{
container.getInventory().remove(item);
event.setCancelled(true);
@ -148,15 +147,11 @@ public class Crash_Items extends Patches implements Listener
}
BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
scheduler.scheduleSyncDelayedTask(main, new Runnable()
scheduler.scheduleSyncDelayedTask(main, () ->
{
@Override
public void run()
if (!event.getSlotType().equals(InventoryType.SlotType.OUTSIDE))
{
if (!event.getSlotType().equals(InventoryType.SlotType.OUTSIDE))
{
event.getWhoClicked().getInventory().getItem(event.getSlot()).setItemMeta(null);
}
event.getCurrentItem().setItemMeta(null);
}
}, 0L);
}
@ -169,7 +164,7 @@ public class Crash_Items extends Patches implements Listener
{
ItemStack item = event.getItemDrop().getItemStack();
if (isCrashItem(item))
if (isCrashItem(item) || containsCrashItem(item))
{
event.setCancelled(true);
clearItemMeta(event.getItemDrop().getItemStack());

View file

@ -217,15 +217,11 @@ public class Disconnect_Items extends Patches implements Listener
}
BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
scheduler.scheduleSyncDelayedTask(main, new Runnable()
scheduler.scheduleSyncDelayedTask(main, () ->
{
@Override
public void run()
if (!event.getSlotType().equals(InventoryType.SlotType.OUTSIDE))
{
if (!event.getSlotType().equals(InventoryType.SlotType.OUTSIDE))
{
event.getWhoClicked().getInventory().getItem(event.getSlot()).setItemMeta(null);
}
event.getWhoClicked().getInventory().getItem(event.getSlot()).setItemMeta(null);
}
}, 0L);
}

View file

@ -44,23 +44,19 @@ public class Handswitch extends Patches implements Listener
public void runnable()
{
BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
scheduler.scheduleSyncRepeatingTask(main, new Runnable()
scheduler.scheduleSyncRepeatingTask(main, () ->
{
@Override
public void run()
switches.clear();
its++;
if (its >= 30)
{
switches.clear();
its++;
if (its >= 30)
for (Player player : cooldown)
{
for (Player player : cooldown)
{
msg(player, SMG.SWITCH.msg);
}
cooldown = new ArrayList<>();
its = 0;
msg(player, SMG.SWITCH.msg);
}
cooldown = new ArrayList<>();
its = 0;
}
}, 20L, 0);
} // Cooldown notification.

View file

@ -1,5 +1,5 @@
name: VulnerabilityPatcher
version: "1.9.3"
version: "1.9.3.1"
api-version: 1.13
main: me.cooljwb.vulnerabilitypatcher.VulnerabilityPatcher
authors: [CoolJWB]