geforkt von Mirrors/Paper
87 Zeilen
4.7 KiB
Diff
87 Zeilen
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 f79ea76c0127b7b57ab0511afbed626a3b42fd05..3cea851c3f5389a5dd92601dfbef2975b2a5948b 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 954768f5f04a583e343b826e832e76cba189af95..c6340b7259242f44a9a681bff2ec46cc633eada3 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
|
|
@@ -71,11 +71,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();
|