mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-26 12:36:07 +01:00
fe53b0e76f
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: 1d522878 PR-966: Introduce getRespawnLocation as a replacement for getBedSpawnLocation cc01b745 PR-965: Add DragonBattle#setPreviouslyKilled 28e3702f SPIGOT-6921, PR-957: Add methods to remove all enchantments on an ItemStack 8872404e PR-961: Add BlockData#copyTo 4054cc7b PR-956: Add method to get an offline player's location CraftBukkit Changes: 292ec79e0 SPIGOT-7568: Call EntityChangeBlockEvent for DecoratedPot b44bf5aa8 SPIGOT-7575: SuspiciousStewMeta creates invalid PotionEffect data 161784713 PR-1340: Centralize the conversion from and to Minecraft / Bukkit registry items even more and add a test case for them b93c5a30d PR-1338: Introduce getRespawnLocation as a replacement for getBedSpawnLocation fb973486c SPIGOT-7570: PrepareItemCraftEvent#isRepair() always returns false c9c24535e PR-1337: Add DragonBattle#setPreviouslyKilled c8b4da803 SPIGOT-6921, PR-1330: Add methods to remove all enchantments on an ItemStack 95bc1c4f5 PR-1333: Add BlockData#copyTo 36e2f9ce1 PR-1329: Add method to get an offline player's location Spigot Changes: c198da22 SPIGOT-7563: Update to latest release of bungeecord-chat
103 lines
5.3 KiB
Diff
103 lines
5.3 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 13270b2197c594dc03d089aea46aa410dd9efd13..493d054cdda04bc08ab610a09c2a1d0290ae046c 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java
|
|
@@ -126,6 +126,7 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
|
|
|
|
private final Class<? super B> bukkitClass;
|
|
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 boolean init;
|
|
@@ -170,6 +171,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;
|
|
}
|
|
@@ -192,4 +194,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 2e6b04a150eae4fbac7b4c6413d81b755ac87be2..6cce693a24e0b1b485832935d398fb26c91e0be0 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/trim/CraftTrimMaterial.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/trim/CraftTrimMaterial.java
|
|
@@ -34,6 +34,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 5a570bae1262f768d86a6078bfded427294ed135..bf13fe2f858ee35c84c5a1f3fb2f7df61a62315b 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/trim/CraftTrimPattern.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/trim/CraftTrimPattern.java
|
|
@@ -34,6 +34,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 1c4966520b6401e6571aa44d5934dfa280bc80e3..010de6fbb75eb5d51639695d260f916072fdb22d 100644
|
|
--- a/src/test/java/org/bukkit/registry/PerRegistryTest.java
|
|
+++ b/src/test/java/org/bukkit/registry/PerRegistryTest.java
|
|
@@ -49,19 +49,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
|
|
@@ -72,7 +75,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);
|
|
}
|
|
|