From 96bdd9b9ea945b8589b101f3f87c38b5ce30483f Mon Sep 17 00:00:00 2001 From: ProfElements Date: Wed, 17 Jan 2024 02:55:23 -0600 Subject: [PATCH 01/10] :sparkles: feat(api): Introduce SlimefunRegistryFinalizedEvent This Event is provided so that plugins that have integrations with each other aren't stuck in a state in which some SlimefunItems may not be available to one plugin or the other. I will use this event to provide a cleaner integration between Dynatech and other plugins. Currently InfinityXpansion, ExoticGarden, and Gastronomicon. --- .../SlimefunRegistryFinalizedEvent.java | 35 +++++++++++++++++++ .../implementation/setup/PostSetup.java | 2 ++ 2 files changed, 37 insertions(+) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunRegistryFinalizedEvent.java diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunRegistryFinalizedEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunRegistryFinalizedEvent.java new file mode 100644 index 0000000000..7fe6c834f7 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunRegistryFinalizedEvent.java @@ -0,0 +1,35 @@ +package io.github.thebusybiscuit.slimefun4.api.events; + +import javax.annotation.Nonnull; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; +import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; + + +/** + * This {@link Event} is fired after {@link Slimefun} finishes loading the + * {@link SlimefunItem} registry before auto loading + * + * @author ProfElements + */ +public class SlimefunRegistryFinalizedEvent extends Event { + + private static final HandlerList handlers = new HandlerList(); + + public SlimefunRegistryFinalizedEvent() {} + + @Nonnull + public static HandlerList getHandlerList() { + return handlers; + } + + @Nonnull + @Override + public HandlerList getHandlers() { + return getHandlerList(); + } + +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java index 13e7e7ef5b..c16fe5202e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java @@ -24,6 +24,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import io.github.thebusybiscuit.slimefun4.api.events.SlimefunRegistryFinalizedEvent; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; @@ -109,6 +110,7 @@ public static void loadItems() { Slimefun.getItemCfg().save(); Slimefun.getResearchCfg().save(); + Bukkit.getPluginManager().callEvent(new SlimefunRegistryFinalizedEvent()); Slimefun.getRegistry().setAutoLoadingMode(true); } From 26b7256f03630c436fffc0d2bd5e34cd3b17f130 Mon Sep 17 00:00:00 2001 From: ProfElements Date: Wed, 17 Jan 2024 03:25:00 -0600 Subject: [PATCH 02/10] :white_check_mark: feat: Add Unit Test for SlimefunRegistryFinalized Event --- .../TestSlimefunRegistryFinalizedEvent.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java new file mode 100644 index 0000000000..514d4ac5ab --- /dev/null +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java @@ -0,0 +1,45 @@ +package io.github.thebusybiscuit.slimefun4.api.events; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import be.seeseemelk.mockbukkit.MockBukkit; +import be.seeseemelk.mockbukkit.ServerMock; +import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; +import io.github.thebusybiscuit.slimefun4.implementation.setup.PostSetup; + +class TestSlimefunRegistryFinalizedEvent { + + private static ServerMock server; + private static Slimefun plugin; + + @BeforeAll + public static void load() { + server = MockBukkit.mock(); + plugin = MockBukkit.load(Slimefun.class); + } + + @AfterAll + public static void unload() { + MockBukkit.unmock(); + } + + + @Test + @DisplayName("Test that SlimefunRegistryFinalizedEvent is fired") + void testEventIsFired() { + + //Make sure post setup does not throw + assertDoesNotThrow(() -> PostSetup.loadItems()); + + //Make sure post setup sent the event + server.getPluginManager().assertEventFired(SlimefunRegistryFinalizedEvent.class, ignored -> true); + + server.getPluginManager().clearEvents(); + } + +} From 480da21142ecabfa93857c9bec908c7788c6049c Mon Sep 17 00:00:00 2001 From: ProfElements Date: Wed, 17 Jan 2024 05:05:03 -0600 Subject: [PATCH 03/10] :bug: fix: Renamed SlimefunRegistryFinalizedEvent to SlimefunItemRegistryFinalizedEvent. Moved call to event upward to make it more readable. Remove `before auto loading` as it was inrelevant to code after a second read. --- ...edEvent.java => SlimefunItemRegistryFinalizedEvent.java} | 6 +++--- .../slimefun4/implementation/setup/PostSetup.java | 5 ++++- .../api/events/TestSlimefunRegistryFinalizedEvent.java | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) rename src/main/java/io/github/thebusybiscuit/slimefun4/api/events/{SlimefunRegistryFinalizedEvent.java => SlimefunItemRegistryFinalizedEvent.java} (80%) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunRegistryFinalizedEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunItemRegistryFinalizedEvent.java similarity index 80% rename from src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunRegistryFinalizedEvent.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunItemRegistryFinalizedEvent.java index 7fe6c834f7..5e2492af26 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunRegistryFinalizedEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunItemRegistryFinalizedEvent.java @@ -11,15 +11,15 @@ /** * This {@link Event} is fired after {@link Slimefun} finishes loading the - * {@link SlimefunItem} registry before auto loading + * {@link SlimefunItem} registry. * * @author ProfElements */ -public class SlimefunRegistryFinalizedEvent extends Event { +public class SlimefunItemRegistryFinalizedEvent extends Event { private static final HandlerList handlers = new HandlerList(); - public SlimefunRegistryFinalizedEvent() {} + public SlimefunItemRegistryFinalizedEvent() {} @Nonnull public static HandlerList getHandlerList() { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java index c16fe5202e..42978f1522 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java @@ -24,6 +24,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import io.github.thebusybiscuit.slimefun4.api.events.SlimefunItemRegistryFinalizedEvent; import io.github.thebusybiscuit.slimefun4.api.events.SlimefunRegistryFinalizedEvent; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; @@ -78,6 +79,8 @@ public static void loadItems() { } } + Bukkit.getPluginManager().callEvent(new SlimefunItemRegistryFinalizedEvent()); + loadOreGrinderRecipes(); loadSmelteryRecipes(); @@ -110,7 +113,7 @@ public static void loadItems() { Slimefun.getItemCfg().save(); Slimefun.getResearchCfg().save(); - Bukkit.getPluginManager().callEvent(new SlimefunRegistryFinalizedEvent()); + Slimefun.getRegistry().setAutoLoadingMode(true); } diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java index 514d4ac5ab..35129f309d 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java @@ -37,7 +37,7 @@ void testEventIsFired() { assertDoesNotThrow(() -> PostSetup.loadItems()); //Make sure post setup sent the event - server.getPluginManager().assertEventFired(SlimefunRegistryFinalizedEvent.class, ignored -> true); + server.getPluginManager().assertEventFired(SlimefunItemRegistryFinalizedEvent.class, ignored -> true); server.getPluginManager().clearEvents(); } From c7d3d8fb0761ce45a18162b7b98327857c382204 Mon Sep 17 00:00:00 2001 From: ProfElements Date: Wed, 17 Jan 2024 05:07:09 -0600 Subject: [PATCH 04/10] :fire: chore: Remove old import --- .../thebusybiscuit/slimefun4/implementation/setup/PostSetup.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java index 42978f1522..4ec89354c8 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java @@ -25,7 +25,6 @@ import com.google.gson.JsonObject; import io.github.thebusybiscuit.slimefun4.api.events.SlimefunItemRegistryFinalizedEvent; -import io.github.thebusybiscuit.slimefun4.api.events.SlimefunRegistryFinalizedEvent; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; From 5f7e0b1b759efce074483f23fe45973024bca1ce Mon Sep 17 00:00:00 2001 From: ProfElements Date: Wed, 17 Jan 2024 05:59:21 -0600 Subject: [PATCH 05/10] :bug: fix: Apply Code Suggestions --- .../api/events/TestSlimefunRegistryFinalizedEvent.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java index 35129f309d..04d5597cc3 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java @@ -1,6 +1,6 @@ package io.github.thebusybiscuit.slimefun4.api.events; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -28,13 +28,11 @@ public static void unload() { MockBukkit.unmock(); } - @Test @DisplayName("Test that SlimefunRegistryFinalizedEvent is fired") void testEventIsFired() { - //Make sure post setup does not throw - assertDoesNotThrow(() -> PostSetup.loadItems()); + Assertions.assertDoesNotThrow(() -> PostSetup.loadItems()); //Make sure post setup sent the event server.getPluginManager().assertEventFired(SlimefunItemRegistryFinalizedEvent.class, ignored -> true); From 814be431e0421f572c4c2ae0e9090b69f1ce1b91 Mon Sep 17 00:00:00 2001 From: ProfElements <43350117+ProfElements@users.noreply.github.com> Date: Wed, 17 Jan 2024 06:03:43 -0600 Subject: [PATCH 06/10] Remove unused whitespace Co-authored-by: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> --- .../thebusybiscuit/slimefun4/implementation/setup/PostSetup.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java index 4ec89354c8..ce8694bd31 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java @@ -112,7 +112,6 @@ public static void loadItems() { Slimefun.getItemCfg().save(); Slimefun.getResearchCfg().save(); - Slimefun.getRegistry().setAutoLoadingMode(true); } From 33076d25baf3a5f3aed43b5359366e451083d83f Mon Sep 17 00:00:00 2001 From: ProfElements <43350117+ProfElements@users.noreply.github.com> Date: Wed, 17 Jan 2024 06:18:18 -0600 Subject: [PATCH 07/10] Remove unneeded whitespace Co-authored-by: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> --- .../slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java index 04d5597cc3..c769511049 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java @@ -27,7 +27,6 @@ public static void load() { public static void unload() { MockBukkit.unmock(); } - @Test @DisplayName("Test that SlimefunRegistryFinalizedEvent is fired") void testEventIsFired() { From bf0dbc20fbe61bd574cb1aa1bc3d2dbdfc40add6 Mon Sep 17 00:00:00 2001 From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> Date: Wed, 17 Jan 2024 07:02:42 -0600 Subject: [PATCH 08/10] re-add new line --- .../slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java index c769511049..04d5597cc3 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java @@ -27,6 +27,7 @@ public static void load() { public static void unload() { MockBukkit.unmock(); } + @Test @DisplayName("Test that SlimefunRegistryFinalizedEvent is fired") void testEventIsFired() { From a3c74f8b81b1dd0c3d463ba7d0b5e9555dd22732 Mon Sep 17 00:00:00 2001 From: Daniel Walsh Date: Wed, 17 Jan 2024 16:32:13 +0000 Subject: [PATCH 09/10] Apply suggestions from code review --- .../api/events/SlimefunItemRegistryFinalizedEvent.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunItemRegistryFinalizedEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunItemRegistryFinalizedEvent.java index 5e2492af26..12943c82bf 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunItemRegistryFinalizedEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunItemRegistryFinalizedEvent.java @@ -11,7 +11,8 @@ /** * This {@link Event} is fired after {@link Slimefun} finishes loading the - * {@link SlimefunItem} registry. + * {@link SlimefunItem} registry. We recommend listening to this event if you + * want to register recipes using items from other addons. * * @author ProfElements */ @@ -31,5 +32,4 @@ public static HandlerList getHandlerList() { public HandlerList getHandlers() { return getHandlerList(); } - } From cbf4840b0b972953879fb7e9bb3b69ea537814da Mon Sep 17 00:00:00 2001 From: Daniel Walsh Date: Thu, 18 Jan 2024 10:58:50 +0000 Subject: [PATCH 10/10] Apply suggestions from code review --- .../api/events/TestSlimefunRegistryFinalizedEvent.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java index 04d5597cc3..bef63828c9 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java @@ -31,13 +31,12 @@ public static void unload() { @Test @DisplayName("Test that SlimefunRegistryFinalizedEvent is fired") void testEventIsFired() { - //Make sure post setup does not throw + // Make sure post setup does not throw Assertions.assertDoesNotThrow(() -> PostSetup.loadItems()); - //Make sure post setup sent the event + // Make sure post setup sent the event server.getPluginManager().assertEventFired(SlimefunItemRegistryFinalizedEvent.class, ignored -> true); server.getPluginManager().clearEvents(); } - }