mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-30 04:02:50 +01:00
86 lines
4.7 KiB
Diff
86 lines
4.7 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
|
|
Date: Mon, 12 Jun 2023 14:42:49 -0400
|
|
Subject: [PATCH] Suppress Item Meta Validation Checks
|
|
|
|
In some cases ItemMeta could validate tags in an ItemStack. This suppresses those warnings and ignores reading the value.
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmor.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmor.java
|
|
index c92981aedebe934cefa1c96a0328fb91fe17acbc..80138632e5216c71fe7060a59dbb2915e740a3c8 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmor.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmor.java
|
|
@@ -68,13 +68,33 @@ 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)));
|
|
+ // Paper start
|
|
+ TrimMaterial trimMaterial = getRegistry(Registry.TRIM_MATERIAL, trimCompound.getString(TRIM_MATERIAL.NBT));
|
|
+ TrimPattern trimPattern = getRegistry(Registry.TRIM_PATTERN, trimCompound.getString(TRIM_PATTERN.NBT));
|
|
+ // Paper end
|
|
|
|
- this.trim = new ArmorTrim(trimMaterial, trimPattern);
|
|
+ this.trim = trimMaterial == null || trimPattern == null ? null : new ArmorTrim(trimMaterial, trimPattern); // Paper
|
|
}
|
|
}
|
|
}
|
|
+ // Paper start
|
|
+ public <T extends org.bukkit.Keyed> T getRegistry(Registry<T> registry, String value) {
|
|
+ if (value == null || value.isEmpty()) {
|
|
+ return null;
|
|
+ }
|
|
+ NamespacedKey namespacedKey = NamespacedKey.fromString(value);
|
|
+ if (namespacedKey == null) {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ T registryValue = registry.get(namespacedKey);
|
|
+ if (registryValue == null) {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ return registryValue;
|
|
+ }
|
|
+ // Paper end
|
|
|
|
CraftMetaArmor(Map<String, Object> map) {
|
|
super(map);
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
index 9b266dd16dbf863dcf08783ec665dd237b048793..4bfa08fe53604145a7b1c4e7630bf46519223b59 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
@@ -489,7 +489,14 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|
continue;
|
|
}
|
|
|
|
- Attribute attribute = CraftAttribute.stringToBukkit(attributeName);
|
|
+ // Paper start
|
|
+ Attribute attribute;
|
|
+ try {
|
|
+ attribute = CraftAttribute.stringToBukkit(attributeName);
|
|
+ } catch (IllegalArgumentException e) {
|
|
+ attribute = null;
|
|
+ }
|
|
+ // Paper end
|
|
if (attribute == null) {
|
|
continue;
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
|
|
index 9b9e20014042da4324c9f4babb05d8ba9513f81d..ee37b43060e0b102ab23cf318fd22041f5abaeb0 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
|
|
@@ -72,11 +72,13 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
|
|
CraftMetaSkull(CompoundTag tag) {
|
|
super(tag);
|
|
|
|
+ try { // Paper - Ignore invalid game profiles
|
|
if (tag.contains(SKULL_OWNER.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND)) {
|
|
this.setProfile(NbtUtils.readGameProfile(tag.getCompound(SKULL_OWNER.NBT)));
|
|
} else if (tag.contains(SKULL_OWNER.NBT, CraftMagicNumbers.NBT.TAG_STRING) && !tag.getString(SKULL_OWNER.NBT).isEmpty()) {
|
|
this.setProfile(new GameProfile(Util.NIL_UUID, tag.getString(SKULL_OWNER.NBT)));
|
|
}
|
|
+ } catch (Exception ignored) {} // Paper
|
|
|
|
if (tag.contains(BLOCK_ENTITY_TAG.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND)) {
|
|
CompoundTag nbtTagCompound = tag.getCompound(BLOCK_ENTITY_TAG.NBT).copy();
|