1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 11:15:51 +00:00

feat(api): Introduce SlimefunItemRegistryFinalizedEvent (#4099)

Co-authored-by: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com>
Co-authored-by: Daniel Walsh <walshydev@gmail.com>
This commit is contained in:
ProfElements 2024-01-18 08:07:18 -06:00 committed by GitHub
parent bcdde8c2dc
commit 7c917c396f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 80 additions and 0 deletions

View File

@ -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. We recommend listening to this event if you
* want to register recipes using items from other addons.
*
* @author ProfElements
*/
public class SlimefunItemRegistryFinalizedEvent extends Event {
private static final HandlerList handlers = new HandlerList();
public SlimefunItemRegistryFinalizedEvent() {}
@Nonnull
public static HandlerList getHandlerList() {
return handlers;
}
@Nonnull
@Override
public HandlerList getHandlers() {
return getHandlerList();
}
}

View File

@ -24,6 +24,7 @@ import org.bukkit.inventory.ItemStack;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import io.github.thebusybiscuit.slimefun4.api.events.SlimefunItemRegistryFinalizedEvent;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
@ -77,6 +78,8 @@ public final class PostSetup {
}
}
Bukkit.getPluginManager().callEvent(new SlimefunItemRegistryFinalizedEvent());
loadOreGrinderRecipes();
loadSmelteryRecipes();

View File

@ -0,0 +1,42 @@
package io.github.thebusybiscuit.slimefun4.api.events;
import org.junit.jupiter.api.Assertions;
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
Assertions.assertDoesNotThrow(() -> PostSetup.loadItems());
// Make sure post setup sent the event
server.getPluginManager().assertEventFired(SlimefunItemRegistryFinalizedEvent.class, ignored -> true);
server.getPluginManager().clearEvents();
}
}