Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@
import io.papermc.paper.registry.tag.TagKey;
import java.util.List;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import net.kyori.adventure.text.Component;
import org.bukkit.Art;
import org.bukkit.DyeColor;
import org.bukkit.FireworkEffect;
import org.bukkit.MusicInstrument;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.block.banner.PatternType;
import org.bukkit.damage.DamageType;
Expand Down Expand Up @@ -82,8 +82,6 @@
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;

import static java.util.Objects.requireNonNull;

/**
* All the different types of data that {@link org.bukkit.inventory.ItemStack ItemStacks}
* and {@link org.bukkit.inventory.ItemType ItemTypes} can have.
Expand Down Expand Up @@ -392,21 +390,21 @@ public final class DataComponentTypes {
public static final DataComponentType.Valued<DyeColor> SHEEP_COLOR = valued("sheep/color");
public static final DataComponentType.Valued<DyeColor> SHULKER_COLOR = valued("shulker/color");

private static DataComponentType.NonValued unvalued(final String name) {
final DataComponentType dataComponentType = requireNonNull(Registry.DATA_COMPONENT_TYPE.get(NamespacedKey.minecraft(name)), name + " unvalued data component type couldn't be found, this is a bug.");
private static DataComponentType.NonValued unvalued(final @KeyPattern.Value String key) {
final DataComponentType dataComponentType = Registry.DATA_COMPONENT_TYPE.getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, key));
if (dataComponentType instanceof DataComponentType.NonValued) {
return (DataComponentType.NonValued) dataComponentType;
}
throw new IllegalStateException(name + " is not a valid unvalued type, it is a " + dataComponentType.getClass().getTypeName());
throw new IllegalStateException(key + " is not a valid unvalued type, it is a " + dataComponentType.getClass().getTypeName());
}

@SuppressWarnings("unchecked")
private static <T> DataComponentType.Valued<T> valued(final String name) {
DataComponentType dataComponentType = requireNonNull(Registry.DATA_COMPONENT_TYPE.get(NamespacedKey.minecraft(name)), name + " valued data component type couldn't be found, this is a bug.");
private static <T> DataComponentType.Valued<T> valued(final @KeyPattern.Value String key) {
DataComponentType dataComponentType = Registry.DATA_COMPONENT_TYPE.getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, key));
if (dataComponentType instanceof DataComponentType.Valued) {
return (DataComponentType.Valued<T>) dataComponentType;
}
throw new IllegalStateException(name + " is not a valid valued type, it is a " + dataComponentType.getClass().getTypeName());
throw new IllegalStateException(key + " is not a valid valued type, it is a " + dataComponentType.getClass().getTypeName());

}

Expand Down
27 changes: 14 additions & 13 deletions paper-api/src/main/java/org/bukkit/Art.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
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 net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import org.bukkit.util.OldEnum;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -129,8 +125,8 @@ public interface Art extends OldEnum<Art>, Keyed {
// End generate - Art

@NotNull
private static Art getArt(@NotNull String key) {
return RegistryAccess.registryAccess().getRegistry(RegistryKey.PAINTING_VARIANT).getOrThrow(NamespacedKey.minecraft(key));
private static Art getArt(@NotNull @KeyPattern.Value String key) {
return RegistryAccess.registryAccess().getRegistry(RegistryKey.PAINTING_VARIANT).getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, key));
}

/**
Expand Down Expand Up @@ -209,7 +205,7 @@ private static Art getArt(@NotNull String key) {
@Deprecated(since = "1.6.2", forRemoval = true)
@Nullable
static Art getById(int id) {
for (Art art : Registry.ART) {
for (Art art : RegistryAccess.registryAccess().getRegistry(RegistryKey.PAINTING_VARIANT)) {
if (id == art.getId()) {
return art;
}
Expand All @@ -231,8 +227,12 @@ static Art getById(int id) {
@Nullable
static Art getByName(@NotNull String name) {
Preconditions.checkArgument(name != null, "Name cannot be null");
final NamespacedKey key = NamespacedKey.fromString(name.toLowerCase(Locale.ROOT));
if (key == null) {
return null;
}

return Bukkit.getUnsafe().get(RegistryKey.PAINTING_VARIANT, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
return Bukkit.getUnsafe().get(RegistryKey.PAINTING_VARIANT, key);
}

/**
Expand All @@ -243,18 +243,19 @@ static Art getByName(@NotNull String name) {
@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(RegistryKey.PAINTING_VARIANT, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
final NamespacedKey key = NamespacedKey.fromString(name.toLowerCase(Locale.ROOT));
final Art art = key == null ? null : Bukkit.getUnsafe().get(RegistryKey.PAINTING_VARIANT, key);
Preconditions.checkArgument(art != null, "No art found with the name %s", name);
return art;
}

/**
* @return an array of all known arts.
* @deprecated use {@link Registry#iterator()}.
* @deprecated use {@link Registry#stream()}.
*/
@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[] values() {
return Lists.newArrayList(Registry.ART).toArray(new Art[0]);
return RegistryAccess.registryAccess().getRegistry(RegistryKey.PAINTING_VARIANT).stream().toArray(Art[]::new);
}
}
14 changes: 8 additions & 6 deletions paper-api/src/main/java/org/bukkit/Fluid.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
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 net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import org.bukkit.util.OldEnum;
import org.jetbrains.annotations.NotNull;

Expand All @@ -25,8 +26,8 @@ public interface Fluid extends OldEnum<Fluid>, Keyed {
// End generate - Fluid

@NotNull
private static Fluid getFluid(@NotNull String key) {
return Registry.FLUID.getOrThrow(NamespacedKey.minecraft(key));
private static Fluid getFluid(@NotNull @KeyPattern.Value String key) {
return Registry.FLUID.getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, key));
}

/**
Expand All @@ -37,18 +38,19 @@ private static Fluid getFluid(@NotNull String key) {
@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(RegistryKey.FLUID, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
final NamespacedKey key = NamespacedKey.fromString(name.toLowerCase(Locale.ROOT));
Fluid fluid = key == null ? null : Bukkit.getUnsafe().get(RegistryKey.FLUID, key);
Preconditions.checkArgument(fluid != null, "No fluid found with the name %s", name);
return fluid;
}

/**
* @return an array of all known fluids.
* @deprecated use {@link Registry#iterator()}.
* @deprecated use {@link Registry#stream()}.
*/
@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[] values() {
return Lists.newArrayList(Registry.FLUID).toArray(new Fluid[0]);
return Registry.FLUID.stream().toArray(Fluid[]::new);
}
}
12 changes: 6 additions & 6 deletions paper-api/src/main/java/org/bukkit/GameEvent.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.bukkit;

import com.google.common.collect.Lists;
import java.util.Collection;
import java.util.Collections;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -250,17 +250,17 @@ public static GameEvent getByKey(@NotNull NamespacedKey namespacedKey) {
* Returns the set of all GameEvents.
*
* @return the memoryKeys
* @deprecated use {@link Registry#iterator()}.
* @deprecated use {@link Registry#stream()}.
*/
@NotNull
@Deprecated(since = "1.20.1")
public static Collection<GameEvent> values() {
return Collections.unmodifiableCollection(Lists.newArrayList(Registry.GAME_EVENT));
return Registry.GAME_EVENT.stream().toList();
}

@NotNull
private static GameEvent getEvent(@NotNull String key) {
return Registry.GAME_EVENT.getOrThrow(NamespacedKey.minecraft(key));
private static GameEvent getEvent(@NotNull @KeyPattern.Value String key) {
return Registry.GAME_EVENT.getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, key));
}
// Paper start
/**
Expand Down
4 changes: 3 additions & 1 deletion paper-api/src/main/java/org/bukkit/GameRules.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.bukkit;

import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
Expand Down Expand Up @@ -132,8 +133,9 @@ public final class GameRules {
public static final GameRule<Boolean> WATER_SOURCE_CONVERSION = getRule("water_source_conversion");
// End generate - GameRules

@SuppressWarnings("unchecked")
private static <T> GameRule<T> getRule(@KeyPattern.Value String key) {
return (GameRule<T>) Registry.GAME_RULE.getOrThrow(NamespacedKey.minecraft(key));
return (GameRule<T>) Registry.GAME_RULE.getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, key));
}

private GameRules() {
Expand Down
6 changes: 4 additions & 2 deletions paper-api/src/main/java/org/bukkit/JukeboxSong.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import net.kyori.adventure.text.Component;
import org.jspecify.annotations.NullMarked;

Expand Down Expand Up @@ -55,8 +57,8 @@ public interface JukeboxSong extends Keyed, Translatable {
JukeboxSong WARD = get("ward");
// End generate - JukeboxSong

private static JukeboxSong get(String key) {
return RegistryAccess.registryAccess().getRegistry(RegistryKey.JUKEBOX_SONG).getOrThrow(NamespacedKey.minecraft(key));
private static JukeboxSong get(@KeyPattern.Value String key) {
return RegistryAccess.registryAccess().getRegistry(RegistryKey.JUKEBOX_SONG).getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, key));
}

/**
Expand Down
12 changes: 6 additions & 6 deletions paper-api/src/main/java/org/bukkit/MusicInstrument.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.bukkit;

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.InstrumentRegistryEntry;
import java.util.Collection;
import java.util.Collections;
import java.util.function.Consumer;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
Expand Down Expand Up @@ -46,8 +46,8 @@ public static MusicInstrument create(final Consumer<RegistryBuilderFactory<Music
public static final MusicInstrument YEARN_GOAT_HORN = getInstrument("yearn_goat_horn");
// End generate - MusicInstrument

private static MusicInstrument getInstrument(final String key) {
return RegistryAccess.registryAccess().getRegistry(RegistryKey.INSTRUMENT).getOrThrow(NamespacedKey.minecraft(key));
private static MusicInstrument getInstrument(final @KeyPattern.Value String key) {
return RegistryAccess.registryAccess().getRegistry(RegistryKey.INSTRUMENT).getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, key));
}

/**
Expand All @@ -60,7 +60,7 @@ private static MusicInstrument getInstrument(final String key) {
@Nullable
@Deprecated(since = "1.20.1")
public static MusicInstrument getByKey(final NamespacedKey namespacedKey) {
return Registry.INSTRUMENT.get(namespacedKey);
return RegistryAccess.registryAccess().getRegistry(RegistryKey.INSTRUMENT).get(namespacedKey);
}

/**
Expand All @@ -71,7 +71,7 @@ public static MusicInstrument getByKey(final NamespacedKey namespacedKey) {
*/
@Deprecated(since = "1.20.1")
public static Collection<MusicInstrument> values() {
return Collections.unmodifiableCollection(Lists.newArrayList(Registry.INSTRUMENT));
return RegistryAccess.registryAccess().getRegistry(RegistryKey.INSTRUMENT).stream().toList();
}

/**
Expand Down
22 changes: 14 additions & 8 deletions paper-api/src/main/java/org/bukkit/Sound.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
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 net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import org.bukkit.util.OldEnum;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -3701,8 +3702,8 @@ public interface Sound extends OldEnum<Sound>, Keyed, net.kyori.adventure.sound.
// End generate - Sound

@NotNull
private static Sound getSound(@NotNull String key) {
return Registry.SOUNDS.getOrThrow(NamespacedKey.minecraft(key));
private static Sound getSound(@NotNull @KeyPattern.Value String key) {
return Registry.SOUNDS.getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, key));
}

/**
Expand All @@ -3713,9 +3714,14 @@ private static Sound getSound(@NotNull String key) {
@NotNull
@Deprecated(since = "1.21.3", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils
static Sound valueOf(@NotNull String name) {
Sound sound = Bukkit.getUnsafe().get(RegistryKey.SOUND_EVENT, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
if (sound != null) {
return sound;
final NamespacedKey key = NamespacedKey.fromString(name.toLowerCase(Locale.ROOT));
Sound sound;

if (key != null) {
sound = Bukkit.getUnsafe().get(RegistryKey.SOUND_EVENT, key);
if (sound != null) {
return sound;
}
}

// Sound keys can have dots in them which where converted to _. Since converting
Expand All @@ -3742,12 +3748,12 @@ static Sound valueOf(@NotNull String name) {

/**
* @return an array of all known sounds.
* @deprecated use {@link Registry#iterator()}.
* @deprecated use {@link Registry#stream()}.
*/
@NotNull
@Deprecated(since = "1.21.3", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils
static Sound[] values() {
return Lists.newArrayList(Registry.SOUNDS).toArray(new Sound[0]);
return Registry.SOUNDS.stream().toArray(Sound[]::new);
}

// Paper start
Expand Down
3 changes: 1 addition & 2 deletions paper-api/src/main/java/org/bukkit/UnsafeValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.bukkit.advancement.Advancement;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.block.Biome;
import org.bukkit.block.data.BlockData;
import org.bukkit.damage.DamageSource;
import org.bukkit.damage.DamageType;
Expand Down Expand Up @@ -142,7 +141,7 @@ public interface UnsafeValues {
String get(Class<?> aClass, String value);

@ApiStatus.Internal
<B extends Keyed> B get(RegistryKey<B> registry, NamespacedKey key);
@Nullable <B extends Keyed> B get(RegistryKey<B> registry, NamespacedKey key);

// Paper start
@Deprecated(forRemoval = true)
Expand Down
Loading
Loading