Fix NPE with enchantable (#11557)

This commit is contained in:
Lulu13022002
2024-11-09 23:26:01 +01:00
parent bbc8fc8fec
commit 16f8d0f984
41 changed files with 161 additions and 110 deletions

View File

@@ -223,11 +223,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
* Attribute.
*
* @see Attribute
+ * @deprecated use {@link io.papermc.paper.registry.RegistryAccess#getRegistry(io.papermc.paper.registry.RegistryKey)} with {@link io.papermc.paper.registry.RegistryKey#ATTRIBUTE}
*/
- Registry<Attribute> ATTRIBUTE = Objects.requireNonNull(Bukkit.getRegistry(Attribute.class), "No registry present for Attribute. This is a bug.");
+ @Deprecated(since = "1.21.3") // Paper
+ Registry<Attribute> ATTRIBUTE = Objects.requireNonNull(io.papermc.paper.registry.RegistryAccess.registryAccess().getRegistry(Attribute.class), "No registry present for Attribute. This is a bug.");
+ Registry<Attribute> ATTRIBUTE = io.papermc.paper.registry.RegistryAccess.registryAccess().getRegistry(io.papermc.paper.registry.RegistryKey.ATTRIBUTE); // Paper
/**
* Server banner patterns.
*
@@ -277,11 +275,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
* Server entity types.
*
@@ -0,0 +0,0 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
* Server instruments.
*
* @see MusicInstrument
+ * @deprecated use {@link io.papermc.paper.registry.RegistryAccess#getRegistry(io.papermc.paper.registry.RegistryKey)} with {@link io.papermc.paper.registry.RegistryKey#INSTRUMENT}
*/
- Registry<MusicInstrument> INSTRUMENT = Objects.requireNonNull(Bukkit.getRegistry(MusicInstrument.class), "No registry present for MusicInstrument. This is a bug.");
+ Registry<MusicInstrument> INSTRUMENT = io.papermc.paper.registry.RegistryAccess.registryAccess().getRegistry(io.papermc.paper.registry.RegistryKey.INSTRUMENT); // Paper
+ @Deprecated(since = "1.21.2")
+ Registry<MusicInstrument> INSTRUMENT = Objects.requireNonNull(io.papermc.paper.registry.RegistryAccess.registryAccess().getRegistry(MusicInstrument.class), "No registry present for Instruments. This is a bug."); // Paper
/**
* Server item types.
*
@@ -389,14 +390,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
* Memory Keys.
*
@@ -0,0 +0,0 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
* Server fluids.
*
* @see Fluid
+ * @deprecated use {@link io.papermc.paper.registry.RegistryAccess#getRegistry(io.papermc.paper.registry.RegistryKey)} with {@link io.papermc.paper.registry.RegistryKey#FLUID}
*/
- Registry<Fluid> FLUID = Objects.requireNonNull(Bukkit.getRegistry(Fluid.class), "No registry present for Fluid. This is a bug.");
+ @Deprecated(since = "1.21.3")
+ Registry<Fluid> FLUID = Objects.requireNonNull(io.papermc.paper.registry.RegistryAccess.registryAccess().getRegistry(Fluid.class), "No registry present for Fluid. This is a bug.");
+ Registry<Fluid> FLUID = io.papermc.paper.registry.RegistryAccess.registryAccess().getRegistry(io.papermc.paper.registry.RegistryKey.FLUID); // Paper
/**
* Frog variants.
*

View File

@@ -204,12 +204,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
return Registry.INSTRUMENT.getOrThrow(NamespacedKey.minecraft(key));
}
+
+ // Paper start - translation key
+ // Paper start - mark translation key as deprecated
+ /**
+ * @deprecated this method assumes that the instrument description
+ * always be a translatable component which is not guaranteed.
+ */
+ @Override
+ public @NotNull String translationKey() {
+ return "instrument.minecraft." + this.getKey().value();
+ }
+ // Paper end - translation key
+ @Deprecated(forRemoval = true)
+ public abstract @NotNull String translationKey();
+ // Paper end - mark translation key as deprecated
}
diff --git a/src/main/java/org/bukkit/Translatable.java b/src/main/java/org/bukkit/Translatable.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644

View File

@@ -155,11 +155,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ */
+ RegistryKey<StructureType> STRUCTURE_TYPE = create("worldgen/structure_type");
+ /**
+ * Built-in registry for instruments.
+ * @see io.papermc.paper.registry.keys.InstrumentKeys
+ */
+ RegistryKey<MusicInstrument> INSTRUMENT = create("instrument");
+ /**
+ * Built-in registry for potion effect types (mob effects).
+ * @see io.papermc.paper.registry.keys.MobEffectKeys
+ */
@@ -275,6 +270,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @see io.papermc.paper.registry.keys.PaintingVariantKeys
+ */
+ RegistryKey<Art> PAINTING_VARIANT = create("painting_variant");
+ /**
+ * Data-driven registry for instruments.
+ * @see io.papermc.paper.registry.keys.InstrumentKeys
+ */
+ RegistryKey<MusicInstrument> INSTRUMENT = create("instrument");
+
+
+ /* ******************* *

View File

@@ -40,17 +40,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ // Paper start - deprecate getKey
+ /**
+ * @deprecated use {@link Registry#getKey(Keyed)} and {@link Registry#INSTRUMENT}. MusicInstruments
+ * can exist without a key.
+ * @deprecated use {@link Registry#getKey(Keyed)}, {@link io.papermc.paper.registry.RegistryAccess#getRegistry(io.papermc.paper.registry.RegistryKey)},
+ * and {@link io.papermc.paper.registry.RegistryKey#INSTRUMENT}. MusicInstruments can exist without a key.
+ */
+ @Deprecated(forRemoval = true, since = "1.20.5")
+ @Override
+ public abstract @NotNull NamespacedKey getKey();
+ // Paper end - deprecate getKey
+
// Paper start - translation key
@Override
public @NotNull String translationKey() {
// Paper start - mark translation key as deprecated
/**
* @deprecated this method assumes that the instrument description
diff --git a/src/main/java/org/bukkit/Registry.java b/src/main/java/org/bukkit/Registry.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/Registry.java
@@ -197,8 +197,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
public abstract StructureType getStructureType();
+ // Paper start - deprecate getKey
+ /**
+ * @deprecated use {@link Registry#getKey(Keyed)} and {@link Registry#STRUCTURE}. Structures
+ * can exist without a key.
+ * @deprecated use {@link Registry#getKey(Keyed)}, {@link io.papermc.paper.registry.RegistryAccess#getRegistry(io.papermc.paper.registry.RegistryKey)},
+ * and {@link io.papermc.paper.registry.RegistryKey#STRUCTURE}. Structures can exist without a key.
+ */
+ @Override
+ @Deprecated(since = "1.20.4")