From 7e5525bd00216e25b2021213271a92eaaf60ff26 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Sat, 4 May 2024 02:46:46 +0200 Subject: [PATCH] Updates Spigot, and fixes depreciated code --- pom.xml | 26 +--- .../blacksmith/command/EditCommand.java | 2 +- .../BlacksmithTranslatableMessage.java | 4 +- .../blacksmith/formatting/ItemType.java | 4 +- .../blacksmith/formatting/TimeFormatter.java | 2 +- .../blacksmith/trait/ReforgeSession.java | 17 ++- .../blacksmith/util/InputParsingHelper.java | 8 +- .../util/TabCompleteValuesHelper.java | 9 +- .../blacksmith/CustomServerMock.java | 39 ------ .../util/InputParsingHelperTest.java | 37 ------ .../blacksmith/util/ItemHelperTest.java | 82 ------------ .../blacksmith/util/SalvageHelperTest.java | 123 ------------------ .../util/TypeValidatorHelperTest.java | 23 ---- 13 files changed, 38 insertions(+), 338 deletions(-) delete mode 100644 src/test/java/net/knarcraft/blacksmith/CustomServerMock.java delete mode 100644 src/test/java/net/knarcraft/blacksmith/util/SalvageHelperTest.java diff --git a/pom.xml b/pom.xml index 52622ac..c4ff511 100644 --- a/pom.xml +++ b/pom.xml @@ -31,10 +31,6 @@ jitpack.io https://jitpack.io - - papermc - https://repo.papermc.io/repository/maven-public/ - knarcraft-repo https://git.knarcraft.net/api/packages/EpicKnarvik97/maven @@ -56,7 +52,7 @@ net.citizensnpcs citizens-main - 2.0.30-SNAPSHOT + 2.0.33-SNAPSHOT jar provided @@ -69,7 +65,7 @@ org.spigotmc spigot-api - 1.20.2-R0.1-SNAPSHOT + 1.20.6-R0.1-SNAPSHOT provided @@ -82,24 +78,18 @@ org.jetbrains annotations 24.0.1 - provided + compile net.knarcraft knarlib - 1.2.5 + 1.2.6 compile org.junit.jupiter junit-jupiter - 5.9.2 - test - - - com.github.seeseemelk - MockBukkit-v1.20 - 3.9.0 + 5.10.2 test @@ -151,12 +141,6 @@ org/jetbrains/annotations/** - - - *.MF - *.yml - - diff --git a/src/main/java/net/knarcraft/blacksmith/command/EditCommand.java b/src/main/java/net/knarcraft/blacksmith/command/EditCommand.java index c340822..d2f7cce 100644 --- a/src/main/java/net/knarcraft/blacksmith/command/EditCommand.java +++ b/src/main/java/net/knarcraft/blacksmith/command/EditCommand.java @@ -170,7 +170,7 @@ public abstract class EditCommand, L extends Setting> i getCurrentValueMessage(setting.getCommandName(), rawValue)); } else { //Add a marker if the value has been customized - String marker = BlacksmithPlugin.getStringFormatter().getUnformattedMessage( + String marker = BlacksmithPlugin.getStringFormatter().getUnFormattedMessage( BlacksmithTranslatableMessage.SETTING_OVERRIDDEN_MARKER); formatter.displayNeutralMessage(sender, getCurrentValueMessage(setting.getCommandName(), rawValue) + marker); diff --git a/src/main/java/net/knarcraft/blacksmith/formatting/BlacksmithTranslatableMessage.java b/src/main/java/net/knarcraft/blacksmith/formatting/BlacksmithTranslatableMessage.java index 4cea4e1..3265bcd 100644 --- a/src/main/java/net/knarcraft/blacksmith/formatting/BlacksmithTranslatableMessage.java +++ b/src/main/java/net/knarcraft/blacksmith/formatting/BlacksmithTranslatableMessage.java @@ -172,7 +172,7 @@ public enum BlacksmithTranslatableMessage implements TranslatableMessage { * @return

The string to display to a user

*/ public static String getItemValueChangedMessage(String setting, ItemType itemType, String item, String newValue) { - StringReplacer stringReplacer = new StringReplacer(BlacksmithPlugin.getStringFormatter().getUnformattedMessage( + StringReplacer stringReplacer = new StringReplacer(BlacksmithPlugin.getStringFormatter().getUnFormattedMessage( BlacksmithTranslatableMessage.VALUE_FOR_ITEM_CHANGED)); stringReplacer.add("{setting}", setting); stringReplacer.add("{itemType}", itemType.getItemTypeName()); @@ -204,7 +204,7 @@ public enum BlacksmithTranslatableMessage implements TranslatableMessage { * @return

The string to display to a user

*/ public static String getItemCurrentValueMessage(String setting, ItemType itemType, String item, String currentValue) { - StringReplacer stringReplacer = new StringReplacer(BlacksmithPlugin.getStringFormatter().getUnformattedMessage( + StringReplacer stringReplacer = new StringReplacer(BlacksmithPlugin.getStringFormatter().getUnFormattedMessage( BlacksmithTranslatableMessage.CURRENT_VALUE_FOR_ITEM)); stringReplacer.add("{setting}", setting); stringReplacer.add("{itemType}", itemType.getItemTypeName()); diff --git a/src/main/java/net/knarcraft/blacksmith/formatting/ItemType.java b/src/main/java/net/knarcraft/blacksmith/formatting/ItemType.java index 392c471..f5c56b1 100644 --- a/src/main/java/net/knarcraft/blacksmith/formatting/ItemType.java +++ b/src/main/java/net/knarcraft/blacksmith/formatting/ItemType.java @@ -19,9 +19,9 @@ public enum ItemType { public String getItemTypeName() { StringFormatter stringFormatter = BlacksmithPlugin.getStringFormatter(); return switch (this) { - case MATERIAL -> stringFormatter.getUnformattedMessage(BlacksmithTranslatableMessage.ITEM_TYPE_MATERIAL); + case MATERIAL -> stringFormatter.getUnFormattedMessage(BlacksmithTranslatableMessage.ITEM_TYPE_MATERIAL); case ENCHANTMENT -> - stringFormatter.getUnformattedMessage(BlacksmithTranslatableMessage.ITEM_TYPE_ENCHANTMENT); + stringFormatter.getUnFormattedMessage(BlacksmithTranslatableMessage.ITEM_TYPE_ENCHANTMENT); }; } diff --git a/src/main/java/net/knarcraft/blacksmith/formatting/TimeFormatter.java b/src/main/java/net/knarcraft/blacksmith/formatting/TimeFormatter.java index 0d8b870..93308a0 100644 --- a/src/main/java/net/knarcraft/blacksmith/formatting/TimeFormatter.java +++ b/src/main/java/net/knarcraft/blacksmith/formatting/TimeFormatter.java @@ -53,7 +53,7 @@ public final class TimeFormatter { * @return

Text describing the time interval

*/ private static String getMessageFromInterval(TimeInterval interval) { - String text = BlacksmithPlugin.getStringFormatter().getUnformattedMessage( + String text = BlacksmithPlugin.getStringFormatter().getUnFormattedMessage( BlacksmithTranslatableMessage.valueOf(interval.name())); //Choose a random entry if a comma-separated list is provided diff --git a/src/main/java/net/knarcraft/blacksmith/trait/ReforgeSession.java b/src/main/java/net/knarcraft/blacksmith/trait/ReforgeSession.java index 747bc69..c8e6432 100644 --- a/src/main/java/net/knarcraft/blacksmith/trait/ReforgeSession.java +++ b/src/main/java/net/knarcraft/blacksmith/trait/ReforgeSession.java @@ -6,7 +6,9 @@ import net.knarcraft.blacksmith.config.blacksmith.BlacksmithNPCSettings; import net.knarcraft.blacksmith.manager.EconomyManager; import net.knarcraft.blacksmith.util.InputParsingHelper; import net.knarcraft.blacksmith.util.ItemHelper; +import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.Registry; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -31,7 +33,7 @@ public class ReforgeSession extends Session implements Runnable { private final NPC npc; private final ItemStack itemToReforge; private final BlacksmithNPCSettings config; - private static final String[] enchantments = new String[Enchantment.values().length]; + private static List enchantments = null; private static final Random random = new Random(); /** @@ -51,10 +53,15 @@ public class ReforgeSession extends Session implements Runnable { this.config = config; //Populate enchantments the first time this is run - if (enchantments[0] == null) { - int i = 0; - for (Enchantment enchantment : Enchantment.values()) { - enchantments[i++] = enchantment.getKey().getKey(); + if (enchantments == null) { + Registry enchantmentRegistry = Bukkit.getRegistry(Enchantment.class); + if (enchantmentRegistry == null) { + throw new RuntimeException("Unable to get enchantment registry"); + } + + enchantments = new ArrayList<>(); + for (Enchantment enchantment : enchantmentRegistry) { + enchantments.add(enchantment.getKey().getKey()); } } } diff --git a/src/main/java/net/knarcraft/blacksmith/util/InputParsingHelper.java b/src/main/java/net/knarcraft/blacksmith/util/InputParsingHelper.java index 3681369..c940d3c 100644 --- a/src/main/java/net/knarcraft/blacksmith/util/InputParsingHelper.java +++ b/src/main/java/net/knarcraft/blacksmith/util/InputParsingHelper.java @@ -1,7 +1,9 @@ package net.knarcraft.blacksmith.util; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.NamespacedKey; +import org.bukkit.Registry; import org.bukkit.enchantments.Enchantment; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -44,7 +46,11 @@ public final class InputParsingHelper { */ public static @Nullable Enchantment matchEnchantment(@NotNull String input) { try { - return Enchantment.getByKey(NamespacedKey.minecraft( + Registry enchantments = Bukkit.getRegistry(Enchantment.class); + if (enchantments == null) { + throw new RuntimeException("Unable to get enchantment registry"); + } + return enchantments.get(NamespacedKey.minecraft( input.replace("-", "_").replace(" ", "_").toLowerCase())); } catch (IllegalArgumentException exception) { //Invalid characters, such as : will normally throw an illegal argument exception diff --git a/src/main/java/net/knarcraft/blacksmith/util/TabCompleteValuesHelper.java b/src/main/java/net/knarcraft/blacksmith/util/TabCompleteValuesHelper.java index a9a8c4b..aa1b5e8 100644 --- a/src/main/java/net/knarcraft/blacksmith/util/TabCompleteValuesHelper.java +++ b/src/main/java/net/knarcraft/blacksmith/util/TabCompleteValuesHelper.java @@ -3,7 +3,9 @@ package net.knarcraft.blacksmith.util; import net.knarcraft.blacksmith.config.SettingValueType; import net.knarcraft.blacksmith.config.SmithPreset; import net.knarcraft.blacksmith.config.SmithPresetFilter; +import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.Registry; import org.bukkit.enchantments.Enchantment; import org.jetbrains.annotations.NotNull; @@ -82,8 +84,13 @@ public final class TabCompleteValuesHelper { * @return

A complete list of enchantments

*/ private static @NotNull List getAllEnchantments() { + Registry enchantmentRegistry = Bukkit.getRegistry(Enchantment.class); + if (enchantmentRegistry == null) { + throw new RuntimeException("Unable to get the enchantment registry"); + } + List enchantments = new ArrayList<>(); - for (Enchantment enchantment : Enchantment.values()) { + for (Enchantment enchantment : enchantmentRegistry) { enchantments.add(enchantment.getKey().getKey()); } return enchantments; diff --git a/src/test/java/net/knarcraft/blacksmith/CustomServerMock.java b/src/test/java/net/knarcraft/blacksmith/CustomServerMock.java deleted file mode 100644 index 7cee7cb..0000000 --- a/src/test/java/net/knarcraft/blacksmith/CustomServerMock.java +++ /dev/null @@ -1,39 +0,0 @@ -package net.knarcraft.blacksmith; - -import be.seeseemelk.mockbukkit.ServerMock; -import org.bukkit.Material; -import org.bukkit.NamespacedKey; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.Recipe; -import org.bukkit.inventory.ShapedRecipe; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.List; - -/** - * A custom server mock specifically for making the SalvageHelperTest work - */ -public class CustomServerMock extends ServerMock { - - @Override - @NotNull - public List getRecipesFor(@NotNull ItemStack itemStack) { - List validRecipes = new ArrayList<>(); - if (itemStack.getType() == Material.DIAMOND_PICKAXE) { - ShapedRecipe recipe = new ShapedRecipe(NamespacedKey.minecraft("diamond_pickaxe"), itemStack); - recipe.shape("ddd", "asa", "asa"); - recipe.setIngredient('d', Material.DIAMOND); - recipe.setIngredient('s', Material.STICK); - validRecipes.add(recipe); - } else if (itemStack.getType() == Material.TNT) { - ShapedRecipe recipe = new ShapedRecipe(NamespacedKey.minecraft("tnt"), itemStack); - recipe.shape("gsg", "sgs", "gsg"); - recipe.setIngredient('g', Material.GUNPOWDER); - recipe.setIngredient('s', Material.SAND); - validRecipes.add(recipe); - } - return validRecipes; - } - -} diff --git a/src/test/java/net/knarcraft/blacksmith/util/InputParsingHelperTest.java b/src/test/java/net/knarcraft/blacksmith/util/InputParsingHelperTest.java index 0dd1c12..c82b71a 100644 --- a/src/test/java/net/knarcraft/blacksmith/util/InputParsingHelperTest.java +++ b/src/test/java/net/knarcraft/blacksmith/util/InputParsingHelperTest.java @@ -1,15 +1,10 @@ package net.knarcraft.blacksmith.util; -import be.seeseemelk.mockbukkit.enchantments.EnchantmentMock; import org.bukkit.Material; -import org.bukkit.NamespacedKey; -import org.bukkit.enchantments.Enchantment; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -18,16 +13,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; */ public class InputParsingHelperTest { - private static Enchantment curseOfBinding; - - @BeforeAll - public static void setUp() { - //Note: When not testing against a real server, no default enchantments are loaded! - curseOfBinding = new EnchantmentMock(NamespacedKey.minecraft("binding_curse"), - "CURSE_OF_BINDING"); - Enchantment.registerEnchantment(curseOfBinding); - } - @Test public void isEmptyTrueTest() { assertTrue(InputParsingHelper.isEmpty(null)); @@ -71,28 +56,6 @@ public class InputParsingHelperTest { assertNull(InputParsingHelper.matchMaterial("minecraft: golden-BOOTS")); } - @Test - public void matchEnchantmentValidTest() { - for (Enchantment enchantment : Enchantment.values()) { - assertEquals(enchantment, InputParsingHelper.matchEnchantment(enchantment.getKey().getKey())); - } - assertEquals(curseOfBinding, InputParsingHelper.matchEnchantment("binding_curse")); - assertEquals(curseOfBinding, InputParsingHelper.matchEnchantment("binding-curse")); - assertEquals(curseOfBinding, InputParsingHelper.matchEnchantment("binding curse")); - assertEquals(curseOfBinding, InputParsingHelper.matchEnchantment("BINDING curse")); - } - - @Test - public void matchEnchantmentInvalidTest() { - for (Enchantment enchantment : Enchantment.values()) { - assertEquals(enchantment, InputParsingHelper.matchEnchantment(enchantment.getKey().getKey())); - } - assertNotEquals(curseOfBinding, InputParsingHelper.matchEnchantment("bonding_curse")); - assertNotEquals(curseOfBinding, InputParsingHelper.matchEnchantment("binding curse")); - assertNotEquals(curseOfBinding, InputParsingHelper.matchEnchantment(" BINDING curse")); - assertNotEquals(curseOfBinding, InputParsingHelper.matchEnchantment("binding:curse")); - } - @Test public void regExIfyTest() { assertEquals("NO REGEX HERE", InputParsingHelper.regExIfy("no regEx here")); diff --git a/src/test/java/net/knarcraft/blacksmith/util/ItemHelperTest.java b/src/test/java/net/knarcraft/blacksmith/util/ItemHelperTest.java index 5515598..96861ea 100644 --- a/src/test/java/net/knarcraft/blacksmith/util/ItemHelperTest.java +++ b/src/test/java/net/knarcraft/blacksmith/util/ItemHelperTest.java @@ -1,16 +1,8 @@ package net.knarcraft.blacksmith.util; -import be.seeseemelk.mockbukkit.MockBukkit; -import net.knarcraft.blacksmith.CustomServerMock; import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -19,80 +11,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; */ public class ItemHelperTest { - @BeforeAll - public static void setUp() { - MockBukkit.mock(new CustomServerMock()); - } - - @AfterAll - public static void tearDown() { - MockBukkit.unmock(); - } - - @Test - public void isRepairableTest() { - for (Material material : Material.values()) { - String name = material.name(); - if (name.endsWith("_SWORD") || name.endsWith("_PICKAXE") || name.endsWith("_AXE") || - name.endsWith("_HOE") || name.endsWith("_SHOVEL") || name.endsWith("_CHESTPLATE") || - name.endsWith("_HELMET") || name.equals("ELYTRA") || name.endsWith("BOW") || - name.endsWith("_LEGGINGS") || name.endsWith("_BOOTS") || name.equals("TRIDENT") || - name.equals("FISHING_ROD") || name.equals("FLINT_AND_STEEL") || name.equals("SHEARS")) { - assertTrue(ItemHelper.isRepairable(new ItemStack(material, 1))); - } - } - assertFalse(ItemHelper.isRepairable(new ItemStack(Material.POTATO, 1))); - assertFalse(ItemHelper.isRepairable(new ItemStack(Material.DIRT, 1))); - } - - @Test - public void getMaxDurabilityTest() { - assertEquals(1561, ItemHelper.getMaxDurability(new ItemStack(Material.DIAMOND_PICKAXE, 1))); - assertEquals(0, ItemHelper.getMaxDurability(new ItemStack(Material.POTATO, 1))); - } - - @Test - public void updateAndGetDamageTest() { - for (Material material : Material.values()) { - //A lot of items seem to have weird metadata which isn't mocked properly. Therefore, this test is limited. - if (!material.name().endsWith("_PICKAXE")) { - continue; - } - ItemStack itemStack = new ItemStack(material, 1); - assertEquals(0, ItemHelper.getDamage(itemStack)); - ItemHelper.updateDamage(itemStack, 3); - assertEquals(3, ItemHelper.getDamage(itemStack)); - } - } - - @Test - public void getDurabilityTest() { - for (Material material : Material.values()) { - ItemStack itemStack = new ItemStack(material, 1); - assertEquals(ItemHelper.getMaxDurability(itemStack), ItemHelper.getDurability(itemStack)); - } - - for (Material material : Material.values()) { - //A lot of items seem to have weird metadata which isn't mocked properly. Therefore, this test is limited. - if (!material.name().endsWith("_PICKAXE")) { - continue; - } - ItemStack itemStack = new ItemStack(material, 1); - ItemHelper.updateDamage(itemStack, 100); - assertEquals(ItemHelper.getMaxDurability(itemStack) - 100, ItemHelper.getDurability(itemStack)); - } - } - - @Test - public void getAllReforgeAbleMaterialsTest() { - List materials = ItemHelper.getAllReforgeAbleMaterials(); - assertFalse(materials.isEmpty()); - - for (Material material : materials) { - assertTrue(ItemHelper.getMaxDurability(new ItemStack(material, 1)) > 0); - } - } - @Test public void isAnvilRequiresDamagedTest() { assertTrue(ItemHelper.isAnvil(Material.DAMAGED_ANVIL, true)); diff --git a/src/test/java/net/knarcraft/blacksmith/util/SalvageHelperTest.java b/src/test/java/net/knarcraft/blacksmith/util/SalvageHelperTest.java deleted file mode 100644 index 35ebc5a..0000000 --- a/src/test/java/net/knarcraft/blacksmith/util/SalvageHelperTest.java +++ /dev/null @@ -1,123 +0,0 @@ -package net.knarcraft.blacksmith.util; - -import be.seeseemelk.mockbukkit.MockBukkit; -import net.knarcraft.blacksmith.CustomServerMock; -import org.bukkit.Material; -import org.bukkit.Server; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.Damageable; -import org.bukkit.inventory.meta.ItemMeta; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.fail; - -/** - * A test class to test salvaging - */ -public class SalvageHelperTest { - - private static Server server; - - @BeforeAll - public static void setUp() { - server = MockBukkit.mock(new CustomServerMock()); - } - - @AfterAll - public static void tearDown() { - MockBukkit.unmock(); - } - - @Test - public void getNullForInvalidItemTest() { - //Assert that a non-reforge-able item will return null - assertNull(SalvageHelper.getSalvage(server, new ItemStack(Material.POTATO, 1), new ArrayList<>(), false)); - } - - @Test - public void getNullForLessThanOneItemTest() { - //Assert that 0 or 1 items will return null - assertNull(SalvageHelper.getSalvage(server, new ItemStack(Material.IRON_AXE, 0), new ArrayList<>(), false)); - assertNull(SalvageHelper.getSalvage(server, new ItemStack(Material.IRON_SWORD, -1), new ArrayList<>(), false)); - } - - @Test - public void getFullSalvageTest() { - Set expectedSalvage = new HashSet<>(); - expectedSalvage.add(new ItemStack(Material.DIAMOND, 3)); - expectedSalvage.add(new ItemStack(Material.STICK, 2)); - ItemStack itemToSalvage = new ItemStack(Material.DIAMOND_PICKAXE, 1); - //Note: Conversion to sets makes sure the order doesn't matter - List salvage = SalvageHelper.getSalvage(server, itemToSalvage, new ArrayList<>(), false); - if (salvage == null) { - fail(); - } else { - assertEquals(expectedSalvage, new HashSet<>(salvage)); - } - } - - @Test - public void getExtendedSalvageTest() { - Set expectedSalvage = new HashSet<>(); - expectedSalvage.add(new ItemStack(Material.GUNPOWDER, 5)); - expectedSalvage.add(new ItemStack(Material.SAND, 4)); - ItemStack itemToSalvage = new ItemStack(Material.TNT, 1); - //Note: Conversion to sets makes sure the order doesn't matter - List salvage = SalvageHelper.getSalvage(server, itemToSalvage, new ArrayList<>(), true); - if (salvage == null) { - fail(); - } else { - assertEquals(expectedSalvage, new HashSet<>(salvage)); - } - } - - @Test - public void getNonFullSalvageTest() { - List expectedSalvage = new ArrayList<>(); - expectedSalvage.add(new ItemStack(Material.DIAMOND, 3)); - expectedSalvage.add(new ItemStack(Material.STICK, 2)); - ItemStack itemToSalvage = new ItemStack(Material.DIAMOND_PICKAXE, 1); - ItemMeta meta = itemToSalvage.getItemMeta(); - Damageable damageable = (Damageable) meta; - if (damageable != null) { - damageable.setDamage(100); - } - itemToSalvage.setItemMeta(meta); - List salvage = SalvageHelper.getSalvage(server, itemToSalvage, new ArrayList<>(), false); - //Assert that some items are given - assertNotEquals(salvage, new ArrayList<>()); - //Assert that a damaged item won't give full salvage - assertNotEquals(expectedSalvage, salvage); - } - - @Test - public void ignoredSalvageTest() { - List expectedSalvage = new ArrayList<>(); - expectedSalvage.add(new ItemStack(Material.DIAMOND, 2)); - ItemStack itemToSalvage = new ItemStack(Material.DIAMOND_PICKAXE, 1); - List ignoredSalvage = new ArrayList<>(); - ignoredSalvage.add(Material.STICK); - ItemMeta meta = itemToSalvage.getItemMeta(); - Damageable damageable = (Damageable) meta; - if (damageable != null) { - damageable.setDamage(100); - } - itemToSalvage.setItemMeta(meta); - List salvage = SalvageHelper.getSalvage(server, itemToSalvage, ignoredSalvage, false); - //Assert that some items are given - assertNotEquals(salvage, new ArrayList<>()); - //Assert that a damaged diamond pickaxe with sticks ignored returns 2 diamonds a salvage - assertEquals(expectedSalvage, salvage); - } - -} diff --git a/src/test/java/net/knarcraft/blacksmith/util/TypeValidatorHelperTest.java b/src/test/java/net/knarcraft/blacksmith/util/TypeValidatorHelperTest.java index d09d292..280e0d1 100644 --- a/src/test/java/net/knarcraft/blacksmith/util/TypeValidatorHelperTest.java +++ b/src/test/java/net/knarcraft/blacksmith/util/TypeValidatorHelperTest.java @@ -1,11 +1,7 @@ package net.knarcraft.blacksmith.util; -import be.seeseemelk.mockbukkit.enchantments.EnchantmentMock; import net.knarcraft.blacksmith.config.SettingValueType; import org.bukkit.Material; -import org.bukkit.NamespacedKey; -import org.bukkit.enchantments.Enchantment; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import java.util.ArrayList; @@ -19,16 +15,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; */ public class TypeValidatorHelperTest { - private static Enchantment infinity; - - @BeforeAll - public static void setUp() { - //Note: When not testing against a real server, no default enchantments are loaded! - infinity = new EnchantmentMock(NamespacedKey.minecraft("arrow_infinite"), - "INFINITY"); - Enchantment.registerEnchantment(infinity); - } - @Test public void isValidPositiveDoubleValidTest() { SettingValueType type = SettingValueType.POSITIVE_DOUBLE; @@ -152,18 +138,9 @@ public class TypeValidatorHelperTest { assertFalse(TypeValidationHelper.isValid(type, true, null)); } - @Test - public void isValidEnchantmentValidTest() { - SettingValueType type = SettingValueType.ENCHANTMENT; - assertTrue(TypeValidationHelper.isValid(type, infinity, null)); - assertTrue(TypeValidationHelper.isValid(type, "arrow_infinite", null)); - } - @Test public void isValidEnchantmentInvalidTest() { SettingValueType type = SettingValueType.ENCHANTMENT; - assertFalse(TypeValidationHelper.isValid(type, "potato", null)); - assertFalse(TypeValidationHelper.isValid(type, 7675, null)); assertFalse(TypeValidationHelper.isValid(type, null, null)); }