2024-01-06 15:07:59 +01:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Nassim Jahnke <nassim@njahnke.dev>
Date: Sat, 6 Jan 2024 14:31:00 +0100
2024-01-06 15:11:45 +01:00
Subject: [PATCH] Fixup NamespacedKey handling
2024-01-06 15:07:59 +01:00
2024-05-26 21:51:15 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java b/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java
2024-10-24 15:25:36 +02:00
index 90b82ad996b2b85628c9a5ddeef9410150b7f70c..5fd22a80e9d05afbea273471cee991732a9485fd 100644
2024-05-26 21:51:15 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java
@@ -38,7 +38,7 @@ public class CraftLootTable implements org.bukkit.loot.LootTable {
}
public static org.bukkit.loot.LootTable minecraftToBukkit(ResourceKey<LootTable> minecraft) {
- return (minecraft == null) ? null : Bukkit.getLootTable(CraftLootTable.minecraftToBukkitKey(minecraft));
+ return (minecraft == null || minecraft.location().getPath().isEmpty()) ? null : Bukkit.getLootTable(CraftLootTable.minecraftToBukkitKey(minecraft)); // Paper - fix some NamespacedKey parsing
}
public static NamespacedKey minecraftToBukkitKey(ResourceKey<LootTable> minecraft) {
2024-05-26 00:58:56 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java b/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java
2024-10-31 23:44:34 +01:00
index 002a3475c6e062071845399ed723754ce4ce9e95..9245f6de141384bfc12e8dd81ce1df366c6a62aa 100644
2024-05-26 00:58:56 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java
2024-10-31 23:44:34 +01:00
@@ -125,6 +125,16 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
2024-05-26 00:58:56 +02:00
+ ", this can happen if a plugin creates its own registry entry with out properly registering it.");
}
+ // Paper start - fixup upstream being dum
+ public static <T extends org.bukkit.Keyed, M> java.util.Optional<T> unwrapAndConvertHolder(final io.papermc.paper.registry.RegistryKey<T> registryKey, final Holder<M> value) {
+ return unwrapAndConvertHolder(io.papermc.paper.registry.RegistryAccess.registryAccess().getRegistry(registryKey), value);
+ }
+
+ public static <T extends org.bukkit.Keyed, M> java.util.Optional<T> unwrapAndConvertHolder(final Registry<T> registry, final Holder<M> value) {
+ return value.unwrapKey().map(key -> registry.get(CraftNamespacedKey.fromMinecraft(key.location())));
+ }
+ // Paper end - fixup upstream being dum
+
// Paper - move to PaperRegistries
// Paper - NOTE: As long as all uses of the method below relate to *serialization* via ConfigurationSerializable, it's fine
2024-01-06 15:07:59 +01:00
diff --git a/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttribute.java b/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttribute.java
2024-10-31 23:44:34 +01:00
index 9ab615347e241ac264fb70f43306075907420885..0d04f0a34d1d1894845b720a407f7190ea78d514 100644
2024-01-06 15:07:59 +01:00
--- a/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttribute.java
+++ b/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttribute.java
2024-10-31 23:44:34 +01:00
@@ -33,6 +33,7 @@ public class CraftAttribute implements Attribute, Handleable<net.minecraft.world
2024-05-11 23:48:37 +02:00
string = FieldRename.convertAttributeName(ApiVersion.CURRENT, string);
string = string.toLowerCase(Locale.ROOT);
NamespacedKey key = NamespacedKey.fromString(string);
+ if (key == null) return null; // Paper - Fixup NamespacedKey handling
2024-01-06 15:07:59 +01:00
2024-05-11 23:48:37 +02:00
// Now also convert from when keys where saved
return CraftRegistry.get(Registry.ATTRIBUTE, key, ApiVersion.CURRENT);
2024-05-26 00:58:56 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBanner.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBanner.java
2024-08-16 23:21:35 +02:00
index afed8bdb9bd6a135e9b5f7bd9bfc61964cb240f7..bb2d1dddca6bfe719b28df136e80a7c5a339a5ce 100644
2024-05-26 00:58:56 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBanner.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBanner.java
2024-07-06 21:19:14 +02:00
@@ -38,7 +38,11 @@ public class CraftBanner extends CraftBlockEntityState<BannerBlockEntity> implem
2024-05-26 00:58:56 +02:00
if (banner.getPatterns() != null) {
for (int i = 0; i < banner.getPatterns().layers().size(); i++) {
BannerPatternLayers.Layer p = banner.getPatterns().layers().get(i);
- this.patterns.add(new Pattern(DyeColor.getByWoolData((byte) p.color().getId()), CraftPatternType.minecraftHolderToBukkit(p.pattern())));
2024-08-16 23:21:35 +02:00
+ // Paper start - fix upstream not handling inlined banner pattern
2024-05-26 00:58:56 +02:00
+ java.util.Optional<org.bukkit.block.banner.PatternType> type = org.bukkit.craftbukkit.CraftRegistry.unwrapAndConvertHolder(org.bukkit.Registry.BANNER_PATTERN, p.pattern());
+ if (type.isEmpty()) continue;
+ this.patterns.add(new Pattern(DyeColor.getByWoolData((byte) p.color().getId()), type.get()));
2024-08-16 23:21:35 +02:00
+ // Paper end - fix upstream not handling inlined banner pattern
2024-05-26 00:58:56 +02:00
}
}
}
2024-08-16 23:21:35 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPainting.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPainting.java
index bcac1359c667ef1ee46384f9c7a5adf4010d2b08..98a4463c9f194f33f4f85d95a0b9fa061cf6faaf 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPainting.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPainting.java
@@ -16,7 +16,7 @@ public class CraftPainting extends CraftHanging implements Painting {
@Override
public Art getArt() {
- return CraftArt.minecraftHolderToBukkit(this.getHandle().getVariant());
+ return org.bukkit.craftbukkit.CraftRegistry.unwrapAndConvertHolder(org.bukkit.Registry.ART, this.getHandle().getVariant()).orElseThrow(() -> new IllegalStateException("Inlined/custom painting variants are not supported yet in the API!")); // Paper
}
@Override
2024-01-06 15:07:59 +01:00
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmor.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmor.java
2024-10-24 15:25:36 +02:00
index 0fdd9dd47594a7e7e785c34c09d9b4a79aad2439..0d3b1692af010bfd7ea83e22e9571dc954906f71 100644
2024-01-06 15:07:59 +01:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmor.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmor.java
2024-06-15 18:28:18 +02:00
@@ -38,8 +38,9 @@ public class CraftMetaArmor extends CraftMetaItem implements ArmorMeta {
2024-04-25 01:25:57 +02:00
super(tag);
2024-01-06 15:07:59 +01:00
2024-04-25 01:25:57 +02:00
getOrEmpty(tag, CraftMetaArmor.TRIM).ifPresent((trimCompound) -> {
- TrimMaterial trimMaterial = CraftTrimMaterial.minecraftHolderToBukkit(trimCompound.material());
- TrimPattern trimPattern = CraftTrimPattern.minecraftHolderToBukkit(trimCompound.pattern());
2024-05-26 00:58:56 +02:00
+ TrimMaterial trimMaterial = org.bukkit.craftbukkit.CraftRegistry.unwrapAndConvertHolder(io.papermc.paper.registry.RegistryKey.TRIM_MATERIAL, trimCompound.material()).orElse(null); // Paper - fix upstream not being correct
+ TrimPattern trimPattern = org.bukkit.craftbukkit.CraftRegistry.unwrapAndConvertHolder(io.papermc.paper.registry.RegistryKey.TRIM_PATTERN, trimCompound.pattern()).orElse(null); // Paper - fix upstream not being correct
2024-04-25 01:25:57 +02:00
+ if (trimMaterial == null || trimPattern == null) return; // Paper - just delete the trim because upstream is not doing this right
2024-01-06 15:07:59 +01:00
2024-04-25 01:25:57 +02:00
this.trim = new ArmorTrim(trimMaterial, trimPattern);
2024-05-26 00:58:56 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java
2024-08-16 23:21:35 +02:00
index 1c1a2d66d1ebcbe2ded732e759d0f9d471d43b56..eb44c19f6af624df458981e46c73a64358d6e1ce 100644
2024-05-26 00:58:56 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java
2024-06-15 18:28:18 +02:00
@@ -42,7 +42,7 @@ public class CraftMetaBanner extends CraftMetaItem implements BannerMeta {
2024-05-26 00:58:56 +02:00
for (int i = 0; i < Math.min(patterns.size(), 20); i++) {
BannerPatternLayers.Layer p = patterns.get(i);
DyeColor color = DyeColor.getByWoolData((byte) p.color().getId());
- PatternType pattern = CraftPatternType.minecraftHolderToBukkit(p.pattern());
2024-08-16 23:21:35 +02:00
+ PatternType pattern = org.bukkit.craftbukkit.CraftRegistry.unwrapAndConvertHolder(org.bukkit.Registry.BANNER_PATTERN, p.pattern()).orElse(null); // Paper - fix upstream not handling inlined banner pattern
2024-01-06 15:07:59 +01:00
2024-05-26 00:58:56 +02:00
if (color != null && pattern != null) {
this.patterns.add(new Pattern(color, pattern));
2024-01-06 15:07:59 +01:00
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMusicInstrument.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMusicInstrument.java
2024-08-16 23:21:35 +02:00
index 478059eb3ad76b41e6a20e9b489a2a4fb19e7c7c..76a3e4893cbdba903a712d6db1d30b9c644795be 100644
2024-01-06 15:07:59 +01:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMusicInstrument.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMusicInstrument.java
2024-06-15 18:28:18 +02:00
@@ -30,7 +30,7 @@ public class CraftMetaMusicInstrument extends CraftMetaItem implements MusicInst
2024-04-25 01:25:57 +02:00
super(tag);
2024-01-06 15:07:59 +01:00
2024-04-25 01:25:57 +02:00
getOrEmpty(tag, CraftMetaMusicInstrument.GOAT_HORN_INSTRUMENT).ifPresent((instrument) -> {
- this.instrument = CraftMusicInstrument.minecraftHolderToBukkit(instrument);
2024-08-16 23:21:35 +02:00
+ this.instrument = org.bukkit.craftbukkit.CraftRegistry.unwrapAndConvertHolder(org.bukkit.Registry.INSTRUMENT, instrument).orElse(null); // Paper - fix upstream not handling inlined instrument
2024-04-25 01:25:57 +02:00
});
2024-01-06 15:07:59 +01:00
}
2024-08-09 22:05:50 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaShield.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaShield.java
index c8eec04685456d89cb41466cddcc3975d0ceeb29..bcd6cc29e4e621805cbd923d747f652ced240c6d 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaShield.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaShield.java
@@ -17,6 +17,7 @@ import org.bukkit.block.BlockState;
import org.bukkit.block.banner.Pattern;
import org.bukkit.block.banner.PatternType;
import org.bukkit.configuration.serialization.DelegateDeserialization;
+import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.block.CraftBlockStates;
import org.bukkit.craftbukkit.block.banner.CraftPatternType;
import org.bukkit.inventory.meta.BlockStateMeta;
@@ -53,7 +54,7 @@ public class CraftMetaShield extends CraftMetaItem implements ShieldMeta, BlockS
for (int i = 0; i < Math.min(patterns.size(), 20); i++) {
BannerPatternLayers.Layer p = patterns.get(i);
DyeColor color = DyeColor.getByWoolData((byte) p.color().getId());
- PatternType pattern = CraftPatternType.minecraftHolderToBukkit(p.pattern());
+ PatternType pattern = CraftRegistry.unwrapAndConvertHolder(io.papermc.paper.registry.RegistryKey.BANNER_PATTERN, p.pattern()).orElse(null); // Paper - fix upstream not being correct
if (color != null && pattern != null) {
this.addPattern(new Pattern(color, pattern));
2024-01-06 15:07:59 +01:00
diff --git a/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionType.java b/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionType.java
2024-05-11 23:48:37 +02:00
index 82a50b06c08b632f77d73745e1fa9bd22dfd950a..f1d8ed4a2b8959873b02d57f6a40323a841f3d7f 100644
2024-01-06 15:07:59 +01:00
--- a/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionType.java
+++ b/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionType.java
2024-05-11 23:48:37 +02:00
@@ -69,6 +69,7 @@ public class CraftPotionType implements PotionType.InternalPotionData {
string = FieldRename.convertPotionTypeName(ApiVersion.CURRENT, string);
string = string.toLowerCase(Locale.ROOT);
NamespacedKey key = NamespacedKey.fromString(string);
+ if (key == null) return null; // Paper - Fixup NamespacedKey handling
2024-01-06 15:07:59 +01:00
2024-05-11 23:48:37 +02:00
// Now also convert from when keys where saved
return CraftRegistry.get(Registry.POTION, key, ApiVersion.CURRENT);
2024-01-06 15:07:59 +01:00
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftNamespacedKey.java b/src/main/java/org/bukkit/craftbukkit/util/CraftNamespacedKey.java
2024-06-14 10:56:28 +02:00
index dc88ba24ed3b0024c39a30c2d90628fc708d63cf..944bed9b6c803df1a312383fed9de7d61e7d2c70 100644
2024-01-06 15:07:59 +01:00
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftNamespacedKey.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftNamespacedKey.java
@@ -13,7 +13,7 @@ public final class CraftNamespacedKey {
return null;
}
ResourceLocation minecraft = ResourceLocation.tryParse(string);
- return (minecraft == null) ? null : CraftNamespacedKey.fromMinecraft(minecraft);
+ return (minecraft == null || minecraft.getPath().isEmpty()) ? null : CraftNamespacedKey.fromMinecraft(minecraft); // Paper - Bukkit's parser does not match Vanilla for empty paths
}
public static NamespacedKey fromString(String string) {