Registry Modification API (#10893)
* Registry Modification API * some fixes * even more fixes
This commit is contained in:
@@ -40,6 +40,36 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
|
||||
+ // 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
|
||||
|
||||
Reference in New Issue
Block a user