diff --git a/pom.xml b/pom.xml index bf588d0a6..ddeacc6bb 100644 --- a/pom.xml +++ b/pom.xml @@ -1,153 +1,156 @@ - - - 4.0.0 - me.mrCookieSlime - Slimefun - - - - 4.3-UNOFFICIAL - - - UTF-8 - 1.8 - 1.8 - - - 1.15.2 - https://hub.spigotmc.org/javadocs/bukkit/ - - + + + 4.0.0 + me.mrCookieSlime + Slimefun + + + + 4.3-UNOFFICIAL + + + UTF-8 + 1.8 + 1.8 + + + 1.15.2 + https://hub.spigotmc.org/javadocs/bukkit/ + + TheBusyBiscuit_Slimefun4 thebusybiscuit-github https://sonarcloud.io - - - - - paper-repo - https://repo.destroystokyo.com/repository/maven-public/ - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - jitpack.io - https://jitpack.io - - - worldedit-worldguard-repo - https://maven.sk89q.com/repo/ - - - bStats-repo - https://repo.codemc.org/repository/maven-public - - - placeholderapi-repo - http://repo.extendedclip.com/content/repositories/placeholderapi/ - - - - - ${project.basedir}/src/main/java - ${project.name} v${project.version} - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - - - - **/package-info.java - - - - - - org.apache.maven.plugins - maven-source-plugin - 3.2.1 - - - attach-sources - - jar - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.0.0-M4 - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.3 - - - - - - - org.bstats - me.mrCookieSlime.Slimefun.bstats - - - io.github.thebusybiscuit.cscorelib2 - me.mrCookieSlime.Slimefun.cscorelib2 - - - - - - - *:* - - META-INF/* - - - - - - - - package - - shade - - - - - + + + + + paper-repo + https://repo.destroystokyo.com/repository/maven-public/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + jitpack.io + https://jitpack.io + + + worldedit-worldguard-repo + https://maven.sk89q.com/repo/ + + + bStats-repo + https://repo.codemc.org/repository/maven-public + + + placeholderapi-repo + http://repo.extendedclip.com/content/repositories/placeholderapi/ + + + + + ${project.basedir}/src/main/java + ${project.name} v${project.version} + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + + + + **/package-info.java + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.2.1 + + + attach-sources + + jar + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M4 + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.3 + + + + + + + org.bstats + me.mrCookieSlime.Slimefun.bstats + + + io.github.thebusybiscuit.cscorelib2 + me.mrCookieSlime.Slimefun.cscorelib2 + + + + + + + *:* + + META-INF/* + + + + + + + + package + + shade + + + + + org.apache.maven.plugins maven-javadoc-plugin 3.2.0 - + ${project.basedir} docs - + Slimefun4 - Javadocs Slimefun4 - Javadocs false -html5 - + ${bukkit.javadocs} - + @@ -177,108 +180,108 @@ - - - - - - - ${basedir}/src/main/resources - true - - - * - languages/* - - - - - - ${basedir} - - - LICENSE - - - - - - - - - org.bukkit - bukkit - ${bukkit.version}-R0.1-SNAPSHOT - provided - - - com.github.TheBusyBiscuit - CS-CoreLib - 8081bb4fe4 - provided - - - - - org.junit.jupiter - junit-jupiter - 5.5.1 - test - - - com.github.seeseemelk - MockBukkit - v1.15-SNAPSHOT - test - - - org.mockito - mockito-core - 3.3.3 - test - - - - - com.github.thebusybiscuit - CS-CoreLib2 - 0.17 - compile - - - org.bstats - bstats-bukkit - 1.7 - compile - - - - - com.sk89q.worldedit - worldedit-bukkit - 7.1.0 - provided - - - me.clip - placeholderapi - 2.10.6 - provided - - - com.github.TheBusyBiscuit - EmeraldEnchants2 - 3cd370b5d8 - provided - - - - - me.minebuilders - clearlag-core - 2.9.7 - system - ${project.basedir}/lib/Clearlag.jar - - + + + + + + + ${basedir}/src/main/resources + true + + + * + languages/* + + + + + + ${basedir} + + + LICENSE + + + + + + + + + org.bukkit + bukkit + ${bukkit.version}-R0.1-SNAPSHOT + provided + + + com.github.TheBusyBiscuit + CS-CoreLib + 8081bb4fe4 + provided + + + + + org.junit.jupiter + junit-jupiter + 5.5.1 + test + + + com.github.seeseemelk + MockBukkit + v1.15-279489afe1-1 + test + + + org.mockito + mockito-core + 3.3.3 + test + + + + + com.github.thebusybiscuit + CS-CoreLib2 + 0.17 + compile + + + org.bstats + bstats-bukkit + 1.7 + compile + + + + + com.sk89q.worldedit + worldedit-bukkit + 7.1.0 + provided + + + me.clip + placeholderapi + 2.10.6 + provided + + + com.github.TheBusyBiscuit + EmeraldEnchants2 + 3cd370b5d8 + provided + + + + + me.minebuilders + clearlag-core + 2.9.7 + system + ${project.basedir}/lib/Clearlag.jar + + diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java index 4a8043418..646dd16f7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java @@ -11,14 +11,7 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin; * */ public enum MinecraftVersion { - - /** - * This is a very special state that represents the environment being a Unit - * Test and not an actual running Minecraft Server. This constant stands at - * the very top because it is the one with the least features. - */ - UNIT_TEST("Unit Test Environment"), - + /** * This constant represents Minecraft (Java Edition) Version 1.14 * (The Update Aquatic) @@ -41,7 +34,13 @@ public enum MinecraftVersion { * This constant represents an exceptional state in which we were unable * to identify the Minecraft Version we are using */ - UNKNOWN("Unknown"); + UNKNOWN("Unknown"), + + /** + * This is a very special state that represents the environment being a Unit + * Test and not an actual running Minecraft Server. + */ + UNIT_TEST("Unit Test Environment"); private final String name; private final String prefix; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/exceptions/PrematureCodeException.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/exceptions/PrematureCodeException.java index f05218a56..d02c773aa 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/exceptions/PrematureCodeException.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/exceptions/PrematureCodeException.java @@ -5,7 +5,7 @@ import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon; /** * A {@link PrematureCodeException} is thrown when a {@link SlimefunAddon} tried * to access Slimefun code before Slimefun was enabled. - * Always let your code inside onEnable() or later, never on class initialization. + * Always let your code run inside onEnable() or later, never on class initialization. * * @author TheBusyBiscuit * diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/IronGolemListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/IronGolemListener.java index dba39fed2..f8b58c187 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/IronGolemListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/IronGolemListener.java @@ -10,6 +10,7 @@ import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; +import io.github.thebusybiscuit.slimefun4.implementation.items.VanillaItem; import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; @@ -40,17 +41,21 @@ public class IronGolemListener implements Listener { item = inv.getItemInOffHand(); } - if (item != null && item.getType() == Material.IRON_INGOT && SlimefunItem.getByItem(item) != null) { - e.setCancelled(true); - SlimefunPlugin.getLocal().sendMessage(e.getPlayer(), "messages.no-iron-golem-heal"); + if (item != null && item.getType() == Material.IRON_INGOT) { + SlimefunItem sfItem = SlimefunItem.getByItem(item); - // This is just there to update the Inventory... - // Somehow cancelling it isn't enough. - if (e.getHand() == EquipmentSlot.HAND) { - inv.setItemInMainHand(item); - } - else if (e.getHand() == EquipmentSlot.OFF_HAND) { - inv.setItemInOffHand(item); + if (sfItem != null && !(sfItem instanceof VanillaItem)) { + e.setCancelled(true); + SlimefunPlugin.getLocal().sendMessage(e.getPlayer(), "messages.no-iron-golem-heal"); + + // This is just there to update the Inventory... + // Somehow cancelling it isn't enough. + if (e.getHand() == EquipmentSlot.HAND) { + inv.setItemInMainHand(item); + } + else if (e.getHand() == EquipmentSlot.OFF_HAND) { + inv.setItemInOffHand(item); + } } } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/VanillaMachinesListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/VanillaMachinesListener.java index b020d977d..50870ff66 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/VanillaMachinesListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/VanillaMachinesListener.java @@ -14,9 +14,8 @@ import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide; -import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; +import io.github.thebusybiscuit.slimefun4.implementation.items.VanillaItem; import me.mrCookieSlime.Slimefun.SlimefunPlugin; -import me.mrCookieSlime.Slimefun.Lists.SlimefunItems; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; /** @@ -39,7 +38,7 @@ public class VanillaMachinesListener implements Listener { public void onGrindstone(InventoryClickEvent e) { // The Grindstone was only ever added in MC 1.14 MinecraftVersion minecraftVersion = SlimefunPlugin.getMinecraftVersion(); - if (minecraftVersion != MinecraftVersion.UNIT_TEST && !minecraftVersion.isAtLeast(MinecraftVersion.MINECRAFT_1_14)) { + if (!minecraftVersion.isAtLeast(MinecraftVersion.MINECRAFT_1_14)) { return; } @@ -60,7 +59,7 @@ public class VanillaMachinesListener implements Listener { SlimefunItem sfItem = SlimefunItem.getByItem(item); if (sfItem != null && !sfItem.isUseableInWorkbench()) { - e.setCancelled(true); + e.setResult(Result.DENY); SlimefunPlugin.getLocal().sendMessage((Player) e.getWhoClicked(), "workbench.not-enhanced", true); break; } @@ -87,7 +86,7 @@ public class VanillaMachinesListener implements Listener { ItemStack item1 = e.getInventory().getContents()[0]; ItemStack item2 = e.getInventory().getContents()[1]; - if (!SlimefunUtils.isItemSimilar(item1, SlimefunItems.ELYTRA, true) && checkForUnallowedItems(item1, item2)) { + if (checkForUnallowedItems(item1, item2)) { e.setCancelled(true); SlimefunPlugin.getLocal().sendMessage((Player) e.getWhoClicked(), "anvil.not-working", true); } @@ -111,11 +110,15 @@ public class VanillaMachinesListener implements Listener { SlimefunItem sfItem1 = SlimefunItem.getByItem(item1); SlimefunItem sfItem2 = SlimefunItem.getByItem(item2); - if ((sfItem1 != null && !sfItem1.isDisabled()) || (sfItem2 != null && !sfItem2.isDisabled())) { + if (isUnallowed(sfItem1) || isUnallowed(sfItem2)) { return true; } } return false; } + + private boolean isUnallowed(SlimefunItem item) { + return item != null && !(item instanceof VanillaItem) && !item.isDisabled(); + } } diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/mocks/SlimefunMocks.java b/src/test/java/io/github/thebusybiscuit/slimefun4/mocks/SlimefunMocks.java index 650dd09c1..83eebc3b0 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/mocks/SlimefunMocks.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/mocks/SlimefunMocks.java @@ -1,13 +1,15 @@ package io.github.thebusybiscuit.slimefun4.mocks; +import static org.mockito.Mockito.when; + import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.mockito.Mockito; -import static org.mockito.Mockito.when; +import io.github.thebusybiscuit.slimefun4.implementation.items.VanillaItem; import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; @@ -31,4 +33,10 @@ public final class SlimefunMocks { return new MockSlimefunItem(category, item, id); } + public static VanillaItem mockVanillaItem(Material type, boolean enabled) { + VanillaItem item = new VanillaItem(category, new ItemStack(type), type.name(), null, new ItemStack[9]); + SlimefunPlugin.getItemCfg().setValue(type.name() + ".enabled", enabled); + return item; + } + } diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/items/TestSlimefunItemRegistration.java b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/items/TestSlimefunItemRegistration.java index ac4b5823c..61c379390 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/items/TestSlimefunItemRegistration.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/items/TestSlimefunItemRegistration.java @@ -9,6 +9,7 @@ import org.junit.jupiter.api.Test; import be.seeseemelk.mockbukkit.MockBukkit; import be.seeseemelk.mockbukkit.ServerMock; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; +import io.github.thebusybiscuit.slimefun4.implementation.items.VanillaItem; import io.github.thebusybiscuit.slimefun4.mocks.SlimefunMocks; import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.ItemState; @@ -38,6 +39,14 @@ public class TestSlimefunItemRegistration { Assertions.assertEquals(ItemState.ENABLED, item.getState()); } + @Test + public void testVanillaItemFallback() { + VanillaItem item = SlimefunMocks.mockVanillaItem(Material.ACACIA_SIGN, false); + item.register(plugin); + + Assertions.assertEquals(ItemState.VANILLA_FALLBACK, item.getState()); + } + @Test public void testIdConflict() { SlimefunItem item = SlimefunMocks.mockSlimefunItem("DUPLICATE_ID", new CustomItem(Material.DIAMOND, "&cTest")); diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/listeners/TestIronGolemListener.java b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/listeners/TestIronGolemListener.java index c3388d632..693670d26 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/listeners/TestIronGolemListener.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/listeners/TestIronGolemListener.java @@ -16,6 +16,7 @@ import org.mockito.Mockito; import be.seeseemelk.mockbukkit.MockBukkit; import be.seeseemelk.mockbukkit.ServerMock; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; +import io.github.thebusybiscuit.slimefun4.implementation.items.VanillaItem; import io.github.thebusybiscuit.slimefun4.implementation.listeners.IronGolemListener; import io.github.thebusybiscuit.slimefun4.mocks.SlimefunMocks; import me.mrCookieSlime.Slimefun.SlimefunPlugin; @@ -76,6 +77,7 @@ public class TestIronGolemListener { public void testWithSlimefunIron() { SlimefunItem slimefunItem = SlimefunMocks.mockSlimefunItem("SLIMEFUN_IRON", new CustomItem(Material.IRON_INGOT, "&cSlimefun Iron")); slimefunItem.register(plugin); + // The Event should be cancelled, we do not wanna use Slimefun Items for this PlayerInteractEntityEvent event = callIronGolemEvent(EquipmentSlot.HAND, slimefunItem.getItem()); Assertions.assertTrue(event.isCancelled()); @@ -84,4 +86,16 @@ public class TestIronGolemListener { Assertions.assertTrue(event2.isCancelled()); } + @Test + public void testWithVanillaIron() { + VanillaItem item = SlimefunMocks.mockVanillaItem(Material.IRON_INGOT, true); + item.register(plugin); + + PlayerInteractEntityEvent event = callIronGolemEvent(EquipmentSlot.HAND, item.getItem()); + Assertions.assertFalse(event.isCancelled()); + + PlayerInteractEntityEvent event2 = callIronGolemEvent(EquipmentSlot.OFF_HAND, item.getItem()); + Assertions.assertFalse(event2.isCancelled()); + } + } diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/listeners/TestVanillaMachinesListener.java b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/listeners/TestVanillaMachinesListener.java index f321095eb..ebd86f958 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/listeners/TestVanillaMachinesListener.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/listeners/TestVanillaMachinesListener.java @@ -1,27 +1,39 @@ package io.github.thebusybiscuit.slimefun4.tests.listeners; +import org.apache.commons.lang.mutable.MutableObject; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.event.Event.Result; import org.bukkit.event.inventory.ClickType; +import org.bukkit.event.inventory.CraftItemEvent; import org.bukkit.event.inventory.InventoryAction; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.inventory.InventoryType.SlotType; +import org.bukkit.event.inventory.PrepareItemCraftEvent; +import org.bukkit.inventory.CraftingInventory; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.Recipe; +import org.bukkit.inventory.ShapedRecipe; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import be.seeseemelk.mockbukkit.MockBukkit; import be.seeseemelk.mockbukkit.ServerMock; -import be.seeseemelk.mockbukkit.inventory.meta.EnchantedBookMetaMock; +import io.github.thebusybiscuit.cscorelib2.item.CustomItem; +import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide; +import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; +import io.github.thebusybiscuit.slimefun4.implementation.items.VanillaItem; import io.github.thebusybiscuit.slimefun4.implementation.listeners.VanillaMachinesListener; import io.github.thebusybiscuit.slimefun4.mocks.SlimefunMocks; import me.mrCookieSlime.Slimefun.SlimefunPlugin; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; public class TestVanillaMachinesListener { @@ -41,15 +53,127 @@ public class TestVanillaMachinesListener { MockBukkit.unmock(); } - @Test - public void testGrindStoneWithoutSlimefunItems() { + private InventoryClickEvent mockGrindStoneEvent(ItemStack item) { Player player = server.addPlayer(); - Inventory inv = SlimefunMocks.mockInventory(InventoryType.GRINDSTONE, new ItemStack(Material.ENCHANTED_BOOK), null); + Inventory inv = SlimefunMocks.mockInventory(InventoryType.GRINDSTONE, item, null); InventoryView view = player.openInventory(inv); InventoryClickEvent event = new InventoryClickEvent(view, SlotType.CONTAINER, 2, ClickType.LEFT, InventoryAction.PICKUP_ONE); - listener.onGrindstone(event); + listener.onGrindstone(event); + return event; + } + + private CraftItemEvent mockCraftingEvent(ItemStack item) { + Recipe recipe = new ShapedRecipe(new NamespacedKey(plugin, "test_recipe"), new ItemStack(Material.EMERALD)); + Player player = server.addPlayer(); + + CraftingInventory inv = Mockito.mock(CraftingInventory.class); + Mockito.when(inv.getContents()).thenReturn(new ItemStack[] { item, null, null, null, null, null, null, null, null }); + + InventoryView view = player.openInventory(inv); + CraftItemEvent event = new CraftItemEvent(recipe, view, SlotType.RESULT, 9, ClickType.LEFT, InventoryAction.PICKUP_ALL); + + listener.onCraft(event); + return event; + } + + private PrepareItemCraftEvent mockPreCraftingEvent(ItemStack item) { + Player player = server.addPlayer(); + + CraftingInventory inv = Mockito.mock(CraftingInventory.class); + MutableObject result = new MutableObject(new ItemStack(Material.EMERALD)); + + Mockito.doAnswer(invocation -> { + ItemStack argument = invocation.getArgument(0); + result.setValue(argument); + return null; + }).when(inv).setResult(Mockito.any()); + + Mockito.when(inv.getResult()).thenAnswer(invocation -> result.getValue()); + Mockito.when(inv.getContents()).thenReturn(new ItemStack[] { null, null, item, null, null, null, null, null, null }); + + InventoryView view = player.openInventory(inv); + PrepareItemCraftEvent event = new PrepareItemCraftEvent(inv, view, false); + + listener.onPrepareCraft(event); + return event; + } + + @Test + public void testGrindStoneWithoutSlimefunItems() { + InventoryClickEvent event = mockGrindStoneEvent(new ItemStack(Material.ENCHANTED_BOOK)); Assertions.assertEquals(Result.DEFAULT, event.getResult()); } + @Test + public void testGrindStoneWithSlimefunItems() { + SlimefunItem item = SlimefunMocks.mockSlimefunItem("ENCHANTED_MOCK_BOOK", new CustomItem(Material.ENCHANTED_BOOK, "&6Mock")); + item.register(plugin); + + InventoryClickEvent event = mockGrindStoneEvent(item.getItem()); + Assertions.assertEquals(Result.DENY, event.getResult()); + } + + @Test + public void testGrindStoneWithVanillaItem() { + VanillaItem item = SlimefunMocks.mockVanillaItem(Material.ENCHANTED_BOOK, true); + item.register(plugin); + + InventoryClickEvent event = mockGrindStoneEvent(item.getItem()); + Assertions.assertEquals(Result.DEFAULT, event.getResult()); + } + + @Test + public void testGrindStoneWithSlimefunGuide() { + InventoryClickEvent event = mockGrindStoneEvent(SlimefunGuide.getItem(SlimefunGuideLayout.CHEST)); + Assertions.assertEquals(Result.DENY, event.getResult()); + } + + @Test + public void testCraftEventWithoutSlimefunItems() { + CraftItemEvent event = mockCraftingEvent(new ItemStack(Material.DIAMOND)); + Assertions.assertEquals(Result.DEFAULT, event.getResult()); + } + + @Test + public void testCraftEventWithSlimefunItem() { + SlimefunItem item = SlimefunMocks.mockSlimefunItem("MOCK_DIAMOND", new CustomItem(Material.DIAMOND, "&cMock Diamond")); + item.register(plugin); + + CraftItemEvent event = mockCraftingEvent(item.getItem()); + Assertions.assertEquals(Result.DENY, event.getResult()); + } + + @Test + public void testCraftEventWithVanillaItem() { + VanillaItem item = SlimefunMocks.mockVanillaItem(Material.DIAMOND, true); + item.register(plugin); + + CraftItemEvent event = mockCraftingEvent(item.getItem()); + Assertions.assertEquals(Result.DEFAULT, event.getResult()); + } + + @Test + public void testPreCraftEventWithoutSlimefunItems() { + PrepareItemCraftEvent event = mockPreCraftingEvent(new ItemStack(Material.DIAMOND)); + Assertions.assertNotNull(event.getInventory().getResult()); + } + + @Test + public void testPreCraftEventWithSlimefunItem() { + SlimefunItem item = SlimefunMocks.mockSlimefunItem("MOCK_DIAMOND2", new CustomItem(Material.DIAMOND, "&cMock Diamond")); + item.register(plugin); + + PrepareItemCraftEvent event = mockPreCraftingEvent(item.getItem()); + Assertions.assertNull(event.getInventory().getResult()); + } + + @Test + public void testPreCraftEventWithVanillaItem() { + VanillaItem item = SlimefunMocks.mockVanillaItem(Material.GOLD_INGOT, true); + item.register(plugin); + + PrepareItemCraftEvent event = mockPreCraftingEvent(item.getItem()); + Assertions.assertNotNull(event.getInventory().getResult()); + } }