From 2b704c8cf9356035beffb3bdde9a863ce666a1fa Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Wed, 15 Jan 2020 14:20:14 +1100 Subject: [PATCH] SPIGOT-5516: Correct EnchantmentTarget values By: md_5 --- .../enchantments/EnchantmentTargetTest.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 paper-server/src/test/java/org/bukkit/enchantments/EnchantmentTargetTest.java diff --git a/paper-server/src/test/java/org/bukkit/enchantments/EnchantmentTargetTest.java b/paper-server/src/test/java/org/bukkit/enchantments/EnchantmentTargetTest.java new file mode 100644 index 0000000000..983aff0047 --- /dev/null +++ b/paper-server/src/test/java/org/bukkit/enchantments/EnchantmentTargetTest.java @@ -0,0 +1,41 @@ +package org.bukkit.enchantments; + +import net.minecraft.server.EnchantmentSlotType; +import net.minecraft.server.IRegistry; +import net.minecraft.server.Item; +import org.bukkit.Material; +import org.bukkit.craftbukkit.util.CraftMagicNumbers; +import org.junit.Assert; +import org.junit.Test; + +public class EnchantmentTargetTest { + + @Test + public void test() { + for (EnchantmentSlotType nmsSlot : EnchantmentSlotType.values()) { + EnchantmentTarget bukkitTarget; + switch (nmsSlot) { + case ARMOR_CHEST: + bukkitTarget = EnchantmentTarget.ARMOR_TORSO; + break; + case DIGGER: + bukkitTarget = EnchantmentTarget.TOOL; + break; + default: + bukkitTarget = EnchantmentTarget.valueOf(nmsSlot.name()); + break; + } + + Assert.assertNotNull("No bukkit target for slot " + nmsSlot, bukkitTarget); + + for (Item item : IRegistry.ITEM) { + Material material = CraftMagicNumbers.getMaterial(item); + + boolean nms = nmsSlot.canEnchant(item); + boolean bukkit = bukkitTarget.includes(material); + + Assert.assertEquals("Slot mismatch for " + bukkitTarget + " and " + material, nms, bukkit); + } + } + } +}