From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 12 Jun 2023 17:32:04 -0300 Subject: [PATCH] Fix invalid armor trim exploit diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmor.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmor.java index c92981aedebe934cefa1c96a0328fb91fe17acbc..2eb3705e1efdd62fa176bf4a1ec126181d083505 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmor.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmor.java @@ -68,10 +68,15 @@ public class CraftMetaArmor extends CraftMetaItem implements ArmorMeta { CompoundTag trimCompound = tag.getCompound(TRIM.NBT); if (trimCompound.contains(TRIM_MATERIAL.NBT, net.minecraft.nbt.Tag.TAG_STRING) && trimCompound.contains(TRIM_PATTERN.NBT, net.minecraft.nbt.Tag.TAG_STRING)) { // Paper - for now, ignore inline definitions of trim material & pattern - TrimMaterial trimMaterial = Registry.TRIM_MATERIAL.get(NamespacedKey.fromString(trimCompound.getString(TRIM_MATERIAL.NBT))); - TrimPattern trimPattern = Registry.TRIM_PATTERN.get(NamespacedKey.fromString(trimCompound.getString(TRIM_PATTERN.NBT))); + // Scissors start + NamespacedKey trimMaterialKey = NamespacedKey.fromString(trimCompound.getString(TRIM_MATERIAL.NBT)); + NamespacedKey trimPatternKey = NamespacedKey.fromString(trimCompound.getString(TRIM_PATTERN.NBT)); - this.trim = new ArmorTrim(trimMaterial, trimPattern); + TrimMaterial trimMaterial = trimMaterialKey != null ? Registry.TRIM_MATERIAL.get(trimMaterialKey) : null; + TrimPattern trimPattern = trimPatternKey != null ? Registry.TRIM_PATTERN.get(trimPatternKey) : null; + + if (trimMaterial != null && trimPattern != null) this.trim = new ArmorTrim(trimMaterial, trimPattern); + // Scissors end } } }