-
Notifications
You must be signed in to change notification settings - Fork 544
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat(api): Introduce SlimefunItemRegistryFinalizedEvent (#4099)
Co-authored-by: JustAHuman-xD <[email protected]> Co-authored-by: Daniel Walsh <[email protected]>
- Loading branch information
1 parent
bcdde8c
commit 7c917c3
Showing
3 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...ava/io/github/thebusybiscuit/slimefun4/api/events/SlimefunItemRegistryFinalizedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. 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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...ava/io/github/thebusybiscuit/slimefun4/api/events/TestSlimefunRegistryFinalizedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |