diff options
Diffstat (limited to 'patches/api/0434-Improve-Registry.patch')
-rw-r--r-- | patches/api/0434-Improve-Registry.patch | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/patches/api/0434-Improve-Registry.patch b/patches/api/0434-Improve-Registry.patch index 1d2d6fa13c..fd25406955 100644 --- a/patches/api/0434-Improve-Registry.patch +++ b/patches/api/0434-Improve-Registry.patch @@ -31,15 +31,45 @@ index 62d2b3f950860dee0898d77b0a29635c3f9a7e23..704dba92f9246ef398ed8d162ebee3cf @Override public @NotNull String translationKey() { diff --git a/src/main/java/org/bukkit/Registry.java b/src/main/java/org/bukkit/Registry.java -index 5ba5cf06bf12fc2e81500e09209e26047e683fa9..802511eaf697d703cadb4b418fe51ea6d31ff3c8 100644 +index 5ba5cf06bf12fc2e81500e09209e26047e683fa9..b02160f42281bc4e20123752a593c5d655305381 100644 --- a/src/main/java/org/bukkit/Registry.java +++ b/src/main/java/org/bukkit/Registry.java -@@ -354,6 +354,49 @@ public interface Registry<T extends Keyed> extends Iterable<T> { +@@ -354,6 +354,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 @@ -84,7 +114,7 @@ index 5ba5cf06bf12fc2e81500e09209e26047e683fa9..802511eaf697d703cadb4b418fe51ea6 /** * Returns a new stream, which contains all registry items, which are registered to the registry. * -@@ -428,5 +471,12 @@ public interface Registry<T extends Keyed> extends Iterable<T> { +@@ -428,5 +501,12 @@ public interface Registry<T extends Keyed> extends Iterable<T> { public Class<T> getType() { return this.type; } |