diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/ResearchSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/ResearchSetup.java index 175037c30..20da9c68e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/ResearchSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/ResearchSetup.java @@ -20,9 +20,17 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; */ public final class ResearchSetup { + private static boolean alreadyRan = false; + private ResearchSetup() {} public static void setupResearches() { + if (alreadyRan) { + throw new UnsupportedOperationException("Researches can only be registered once!"); + } + + alreadyRan = true; + register("walking_sticks", 0, "Walking Sticks", 1, SlimefunItems.GRANDMAS_WALKING_STICK, SlimefunItems.GRANDPAS_WALKING_STICK); register("portable_crafter", 1, "Portable Crafter", 1, SlimefunItems.PORTABLE_CRAFTER); register("fortune_cookie", 2, "Fortune Cookie", 1, SlimefunItems.FORTUNE_COOKIE); diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/researches/TestResearchSetup.java b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/researches/TestResearchSetup.java new file mode 100644 index 000000000..c28cc820d --- /dev/null +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/researches/TestResearchSetup.java @@ -0,0 +1,36 @@ +package io.github.thebusybiscuit.slimefun4.tests.researches; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import be.seeseemelk.mockbukkit.MockBukkit; +import io.github.thebusybiscuit.slimefun4.implementation.setup.ResearchSetup; +import me.mrCookieSlime.Slimefun.SlimefunPlugin; + +public class TestResearchSetup { + + @BeforeAll + public static void load() { + MockBukkit.mock(); + MockBukkit.load(SlimefunPlugin.class); + } + + @AfterAll + public static void unload() { + MockBukkit.unmock(); + } + + @Test + public void testForExceptions() { + // Not really ideal but still important to test. + // Research amount is variable, so we can't test for that. + // We are really only concerned about any runtime exceptions here. + Assertions.assertDoesNotThrow(() -> ResearchSetup.setupResearches()); + + // Running it a second time should NOT be allowed. + Assertions.assertThrows(UnsupportedOperationException.class, () -> ResearchSetup.setupResearches()); + } + +}