Skip to content

Commit

Permalink
Merge branch 'Slimefun:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
WalshyDev committed Jan 18, 2024
2 parents e76e479 + 7c917c3 commit 644ca62
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/discord-webhook.yml
Expand Up @@ -32,7 +32,7 @@ jobs:
architecture: x64

- name: Cache Maven packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/maven-compiler.yml
Expand Up @@ -36,7 +36,7 @@ jobs:
architecture: x64

- name: Cache Maven packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Expand Up @@ -30,7 +30,7 @@ jobs:
architecture: x64

- name: Cache Maven packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/sonarcloud.yml
Expand Up @@ -32,14 +32,14 @@ jobs:
architecture: x64

- name: Cache SonarCloud packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Cache Maven packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand Down
@@ -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();
}
}
Expand Up @@ -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.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
Expand Down Expand Up @@ -77,6 +78,8 @@ public static void loadItems() {
}
}

Bukkit.getPluginManager().callEvent(new SlimefunItemRegistryFinalizedEvent());

loadOreGrinderRecipes();
loadSmelteryRecipes();

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

0 comments on commit 644ca62

Please sign in to comment.