mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-08 16:12:18 -07:00
[ci skip] use more jspecify in server
This commit is contained in:
@@ -81,14 +81,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+import org.bukkit.inventory.meta.trim.TrimPattern;
|
||||
+import org.bukkit.map.MapCursor;
|
||||
+import org.bukkit.potion.PotionEffectType;
|
||||
+import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
+import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
+import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
+import org.jspecify.annotations.Nullable;
|
||||
+
|
||||
+import static io.papermc.paper.registry.entry.RegistryEntry.apiOnly;
|
||||
+import static io.papermc.paper.registry.entry.RegistryEntry.entry;
|
||||
+
|
||||
+@DefaultQualifier(NonNull.class)
|
||||
+public final class PaperRegistries {
|
||||
+
|
||||
+ static final List<RegistryEntry<?, ?>> REGISTRY_ENTRIES;
|
||||
@@ -194,14 +191,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+import net.minecraft.resources.ResourceKey;
|
||||
+import org.bukkit.Keyed;
|
||||
+import org.bukkit.Registry;
|
||||
+import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
+import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
+import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
+import org.jetbrains.annotations.VisibleForTesting;
|
||||
+import org.jspecify.annotations.Nullable;
|
||||
+
|
||||
+import static java.util.Objects.requireNonNull;
|
||||
+
|
||||
+@DefaultQualifier(NonNull.class)
|
||||
+public class PaperRegistryAccess implements RegistryAccess {
|
||||
+
|
||||
+ // We store the API registries in a memoized supplier, so they can be created on-demand.
|
||||
@@ -224,14 +216,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ @Deprecated(forRemoval = true)
|
||||
+ @Override
|
||||
+ public <T extends Keyed> @Nullable Registry<T> getRegistry(final Class<T> type) {
|
||||
+ final @Nullable RegistryKey<T> registryKey = byType(type);
|
||||
+ final RegistryKey<T> registryKey = byType(type);
|
||||
+ // If our mapping from Class -> RegistryKey did not contain the passed type it was either a completely invalid type or a registry
|
||||
+ // that merely exists as a SimpleRegistry in the org.bukkit.Registry type. We cannot return a registry for these, return null
|
||||
+ // as per method contract in Bukkit#getRegistry.
|
||||
+ if (registryKey == null) return null;
|
||||
+
|
||||
+ final @Nullable RegistryEntry<?, T> entry = PaperRegistries.getEntry(registryKey);
|
||||
+ final @Nullable RegistryHolder<T> registry = (RegistryHolder<T>) this.registries.get(registryKey);
|
||||
+ final RegistryEntry<?, T> entry = PaperRegistries.getEntry(registryKey);
|
||||
+ final RegistryHolder<T> registry = (RegistryHolder<T>) this.registries.get(registryKey);
|
||||
+ if (registry != null) {
|
||||
+ // if the registry exists, return right away. Since this is the "legacy" method, we return DelayedRegistry
|
||||
+ // for the non-builtin Registry instances stored as fields in Registry.
|
||||
@@ -364,10 +356,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+import java.util.function.Supplier;
|
||||
+import org.bukkit.Keyed;
|
||||
+import org.bukkit.Registry;
|
||||
+import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
+import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
+
|
||||
+@DefaultQualifier(NonNull.class)
|
||||
+public interface RegistryHolder<B extends Keyed> {
|
||||
+
|
||||
+ Registry<B> get();
|
||||
@@ -487,10 +476,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+import org.bukkit.NamespacedKey;
|
||||
+import org.bukkit.craftbukkit.CraftRegistry;
|
||||
+import org.bukkit.craftbukkit.util.ApiVersion;
|
||||
+import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
+import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
+
|
||||
+@DefaultQualifier(NonNull.class)
|
||||
+public class CraftRegistryEntry<M, B extends Keyed> extends BaseRegistryEntry<M, B> { // TODO remove Keyed
|
||||
+
|
||||
+ private static final BiFunction<NamespacedKey, ApiVersion, NamespacedKey> EMPTY = (namespacedKey, apiVersion) -> namespacedKey;
|
||||
@@ -544,10 +530,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+import org.bukkit.Keyed;
|
||||
+import org.bukkit.NamespacedKey;
|
||||
+import org.bukkit.craftbukkit.util.ApiVersion;
|
||||
+import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
+import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
+
|
||||
+@DefaultQualifier(NonNull.class)
|
||||
+public interface RegistryEntry<M, B extends Keyed> extends RegistryEntryInfo<M, B> { // TODO remove Keyed
|
||||
+
|
||||
+ RegistryHolder<B> createRegistryHolder(Registry<M> nmsRegistry);
|
||||
@@ -607,11 +590,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/registry/entry/package-info.java
|
||||
@@ -0,0 +0,0 @@
|
||||
+@DefaultQualifier(NonNull.class)
|
||||
+@NullMarked
|
||||
+package io.papermc.paper.registry.entry;
|
||||
+
|
||||
+import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
+import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
diff --git a/src/main/java/io/papermc/paper/registry/legacy/DelayedRegistry.java b/src/main/java/io/papermc/paper/registry/legacy/DelayedRegistry.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
||||
@@ -623,14 +605,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+import java.util.Iterator;
|
||||
+import java.util.function.Supplier;
|
||||
+import java.util.stream.Stream;
|
||||
+import net.kyori.adventure.key.Key;
|
||||
+import org.bukkit.Keyed;
|
||||
+import org.bukkit.NamespacedKey;
|
||||
+import org.bukkit.Registry;
|
||||
+import org.bukkit.craftbukkit.CraftRegistry;
|
||||
+import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
+import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import org.jspecify.annotations.Nullable;
|
||||
+
|
||||
+/**
|
||||
+ * This is to support the now-deprecated fields in {@link Registry} for
|
||||
@@ -638,7 +616,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ */
|
||||
+public final class DelayedRegistry<T extends Keyed, R extends Registry<T>> implements Registry<T> {
|
||||
+
|
||||
+ private @MonotonicNonNull Supplier<? extends R> delegate;
|
||||
+ private @Nullable Supplier<? extends R> delegate;
|
||||
+
|
||||
+ public void load(final Supplier<? extends R> registry) {
|
||||
+ if (this.delegate != null) {
|
||||
@@ -660,7 +638,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public @NotNull T getOrThrow(@NotNull final NamespacedKey key) {
|
||||
+ public T getOrThrow(final NamespacedKey key) {
|
||||
+ return this.delegate().getOrThrow(key);
|
||||
+ }
|
||||
+
|
||||
@@ -675,7 +653,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public NamespacedKey getKey(final T value) {
|
||||
+ public @Nullable NamespacedKey getKey(final T value) {
|
||||
+ return this.delegate().getKey(value);
|
||||
+ }
|
||||
+}
|
||||
@@ -756,11 +734,20 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/registry/legacy/package-info.java
|
||||
@@ -0,0 +0,0 @@
|
||||
+@DefaultQualifier(NonNull.class)
|
||||
+@NullMarked
|
||||
+package io.papermc.paper.registry.legacy;
|
||||
+
|
||||
+import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
+import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
diff --git a/src/main/java/io/papermc/paper/registry/package-info.java b/src/main/java/io/papermc/paper/registry/package-info.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/registry/package-info.java
|
||||
@@ -0,0 +0,0 @@
|
||||
+@NullMarked
|
||||
+package io.papermc.paper.registry;
|
||||
+
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
diff --git a/src/main/java/net/minecraft/core/registries/BuiltInRegistries.java b/src/main/java/net/minecraft/core/registries/BuiltInRegistries.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/core/registries/BuiltInRegistries.java
|
||||
|
Reference in New Issue
Block a user