Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RegistrySet API #10699

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions patches/api/0003-Test-changes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ index 0000000000000000000000000000000000000000..77154095cfb8b259bdb318e8ff40cb6f
+ }
+}
diff --git a/src/test/java/org/bukkit/AnnotationTest.java b/src/test/java/org/bukkit/AnnotationTest.java
index 64e7aef6220097edefdff3b98a771b988365930d..a899f63eb2ce58b3cf708e91819cbbdeffda5d9f 100644
index 64e7aef6220097edefdff3b98a771b988365930d..d9091ba1e5a55e03adca98305233cce9d6888609 100644
--- a/src/test/java/org/bukkit/AnnotationTest.java
+++ b/src/test/java/org/bukkit/AnnotationTest.java
@@ -29,7 +29,13 @@ public class AnnotationTest {
Expand Down Expand Up @@ -103,7 +103,7 @@ index 64e7aef6220097edefdff3b98a771b988365930d..a899f63eb2ce58b3cf708e91819cbbde
};

@Test
@@ -67,14 +83,40 @@ public class AnnotationTest {
@@ -67,14 +83,48 @@ public class AnnotationTest {
}

if (mustBeAnnotated(Type.getReturnType(method.desc)) && !isWellAnnotated(method.invisibleAnnotations)) {
Expand Down Expand Up @@ -132,8 +132,16 @@ index 64e7aef6220097edefdff3b98a771b988365930d..a899f63eb2ce58b3cf708e91819cbbde
for (int i = 0; i < paramTypes.length; i++) {
if (mustBeAnnotated(paramTypes[i]) ^ isWellAnnotated(method.invisibleParameterAnnotations == null ? null : method.invisibleParameterAnnotations[i])) {
+ // Paper start
+ if (method.invisibleTypeAnnotations != null || method.visibleTypeAnnotations != null) {
+ for (final org.objectweb.asm.tree.TypeAnnotationNode invisibleTypeAnnotation : java.util.Objects.requireNonNullElse(method.invisibleTypeAnnotations, method.visibleTypeAnnotations)) {
+ if (method.invisibleTypeAnnotations != null) {
+ for (final org.objectweb.asm.tree.TypeAnnotationNode invisibleTypeAnnotation : method.invisibleTypeAnnotations) {
+ final org.objectweb.asm.TypeReference ref = new org.objectweb.asm.TypeReference(invisibleTypeAnnotation.typeRef);
+ if (ref.getSort() == org.objectweb.asm.TypeReference.METHOD_FORMAL_PARAMETER && ref.getTypeParameterIndex() == i && java.util.Arrays.asList(ACCEPTED_ANNOTATIONS).contains(invisibleTypeAnnotation.desc)) {
+ continue dancing;
+ }
+ }
+ }
+ if (method.visibleTypeAnnotations != null) {
+ for (final org.objectweb.asm.tree.TypeAnnotationNode invisibleTypeAnnotation : method.visibleTypeAnnotations) {
+ final org.objectweb.asm.TypeReference ref = new org.objectweb.asm.TypeReference(invisibleTypeAnnotation.typeRef);
+ if (ref.getSort() == org.objectweb.asm.TypeReference.METHOD_FORMAL_PARAMETER && ref.getTypeParameterIndex() == i && java.util.Arrays.asList(ACCEPTED_ANNOTATIONS).contains(invisibleTypeAnnotation.desc)) {
+ continue dancing;
Expand All @@ -144,7 +152,7 @@ index 64e7aef6220097edefdff3b98a771b988365930d..a899f63eb2ce58b3cf708e91819cbbde
ParameterNode paramNode = parameters == null ? null : parameters.get(i);
String paramName = paramNode == null ? null : paramNode.name;

@@ -91,13 +133,18 @@ public class AnnotationTest {
@@ -91,13 +141,18 @@ public class AnnotationTest {

Collections.sort(errors);

Expand All @@ -167,7 +175,7 @@ index 64e7aef6220097edefdff3b98a771b988365930d..a899f63eb2ce58b3cf708e91819cbbde
}

private static void collectClasses(@NotNull File from, @NotNull Map<String, ClassNode> to) throws IOException {
@@ -140,6 +187,11 @@ public class AnnotationTest {
@@ -140,6 +195,11 @@ public class AnnotationTest {
// Exceptions are excluded
return false;
}
Expand All @@ -179,7 +187,7 @@ index 64e7aef6220097edefdff3b98a771b988365930d..a899f63eb2ce58b3cf708e91819cbbde

for (String excludedClass : EXCLUDED_CLASSES) {
if (excludedClass.equals(clazz.name)) {
@@ -152,7 +204,7 @@ public class AnnotationTest {
@@ -152,7 +212,7 @@ public class AnnotationTest {

private static boolean isMethodIncluded(@NotNull ClassNode clazz, @NotNull MethodNode method, @NotNull Map<String, ClassNode> allClasses) {
// Exclude private, synthetic and deprecated methods
Expand All @@ -188,7 +196,7 @@ index 64e7aef6220097edefdff3b98a771b988365930d..a899f63eb2ce58b3cf708e91819cbbde
return false;
}

@@ -170,11 +222,30 @@ public class AnnotationTest {
@@ -170,11 +230,30 @@ public class AnnotationTest {
if ("<init>".equals(method.name) && isAnonymous(clazz)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion patches/api/0073-AsyncTabCompleteEvent.patch
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ index 270e6d8ad4358baa256cee5f16cff281f063ce3b..b43c3cb5c88eada186d6f81712c244aa

@Override
diff --git a/src/test/java/org/bukkit/AnnotationTest.java b/src/test/java/org/bukkit/AnnotationTest.java
index a899f63eb2ce58b3cf708e91819cbbdeffda5d9f..057dc3ebea3516863dda24252fe05d344c16fab3 100644
index d9091ba1e5a55e03adca98305233cce9d6888609..b82f07a2879412f6b30643ca93a97439aa49a98a 100644
--- a/src/test/java/org/bukkit/AnnotationTest.java
+++ b/src/test/java/org/bukkit/AnnotationTest.java
@@ -48,6 +48,8 @@ public class AnnotationTest {
Expand Down
36 changes: 33 additions & 3 deletions patches/api/0434-Improve-Registry.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion patches/api/0478-Registry-Modification-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ index 0000000000000000000000000000000000000000..f4d4ebf6cbed1b4a9955ceb2d0586782
+public interface RegistryEntryAddEventType<T, B extends RegistryBuilder<T>> extends LifecycleEventType<BootstrapContext, RegistryEntryAddEvent<T, B>, RegistryEntryAddConfiguration<T>> {
+}
diff --git a/src/main/java/org/bukkit/Registry.java b/src/main/java/org/bukkit/Registry.java
index 802511eaf697d703cadb4b418fe51ea6d31ff3c8..85c4f231dc343c73f1678819f1ac95d5a7ffd080 100644
index b02160f42281bc4e20123752a593c5d655305381..240500771bac439156b4c5d93ff047ae45d56154 100644
--- a/src/main/java/org/bukkit/Registry.java
+++ b/src/main/java/org/bukkit/Registry.java
@@ -353,6 +353,27 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
Expand Down
Loading
Loading