Skip to content

Commit 36108a4

Browse files
committed
redo
1 parent 9a7982a commit 36108a4

File tree

32 files changed

+183
-169
lines changed

32 files changed

+183
-169
lines changed

paper-api/src/main/java/io/papermc/paper/datacomponent/DataComponentTypes.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@
4848
import io.papermc.paper.registry.tag.TagKey;
4949
import java.util.List;
5050
import net.kyori.adventure.key.Key;
51+
import net.kyori.adventure.key.KeyPattern;
5152
import net.kyori.adventure.text.Component;
5253
import org.bukkit.Art;
5354
import org.bukkit.DyeColor;
5455
import org.bukkit.FireworkEffect;
5556
import org.bukkit.MusicInstrument;
56-
import org.bukkit.NamespacedKey;
5757
import org.bukkit.Registry;
5858
import org.bukkit.block.banner.PatternType;
5959
import org.bukkit.damage.DamageType;
@@ -82,8 +82,6 @@
8282
import org.jetbrains.annotations.ApiStatus;
8383
import org.jspecify.annotations.NullMarked;
8484

85-
import static java.util.Objects.requireNonNull;
86-
8785
/**
8886
* All the different types of data that {@link org.bukkit.inventory.ItemStack ItemStacks}
8987
* and {@link org.bukkit.inventory.ItemType ItemTypes} can have.
@@ -392,21 +390,21 @@ public final class DataComponentTypes {
392390
public static final DataComponentType.Valued<DyeColor> SHEEP_COLOR = valued("sheep/color");
393391
public static final DataComponentType.Valued<DyeColor> SHULKER_COLOR = valued("shulker/color");
394392

395-
private static DataComponentType.NonValued unvalued(final String name) {
396-
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.");
393+
private static DataComponentType.NonValued unvalued(final @KeyPattern.Value String key) {
394+
final DataComponentType dataComponentType = Registry.DATA_COMPONENT_TYPE.getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, key));
397395
if (dataComponentType instanceof DataComponentType.NonValued) {
398396
return (DataComponentType.NonValued) dataComponentType;
399397
}
400-
throw new IllegalStateException(name + " is not a valid unvalued type, it is a " + dataComponentType.getClass().getTypeName());
398+
throw new IllegalStateException(key + " is not a valid unvalued type, it is a " + dataComponentType.getClass().getTypeName());
401399
}
402400

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

411409
}
412410

paper-api/src/main/java/org/bukkit/Art.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
package org.bukkit;
22

33
import com.google.common.base.Preconditions;
4-
import com.google.common.collect.Lists;
54
import io.papermc.paper.registry.RegistryAccess;
6-
import io.papermc.paper.registry.RegistryBuilderFactory;
75
import io.papermc.paper.registry.RegistryKey;
8-
import io.papermc.paper.registry.data.InlinedRegistryBuilderProvider;
9-
import io.papermc.paper.registry.data.PaintingVariantRegistryEntry;
106
import java.util.Locale;
11-
import java.util.function.Consumer;
7+
import net.kyori.adventure.key.Key;
8+
import net.kyori.adventure.key.KeyPattern;
129
import org.bukkit.util.OldEnum;
13-
import org.jetbrains.annotations.ApiStatus;
1410
import org.jetbrains.annotations.NotNull;
1511
import org.jetbrains.annotations.Nullable;
1612

@@ -129,8 +125,8 @@ public interface Art extends OldEnum<Art>, Keyed {
129125
// End generate - Art
130126

131127
@NotNull
132-
private static Art getArt(@NotNull String key) {
133-
return RegistryAccess.registryAccess().getRegistry(RegistryKey.PAINTING_VARIANT).getOrThrow(NamespacedKey.minecraft(key));
128+
private static Art getArt(@NotNull @KeyPattern.Value String key) {
129+
return RegistryAccess.registryAccess().getRegistry(RegistryKey.PAINTING_VARIANT).getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, key));
134130
}
135131

136132
/**
@@ -209,7 +205,7 @@ private static Art getArt(@NotNull String key) {
209205
@Deprecated(since = "1.6.2", forRemoval = true)
210206
@Nullable
211207
static Art getById(int id) {
212-
for (Art art : Registry.ART) {
208+
for (Art art : RegistryAccess.registryAccess().getRegistry(RegistryKey.PAINTING_VARIANT)) {
213209
if (id == art.getId()) {
214210
return art;
215211
}
@@ -232,7 +228,9 @@ static Art getById(int id) {
232228
static Art getByName(@NotNull String name) {
233229
Preconditions.checkArgument(name != null, "Name cannot be null");
234230
final NamespacedKey key = NamespacedKey.fromString(name.toLowerCase(Locale.ROOT));
235-
Preconditions.checkArgument(key != null, "Invalid name %s", name);
231+
if (key == null) {
232+
return null;
233+
}
236234

237235
return Bukkit.getUnsafe().get(RegistryKey.PAINTING_VARIANT, key);
238236
}
@@ -245,18 +243,19 @@ static Art getByName(@NotNull String name) {
245243
@NotNull
246244
@Deprecated(since = "1.21.3", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils
247245
static Art valueOf(@NotNull String name) {
248-
Art art = Art.getByName(name);
246+
final NamespacedKey key = NamespacedKey.fromString(name.toLowerCase(Locale.ROOT));
247+
final Art art = key == null ? null : Bukkit.getUnsafe().get(RegistryKey.PAINTING_VARIANT, key);
249248
Preconditions.checkArgument(art != null, "No art found with the name %s", name);
250249
return art;
251250
}
252251

253252
/**
254253
* @return an array of all known arts.
255-
* @deprecated use {@link Registry#iterator()}.
254+
* @deprecated use {@link Registry#stream()}.
256255
*/
257256
@NotNull
258257
@Deprecated(since = "1.21.3", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils
259258
static Art[] values() {
260-
return Lists.newArrayList(Registry.ART).toArray(new Art[0]);
259+
return RegistryAccess.registryAccess().getRegistry(RegistryKey.PAINTING_VARIANT).stream().toArray(Art[]::new);
261260
}
262261
}

paper-api/src/main/java/org/bukkit/Fluid.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package org.bukkit;
22

33
import com.google.common.base.Preconditions;
4-
import com.google.common.collect.Lists;
54
import io.papermc.paper.registry.RegistryKey;
65
import java.util.Locale;
6+
import net.kyori.adventure.key.Key;
7+
import net.kyori.adventure.key.KeyPattern;
78
import org.bukkit.util.OldEnum;
89
import org.jetbrains.annotations.NotNull;
910

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

2728
@NotNull
28-
private static Fluid getFluid(@NotNull String key) {
29-
return Registry.FLUID.getOrThrow(NamespacedKey.minecraft(key));
29+
private static Fluid getFluid(@NotNull @KeyPattern.Value String key) {
30+
return Registry.FLUID.getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, key));
3031
}
3132

3233
/**
@@ -38,19 +39,18 @@ private static Fluid getFluid(@NotNull String key) {
3839
@Deprecated(since = "1.21.3", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils
3940
static Fluid valueOf(@NotNull String name) {
4041
final NamespacedKey key = NamespacedKey.fromString(name.toLowerCase(Locale.ROOT));
41-
Preconditions.checkArgument(key != null, "Invalid name %s", name);
42-
Fluid fluid = Bukkit.getUnsafe().get(RegistryKey.FLUID, key);
42+
Fluid fluid = key == null ? null : Bukkit.getUnsafe().get(RegistryKey.FLUID, key);
4343
Preconditions.checkArgument(fluid != null, "No fluid found with the name %s", name);
4444
return fluid;
4545
}
4646

4747
/**
4848
* @return an array of all known fluids.
49-
* @deprecated use {@link Registry#iterator()}.
49+
* @deprecated use {@link Registry#stream()}.
5050
*/
5151
@NotNull
5252
@Deprecated(since = "1.21.3", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils
5353
static Fluid[] values() {
54-
return Lists.newArrayList(Registry.FLUID).toArray(new Fluid[0]);
54+
return Registry.FLUID.stream().toArray(Fluid[]::new);
5555
}
5656
}

paper-api/src/main/java/org/bukkit/GameEvent.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package org.bukkit;
22

3-
import com.google.common.collect.Lists;
43
import java.util.Collection;
5-
import java.util.Collections;
4+
import net.kyori.adventure.key.Key;
5+
import net.kyori.adventure.key.KeyPattern;
66
import org.jetbrains.annotations.NotNull;
77
import org.jetbrains.annotations.Nullable;
88

@@ -250,17 +250,17 @@ public static GameEvent getByKey(@NotNull NamespacedKey namespacedKey) {
250250
* Returns the set of all GameEvents.
251251
*
252252
* @return the memoryKeys
253-
* @deprecated use {@link Registry#iterator()}.
253+
* @deprecated use {@link Registry#stream()}.
254254
*/
255255
@NotNull
256256
@Deprecated(since = "1.20.1")
257257
public static Collection<GameEvent> values() {
258-
return Collections.unmodifiableCollection(Lists.newArrayList(Registry.GAME_EVENT));
258+
return Registry.GAME_EVENT.stream().toList();
259259
}
260260

261261
@NotNull
262-
private static GameEvent getEvent(@NotNull String key) {
263-
return Registry.GAME_EVENT.getOrThrow(NamespacedKey.minecraft(key));
262+
private static GameEvent getEvent(@NotNull @KeyPattern.Value String key) {
263+
return Registry.GAME_EVENT.getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, key));
264264
}
265265
// Paper start
266266
/**

paper-api/src/main/java/org/bukkit/GameRules.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.bukkit;
22

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

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

139141
private GameRules() {

paper-api/src/main/java/org/bukkit/JukeboxSong.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import io.papermc.paper.registry.RegistryAccess;
44
import io.papermc.paper.registry.RegistryKey;
5+
import net.kyori.adventure.key.Key;
6+
import net.kyori.adventure.key.KeyPattern;
57
import net.kyori.adventure.text.Component;
68
import org.jspecify.annotations.NullMarked;
79

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

58-
private static JukeboxSong get(String key) {
59-
return RegistryAccess.registryAccess().getRegistry(RegistryKey.JUKEBOX_SONG).getOrThrow(NamespacedKey.minecraft(key));
60+
private static JukeboxSong get(@KeyPattern.Value String key) {
61+
return RegistryAccess.registryAccess().getRegistry(RegistryKey.JUKEBOX_SONG).getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, key));
6062
}
6163

6264
/**

paper-api/src/main/java/org/bukkit/MusicInstrument.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package org.bukkit;
22

3-
import com.google.common.collect.Lists;
43
import io.papermc.paper.registry.RegistryAccess;
54
import io.papermc.paper.registry.RegistryBuilderFactory;
65
import io.papermc.paper.registry.RegistryKey;
76
import io.papermc.paper.registry.data.InlinedRegistryBuilderProvider;
87
import io.papermc.paper.registry.data.InstrumentRegistryEntry;
98
import java.util.Collection;
10-
import java.util.Collections;
119
import java.util.function.Consumer;
10+
import net.kyori.adventure.key.Key;
11+
import net.kyori.adventure.key.KeyPattern;
1212
import net.kyori.adventure.text.Component;
1313
import org.jetbrains.annotations.ApiStatus;
1414
import org.jspecify.annotations.NullMarked;
@@ -46,8 +46,8 @@ public static MusicInstrument create(final Consumer<RegistryBuilderFactory<Music
4646
public static final MusicInstrument YEARN_GOAT_HORN = getInstrument("yearn_goat_horn");
4747
// End generate - MusicInstrument
4848

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

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

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

7777
/**

paper-api/src/main/java/org/bukkit/Sound.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package org.bukkit;
22

33
import com.google.common.base.Preconditions;
4-
import com.google.common.collect.Lists;
54
import io.papermc.paper.registry.RegistryKey;
65
import java.util.Locale;
6+
import net.kyori.adventure.key.Key;
7+
import net.kyori.adventure.key.KeyPattern;
78
import org.bukkit.util.OldEnum;
89
import org.jetbrains.annotations.NotNull;
910

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

37033704
@NotNull
3704-
private static Sound getSound(@NotNull String key) {
3705-
return Registry.SOUNDS.getOrThrow(NamespacedKey.minecraft(key));
3705+
private static Sound getSound(@NotNull @KeyPattern.Value String key) {
3706+
return Registry.SOUNDS.getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, key));
37063707
}
37073708

37083709
/**
@@ -3747,12 +3748,12 @@ static Sound valueOf(@NotNull String name) {
37473748

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

37583759
// Paper start

paper-api/src/main/java/org/bukkit/UnsafeValues.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import org.bukkit.advancement.Advancement;
88
import org.bukkit.attribute.Attribute;
99
import org.bukkit.attribute.AttributeModifier;
10-
import org.bukkit.block.Biome;
1110
import org.bukkit.block.data.BlockData;
1211
import org.bukkit.damage.DamageSource;
1312
import org.bukkit.damage.DamageType;
@@ -142,7 +141,7 @@ public interface UnsafeValues {
142141
String get(Class<?> aClass, String value);
143142

144143
@ApiStatus.Internal
145-
<B extends Keyed> B get(RegistryKey<B> registry, NamespacedKey key);
144+
@Nullable <B extends Keyed> B get(RegistryKey<B> registry, NamespacedKey key);
146145

147146
// Paper start
148147
@Deprecated(forRemoval = true)

paper-api/src/main/java/org/bukkit/attribute/Attribute.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package org.bukkit.attribute;
22

33
import com.google.common.base.Preconditions;
4-
import com.google.common.collect.Lists;
54
import io.papermc.paper.registry.RegistryKey;
65
import java.util.Locale;
6+
import net.kyori.adventure.key.Key;
7+
import net.kyori.adventure.key.KeyPattern;
78
import org.bukkit.Bukkit;
89
import org.bukkit.Keyed;
910
import org.bukkit.NamespacedKey;
@@ -159,8 +160,8 @@ public interface Attribute extends OldEnum<Attribute>, Keyed, Translatable, net.
159160
Attribute WAYPOINT_RECEIVE_RANGE = getAttribute("waypoint_receive_range");
160161

161162
@NotNull
162-
private static Attribute getAttribute(@NotNull String key) {
163-
return Registry.ATTRIBUTE.getOrThrow(NamespacedKey.minecraft(key));
163+
private static Attribute getAttribute(@NotNull @KeyPattern.Value String key) {
164+
return Registry.ATTRIBUTE.getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, key));
164165
}
165166

166167
/**
@@ -178,20 +179,19 @@ private static Attribute getAttribute(@NotNull String key) {
178179
@Deprecated(since = "1.21.3", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils
179180
static Attribute valueOf(@NotNull String name) {
180181
final NamespacedKey key = NamespacedKey.fromString(name.toLowerCase(Locale.ROOT));
181-
Preconditions.checkArgument(key != null, "Invalid name %s", name);
182-
Attribute attribute = Bukkit.getUnsafe().get(RegistryKey.ATTRIBUTE, key);
182+
Attribute attribute = key == null ? null : Bukkit.getUnsafe().get(RegistryKey.ATTRIBUTE, key);
183183
Preconditions.checkArgument(attribute != null, "No attribute found with the name %s", name);
184184
return attribute;
185185
}
186186

187187
/**
188188
* @return an array of all known attributes.
189-
* @deprecated use {@link Registry#iterator()}.
189+
* @deprecated use {@link Registry#stream()}.
190190
*/
191191
@NotNull
192192
@Deprecated(since = "1.21.3", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils
193193
static Attribute[] values() {
194-
return Lists.newArrayList(Registry.ATTRIBUTE).toArray(new Attribute[0]);
194+
return Registry.ATTRIBUTE.stream().toArray(Attribute[]::new);
195195
}
196196

197197
/**

0 commit comments

Comments
 (0)