Skip to content

Commit 15b6b3d

Browse files
Add StructuresLocateEvent as replacement for StructureLocateEvent (#7524)
1 parent 753bf2c commit 15b6b3d

File tree

418 files changed

+1084
-267
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

418 files changed

+1084
-267
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Jake Potrebic <jake.m.potrebic@gmail.com>
3+
Date: Wed, 2 Mar 2022 13:36:21 -0800
4+
Subject: [PATCH] Add PaperRegistry
5+
6+
7+
diff --git a/src/main/java/io/papermc/paper/registry/Reference.java b/src/main/java/io/papermc/paper/registry/Reference.java
8+
new file mode 100644
9+
index 0000000000000000000000000000000000000000..d880810cbf05bc45051fe29515054211572e33b4
10+
--- /dev/null
11+
+++ b/src/main/java/io/papermc/paper/registry/Reference.java
12+
@@ -0,0 +1,43 @@
13+
+package io.papermc.paper.registry;
14+
+
15+
+import org.bukkit.Keyed;
16+
+import org.bukkit.NamespacedKey;
17+
+import org.bukkit.Registry;
18+
+import org.jetbrains.annotations.NotNull;
19+
+import org.jetbrains.annotations.Nullable;
20+
+
21+
+/**
22+
+ * Represents a reference to a server-backed registry value that may
23+
+ * change.
24+
+ *
25+
+ * @param <T> type of the value
26+
+ */
27+
+public interface Reference<T extends Keyed> extends Keyed {
28+
+
29+
+ /**
30+
+ * Gets the value from the registry with the key.
31+
+ *
32+
+ * @return the value
33+
+ * @throws java.util.NoSuchElementException if there is no value with this key
34+
+ */
35+
+ @NotNull T value();
36+
+
37+
+ /**
38+
+ * Gets the value from the registry with the key.
39+
+ *
40+
+ * @return the value or null if it doesn't exist
41+
+ */
42+
+ @Nullable T valueOrNull();
43+
+
44+
+ /**
45+
+ * Creates a reference to a registered value.
46+
+ *
47+
+ * @param registry the registry the value is located in
48+
+ * @param key the key to the value
49+
+ * @param <T> the type of the value
50+
+ * @return a reference
51+
+ */
52+
+ static <T extends Keyed> @NotNull Reference<T> create(@NotNull Registry<T> registry, @NotNull NamespacedKey key) {
53+
+ return new ReferenceImpl<>(registry, key);
54+
+ }
55+
+}
56+
diff --git a/src/main/java/io/papermc/paper/registry/ReferenceImpl.java b/src/main/java/io/papermc/paper/registry/ReferenceImpl.java
57+
new file mode 100644
58+
index 0000000000000000000000000000000000000000..f29e76a6b66ddfec12ddf8db6dcb2df6083b5982
59+
--- /dev/null
60+
+++ b/src/main/java/io/papermc/paper/registry/ReferenceImpl.java
61+
@@ -0,0 +1,31 @@
62+
+package io.papermc.paper.registry;
63+
+
64+
+import org.bukkit.Keyed;
65+
+import org.bukkit.NamespacedKey;
66+
+import org.bukkit.Registry;
67+
+import org.jetbrains.annotations.NotNull;
68+
+import org.jetbrains.annotations.Nullable;
69+
+
70+
+import java.util.NoSuchElementException;
71+
+
72+
+record ReferenceImpl<T extends Keyed>(@NotNull Registry<T> registry, @NotNull NamespacedKey key) implements Reference<T> {
73+
+
74+
+ @Override
75+
+ public @NotNull T value() {
76+
+ final T value = this.registry.get(this.key);
77+
+ if (value == null) {
78+
+ throw new NoSuchElementException("No such value with key " + this.key);
79+
+ }
80+
+ return value;
81+
+ }
82+
+
83+
+ @Override
84+
+ public @Nullable T valueOrNull() {
85+
+ return this.registry.get(this.key);
86+
+ }
87+
+
88+
+ @Override
89+
+ public @NotNull NamespacedKey getKey() {
90+
+ return this.key;
91+
+ }
92+
+}
93+
diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
94+
index b24439b379be1a90dde4e6f4dbe5ca3fdd8face4..0697214210a6e87f690b9454d9651d06ca57a524 100644
95+
--- a/src/main/java/org/bukkit/UnsafeValues.java
96+
+++ b/src/main/java/org/bukkit/UnsafeValues.java
97+
@@ -147,5 +147,15 @@ public interface UnsafeValues {
98+
* Use this when sending custom packets, so that there are no collisions on the client or server.
99+
*/
100+
public int nextEntityId();
101+
+
102+
+ /**
103+
+ * Gets the server-backed registry for a type.
104+
+ *
105+
+ * @param classOfT type
106+
+ * @param <T> type
107+
+ * @return the server-backed registry
108+
+ * @throws IllegalArgumentException if there isn't a registry for that type
109+
+ */
110+
+ <T extends Keyed> @org.jetbrains.annotations.NotNull Registry<T> registryFor(Class<T> classOfT);
111+
// Paper end
112+
}

patches/api/0256-Add-StructureLocateEvent.patch

Lines changed: 0 additions & 167 deletions
This file was deleted.

0 commit comments

Comments
 (0)