* By default, a category is automatically registered when a {@link SlimefunItem} was added to it. + * + * @param addon + * The {@link SlimefunAddon} that wants to register this {@link Category} */ + public void register(@Nonnull SlimefunAddon addon) { + Validate.notNull(addon, "The Addon cannot be null"); + this.addon = addon; + + SlimefunPlugin.getRegistry().getCategories().add(this); + Collections.sort(SlimefunPlugin.getRegistry().getCategories(), Comparator.comparingInt(Category::getTier)); + } + + /** + * Old way of registering categories, do not call this manually. + * + * @deprecated Please use {@link #register(SlimefunAddon)} instead. + */ + @Deprecated public void register() { SlimefunPlugin.getRegistry().getCategories().add(this); Collections.sort(SlimefunPlugin.getRegistry().getCategories(), Comparator.comparingInt(Category::getTier)); } + /** + * This returns the {@link SlimefunAddon} which has registered this {@link Category}. + * Or null if it has not been registered yet. + * + * @return The {@link SlimefunAddon} or null if unregistered + */ + @Nullable + public final SlimefunAddon getAddon() { + return addon; + } + /** * Adds the given {@link SlimefunItem} to this {@link Category}. * diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java index 9f487f678..c23fbdc17 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java @@ -477,7 +477,7 @@ public class SlimefunItem implements Placeable { private final void onEnable() { // Register the Category too if it hasn't been registered yet if (!category.isRegistered()) { - category.register(); + category.register(addon); } // Send out deprecation warnings for any classes or interfaces diff --git a/src/main/java/me/mrCookieSlime/Slimefun/api/Slimefun.java b/src/main/java/me/mrCookieSlime/Slimefun/api/Slimefun.java index 1161fa5f1..6b843802c 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/api/Slimefun.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/api/Slimefun.java @@ -1,9 +1,6 @@ package me.mrCookieSlime.Slimefun.api; import java.util.Optional; -import java.util.logging.Logger; - -import javax.annotation.Nonnull; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -25,17 +22,6 @@ public final class Slimefun { private Slimefun() {} - /** - * This returns the {@link Logger} for Slimefun. - * - * @deprecated Use {@link SlimefunPlugin#logger()} instead - */ - @Deprecated - @Nonnull - public static Logger getLogger() { - return SlimefunPlugin.logger(); - } - /** * Checks if this player can use this item. * diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 9413104e2..84aff21b3 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -20,7 +20,6 @@ options: drop-excess-sf-give-items: false guide: - default-view-book: false show-vanilla-recipes: true receive-on-first-join: true diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 692b065ca..fa3936eaa 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -23,7 +23,6 @@ softdepend: # We hook into these plugins too, but they depend on Slimefun. loadBefore: - ChestTerminal -- ExoticGarden # Our commands commands: diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/commands/TestGuideCommand.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/commands/TestGuideCommand.java index 663d1e1bc..cd1055a5b 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/commands/TestGuideCommand.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/commands/TestGuideCommand.java @@ -12,7 +12,7 @@ import org.junit.jupiter.params.provider.ValueSource; import be.seeseemelk.mockbukkit.MockBukkit; import be.seeseemelk.mockbukkit.ServerMock; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide; -import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; +import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; @@ -39,7 +39,7 @@ class TestGuideCommand { player.setOp(op); server.execute("slimefun", player, "guide").assertSucceeded(); - ItemStack guide = SlimefunGuide.getItem(SlimefunGuideLayout.CHEST); + ItemStack guide = SlimefunGuide.getItem(SlimefunGuideMode.SURVIVAL_MODE); Assertions.assertEquals(op, SlimefunUtils.containsSimilarItem(player.getInventory(), guide, true)); } } diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/guide/TestBookSlimefunGuide.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/guide/TestBookSlimefunGuide.java deleted file mode 100644 index 6d56a54e6..000000000 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/guide/TestBookSlimefunGuide.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.thebusybiscuit.slimefun4.testing.tests.guide; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import be.seeseemelk.mockbukkit.MockBukkit; -import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; -import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; -import io.github.thebusybiscuit.slimefun4.implementation.guide.BookSlimefunGuide; - -class TestBookSlimefunGuide { - - @BeforeAll - public static void load() { - MockBukkit.mock(); - MockBukkit.load(SlimefunPlugin.class); - } - - @AfterAll - public static void unload() { - MockBukkit.unmock(); - } - - @Test - @DisplayName("Test Getters for Chest Slimefun Guide") - void testBasicGetters() { - BookSlimefunGuide guide = new BookSlimefunGuide(); - - Assertions.assertEquals(SlimefunGuideLayout.BOOK, guide.getLayout()); - Assertions.assertTrue(guide.isSurvivalMode()); - } - -} diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/guide/TestChestSlimefunGuide.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/guide/TestChestSlimefunGuide.java deleted file mode 100644 index 5880e650f..000000000 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/guide/TestChestSlimefunGuide.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.thebusybiscuit.slimefun4.testing.tests.guide; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import be.seeseemelk.mockbukkit.MockBukkit; -import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; -import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; -import io.github.thebusybiscuit.slimefun4.implementation.guide.ChestSlimefunGuide; - -class TestChestSlimefunGuide { - - @BeforeAll - public static void load() { - MockBukkit.mock(); - MockBukkit.load(SlimefunPlugin.class); - } - - @AfterAll - public static void unload() { - MockBukkit.unmock(); - } - - @Test - @DisplayName("Test Getters for Chest Slimefun Guide") - void testBasicGetters() { - ChestSlimefunGuide guide = new ChestSlimefunGuide(false); - - Assertions.assertEquals(SlimefunGuideLayout.CHEST, guide.getLayout()); - Assertions.assertTrue(guide.isSurvivalMode()); - } - -} diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/listeners/TestGrindstoneListener.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/listeners/TestGrindstoneListener.java index 19a74a5dc..b171f1570 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/listeners/TestGrindstoneListener.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/listeners/TestGrindstoneListener.java @@ -22,7 +22,7 @@ import be.seeseemelk.mockbukkit.MockBukkit; import be.seeseemelk.mockbukkit.ServerMock; 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.core.guide.SlimefunGuideMode; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.items.VanillaItem; import io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting.GrindstoneListener; @@ -82,8 +82,8 @@ public class TestGrindstoneListener { } @ParameterizedTest - @EnumSource(SlimefunGuideLayout.class) - public void testGrindStoneWithSlimefunGuide(SlimefunGuideLayout layout) { + @EnumSource(SlimefunGuideMode.class) + public void testGrindStoneWithSlimefunGuide(SlimefunGuideMode layout) { InventoryClickEvent event = mockGrindStoneEvent(SlimefunGuide.getItem(layout)); Assertions.assertEquals(Result.DENY, event.getResult()); } diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/registration/TestCategories.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/registration/TestCategories.java index 5a6d87450..bb0aadca7 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/registration/TestCategories.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/registration/TestCategories.java @@ -10,6 +10,7 @@ import org.bukkit.inventory.ItemStack; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import be.seeseemelk.mockbukkit.MockBukkit; @@ -19,7 +20,7 @@ import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; import io.github.thebusybiscuit.slimefun4.core.categories.FlexCategory; import io.github.thebusybiscuit.slimefun4.core.categories.LockedCategory; import io.github.thebusybiscuit.slimefun4.core.categories.SeasonalCategory; -import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; +import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode; import io.github.thebusybiscuit.slimefun4.core.researching.Research; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.testing.TestUtilities; @@ -28,7 +29,7 @@ import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -public class TestCategories { +class TestCategories { private static ServerMock server; private static SlimefunPlugin plugin; @@ -45,17 +46,23 @@ public class TestCategories { } @Test - public void testCategoryGetters() { + @DisplayName("Test the Getters for Category") + void testCategoryGetters() { Category category = new Category(new NamespacedKey(plugin, "getter_test"), new CustomItem(Material.DIAMOND_AXE, "&6Testing")); Assertions.assertEquals(3, category.getTier()); Assertions.assertEquals(new NamespacedKey(SlimefunPlugin.instance(), "getter_test"), category.getKey()); Assertions.assertEquals("Testing", category.getUnlocalizedName()); Assertions.assertEquals(0, category.getItems().size()); + + Assertions.assertNull(category.getAddon()); + category.register(plugin); + Assertions.assertEquals(plugin, category.getAddon()); } @Test - public void testAddItem() { + @DisplayName("Test adding an item to a Category") + void testAddItem() { Category category = new Category(new NamespacedKey(plugin, "items_test"), new CustomItem(Material.DIAMOND_AXE, "&6Testing")); SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "CATEGORY_ITEMS_TEST_ITEM", new CustomItem(Material.BAMBOO, "&6Test Bamboo")); item.setCategory(category); @@ -73,7 +80,8 @@ public class TestCategories { } @Test - public void testHidden() { + @DisplayName("Test hidden Categories") + void testHidden() { Category category = new Category(new NamespacedKey(plugin, "hiddenCategory"), new ItemStack(Material.BEACON)); Player player = server.addPlayer(); @@ -103,7 +111,8 @@ public class TestCategories { } @Test - public void testContains() { + @DisplayName("Test Category#contains") + void testContains() { SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "CATEGORY_TEST_ITEM_2", new CustomItem(Material.BOW, "&6Test Bow")); item.register(plugin); item.load(); @@ -118,16 +127,17 @@ public class TestCategories { } @Test - public void testLockedCategoriesParents() { + @DisplayName("Test LockedCategory parental locking") + void testLockedCategoriesParents() { Assertions.assertThrows(IllegalArgumentException.class, () -> new LockedCategory(new NamespacedKey(plugin, "locked"), new CustomItem(Material.GOLD_NUGGET, "&6Locked Test"), (NamespacedKey) null)); Category category = new Category(new NamespacedKey(plugin, "unlocked"), new CustomItem(Material.EMERALD, "&5I am SHERlocked")); - category.register(); + category.register(plugin); Category unregistered = new Category(new NamespacedKey(plugin, "unregistered"), new CustomItem(Material.EMERALD, "&5I am unregistered")); LockedCategory locked = new LockedCategory(new NamespacedKey(plugin, "locked"), new CustomItem(Material.GOLD_NUGGET, "&6Locked Test"), category.getKey(), unregistered.getKey()); - locked.register(); + locked.register(plugin); Assertions.assertTrue(locked.getParents().contains(category)); Assertions.assertFalse(locked.getParents().contains(unregistered)); @@ -143,17 +153,18 @@ public class TestCategories { } @Test - public void testLockedCategoriesUnlocking() throws InterruptedException { + @DisplayName("Test an unlocked LockedCategory") + void testLockedCategoriesUnlocking() throws InterruptedException { Player player = server.addPlayer(); PlayerProfile profile = TestUtilities.awaitProfile(player); Assertions.assertThrows(IllegalArgumentException.class, () -> new LockedCategory(new NamespacedKey(plugin, "locked"), new CustomItem(Material.GOLD_NUGGET, "&6Locked Test"), (NamespacedKey) null)); Category category = new Category(new NamespacedKey(plugin, "parent"), new CustomItem(Material.EMERALD, "&5I am SHERlocked")); - category.register(); + category.register(plugin); LockedCategory locked = new LockedCategory(new NamespacedKey(plugin, "locked"), new CustomItem(Material.GOLD_NUGGET, "&6Locked Test"), category.getKey()); - locked.register(); + locked.register(plugin); // No Items, so it should be unlocked Assertions.assertTrue(locked.hasUnlocked(player, profile)); @@ -176,7 +187,8 @@ public class TestCategories { } @Test - public void testSeasonalCategories() { + @DisplayName("Test a seasonal Category") + void testSeasonalCategories() { // Category with current Month Month month = LocalDate.now().getMonth(); SeasonalCategory category = new SeasonalCategory(new NamespacedKey(plugin, "seasonal"), month, 1, new CustomItem(Material.NETHER_STAR, "&cSeasonal Test")); @@ -196,16 +208,17 @@ public class TestCategories { } @Test - public void testFlexCategory() { + @DisplayName("Test the FlexCategory") + void testFlexCategory() { FlexCategory category = new FlexCategory(new NamespacedKey(plugin, "flex"), new CustomItem(Material.REDSTONE, "&4Weird flex but ok")) { @Override - public void open(Player p, PlayerProfile profile, SlimefunGuideLayout layout) { + public void open(Player p, PlayerProfile profile, SlimefunGuideMode layout) { // Nothing } @Override - public boolean isVisible(Player p, PlayerProfile profile, SlimefunGuideLayout layout) { + public boolean isVisible(Player p, PlayerProfile profile, SlimefunGuideMode layout) { return true; } };