Skip to content

Commit 644ca62

Browse files
authored
Merge branch 'Slimefun:master' into master
2 parents e76e479 + 7c917c3 commit 644ca62

7 files changed

Lines changed: 85 additions & 5 deletions

File tree

.github/workflows/discord-webhook.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
architecture: x64
3333

3434
- name: Cache Maven packages
35-
uses: actions/cache@v3
35+
uses: actions/cache@v4
3636
with:
3737
path: ~/.m2
3838
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}

.github/workflows/maven-compiler.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
architecture: x64
3737

3838
- name: Cache Maven packages
39-
uses: actions/cache@v3
39+
uses: actions/cache@v4
4040
with:
4141
path: ~/.m2
4242
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}

.github/workflows/pull-request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
architecture: x64
3131

3232
- name: Cache Maven packages
33-
uses: actions/cache@v3
33+
uses: actions/cache@v4
3434
with:
3535
path: ~/.m2
3636
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}

.github/workflows/sonarcloud.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ jobs:
3232
architecture: x64
3333

3434
- name: Cache SonarCloud packages
35-
uses: actions/cache@v3
35+
uses: actions/cache@v4
3636
with:
3737
path: ~/.sonar/cache
3838
key: ${{ runner.os }}-sonar
3939
restore-keys: ${{ runner.os }}-sonar
4040

4141
- name: Cache Maven packages
42-
uses: actions/cache@v3
42+
uses: actions/cache@v4
4343
with:
4444
path: ~/.m2
4545
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package io.github.thebusybiscuit.slimefun4.api.events;
2+
3+
import javax.annotation.Nonnull;
4+
5+
import org.bukkit.event.Event;
6+
import org.bukkit.event.HandlerList;
7+
8+
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
9+
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
10+
11+
12+
/**
13+
* This {@link Event} is fired after {@link Slimefun} finishes loading the
14+
* {@link SlimefunItem} registry. We recommend listening to this event if you
15+
* want to register recipes using items from other addons.
16+
*
17+
* @author ProfElements
18+
*/
19+
public class SlimefunItemRegistryFinalizedEvent extends Event {
20+
21+
private static final HandlerList handlers = new HandlerList();
22+
23+
public SlimefunItemRegistryFinalizedEvent() {}
24+
25+
@Nonnull
26+
public static HandlerList getHandlerList() {
27+
return handlers;
28+
}
29+
30+
@Nonnull
31+
@Override
32+
public HandlerList getHandlers() {
33+
return getHandlerList();
34+
}
35+
}

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/PostSetup.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.google.gson.JsonElement;
2525
import com.google.gson.JsonObject;
2626

27+
import io.github.thebusybiscuit.slimefun4.api.events.SlimefunItemRegistryFinalizedEvent;
2728
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
2829
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
2930
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
@@ -77,6 +78,8 @@ public static void loadItems() {
7778
}
7879
}
7980

81+
Bukkit.getPluginManager().callEvent(new SlimefunItemRegistryFinalizedEvent());
82+
8083
loadOreGrinderRecipes();
8184
loadSmelteryRecipes();
8285

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package io.github.thebusybiscuit.slimefun4.api.events;
2+
3+
import org.junit.jupiter.api.Assertions;
4+
5+
import org.junit.jupiter.api.AfterAll;
6+
import org.junit.jupiter.api.BeforeAll;
7+
import org.junit.jupiter.api.DisplayName;
8+
import org.junit.jupiter.api.Test;
9+
10+
import be.seeseemelk.mockbukkit.MockBukkit;
11+
import be.seeseemelk.mockbukkit.ServerMock;
12+
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
13+
import io.github.thebusybiscuit.slimefun4.implementation.setup.PostSetup;
14+
15+
class TestSlimefunRegistryFinalizedEvent {
16+
17+
private static ServerMock server;
18+
private static Slimefun plugin;
19+
20+
@BeforeAll
21+
public static void load() {
22+
server = MockBukkit.mock();
23+
plugin = MockBukkit.load(Slimefun.class);
24+
}
25+
26+
@AfterAll
27+
public static void unload() {
28+
MockBukkit.unmock();
29+
}
30+
31+
@Test
32+
@DisplayName("Test that SlimefunRegistryFinalizedEvent is fired")
33+
void testEventIsFired() {
34+
// Make sure post setup does not throw
35+
Assertions.assertDoesNotThrow(() -> PostSetup.loadItems());
36+
37+
// Make sure post setup sent the event
38+
server.getPluginManager().assertEventFired(SlimefunItemRegistryFinalizedEvent.class, ignored -> true);
39+
40+
server.getPluginManager().clearEvents();
41+
}
42+
}

0 commit comments

Comments
 (0)