Don't use delayed registries in impl anywhere (#11918)

This commit is contained in:
Jake Potrebic
2025-01-11 11:02:28 -08:00
committed by GitHub
parent 19ddbeff9e
commit ac3aaa248b
55 changed files with 145 additions and 133 deletions

View File

@ -2,12 +2,13 @@ package org.bukkit;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryBuilderFactory;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.InlinedRegistryBuilderProvider;
import io.papermc.paper.registry.data.PaintingVariantRegistryEntry;
import java.util.Locale;
import java.util.function.Consumer;
import org.bukkit.packs.DataPack;
import org.bukkit.util.OldEnum;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
@ -18,8 +19,8 @@ import org.jetbrains.annotations.Nullable;
* <p>
* The arts listed in this interface are present in the default server
* or can be enabled via a {@link FeatureFlag}.
* There may be additional arts present in the server, for example from a {@link DataPack}
* which can be accessed via {@link Registry#ART}.
* There may be additional arts present in the server, for example from a {@link io.papermc.paper.datapack.Datapack}
* which can be accessed via {@link RegistryAccess#registryAccess()} and {@link RegistryKey#PAINTING_VARIANT}.
*/
public interface Art extends OldEnum<Art>, Keyed {
@ -87,7 +88,7 @@ public interface Art extends OldEnum<Art>, Keyed {
@NotNull
private static Art getArt(@NotNull String key) {
return Registry.ART.getOrThrow(NamespacedKey.minecraft(key));
return RegistryAccess.registryAccess().getRegistry(RegistryKey.PAINTING_VARIANT).getOrThrow(NamespacedKey.minecraft(key));
}
/**
@ -189,7 +190,7 @@ public interface Art extends OldEnum<Art>, Keyed {
static Art getByName(@NotNull String name) {
Preconditions.checkArgument(name != null, "Name cannot be null");
return Bukkit.getUnsafe().get(Registry.ART, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
return Bukkit.getUnsafe().get(RegistryKey.PAINTING_VARIANT, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
}
/**
@ -200,7 +201,7 @@ public interface Art extends OldEnum<Art>, Keyed {
@NotNull
@Deprecated(since = "1.21.3", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils
static Art valueOf(@NotNull String name) {
Art art = Bukkit.getUnsafe().get(Registry.ART, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
Art art = Bukkit.getUnsafe().get(RegistryKey.PAINTING_VARIANT, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
Preconditions.checkArgument(art != null, "No art found with the name %s", name);
return art;
}

View File

@ -2,6 +2,7 @@ package org.bukkit;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import io.papermc.paper.registry.RegistryKey;
import java.util.Locale;
import org.bukkit.util.OldEnum;
import org.jetbrains.annotations.NotNull;
@ -45,7 +46,7 @@ public interface Fluid extends OldEnum<Fluid>, Keyed {
@NotNull
@Deprecated(since = "1.21.3", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils
static Fluid valueOf(@NotNull String name) {
Fluid fluid = Bukkit.getUnsafe().get(Registry.FLUID, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
Fluid fluid = Bukkit.getUnsafe().get(RegistryKey.FLUID, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
Preconditions.checkArgument(fluid != null, "No fluid found with the name %s", name);
return fluid;
}

View File

@ -1,5 +1,7 @@
package org.bukkit;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
@ -31,7 +33,7 @@ public interface JukeboxSong extends Keyed, Translatable {
@NotNull
private static JukeboxSong get(@NotNull String key) {
return Registry.JUKEBOX_SONG.getOrThrow(NamespacedKey.minecraft(key));
return RegistryAccess.registryAccess().getRegistry(RegistryKey.JUKEBOX_SONG).getOrThrow(NamespacedKey.minecraft(key));
}
// Paper start - adventure

View File

@ -1,6 +1,8 @@
package org.bukkit;
import com.google.common.collect.Lists;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import java.util.Collection;
import java.util.Collections;
import org.jetbrains.annotations.NotNull;
@ -44,7 +46,7 @@ public abstract class MusicInstrument implements Keyed, net.kyori.adventure.tran
@NotNull
private static MusicInstrument getInstrument(@NotNull String key) {
return Registry.INSTRUMENT.getOrThrow(NamespacedKey.minecraft(key));
return RegistryAccess.registryAccess().getRegistry(RegistryKey.INSTRUMENT).getOrThrow(NamespacedKey.minecraft(key));
}
// Paper start - deprecate getKey

View File

@ -2,6 +2,7 @@ package org.bukkit;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import io.papermc.paper.registry.RegistryKey;
import java.util.Locale;
import org.bukkit.packs.DataPack;
import org.bukkit.util.OldEnum;
@ -1687,7 +1688,7 @@ public interface Sound extends OldEnum<Sound>, Keyed, net.kyori.adventure.sound.
@NotNull
@Deprecated(since = "1.21.3")
static Sound valueOf(@NotNull String name) {
Sound sound = Bukkit.getUnsafe().get(Registry.SOUNDS, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
Sound sound = Bukkit.getUnsafe().get(RegistryKey.SOUND_EVENT, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
if (sound != null) {
return sound;
}

View File

@ -2,6 +2,7 @@ package org.bukkit;
import com.google.common.collect.Multimap;
import io.papermc.paper.entity.EntitySerializationFlag;
import io.papermc.paper.registry.RegistryKey;
import org.bukkit.advancement.Advancement;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier;
@ -140,7 +141,7 @@ public interface UnsafeValues {
String get(Class<?> aClass, String value);
@ApiStatus.Internal
<B extends Keyed> B get(Registry<B> registry, NamespacedKey key);
<B extends Keyed> B get(RegistryKey<B> registry, NamespacedKey key);
@ApiStatus.Internal
Biome getCustomBiome();

View File

@ -2,6 +2,7 @@ package org.bukkit.attribute;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import io.papermc.paper.registry.RegistryKey;
import java.util.Locale;
import org.bukkit.Bukkit;
import org.bukkit.Keyed;
@ -158,7 +159,7 @@ public interface Attribute extends OldEnum<Attribute>, Keyed, Translatable, net.
@NotNull
@Deprecated(since = "1.21.3", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils
static Attribute valueOf(@NotNull String name) {
Attribute attribute = Bukkit.getUnsafe().get(Registry.ATTRIBUTE, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
Attribute attribute = Bukkit.getUnsafe().get(RegistryKey.ATTRIBUTE, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
Preconditions.checkArgument(attribute != null, "No attribute found with the name %s", name);
return attribute;
}

View File

@ -2,13 +2,14 @@ package org.bukkit.block;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import java.util.Locale;
import org.bukkit.Bukkit;
import org.bukkit.FeatureFlag;
import org.bukkit.Keyed;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.packs.DataPack;
import org.bukkit.util.OldEnum;
import org.jetbrains.annotations.NotNull;
@ -17,8 +18,8 @@ import org.jetbrains.annotations.NotNull;
* <p>
* The Biomes listed in this interface are present in the default server
* or can be enabled via a {@link FeatureFlag}.
* There may be additional biomes present in the server, for example from a {@link DataPack}
* which can be accessed via {@link Registry#BIOME}.
* There may be additional biomes present in the server, for example from a {@link io.papermc.paper.datapack.Datapack}
* which can be accessed via {@link io.papermc.paper.registry.RegistryAccess#getRegistry(RegistryKey)} and {@link RegistryKey#BIOME}.
*/
public interface Biome extends OldEnum<Biome>, Keyed, net.kyori.adventure.translation.Translatable { // Paper - Adventure translations
@ -98,7 +99,7 @@ public interface Biome extends OldEnum<Biome>, Keyed, net.kyori.adventure.transl
@NotNull
private static Biome getBiome(@NotNull String key) {
return Registry.BIOME.getOrThrow(NamespacedKey.minecraft(key));
return RegistryAccess.registryAccess().getRegistry(RegistryKey.BIOME).getOrThrow(NamespacedKey.minecraft(key));
}
/**
@ -113,7 +114,7 @@ public interface Biome extends OldEnum<Biome>, Keyed, net.kyori.adventure.transl
return Biome.CUSTOM;
}
Biome biome = Bukkit.getUnsafe().get(Registry.BIOME, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
Biome biome = Bukkit.getUnsafe().get(RegistryKey.BIOME, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
Preconditions.checkArgument(biome != null, "No biome found with the name %s", name);
return biome;
}

View File

@ -2,6 +2,7 @@ package org.bukkit.block.banner;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import io.papermc.paper.registry.RegistryKey;
import java.util.Map;
import java.util.NoSuchElementException;
import org.bukkit.Bukkit;
@ -45,7 +46,7 @@ public class Pattern implements ConfigurationSerializable {
PatternType patternType = PatternType.getByIdentifier(value);
if (patternType == null) {
patternType = Bukkit.getUnsafe().get(Registry.BANNER_PATTERN, NamespacedKey.fromString(value));
patternType = Bukkit.getUnsafe().get(RegistryKey.BANNER_PATTERN, NamespacedKey.fromString(value));
}
Preconditions.checkNotNull(patternType, "Pattern type for key %s cannot be null", value);

View File

@ -2,6 +2,8 @@ package org.bukkit.block.banner;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import java.util.Locale;
import org.bukkit.Keyed;
import org.bukkit.NamespacedKey;
@ -95,8 +97,7 @@ public interface PatternType extends OldEnum<PatternType>, Keyed {
*
* @param identifier the identifier
* @return the matched pattern type or null
* @see Registry#BANNER_PATTERN
* @deprecated magic value, use {@link Registry#get(NamespacedKey)} instead
* @deprecated magic value, use {@link Registry#get(NamespacedKey)} instead with {@link io.papermc.paper.registry.RegistryAccess#getRegistry(io.papermc.paper.registry.RegistryKey)} and {@link io.papermc.paper.registry.RegistryKey#BANNER_PATTERN}
*/
@Contract("null -> null")
@Nullable
@ -117,7 +118,7 @@ public interface PatternType extends OldEnum<PatternType>, Keyed {
@NotNull
private static PatternType getType(@NotNull String key) {
return Registry.BANNER_PATTERN.getOrThrow(NamespacedKey.minecraft(key));
return RegistryAccess.registryAccess().getRegistry(RegistryKey.BANNER_PATTERN).getOrThrow(NamespacedKey.minecraft(key));
}
/**

View File

@ -1,5 +1,7 @@
package org.bukkit.damage;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import org.bukkit.Keyed;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
@ -12,7 +14,7 @@ import org.jetbrains.annotations.NotNull;
* <p>
* Constants in this class include the base types provided by the vanilla
* server. Data packs are capable of registering more types of damage which may
* be obtained through the {@link Registry#DAMAGE_TYPE}.
* be obtained through {@link io.papermc.paper.registry.RegistryAccess#getRegistry(RegistryKey)} and {@link RegistryKey#DAMAGE_TYPE}.
*
* @see <a href="https://minecraft.wiki/w/Damage_type">Minecraft Wiki</a>
*/
@ -71,7 +73,7 @@ public interface DamageType extends Keyed, Translatable {
@NotNull
private static DamageType getDamageType(@NotNull String key) {
return Registry.DAMAGE_TYPE.getOrThrow(NamespacedKey.minecraft(key));
return RegistryAccess.registryAccess().getRegistry(RegistryKey.DAMAGE_TYPE).getOrThrow(NamespacedKey.minecraft(key));
}
/**

View File

@ -1,6 +1,8 @@
package org.bukkit.enchantments;
import com.google.common.collect.Lists;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import java.util.Locale;
import org.bukkit.Keyed;
import org.bukkit.NamespacedKey;
@ -229,7 +231,7 @@ public abstract class Enchantment implements Keyed, Translatable, net.kyori.adve
@NotNull
private static Enchantment getEnchantment(@NotNull String key) {
return Registry.ENCHANTMENT.getOrThrow(NamespacedKey.minecraft(key));
return RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT).getOrThrow(NamespacedKey.minecraft(key));
}
/**

View File

@ -1,5 +1,7 @@
package org.bukkit.entity;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import org.bukkit.DyeColor;
import org.bukkit.Keyed;
import org.bukkit.NamespacedKey;
@ -105,7 +107,7 @@ public interface Wolf extends Tameable, Sittable, io.papermc.paper.entity.Collar
@NotNull
private static Variant getVariant(@NotNull String key) {
return Registry.WOLF_VARIANT.getOrThrow(NamespacedKey.minecraft(key));
return RegistryAccess.registryAccess().getRegistry(RegistryKey.WOLF_VARIANT).getOrThrow(NamespacedKey.minecraft(key));
}
}
}

View File

@ -1,5 +1,7 @@
package org.bukkit.generator.structure;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import org.bukkit.Keyed;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
@ -10,7 +12,7 @@ import org.jetbrains.annotations.NotNull;
*
* Listed structures are present in the default server. Depending on the server
* there might be additional structures present (for example structures added by
* data packs), which can be received via {@link Registry#STRUCTURE}.
* data packs), which can be received via {@link io.papermc.paper.registry.RegistryAccess#getRegistry(io.papermc.paper.registry.RegistryKey)} and {@link io.papermc.paper.registry.RegistryKey#STRUCTURE}.
*/
public abstract class Structure implements Keyed {
@ -51,7 +53,7 @@ public abstract class Structure implements Keyed {
@NotNull
private static Structure getStructure(@NotNull String name) {
return Registry.STRUCTURE.getOrThrow(NamespacedKey.minecraft(name));
return RegistryAccess.registryAccess().getRegistry(RegistryKey.STRUCTURE).getOrThrow(NamespacedKey.minecraft(name));
}
/**

View File

@ -2,6 +2,7 @@ package org.bukkit.inventory;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import io.papermc.paper.registry.RegistryKey;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
@ -543,7 +544,7 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat
stringKey = Bukkit.getUnsafe().get(Enchantment.class, stringKey);
NamespacedKey key = NamespacedKey.fromString(stringKey.toLowerCase(Locale.ROOT));
Enchantment enchantment = Bukkit.getUnsafe().get(Registry.ENCHANTMENT, key);
Enchantment enchantment = Bukkit.getUnsafe().get(RegistryKey.ENCHANTMENT, key);
if ((enchantment != null) && (entry.getValue() instanceof Integer)) {
result.addUnsafeEnchantment(enchantment, (Integer) entry.getValue());

View File

@ -1,5 +1,7 @@
package org.bukkit.inventory.meta.trim;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import org.bukkit.Keyed;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
@ -59,7 +61,7 @@ public interface TrimMaterial extends Keyed, Translatable {
@NotNull
private static TrimMaterial getTrimMaterial(@NotNull String key) {
return Registry.TRIM_MATERIAL.getOrThrow(NamespacedKey.minecraft(key));
return RegistryAccess.registryAccess().getRegistry(RegistryKey.TRIM_MATERIAL).getOrThrow(NamespacedKey.minecraft(key));
}
// Paper start - adventure

View File

@ -1,5 +1,7 @@
package org.bukkit.inventory.meta.trim;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import org.bukkit.Keyed;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
@ -87,7 +89,7 @@ public interface TrimPattern extends Keyed, Translatable {
@NotNull
private static TrimPattern getTrimPattern(@NotNull String key) {
return Registry.TRIM_PATTERN.getOrThrow(NamespacedKey.minecraft(key));
return RegistryAccess.registryAccess().getRegistry(RegistryKey.TRIM_PATTERN).getOrThrow(NamespacedKey.minecraft(key));
}
// Paper start - adventure

View File

@ -2,6 +2,7 @@ package org.bukkit.potion;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import io.papermc.paper.registry.RegistryKey;
import java.util.Map;
import java.util.NoSuchElementException;
import org.bukkit.Bukkit;
@ -175,7 +176,7 @@ public class PotionEffect implements ConfigurationSerializable {
private static PotionEffectType getEffectType(@NotNull Map<?, ?> map) {
PotionEffectType effect;
if (map.get(TYPE) instanceof String value) {
effect = Bukkit.getUnsafe().get(Registry.EFFECT, NamespacedKey.fromString(value));
effect = Bukkit.getUnsafe().get(RegistryKey.MOB_EFFECT, NamespacedKey.fromString(value));
} else {
int type = getInt(map, TYPE);
effect = PotionEffectType.getById(type);