mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 23:38:25 +01:00
#1058: Add tests for Minecraft registry <-> Bukkit fields
By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
parent
49d12d442a
commit
42cd6c82ff
21 changed files with 147 additions and 121 deletions
|
@ -1,6 +1,5 @@
|
|||
package org.bukkit;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
@ -140,11 +139,6 @@ public abstract class GameEvent implements Keyed {
|
|||
|
||||
@NotNull
|
||||
private static GameEvent getEvent(@NotNull String key) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.minecraft(key);
|
||||
GameEvent gameEvent = Registry.GAME_EVENT.get(namespacedKey);
|
||||
|
||||
Preconditions.checkNotNull(gameEvent, "No GameEvent found for %s. This is a bug.", namespacedKey);
|
||||
|
||||
return gameEvent;
|
||||
return Registry.GAME_EVENT.getOrThrow(NamespacedKey.minecraft(key));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.bukkit;
|
||||
|
||||
import java.util.Objects;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -31,7 +30,7 @@ public interface JukeboxSong extends Keyed, Translatable {
|
|||
public static final JukeboxSong CREATOR_MUSIC_BOX = get("creator_music_box");
|
||||
|
||||
@NotNull
|
||||
private static JukeboxSong get(@NotNull String s) {
|
||||
return Objects.requireNonNull(Registry.JUKEBOX_SONG.get(NamespacedKey.minecraft(s)), "Missing song " + s);
|
||||
private static JukeboxSong get(@NotNull String key) {
|
||||
return Registry.JUKEBOX_SONG.getOrThrow(NamespacedKey.minecraft(key));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.bukkit;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
@ -45,11 +44,6 @@ public abstract class MusicInstrument implements Keyed {
|
|||
|
||||
@NotNull
|
||||
private static MusicInstrument getInstrument(@NotNull String key) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.minecraft(key);
|
||||
MusicInstrument instrument = Registry.INSTRUMENT.get(namespacedKey);
|
||||
|
||||
Preconditions.checkNotNull(instrument, "No MusicInstrument found for %s. This is a bug.", namespacedKey);
|
||||
|
||||
return instrument;
|
||||
return Registry.INSTRUMENT.getOrThrow(NamespacedKey.minecraft(key));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,6 +60,16 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
|
|||
return Bukkit.getAdvancement(key);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Advancement getOrThrow(@NotNull NamespacedKey key) {
|
||||
Advancement advancement = get(key);
|
||||
|
||||
Preconditions.checkArgument(advancement != null, "No registry entry found for key " + key);
|
||||
|
||||
return advancement;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Stream<Advancement> stream() {
|
||||
|
@ -118,6 +128,16 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
|
|||
return Bukkit.getBossBar(key);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public KeyedBossBar getOrThrow(@NotNull NamespacedKey key) {
|
||||
KeyedBossBar keyedBossBar = get(key);
|
||||
|
||||
Preconditions.checkArgument(keyedBossBar != null, "No registry entry found for key " + key);
|
||||
|
||||
return keyedBossBar;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Stream<KeyedBossBar> stream() {
|
||||
|
@ -210,13 +230,13 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
|
|||
*
|
||||
* @see Structure
|
||||
*/
|
||||
Registry<Structure> STRUCTURE = Bukkit.getRegistry(Structure.class);
|
||||
Registry<Structure> STRUCTURE = Objects.requireNonNull(Bukkit.getRegistry(Structure.class), "No registry present for Structure. This is a bug.");
|
||||
/**
|
||||
* Server structure types.
|
||||
*
|
||||
* @see StructureType
|
||||
*/
|
||||
Registry<StructureType> STRUCTURE_TYPE = Bukkit.getRegistry(StructureType.class);
|
||||
Registry<StructureType> STRUCTURE_TYPE = Objects.requireNonNull(Bukkit.getRegistry(StructureType.class), "No registry present for StructureType. This is a bug.");
|
||||
/**
|
||||
* Sound keys.
|
||||
*
|
||||
|
@ -229,14 +249,14 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
|
|||
* @see TrimMaterial
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
Registry<TrimMaterial> TRIM_MATERIAL = Bukkit.getRegistry(TrimMaterial.class);
|
||||
Registry<TrimMaterial> TRIM_MATERIAL = Objects.requireNonNull(Bukkit.getRegistry(TrimMaterial.class), "No registry present for TrimMaterial. This is a bug.");
|
||||
/**
|
||||
* Trim patterns.
|
||||
*
|
||||
* @see TrimPattern
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
Registry<TrimPattern> TRIM_PATTERN = Bukkit.getRegistry(TrimPattern.class);
|
||||
Registry<TrimPattern> TRIM_PATTERN = Objects.requireNonNull(Bukkit.getRegistry(TrimPattern.class), "No registry present for TrimPattern. This is a bug.");
|
||||
/**
|
||||
* Damage types.
|
||||
*
|
||||
|
@ -282,6 +302,16 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
|
|||
return MemoryKey.getByKey(key);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public MemoryKey getOrThrow(@NotNull NamespacedKey key) {
|
||||
MemoryKey memoryKey = get(key);
|
||||
|
||||
Preconditions.checkArgument(memoryKey != null, "No registry entry found for key " + key);
|
||||
|
||||
return memoryKey;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Stream<MemoryKey> stream() {
|
||||
|
@ -327,6 +357,18 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
|
|||
@Nullable
|
||||
T get(@NotNull NamespacedKey key);
|
||||
|
||||
/**
|
||||
* Get the object by its key.
|
||||
*
|
||||
* If there is no object with the given key, an exception will be thrown.
|
||||
*
|
||||
* @param key to get the object from
|
||||
* @return object with the given key
|
||||
* @throws IllegalArgumentException if there is no object with the given key
|
||||
*/
|
||||
@NotNull
|
||||
T getOrThrow(@NotNull NamespacedKey key);
|
||||
|
||||
/**
|
||||
* Returns a new stream, which contains all registry items, which are registered to the registry.
|
||||
*
|
||||
|
@ -381,6 +423,16 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
|
|||
return map.get(key);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public T getOrThrow(@NotNull NamespacedKey key) {
|
||||
T object = get(key);
|
||||
|
||||
Preconditions.checkArgument(object != null, "No registry entry found for key " + key);
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Stream<T> stream() {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.bukkit.block;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.function.Consumer;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.Material;
|
||||
|
@ -108,6 +107,7 @@ import org.bukkit.block.data.type.TrialSpawner;
|
|||
import org.bukkit.block.data.type.Tripwire;
|
||||
import org.bukkit.block.data.type.TripwireHook;
|
||||
import org.bukkit.block.data.type.TurtleEgg;
|
||||
import org.bukkit.block.data.type.Vault;
|
||||
import org.bukkit.block.data.type.Wall;
|
||||
import org.bukkit.block.data.type.WallHangingSign;
|
||||
import org.bukkit.block.data.type.WallSign;
|
||||
|
@ -3295,16 +3295,20 @@ public interface BlockType extends Keyed, Translatable {
|
|||
* BlockData: {@link TrialSpawner}
|
||||
*/
|
||||
BlockType.Typed<TrialSpawner> TRIAL_SPAWNER = getBlockType("trial_spawner");
|
||||
|
||||
/**
|
||||
* BlockData: {@link Vault}
|
||||
*/
|
||||
BlockType.Typed<Vault> VAULT = getBlockType("vault");
|
||||
/**
|
||||
* BlockData: {@link Waterlogged}
|
||||
*/
|
||||
BlockType.Typed<Waterlogged> HEAVY_CORE = getBlockType("heavy_core");
|
||||
//</editor-fold>
|
||||
|
||||
@NotNull
|
||||
private static <B extends BlockType> B getBlockType(@NotNull String key) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.minecraft(key);
|
||||
BlockType blockType = Registry.BLOCK.get(namespacedKey);
|
||||
Preconditions.checkNotNull(blockType, "No BlockType found for %s. This is a bug.", namespacedKey);
|
||||
// Cast instead of using BlockType#typed, since block type can be a mock during testing and would return null
|
||||
return (B) blockType;
|
||||
return (B) Registry.BLOCK.getOrThrow(NamespacedKey.minecraft(key));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -100,11 +100,7 @@ public interface PatternType extends OldEnum<PatternType>, Keyed {
|
|||
|
||||
@NotNull
|
||||
private static PatternType getType(@NotNull String key) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.minecraft(key);
|
||||
PatternType type = Registry.BANNER_PATTERN.get(namespacedKey);
|
||||
|
||||
Preconditions.checkNotNull(type, "No Banner Pattern found for %s. This is a bug.", namespacedKey);
|
||||
return type;
|
||||
return Registry.BANNER_PATTERN.getOrThrow(NamespacedKey.minecraft(key));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.bukkit.damage;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
|
@ -66,11 +65,11 @@ public interface DamageType extends Keyed, Translatable {
|
|||
public static final DamageType BAD_RESPAWN_POINT = getDamageType("bad_respawn_point");
|
||||
public static final DamageType OUTSIDE_BORDER = getDamageType("outside_border");
|
||||
public static final DamageType GENERIC_KILL = getDamageType("generic_kill");
|
||||
public static final DamageType WIND_CHARGE = getDamageType("wind_charge");
|
||||
|
||||
@NotNull
|
||||
private static DamageType getDamageType(@NotNull String key) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.minecraft(key);
|
||||
return Preconditions.checkNotNull(Registry.DAMAGE_TYPE.get(namespacedKey), "No DamageType found for %s. This is a bug.", namespacedKey);
|
||||
return Registry.DAMAGE_TYPE.getOrThrow(NamespacedKey.minecraft(key));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.bukkit.enchantments;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.Locale;
|
||||
import org.bukkit.Keyed;
|
||||
|
@ -230,12 +229,7 @@ public abstract class Enchantment implements Keyed, Translatable {
|
|||
|
||||
@NotNull
|
||||
private static Enchantment getEnchantment(@NotNull String key) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.minecraft(key);
|
||||
Enchantment enchantment = Registry.ENCHANTMENT.get(namespacedKey);
|
||||
|
||||
Preconditions.checkNotNull(enchantment, "No Enchantment found for %s. This is a bug.", namespacedKey);
|
||||
|
||||
return enchantment;
|
||||
return Registry.ENCHANTMENT.getOrThrow(NamespacedKey.minecraft(key));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -64,11 +64,7 @@ public interface Cat extends Tameable, Sittable {
|
|||
|
||||
@NotNull
|
||||
private static Type getType(@NotNull String key) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.minecraft(key);
|
||||
Type type = Registry.CAT_VARIANT.get(namespacedKey);
|
||||
|
||||
Preconditions.checkNotNull(type, "No cat type found for %s. This is a bug.", namespacedKey);
|
||||
return type;
|
||||
return Registry.CAT_VARIANT.getOrThrow(NamespacedKey.minecraft(key));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -65,11 +65,7 @@ public interface Frog extends Animals {
|
|||
|
||||
@NotNull
|
||||
private static Variant getVariant(@NotNull String key) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.minecraft(key);
|
||||
Variant variant = Registry.FROG_VARIANT.get(namespacedKey);
|
||||
|
||||
Preconditions.checkNotNull(variant, "No frog variant found for %s. This is a bug.", namespacedKey);
|
||||
return variant;
|
||||
return Registry.FROG_VARIANT.getOrThrow(NamespacedKey.minecraft(key));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -134,11 +134,7 @@ public interface Villager extends AbstractVillager {
|
|||
|
||||
@NotNull
|
||||
private static Type getType(@NotNull String key) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.minecraft(key);
|
||||
Type type = Registry.VILLAGER_TYPE.get(namespacedKey);
|
||||
|
||||
Preconditions.checkNotNull(type, "No villager type found for %s. This is a bug.", namespacedKey);
|
||||
return type;
|
||||
return Registry.VILLAGER_TYPE.getOrThrow(NamespacedKey.minecraft(key));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -245,11 +241,7 @@ public interface Villager extends AbstractVillager {
|
|||
|
||||
@NotNull
|
||||
private static Profession getProfession(@NotNull String key) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.minecraft(key);
|
||||
Profession profession = Registry.VILLAGER_PROFESSION.get(namespacedKey);
|
||||
|
||||
Preconditions.checkNotNull(profession, "No villager profession found for %s. This is a bug.", namespacedKey);
|
||||
return profession;
|
||||
return Registry.VILLAGER_PROFESSION.getOrThrow(NamespacedKey.minecraft(key));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.bukkit.entity;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.NamespacedKey;
|
||||
|
@ -104,10 +103,7 @@ public interface Wolf extends Tameable, Sittable {
|
|||
|
||||
@NotNull
|
||||
private static Variant getVariant(@NotNull String key) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.minecraft(key);
|
||||
Variant variant = Registry.WOLF_VARIANT.get(namespacedKey);
|
||||
Preconditions.checkNotNull(variant, "No Wolf Variant found for %s. This is a bug.", namespacedKey);
|
||||
return variant;
|
||||
return Registry.WOLF_VARIANT.getOrThrow(NamespacedKey.minecraft(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,8 +49,9 @@ public abstract class Structure implements Keyed {
|
|||
public static final Structure TRAIL_RUINS = getStructure("trail_ruins");
|
||||
public static final Structure TRIAL_CHAMBERS = getStructure("trial_chambers");
|
||||
|
||||
private static Structure getStructure(String name) {
|
||||
return Registry.STRUCTURE.get(NamespacedKey.minecraft(name));
|
||||
@NotNull
|
||||
private static Structure getStructure(@NotNull String name) {
|
||||
return Registry.STRUCTURE.getOrThrow(NamespacedKey.minecraft(name));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.bukkit.generator.structure;
|
|||
import org.bukkit.Keyed;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Represent a StructureType of a {@link Structure}.
|
||||
|
@ -31,7 +32,8 @@ public abstract class StructureType implements Keyed {
|
|||
public static final StructureType SWAMP_HUT = getStructureType("swamp_hut");
|
||||
public static final StructureType WOODLAND_MANSION = getStructureType("woodland_mansion");
|
||||
|
||||
private static StructureType getStructureType(String name) {
|
||||
return Registry.STRUCTURE_TYPE.get(NamespacedKey.minecraft(name));
|
||||
@NotNull
|
||||
private static StructureType getStructureType(@NotNull String name) {
|
||||
return Registry.STRUCTURE_TYPE.getOrThrow(NamespacedKey.minecraft(name));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.bukkit.inventory;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Multimap;
|
||||
import java.util.function.Consumer;
|
||||
import org.bukkit.Keyed;
|
||||
|
@ -31,6 +30,7 @@ import org.bukkit.inventory.meta.MapMeta;
|
|||
import org.bukkit.inventory.meta.MusicInstrumentMeta;
|
||||
import org.bukkit.inventory.meta.OminousBottleMeta;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.inventory.meta.ShieldMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.inventory.meta.SpawnEggMeta;
|
||||
import org.bukkit.inventory.meta.SuspiciousStewMeta;
|
||||
|
@ -1028,8 +1028,8 @@ public interface ItemType extends Keyed, Translatable {
|
|||
* ItemMeta: {@link ColorableArmorMeta}
|
||||
*/
|
||||
ItemType.Typed<ColorableArmorMeta> WOLF_ARMOR = getItemType("wolf_armor");
|
||||
ItemType.Typed<ItemMeta> BOWL = getItemType("bowl");
|
||||
ItemType.Typed<ItemMeta> FLINT_AND_STEEL = getItemType("flint_and_steel");
|
||||
ItemType.Typed<ItemMeta> BOWL = getItemType("bowl");
|
||||
ItemType.Typed<ItemMeta> APPLE = getItemType("apple");
|
||||
ItemType.Typed<ItemMeta> BOW = getItemType("bow");
|
||||
ItemType.Typed<ItemMeta> ARROW = getItemType("arrow");
|
||||
|
@ -1891,9 +1891,9 @@ public interface ItemType extends Keyed, Translatable {
|
|||
*/
|
||||
ItemType.Typed<PotionMeta> LINGERING_POTION = getItemType("lingering_potion");
|
||||
/**
|
||||
* ItemMeta: {@link BlockStateMeta}
|
||||
* ItemMeta: {@link ShieldMeta}
|
||||
*/
|
||||
ItemType.Typed<BlockStateMeta> SHIELD = getItemType("shield");
|
||||
ItemType.Typed<ShieldMeta> SHIELD = getItemType("shield");
|
||||
ItemType.Typed<ItemMeta> TOTEM_OF_UNDYING = getItemType("totem_of_undying");
|
||||
ItemType.Typed<ItemMeta> SHULKER_SHELL = getItemType("shulker_shell");
|
||||
ItemType.Typed<ItemMeta> IRON_NUGGET = getItemType("iron_nugget");
|
||||
|
@ -2109,17 +2109,12 @@ public interface ItemType extends Keyed, Translatable {
|
|||
*/
|
||||
ItemType.Typed<OminousBottleMeta> OMINOUS_BOTTLE = getItemType("ominous_bottle");
|
||||
ItemType.Typed<ItemMeta> BREEZE_ROD = getItemType("breeze_rod");
|
||||
|
||||
|
||||
//</editor-fold>
|
||||
|
||||
@NotNull
|
||||
private static <M extends ItemType> M getItemType(@NotNull String key) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.minecraft(key);
|
||||
ItemType itemType = Registry.ITEM.get(namespacedKey);
|
||||
Preconditions.checkNotNull(itemType, "No ItemType found for %s. This is a bug.", namespacedKey);
|
||||
// Cast instead of using ItemType#typed, since item type can be a mock during testing and would return null
|
||||
return (M) itemType;
|
||||
return (M) Registry.ITEM.getOrThrow(NamespacedKey.minecraft(key));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.bukkit.inventory;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
|
@ -183,9 +182,8 @@ public interface MenuType extends Keyed {
|
|||
@NotNull
|
||||
Class<? extends InventoryView> getInventoryViewClass();
|
||||
|
||||
@NotNull
|
||||
private static <T extends MenuType> T get(@NotNull final String key) {
|
||||
final MenuType type = Registry.MENU.get(NamespacedKey.minecraft(key));
|
||||
Preconditions.checkArgument(type != null, "The given string key must be an existing menu type");
|
||||
return (T) type;
|
||||
return (T) Registry.MENU.getOrThrow(NamespacedKey.minecraft(key));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import org.bukkit.Material;
|
|||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.Translatable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Represents a material that may be used in an {@link ArmorTrim}.
|
||||
|
@ -14,41 +15,46 @@ public interface TrimMaterial extends Keyed, Translatable {
|
|||
/**
|
||||
* {@link Material#QUARTZ}.
|
||||
*/
|
||||
public static final TrimMaterial QUARTZ = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("quartz"));
|
||||
public static final TrimMaterial QUARTZ = getTrimMaterial("quartz");
|
||||
/**
|
||||
* {@link Material#IRON_INGOT}.
|
||||
*/
|
||||
public static final TrimMaterial IRON = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("iron"));
|
||||
public static final TrimMaterial IRON = getTrimMaterial("iron");
|
||||
/**
|
||||
* {@link Material#NETHERITE_INGOT}.
|
||||
*/
|
||||
public static final TrimMaterial NETHERITE = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("netherite"));
|
||||
public static final TrimMaterial NETHERITE = getTrimMaterial("netherite");
|
||||
/**
|
||||
* {@link Material#REDSTONE}.
|
||||
*/
|
||||
public static final TrimMaterial REDSTONE = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("redstone"));
|
||||
public static final TrimMaterial REDSTONE = getTrimMaterial("redstone");
|
||||
/**
|
||||
* {@link Material#COPPER_INGOT}.
|
||||
*/
|
||||
public static final TrimMaterial COPPER = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("copper"));
|
||||
public static final TrimMaterial COPPER = getTrimMaterial("copper");
|
||||
/**
|
||||
* {@link Material#GOLD_INGOT}.
|
||||
*/
|
||||
public static final TrimMaterial GOLD = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("gold"));
|
||||
public static final TrimMaterial GOLD = getTrimMaterial("gold");
|
||||
/**
|
||||
* {@link Material#EMERALD}.
|
||||
*/
|
||||
public static final TrimMaterial EMERALD = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("emerald"));
|
||||
public static final TrimMaterial EMERALD = getTrimMaterial("emerald");
|
||||
/**
|
||||
* {@link Material#DIAMOND}.
|
||||
*/
|
||||
public static final TrimMaterial DIAMOND = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("diamond"));
|
||||
public static final TrimMaterial DIAMOND = getTrimMaterial("diamond");
|
||||
/**
|
||||
* {@link Material#LAPIS_LAZULI}.
|
||||
*/
|
||||
public static final TrimMaterial LAPIS = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("lapis"));
|
||||
public static final TrimMaterial LAPIS = getTrimMaterial("lapis");
|
||||
/**
|
||||
* {@link Material#AMETHYST_SHARD}.
|
||||
*/
|
||||
public static final TrimMaterial AMETHYST = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft("amethyst"));
|
||||
public static final TrimMaterial AMETHYST = getTrimMaterial("amethyst");
|
||||
|
||||
@NotNull
|
||||
private static TrimMaterial getTrimMaterial(@NotNull String key) {
|
||||
return Registry.TRIM_MATERIAL.getOrThrow(NamespacedKey.minecraft(key));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import org.bukkit.Material;
|
|||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.Translatable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Represents a pattern that may be used in an {@link ArmorTrim}.
|
||||
|
@ -14,73 +15,78 @@ public interface TrimPattern extends Keyed, Translatable {
|
|||
/**
|
||||
* {@link Material#SENTRY_ARMOR_TRIM_SMITHING_TEMPLATE}.
|
||||
*/
|
||||
public static final TrimPattern SENTRY = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("sentry"));
|
||||
public static final TrimPattern SENTRY = getTrimPattern("sentry");
|
||||
/**
|
||||
* {@link Material#DUNE_ARMOR_TRIM_SMITHING_TEMPLATE}.
|
||||
*/
|
||||
public static final TrimPattern DUNE = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("dune"));
|
||||
public static final TrimPattern DUNE = getTrimPattern("dune");
|
||||
/**
|
||||
* {@link Material#COAST_ARMOR_TRIM_SMITHING_TEMPLATE}.
|
||||
*/
|
||||
public static final TrimPattern COAST = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("coast"));
|
||||
public static final TrimPattern COAST = getTrimPattern("coast");
|
||||
/**
|
||||
* {@link Material#WILD_ARMOR_TRIM_SMITHING_TEMPLATE}.
|
||||
*/
|
||||
public static final TrimPattern WILD = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("wild"));
|
||||
public static final TrimPattern WILD = getTrimPattern("wild");
|
||||
/**
|
||||
* {@link Material#WARD_ARMOR_TRIM_SMITHING_TEMPLATE}.
|
||||
*/
|
||||
public static final TrimPattern WARD = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("ward"));
|
||||
public static final TrimPattern WARD = getTrimPattern("ward");
|
||||
/**
|
||||
* {@link Material#EYE_ARMOR_TRIM_SMITHING_TEMPLATE}.
|
||||
*/
|
||||
public static final TrimPattern EYE = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("eye"));
|
||||
public static final TrimPattern EYE = getTrimPattern("eye");
|
||||
/**
|
||||
* {@link Material#VEX_ARMOR_TRIM_SMITHING_TEMPLATE}.
|
||||
*/
|
||||
public static final TrimPattern VEX = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("vex"));
|
||||
public static final TrimPattern VEX = getTrimPattern("vex");
|
||||
/**
|
||||
* {@link Material#TIDE_ARMOR_TRIM_SMITHING_TEMPLATE}.
|
||||
*/
|
||||
public static final TrimPattern TIDE = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("tide"));
|
||||
public static final TrimPattern TIDE = getTrimPattern("tide");
|
||||
/**
|
||||
* {@link Material#SNOUT_ARMOR_TRIM_SMITHING_TEMPLATE}.
|
||||
*/
|
||||
public static final TrimPattern SNOUT = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("snout"));
|
||||
public static final TrimPattern SNOUT = getTrimPattern("snout");
|
||||
/**
|
||||
* {@link Material#RIB_ARMOR_TRIM_SMITHING_TEMPLATE}.
|
||||
*/
|
||||
public static final TrimPattern RIB = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("rib"));
|
||||
public static final TrimPattern RIB = getTrimPattern("rib");
|
||||
/**
|
||||
* {@link Material#SPIRE_ARMOR_TRIM_SMITHING_TEMPLATE}.
|
||||
*/
|
||||
public static final TrimPattern SPIRE = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("spire"));
|
||||
public static final TrimPattern SPIRE = getTrimPattern("spire");
|
||||
/**
|
||||
* {@link Material#WAYFINDER_ARMOR_TRIM_SMITHING_TEMPLATE}.
|
||||
*/
|
||||
public static final TrimPattern WAYFINDER = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("wayfinder"));
|
||||
public static final TrimPattern WAYFINDER = getTrimPattern("wayfinder");
|
||||
/**
|
||||
* {@link Material#SHAPER_ARMOR_TRIM_SMITHING_TEMPLATE}.
|
||||
*/
|
||||
public static final TrimPattern SHAPER = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("shaper"));
|
||||
public static final TrimPattern SHAPER = getTrimPattern("shaper");
|
||||
/**
|
||||
* {@link Material#SILENCE_ARMOR_TRIM_SMITHING_TEMPLATE}.
|
||||
*/
|
||||
public static final TrimPattern SILENCE = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("silence"));
|
||||
public static final TrimPattern SILENCE = getTrimPattern("silence");
|
||||
/**
|
||||
* {@link Material#RAISER_ARMOR_TRIM_SMITHING_TEMPLATE}.
|
||||
*/
|
||||
public static final TrimPattern RAISER = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("raiser"));
|
||||
public static final TrimPattern RAISER = getTrimPattern("raiser");
|
||||
/**
|
||||
* {@link Material#HOST_ARMOR_TRIM_SMITHING_TEMPLATE}.
|
||||
*/
|
||||
public static final TrimPattern HOST = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("host"));
|
||||
public static final TrimPattern HOST = getTrimPattern("host");
|
||||
/**
|
||||
* {@link Material#FLOW_ARMOR_TRIM_SMITHING_TEMPLATE}.
|
||||
*/
|
||||
public static final TrimPattern FLOW = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("flow"));
|
||||
public static final TrimPattern FLOW = getTrimPattern("flow");
|
||||
/**
|
||||
* {@link Material#BOLT_ARMOR_TRIM_SMITHING_TEMPLATE}.
|
||||
*/
|
||||
public static final TrimPattern BOLT = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft("bolt"));
|
||||
public static final TrimPattern BOLT = getTrimPattern("bolt");
|
||||
|
||||
@NotNull
|
||||
private static TrimPattern getTrimPattern(@NotNull String key) {
|
||||
return Registry.TRIM_PATTERN.getOrThrow(NamespacedKey.minecraft(key));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -269,11 +269,7 @@ public final class MapCursor {
|
|||
|
||||
@NotNull
|
||||
private static Type getType(@NotNull String key) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.minecraft(key);
|
||||
Type type = Registry.MAP_DECORATION_TYPE.get(namespacedKey);
|
||||
|
||||
Preconditions.checkNotNull(type, "No type found for %s. This is a bug.", namespacedKey);
|
||||
return type;
|
||||
return Registry.MAP_DECORATION_TYPE.getOrThrow(NamespacedKey.minecraft(key));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -222,9 +222,8 @@ public abstract class PotionEffectType implements Keyed, Translatable {
|
|||
|
||||
@NotNull
|
||||
private static PotionEffectType getPotionEffectType(int typeId, @NotNull String key) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.minecraft(key);
|
||||
PotionEffectType potionEffectType = Registry.EFFECT.get(namespacedKey);
|
||||
Preconditions.checkNotNull(potionEffectType, "No PotionEffectType found for %s. This is a bug.", namespacedKey);
|
||||
PotionEffectType potionEffectType = Registry.EFFECT.getOrThrow(NamespacedKey.minecraft(key));
|
||||
|
||||
if (typeId > 0) {
|
||||
ID_MAP.put(typeId, potionEffectType);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.bukkit.support;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
|
@ -57,6 +58,16 @@ public final class TestServer {
|
|||
return cache.computeIfAbsent(key, key2 -> mock(theClass, withSettings().stubOnly()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Keyed getOrThrow(@NotNull NamespacedKey key) {
|
||||
Keyed keyed = get(key);
|
||||
|
||||
Preconditions.checkArgument(keyed != null, "No registry entry found for key " + key);
|
||||
|
||||
return keyed;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Stream<Keyed> stream() {
|
||||
|
|
Loading…
Reference in a new issue