Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat(api): Introduce SlimefunItemRegistryFinalizedEvent #4099

Merged
merged 10 commits into from
Jan 18, 2024
Original file line number Diff line number Diff line change
@@ -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
ProfElements marked this conversation as resolved.
Show resolved Hide resolved
*
* @author ProfElements
*/
public class SlimefunRegistryFinalizedEvent extends Event {
ProfElements marked this conversation as resolved.
Show resolved Hide resolved

private static final HandlerList handlers = new HandlerList();

public SlimefunRegistryFinalizedEvent() {}

@Nonnull
public static HandlerList getHandlerList() {
return handlers;
}

@Nonnull
@Override
public HandlerList getHandlers() {
return getHandlerList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -109,6 +110,7 @@ public static void loadItems() {

Slimefun.getItemCfg().save();
Slimefun.getResearchCfg().save();
Bukkit.getPluginManager().callEvent(new SlimefunRegistryFinalizedEvent());
ProfElements marked this conversation as resolved.
Show resolved Hide resolved
Slimefun.getRegistry().setAutoLoadingMode(true);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.github.thebusybiscuit.slimefun4.api.events;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
ProfElements marked this conversation as resolved.
Show resolved Hide resolved

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();
}

ProfElements marked this conversation as resolved.
Show resolved Hide resolved

@Test
JustAHuman-xD marked this conversation as resolved.
Show resolved Hide resolved
@DisplayName("Test that SlimefunRegistryFinalizedEvent is fired")
void testEventIsFired() {

ProfElements marked this conversation as resolved.
Show resolved Hide resolved
//Make sure post setup does not throw
WalshyDev marked this conversation as resolved.
Show resolved Hide resolved
assertDoesNotThrow(() -> PostSetup.loadItems());

//Make sure post setup sent the event
WalshyDev marked this conversation as resolved.
Show resolved Hide resolved
server.getPluginManager().assertEventFired(SlimefunRegistryFinalizedEvent.class, ignored -> true);

server.getPluginManager().clearEvents();
}

WalshyDev marked this conversation as resolved.
Show resolved Hide resolved
}