aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0245-Add-PaperRegistry.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patches/api/0245-Add-PaperRegistry.patch')
-rw-r--r--patches/api/0245-Add-PaperRegistry.patch92
1 files changed, 92 insertions, 0 deletions
diff --git a/patches/api/0245-Add-PaperRegistry.patch b/patches/api/0245-Add-PaperRegistry.patch
new file mode 100644
index 0000000000..8cc1e1b931
--- /dev/null
+++ b/patches/api/0245-Add-PaperRegistry.patch
@@ -0,0 +1,92 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Jake Potrebic <[email protected]>
+Date: Wed, 2 Mar 2022 13:36:21 -0800
+Subject: [PATCH] Add PaperRegistry
+
+
+diff --git a/src/main/java/io/papermc/paper/registry/Reference.java b/src/main/java/io/papermc/paper/registry/Reference.java
+new file mode 100644
+index 0000000000000000000000000000000000000000..d880810cbf05bc45051fe29515054211572e33b4
+--- /dev/null
++++ b/src/main/java/io/papermc/paper/registry/Reference.java
+@@ -0,0 +1,43 @@
++package io.papermc.paper.registry;
++
++import org.bukkit.Keyed;
++import org.bukkit.NamespacedKey;
++import org.bukkit.Registry;
++import org.jetbrains.annotations.NotNull;
++import org.jetbrains.annotations.Nullable;
++
++/**
++ * Represents a reference to a server-backed registry value that may
++ * change.
++ *
++ * @param <T> type of the value
++ */
++public interface Reference<T extends Keyed> extends Keyed {
++
++ /**
++ * Gets the value from the registry with the key.
++ *
++ * @return the value
++ * @throws java.util.NoSuchElementException if there is no value with this key
++ */
++ @NotNull T value();
++
++ /**
++ * Gets the value from the registry with the key.
++ *
++ * @return the value or null if it doesn't exist
++ */
++ @Nullable T valueOrNull();
++
++ /**
++ * Creates a reference to a registered value.
++ *
++ * @param registry the registry the value is located in
++ * @param key the key to the value
++ * @param <T> the type of the value
++ * @return a reference
++ */
++ static <T extends Keyed> @NotNull Reference<T> create(@NotNull Registry<T> registry, @NotNull NamespacedKey key) {
++ return new ReferenceImpl<>(registry, key);
++ }
++}
+diff --git a/src/main/java/io/papermc/paper/registry/ReferenceImpl.java b/src/main/java/io/papermc/paper/registry/ReferenceImpl.java
+new file mode 100644
+index 0000000000000000000000000000000000000000..f29e76a6b66ddfec12ddf8db6dcb2df6083b5982
+--- /dev/null
++++ b/src/main/java/io/papermc/paper/registry/ReferenceImpl.java
+@@ -0,0 +1,31 @@
++package io.papermc.paper.registry;
++
++import org.bukkit.Keyed;
++import org.bukkit.NamespacedKey;
++import org.bukkit.Registry;
++import org.jetbrains.annotations.NotNull;
++import org.jetbrains.annotations.Nullable;
++
++import java.util.NoSuchElementException;
++
++record ReferenceImpl<T extends Keyed>(@NotNull Registry<T> registry, @NotNull NamespacedKey key) implements Reference<T> {
++
++ @Override
++ public @NotNull T value() {
++ final T value = this.registry.get(this.key);
++ if (value == null) {
++ throw new NoSuchElementException("No such value with key " + this.key);
++ }
++ return value;
++ }
++
++ @Override
++ public @Nullable T valueOrNull() {
++ return this.registry.get(this.key);
++ }
++
++ @Override
++ public @NotNull NamespacedKey getKey() {
++ return this.key;
++ }
++}