mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-01 12:41:50 +01:00
d1a72eac31
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: 1fc1020a PR-1049: Add MenuType API 8ae2e3be PR-1055: Expand riptiding API cac68bfb SPIGOT-7890: AttributeModifier#getUniqueId() doesn't match the UUID passed to its constructor 7004fcf2 SPIGOT-7886: Fix mistake in AttributeModifier UUID shim 1ac7f950 PR-1054: Add FireworkMeta#hasPower 4cfb565f SPIGOT-7873: Add powered state for skulls CraftBukkit Changes: bbb30e7a8 SPIGOT-7894: NPE when sending tile entity update ba21e9472 SPIGOT-7895: PlayerItemBreakEvent not firing 0fb24bbe0 SPIGOT-7875: Fix PlayerItemConsumeEvent cancellation causing client-side desync 815066449 SPIGOT-7891: Can't remove second ingredient of MerchantRecipe 45c206f2c PR-1458: Add MenuType API 19c8ef9ae SPIGOT-7867: Merchant instanceof AbstractVillager always returns false 4e006d28f PR-1468: Expand riptiding API bd8aded7d Ignore checks in CraftPlayerProfile for ResolvableProfile used in profile components 8679620b5 SPIGOT-7889: Fix tool component deserialisation without speed and/or correct-for-drops 8d5222691 SPIGOT-7882, PR-1467: Fix conversion of name in Profile Component to empty if it is missing 63f91669a SPIGOT-7887: Remove duplicate ProjectileHitEvent for fireballs 7070de8c8 SPIGOT-7878: Server#getLootTable does not return null on invalid loot table 060ee6cae SPIGOT-7876: Can't kick player or disconnect player in PlayerLoginEvent when checking for cookies 7ccb86cc0 PR-1465: Add FireworkMeta#hasPower 804ad6491 SPIGOT-7873: Add powered state for skulls f9610cdcb Improve minecart movement Spigot Changes: a759b629 Rebuild patches Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
239 lines
10 KiB
Diff
239 lines
10 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:10 -0800
|
|
Subject: [PATCH] Improve Registry
|
|
|
|
Adds Registry#getKey(Object) which should be the
|
|
primary way people get the key for an object. Registry
|
|
items need to exist without having a key and so
|
|
getKey() methods on Keyed objects that have a registry
|
|
are marked as Deprecated or Obsolete.
|
|
|
|
diff --git a/src/main/java/org/bukkit/Art.java b/src/main/java/org/bukkit/Art.java
|
|
index 042d1d932a33022e4fc873652f70dc6ed342d46a..dbbd997d4693f1d9f551bae2ed1d7906c9f39c12 100644
|
|
--- a/src/main/java/org/bukkit/Art.java
|
|
+++ b/src/main/java/org/bukkit/Art.java
|
|
@@ -103,6 +103,13 @@ public enum Art implements Keyed {
|
|
return id;
|
|
}
|
|
|
|
+ // Paper start - deprecate getKey
|
|
+ /**
|
|
+ * @deprecated use {@link Registry#getKey(Keyed)} and {@link Registry#ART}. Painting variants
|
|
+ * can exist without a key.
|
|
+ */
|
|
+ @Deprecated(since = "1.21")
|
|
+ // Paper end - deprecate getKey
|
|
@NotNull
|
|
@Override
|
|
public NamespacedKey getKey() {
|
|
diff --git a/src/main/java/org/bukkit/MusicInstrument.java b/src/main/java/org/bukkit/MusicInstrument.java
|
|
index 62d2b3f950860dee0898d77b0a29635c3f9a7e23..98fdfc8978fea1937e31a7427433a1927d42ec7d 100644
|
|
--- a/src/main/java/org/bukkit/MusicInstrument.java
|
|
+++ b/src/main/java/org/bukkit/MusicInstrument.java
|
|
@@ -53,6 +53,16 @@ public abstract class MusicInstrument implements Keyed, net.kyori.adventure.tran
|
|
return instrument;
|
|
}
|
|
|
|
+ // Paper start - deprecate getKey
|
|
+ /**
|
|
+ * @deprecated use {@link Registry#getKey(Keyed)} and {@link Registry#INSTRUMENT}. MusicInstruments
|
|
+ * can exist without a key.
|
|
+ */
|
|
+ @Deprecated(forRemoval = true, since = "1.20.5")
|
|
+ @Override
|
|
+ public abstract @NotNull NamespacedKey getKey();
|
|
+ // Paper end - deprecate getKey
|
|
+
|
|
// Paper start - translation key
|
|
@Override
|
|
public @NotNull String translationKey() {
|
|
diff --git a/src/main/java/org/bukkit/Registry.java b/src/main/java/org/bukkit/Registry.java
|
|
index 7870a796e719148a42d18f1497b56c0d8f651a43..ff82bf3ea959c78e71ec7b0972a2d472f20aaf04 100644
|
|
--- a/src/main/java/org/bukkit/Registry.java
|
|
+++ b/src/main/java/org/bukkit/Registry.java
|
|
@@ -367,6 +367,79 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
|
|
@Nullable
|
|
T get(@NotNull NamespacedKey key);
|
|
|
|
+ // Paper start - improve Registry
|
|
+ /**
|
|
+ * Gets the object by its key or throws if it doesn't exist.
|
|
+ *
|
|
+ * @param key the key to get the object of in this registry
|
|
+ * @return the object for the key
|
|
+ * @throws java.util.NoSuchElementException if the key doesn't point to an object in the registry
|
|
+ */
|
|
+ default @NotNull T getOrThrow(final net.kyori.adventure.key.@NotNull Key key) {
|
|
+ final T value = this.get(key);
|
|
+ if (value == null) {
|
|
+ throw new java.util.NoSuchElementException("No value for " + key + " in " + this);
|
|
+ }
|
|
+ return value;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Gets the object by its key or throws if it doesn't exist.
|
|
+ *
|
|
+ * @param key the key to get the object of in this registry
|
|
+ * @return the object for the key
|
|
+ * @throws java.util.NoSuchElementException if the key doesn't point to an object in the registry
|
|
+ */
|
|
+ default @NotNull T getOrThrow(final io.papermc.paper.registry.@NotNull TypedKey<T> key) {
|
|
+ final T value = this.get(key);
|
|
+ if (value == null) {
|
|
+ throw new java.util.NoSuchElementException("No value for " + key + " in " + this);
|
|
+ }
|
|
+ return value;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Gets the key for this object or throws if it doesn't exist.
|
|
+ * <p>
|
|
+ * Some types can exist without being in a registry
|
|
+ * and such will have no key associated with them. This
|
|
+ * method throw an exception if it isn't in this registry.
|
|
+ *
|
|
+ * @param value the value to get the key of in this registry
|
|
+ * @return the key for the value
|
|
+ * @throws java.util.NoSuchElementException if the value doesn't exist in this registry
|
|
+ * @see #getKey(Keyed)
|
|
+ */
|
|
+ default @NotNull NamespacedKey getKeyOrThrow(final @NotNull T value) {
|
|
+ Preconditions.checkArgument(value != null, "value cannot be null");
|
|
+ final NamespacedKey key = this.getKey(value);
|
|
+ if (key == null) {
|
|
+ throw new java.util.NoSuchElementException(value + " has no key in " + this);
|
|
+ }
|
|
+ return key;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Get the key for this object.
|
|
+ * <p>
|
|
+ * Some types can exist without being in a registry
|
|
+ * and such will have no key associated with them. This
|
|
+ * method will return null.
|
|
+ *
|
|
+ * @param value the value to get the key of in this registry
|
|
+ * @return the key for the value or null if not in the registry
|
|
+ * @see #getKeyOrThrow(Keyed)
|
|
+ */
|
|
+ default @Nullable NamespacedKey getKey(final @NotNull T value) {
|
|
+ Preconditions.checkArgument(value != null, "value cannot be null");
|
|
+ //noinspection ConstantValue (it might not be in the future...)
|
|
+ if (value instanceof Keyed) {
|
|
+ return value.getKey();
|
|
+ }
|
|
+ return null;
|
|
+ }
|
|
+ // Paper end - improve Registry
|
|
+
|
|
/**
|
|
* Returns a new stream, which contains all registry items, which are registered to the registry.
|
|
*
|
|
@@ -441,5 +514,12 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
|
|
public Class<T> getType() {
|
|
return this.type;
|
|
}
|
|
+
|
|
+ // Paper start - improve Registry
|
|
+ @Override
|
|
+ public @NotNull NamespacedKey getKey(final @NotNull T value) {
|
|
+ return value.getKey();
|
|
+ }
|
|
+ // Paper end - improve Registry
|
|
}
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/Sound.java b/src/main/java/org/bukkit/Sound.java
|
|
index 8c7b50906fc5b84c5570408f357410810bbfbded..7a35120c82b88774de777d3c3176ef553a8e9244 100644
|
|
--- a/src/main/java/org/bukkit/Sound.java
|
|
+++ b/src/main/java/org/bukkit/Sound.java
|
|
@@ -1636,6 +1636,13 @@ public enum Sound implements Keyed, net.kyori.adventure.sound.Sound.Type { // Pa
|
|
this.key = NamespacedKey.minecraft(key);
|
|
}
|
|
|
|
+ // Paper start - deprecate getKey
|
|
+ /**
|
|
+ * @deprecated use {@link Registry#getKey(Keyed)} and {@link Registry#SOUNDS}. Sounds
|
|
+ * can exist without a key.
|
|
+ */
|
|
+ @Deprecated(since = "1.20.5")
|
|
+ // Paper end - deprecate getKey
|
|
@NotNull
|
|
@Override
|
|
public NamespacedKey getKey() {
|
|
diff --git a/src/main/java/org/bukkit/block/banner/PatternType.java b/src/main/java/org/bukkit/block/banner/PatternType.java
|
|
index 9e90572745909538e942b7fbe788b5286c6cc9a3..e2afb2582a27b94a922754115dbb6b4ca35e0154 100644
|
|
--- a/src/main/java/org/bukkit/block/banner/PatternType.java
|
|
+++ b/src/main/java/org/bukkit/block/banner/PatternType.java
|
|
@@ -56,6 +56,13 @@ public interface PatternType extends OldEnum<PatternType>, Keyed {
|
|
PatternType FLOW = getType("flow");
|
|
PatternType GUSTER = getType("guster");
|
|
|
|
+ // Paper start - deprecate getKey
|
|
+ /**
|
|
+ * @deprecated use {@link Registry#getKey(Keyed)} and {@link Registry#BANNER_PATTERN}. PatternTypes
|
|
+ * can exist without a key.
|
|
+ */
|
|
+ @Deprecated(since = "1.20.5")
|
|
+ // Paper end - deprecate getKey
|
|
@Override
|
|
@NotNull
|
|
public NamespacedKey getKey();
|
|
diff --git a/src/main/java/org/bukkit/generator/structure/Structure.java b/src/main/java/org/bukkit/generator/structure/Structure.java
|
|
index 1a766e68713d4014783b3224b9395644116784fa..978054ee364f9a3330525b9b50da5325ebb6ef57 100644
|
|
--- a/src/main/java/org/bukkit/generator/structure/Structure.java
|
|
+++ b/src/main/java/org/bukkit/generator/structure/Structure.java
|
|
@@ -60,4 +60,13 @@ public abstract class Structure implements Keyed {
|
|
*/
|
|
@NotNull
|
|
public abstract StructureType getStructureType();
|
|
+ // Paper start - deprecate getKey
|
|
+ /**
|
|
+ * @deprecated use {@link Registry#getKey(Keyed)} and {@link Registry#STRUCTURE}. Structures
|
|
+ * can exist without a key.
|
|
+ */
|
|
+ @Override
|
|
+ @Deprecated(since = "1.20.4")
|
|
+ public abstract @NotNull NamespacedKey getKey();
|
|
+ // Paper end - deprecate getKey
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/inventory/meta/trim/TrimMaterial.java b/src/main/java/org/bukkit/inventory/meta/trim/TrimMaterial.java
|
|
index 941fac4eee338870d8c30cb1f64cab572cf54548..74816d6da4d7c8d2fa8a7b93fdc4bf29c8d12803 100644
|
|
--- a/src/main/java/org/bukkit/inventory/meta/trim/TrimMaterial.java
|
|
+++ b/src/main/java/org/bukkit/inventory/meta/trim/TrimMaterial.java
|
|
@@ -68,4 +68,14 @@ public interface TrimMaterial extends Keyed, Translatable {
|
|
@Deprecated(forRemoval = true)
|
|
@org.jetbrains.annotations.NotNull String getTranslationKey();
|
|
// Paper end - adventure
|
|
+
|
|
+ // Paper start - Registry#getKey
|
|
+ /**
|
|
+ * @deprecated use {@link Registry#getKey(Keyed)} and {@link Registry#TRIM_MATERIAL}. TrimMaterials
|
|
+ * can exist without a key.
|
|
+ */
|
|
+ @Deprecated(forRemoval = true, since = "1.20.4")
|
|
+ @Override
|
|
+ org.bukkit.@org.jetbrains.annotations.NotNull NamespacedKey getKey();
|
|
+ // Paper end - Registry#getKey
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/inventory/meta/trim/TrimPattern.java b/src/main/java/org/bukkit/inventory/meta/trim/TrimPattern.java
|
|
index f2242ddc4085f7e7cdd748d860857822e3d9b007..087e99ed281c0b282d91345067bfca80762faa0b 100644
|
|
--- a/src/main/java/org/bukkit/inventory/meta/trim/TrimPattern.java
|
|
+++ b/src/main/java/org/bukkit/inventory/meta/trim/TrimPattern.java
|
|
@@ -100,4 +100,14 @@ public interface TrimPattern extends Keyed, Translatable {
|
|
@Deprecated(forRemoval = true)
|
|
@org.jetbrains.annotations.NotNull String getTranslationKey();
|
|
// Paper end - adventure
|
|
+
|
|
+ // Paper start - Registry#getKey
|
|
+ /**
|
|
+ * @deprecated use {@link Registry#getKey(Keyed)} and {@link Registry#TRIM_PATTERN}. TrimPatterns
|
|
+ * can exist without a key.
|
|
+ */
|
|
+ @Deprecated(forRemoval = true, since = "1.20.4")
|
|
+ @Override
|
|
+ org.bukkit.@org.jetbrains.annotations.NotNull NamespacedKey getKey();
|
|
+ // Paper end - Registry#getKey
|
|
}
|