mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-04 16:34:44 +01:00
79e2cb620e
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 376e37db SPIGOT-7677: Update which entities are marked as spawnable 06c4add3 SPIGOT-7737: Add separate TreeType.MEGA_PINE 19b7caaa SPIGOT-7731: Spawn eggs cannot have damage e585297e PR-1022: Add force option to Player#spawnParticle d26e0094 PR-1018: Add methods to get players seeing specific chunks 8df1ed18 PR-978: Add Material#isCompostable and Material#getCompostChance 4b9b59c7 SPIGOT-7676: Enforce locale parameter in toLowerCase and toUpperCase method calls and always use root locale 8d1e700a PR-1020: Cast instead of using #typed when getting BlockType and ItemType to better work with testing / mocks fa28607a PR-1016: Fix incorrect assumption of Fireball having constant speed 4c6c8586 PR-1015: Add a tool component to ItemMeta 6f6b2123 PR-1014: Add PotionEffectTypeCategory to distinguish between beneficial and harmful effects f511cfe1 PR-1013, SPIGOT-4288, SPIGOT-6202: Add material rerouting in preparation for the switch to ItemType and BlockType def44cbf SPIGOT-7669: Fix typo in ProjectileHitEvent#getHitBlockFace documentation 53fa4f72 PR-1011: Throw an exception if a RecipeChoice is ever supplied air CraftBukkit Changes: ee95e171a SPIGOT-7737: Add separate TreeType.MEGA_PINE 0dae4c62c Fix spawn egg equality check and copy constructor ab59e847c Fix spawn eggs with no entity creating invalid stacks and disconnect creative clients 3b6093b28 SPIGOT-7736: Creative spawn egg use loses components c6b4d5a87 SPIGOT-7731: Spawn eggs cannot have damage 340ccd57f SPIGOT-7735: Fix serialization of player heads with note block sound fd2f41834 SPIGOT-7734: Can't register a custom advancement using unsafe() 02456e2a5 PR-1413: Add force option to Player#spawnParticle 6a61f38b2 SPIGOT-7680: Per-world weather command 58c41cebb PR-1409: Add methods to get players seeing specific chunks 16c976797 PR-1412: Fix shipwreck loot tables not being set for BlockTransformers 7189ba636 PR-1360: Add Material#isCompostable and Material#getCompostChance 900384556 SPIGOT-7676: Enforce locale parameter in toLowerCase and toUpperCase method calls and always use root locale bdb40c5f1 Increase outdated build delay d6607c7dd SPIGOT-7675: Fix FoodComponent config deserialization b148ed332 PR-1406: Fix incorrect assumption of Fireball having constant speed 3ec31ca75 PR-1405: Add a tool component to ItemMeta 5d7d675b9 PR-1404: Add PotionEffectTypeCategory to distinguish between beneficial and harmful effects 960827981 PR-1403, SPIGOT-4288, SPIGOT-6202: Add material rerouting in preparation for the switch to ItemType and BlockType 94e44ec93 PR-1401: Add a config option to accept old keys in registry get calls a43701920 PR-1402: Fix ChunkSnapshot#isSectionEmpty() is always false 87d0a3368 SPIGOT-7668: Move NONE Registry updater to FieldRename to avoid some class loader issues 2ea1e7ac2 PR-1399: Fix regression preventing positive .setDamage value from causing knockback for 0 damage events ba2d49d21 Increase outdated build delay Spigot Changes: fcd94e21 Rebuild patches 342f4939 SPIGOT-7661: Add experimental unload-frozen-chunks option
171 lines
13 KiB
Diff
171 lines
13 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Nassim Jahnke <nassim@njahnke.dev>
|
|
Date: Sat, 6 Jan 2024 14:31:00 +0100
|
|
Subject: [PATCH] Fixup NamespacedKey handling
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/inventory/LoomMenu.java b/src/main/java/net/minecraft/world/inventory/LoomMenu.java
|
|
index 4f3f6ea43030853bd9df067358a1f4d16c40e6d4..531336c44c46555fef8c001fe8ca00c93624ad42 100644
|
|
--- a/src/main/java/net/minecraft/world/inventory/LoomMenu.java
|
|
+++ b/src/main/java/net/minecraft/world/inventory/LoomMenu.java
|
|
@@ -171,12 +171,28 @@ public class LoomMenu extends AbstractContainerMenu {
|
|
return stillValid(this.access, player, Blocks.LOOM);
|
|
}
|
|
|
|
+ private static final org.slf4j.Logger LOGGER = com.mojang.logging.LogUtils.getLogger(); // Paper - handle custom banner pattern, skip the event
|
|
+ private static boolean PRINTED_PATTERN_TYPE_NAG = false; // Paper - handle custom banner pattern, skip the event
|
|
+
|
|
@Override
|
|
public boolean clickMenuButton(net.minecraft.world.entity.player.Player player, int id) {
|
|
if (id >= 0 && id < this.selectablePatterns.size()) {
|
|
+ // Paper start - handle custom banner pattern, skip the event (todo remove once this is supported)
|
|
+ java.util.Optional<org.bukkit.block.banner.PatternType> patternType = org.bukkit.craftbukkit.CraftRegistry.unwrapAndConvertHolder(org.bukkit.Registry.BANNER_PATTERN, this.selectablePatterns.get(id));
|
|
+ if (patternType.isEmpty()) {
|
|
+ if (!PRINTED_PATTERN_TYPE_NAG) {
|
|
+ LOGGER.warn("A datapack added a custom banner pattern, those are not supported yet in the API, skipping the PlayerLoomPatternSelectEvent for {}.", player.getScoreboardName());
|
|
+ PRINTED_PATTERN_TYPE_NAG = true;
|
|
+ }
|
|
+ this.selectedBannerPatternIndex.set(id);
|
|
+ this.setupResultSlot((Holder) this.selectablePatterns.get(id));
|
|
+ return true;
|
|
+ }
|
|
+ // Paper end - handle custom banner pattern
|
|
+
|
|
// Paper start - Add PlayerLoomPatternSelectEvent
|
|
int selectablePatternIndex = id;
|
|
- io.papermc.paper.event.player.PlayerLoomPatternSelectEvent event = new io.papermc.paper.event.player.PlayerLoomPatternSelectEvent((Player) player.getBukkitEntity(), ((CraftInventoryLoom) getBukkitView().getTopInventory()), org.bukkit.craftbukkit.block.banner.CraftPatternType.minecraftHolderToBukkit((this.selectablePatterns.get(selectablePatternIndex))));
|
|
+ io.papermc.paper.event.player.PlayerLoomPatternSelectEvent event = new io.papermc.paper.event.player.PlayerLoomPatternSelectEvent((Player) player.getBukkitEntity(), ((CraftInventoryLoom) getBukkitView().getTopInventory()), patternType.get());
|
|
if (!event.callEvent()) {
|
|
player.containerMenu.sendAllDataToRemote();
|
|
return false;
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java b/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java
|
|
index 209c6b64e79c29ea3bb84ddbe89a8bff66f81d0f..1f90f4b3f310b8cf5750c3a581be178f19b979d2 100644
|
|
--- 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) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java b/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java
|
|
index 3adf18d5e736abff701a4866ee1f8403aeafca84..4a5778d1751b774c825bbce0e870e2998278afe3 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java
|
|
@@ -110,6 +110,16 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
|
|
+ ", 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
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttribute.java b/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttribute.java
|
|
index cc97638e038ea64ad180ebfded2528aa07d1809e..10e4318782107644f67818109784fff60d017e0a 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttribute.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttribute.java
|
|
@@ -37,6 +37,7 @@ public class CraftAttribute {
|
|
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
|
|
|
|
// Now also convert from when keys where saved
|
|
return CraftRegistry.get(Registry.ATTRIBUTE, key, ApiVersion.CURRENT);
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBanner.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBanner.java
|
|
index 65a9213ce8197d50a58f94edfd60c25c2be848be..28d8fd2e3eb87e989621ffa6b0e5005bd181391c 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBanner.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBanner.java
|
|
@@ -36,7 +36,11 @@ public class CraftBanner extends CraftBlockEntityState<BannerBlockEntity> implem
|
|
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())));
|
|
+ // Paper start - fix upstream not handling custom banner pattern
|
|
+ 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()));
|
|
+ // Paper end
|
|
}
|
|
}
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmor.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmor.java
|
|
index 12b95c4455e741b65b844eab362f02bce54eb525..13b91cddffbe8ae6f07ce5c0ae45beba151e1aca 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmor.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmor.java
|
|
@@ -69,8 +69,9 @@ public class CraftMetaArmor extends CraftMetaItem implements ArmorMeta {
|
|
super(tag);
|
|
|
|
getOrEmpty(tag, CraftMetaArmor.TRIM).ifPresent((trimCompound) -> {
|
|
- TrimMaterial trimMaterial = CraftTrimMaterial.minecraftHolderToBukkit(trimCompound.material());
|
|
- TrimPattern trimPattern = CraftTrimPattern.minecraftHolderToBukkit(trimCompound.pattern());
|
|
+ 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
|
|
+ if (trimMaterial == null || trimPattern == null) return; // Paper - just delete the trim because upstream is not doing this right
|
|
|
|
this.trim = new ArmorTrim(trimMaterial, trimPattern);
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java
|
|
index 524aadad91c855f6c201999831824f7ce06f9ed6..d53df6f114c285b880167385807775e400c80fc9 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java
|
|
@@ -80,7 +80,7 @@ public class CraftMetaBanner extends CraftMetaItem implements BannerMeta {
|
|
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 = org.bukkit.craftbukkit.CraftRegistry.unwrapAndConvertHolder(org.bukkit.Registry.BANNER_PATTERN, p.pattern()).orElse(null); // Paper - fix upstream not handling custom banner pattern
|
|
|
|
if (color != null && pattern != null) {
|
|
this.patterns.add(new Pattern(color, pattern));
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMusicInstrument.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMusicInstrument.java
|
|
index 67905f804ccc102faa942499f5ba218f710ab9cc..4eb2993903f5fa9fb9fd65282a42f26b3aa1e7bd 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMusicInstrument.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMusicInstrument.java
|
|
@@ -31,7 +31,7 @@ public class CraftMetaMusicInstrument extends CraftMetaItem implements MusicInst
|
|
super(tag);
|
|
|
|
getOrEmpty(tag, CraftMetaMusicInstrument.GOAT_HORN_INSTRUMENT).ifPresent((instrument) -> {
|
|
- this.instrument = CraftMusicInstrument.minecraftHolderToBukkit(instrument);
|
|
+ this.instrument = org.bukkit.craftbukkit.CraftRegistry.unwrapAndConvertHolder(org.bukkit.Registry.INSTRUMENT, instrument).orElse(null); // Paper - fix upstream not handling custom instruments
|
|
});
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionType.java b/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionType.java
|
|
index 82a50b06c08b632f77d73745e1fa9bd22dfd950a..f1d8ed4a2b8959873b02d57f6a40323a841f3d7f 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionType.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionType.java
|
|
@@ -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
|
|
|
|
// Now also convert from when keys where saved
|
|
return CraftRegistry.get(Registry.POTION, key, ApiVersion.CURRENT);
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftNamespacedKey.java b/src/main/java/org/bukkit/craftbukkit/util/CraftNamespacedKey.java
|
|
index 5f40d240b879e3989897b6e45725a8e5a6a7f194..5014192edb9616ce725fc1592832034789527b6f 100644
|
|
--- 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) {
|