mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-22 10:35:38 +01:00
77a5779e24
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: 2ec53f49 PR-1050: Fix empty result check for Complex Recipes 10671012 PR-1044: Add CrafterCraftEvent 4d87ffe0 Use correct method in JavaDoc ae5e5817 SPIGOT-7850: Add API for Bogged shear state 46b6d445 SPIGOT-7837: Support data pack banner patterns d5d0cefc Fix JavaDoc error b3c2b83d PR-1036: Add API for InventoryView derivatives 1fe2c75a SPIGOT-7809: Add ShieldMeta CraftBukkit Changes: 8ee6fd1b8 SPIGOT-7857: Improve ItemMeta block data deserialization 8f26c30c6 SPIGOT-7857: Fix spurious internal NBT tag when deserializing BlockStateMeta 759061b93 SPIGOT-7855: Fire does not spread or burn blocks 00fc9fb64 SPIGOT-7853: AnvilInventory#getRepairCost() always returns 0 7501e2e04 PR-1450: Add CrafterCraftEvent 8c51673e7 SPIGOT-5731: PortalCreateEvent#getEntity returns null for nether portals ignited by flint and steel d53d0d0b1 PR-1456: Fix inverted logic in CraftCrafterView#setSlotDisabled 682a678c8 SPIGOT-7850: Add API for Bogged shear state fccf5243a SPIGOT-7837: Support data pack banner patterns 9c3bd4390 PR-1431: Add API for InventoryView derivatives 0cc6acbc4 SPIGOT-7849: Fix FoodComponent serialize with "using-converts-to" using null 2c5474952 Don't rely on tags for CraftItemMetas 20d107e46 SPIGOT-7846: Fix ItemMeta for hanging signs 76f59e315 Remove redundant clone in Dropper InventoryMoveItemEvent e61a53d25 SPIGOT-7817: Call InventoryMoveItemEvent for Crafters 894682e2d SPIGOT-7839: Remove redundant Java version checks 2c12b2187 SPIGOT-7809: Add ShieldMeta and fix setting shield base colours Spigot Changes: fb8fb722 Rebuild patches 34bd42b7 SPIGOT-7835: Fix issue with custom hopper settings
103 lines
5.4 KiB
Diff
103 lines
5.4 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
Date: Wed, 20 Dec 2023 02:03:05 -0800
|
|
Subject: [PATCH] Improve Registry
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java b/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java
|
|
index 154733684a53ff84ca8c2a994b96b68733e9fba5..1da61e0392ec1e15c0ab9d7d71b2b2b682d10130 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java
|
|
@@ -153,6 +153,7 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
|
|
|
|
private final Class<?> bukkitClass; // Paper - relax preload class
|
|
private final Map<NamespacedKey, B> cache = new HashMap<>();
|
|
+ private final Map<B, NamespacedKey> byValue = new java.util.IdentityHashMap<>(); // Paper - improve Registry
|
|
private final net.minecraft.core.Registry<M> minecraftRegistry;
|
|
private final BiFunction<NamespacedKey, M, B> minecraftToBukkit;
|
|
private final BiFunction<NamespacedKey, ApiVersion, NamespacedKey> serializationUpdater; // Paper - rename to make it *clear* what it is *only* for
|
|
@@ -201,6 +202,7 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
|
|
}
|
|
|
|
this.cache.put(namespacedKey, bukkit);
|
|
+ this.byValue.put(bukkit, namespacedKey); // Paper - improve Registry
|
|
|
|
return bukkit;
|
|
}
|
|
@@ -223,4 +225,11 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
|
|
|
|
return this.minecraftToBukkit.apply(namespacedKey, minecraft);
|
|
}
|
|
+
|
|
+ // Paper start - improve Registry
|
|
+ @Override
|
|
+ public NamespacedKey getKey(final B value) {
|
|
+ return this.byValue.get(value);
|
|
+ }
|
|
+ // Paper end - improve Registry
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/trim/CraftTrimMaterial.java b/src/main/java/org/bukkit/craftbukkit/inventory/trim/CraftTrimMaterial.java
|
|
index cd3e35867075e65f46051fb88d8a2460a8bb4b53..76627683f256a034a147765db693a9fd2ab9613f 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/trim/CraftTrimMaterial.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/trim/CraftTrimMaterial.java
|
|
@@ -54,6 +54,7 @@ public class CraftTrimMaterial implements TrimMaterial, Handleable<net.minecraft
|
|
@Override
|
|
@NotNull
|
|
public NamespacedKey getKey() {
|
|
+ if (true) return java.util.Objects.requireNonNull(org.bukkit.Registry.TRIM_MATERIAL.getKey(this), () -> this + " doesn't have a key"); // Paper
|
|
return this.key;
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/trim/CraftTrimPattern.java b/src/main/java/org/bukkit/craftbukkit/inventory/trim/CraftTrimPattern.java
|
|
index 364f8d7a7106259401154d91b1b79869d014a469..f336bf98574e4fdeabc3b210629834393ec11a74 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/trim/CraftTrimPattern.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/trim/CraftTrimPattern.java
|
|
@@ -54,6 +54,7 @@ public class CraftTrimPattern implements TrimPattern, Handleable<net.minecraft.w
|
|
@Override
|
|
@NotNull
|
|
public NamespacedKey getKey() {
|
|
+ if (true) return java.util.Objects.requireNonNull(org.bukkit.Registry.TRIM_PATTERN.getKey(this), () -> this + " doesn't have a key"); // Paper
|
|
return this.key;
|
|
}
|
|
|
|
diff --git a/src/test/java/org/bukkit/registry/PerRegistryTest.java b/src/test/java/org/bukkit/registry/PerRegistryTest.java
|
|
index 4e4ea083063daf22f1bb785ef212958ea889c43b..dad7935f9a4c7c8bb2a755cc0631330a59834233 100644
|
|
--- a/src/test/java/org/bukkit/registry/PerRegistryTest.java
|
|
+++ b/src/test/java/org/bukkit/registry/PerRegistryTest.java
|
|
@@ -48,19 +48,22 @@ public class PerRegistryTest extends AbstractTestingBase {
|
|
|
|
@ParameterizedTest
|
|
@MethodSource("data")
|
|
- public void testGet(Registry<?> registry) {
|
|
+ public <T extends Keyed> void testGet(Registry<T> registry) { // Paper - improve Registry
|
|
registry.forEach(element -> {
|
|
+ NamespacedKey key = registry.getKey(element); // Paper - improve Registry
|
|
+ assertNotNull(key); // Paper - improve Registry
|
|
// Values in the registry should be referentially equal to what is returned with #get()
|
|
// This ensures that new instances are not created each time #get() is invoked
|
|
- assertSame(element, registry.get(element.getKey()));
|
|
+ assertSame(element, registry.get(key)); // Paper - improve Registry
|
|
});
|
|
}
|
|
|
|
@ParameterizedTest
|
|
@MethodSource("data")
|
|
- public void testMatch(Registry<?> registry) {
|
|
+ public <T extends Keyed> void testMatch(Registry<T> registry) { // Paper - improve Registry
|
|
registry.forEach(element -> {
|
|
- NamespacedKey key = element.getKey();
|
|
+ NamespacedKey key = registry.getKey(element); // Paper - improve Registry
|
|
+ assertNotNull(key); // Paper - improve Registry
|
|
|
|
this.assertSameMatchWithKeyMessage(registry, element, key.toString()); // namespace:key
|
|
this.assertSameMatchWithKeyMessage(registry, element, key.getKey()); // key
|
|
@@ -71,7 +74,7 @@ public class PerRegistryTest extends AbstractTestingBase {
|
|
});
|
|
}
|
|
|
|
- private void assertSameMatchWithKeyMessage(Registry<?> registry, Keyed element, String key) {
|
|
+ private <T extends Keyed> void assertSameMatchWithKeyMessage(Registry<T> registry, T element, String key) { // Paper - improve Registry
|
|
assertSame(element, registry.match(key), key);
|
|
}
|
|
|