#1058: Add tests for Minecraft registry <-> Bukkit fields
By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user