diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/PreCanUnlockResearchEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/PlayerPreResearchEvent.java similarity index 85% rename from src/main/java/io/github/thebusybiscuit/slimefun4/api/events/PreCanUnlockResearchEvent.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/api/events/PlayerPreResearchEvent.java index eda49dcb4..68140ee46 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/PreCanUnlockResearchEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/PlayerPreResearchEvent.java @@ -11,11 +11,12 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import io.github.thebusybiscuit.slimefun4.core.researching.Research; import io.github.thebusybiscuit.slimefun4.implementation.guide.BookSlimefunGuide; import io.github.thebusybiscuit.slimefun4.implementation.guide.ChestSlimefunGuide; +import io.github.thebusybiscuit.slimefun4.implementation.guide.CheatSheetSlimefunGuide; /** - * This {@link Event} is called whenever a {@link Player} clicks to unlock a research. + * This {@link Event} is called whenever a {@link Player} clicks to unlock a {@link Research}. * This is called before {@link Research#canUnlock(Player)}. - * The event is not called for the cheat sheet. + * The {@link Event} is not called for {@link CheatSheetSlimefunGuide}. * * @author uiytt * @@ -23,7 +24,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.guide.ChestSlimefunGuid * @see BookSlimefunGuide * */ -public class PreCanUnlockResearchEvent extends Event implements Cancellable { +public class PlayerPreResearchEvent extends Event implements Cancellable { private static final HandlerList handlers = new HandlerList(); @@ -34,7 +35,7 @@ public class PreCanUnlockResearchEvent extends Event implements Cancellable { @ParametersAreNonnullByDefault - public PreCanUnlockResearchEvent(Player p, Research research, SlimefunItem slimefunItem) { + public PlayerPreResearchEvent(Player p, Research research, SlimefunItem slimefunItem) { Validate.notNull(p, "The Player cannot be null"); Validate.notNull(research, "Research cannot be null"); Validate.notNull(slimefunItem, "SlimefunItem cannot be null"); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/researching/Research.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/researching/Research.java index 8cb014bf7..ca466f4f6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/researching/Research.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/researching/Research.java @@ -10,10 +10,8 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import io.github.thebusybiscuit.slimefun4.api.events.PreCanUnlockResearchEvent; +import io.github.thebusybiscuit.slimefun4.api.events.PlayerPreResearchEvent; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation; -import io.github.thebusybiscuit.slimefun4.implementation.guide.BookSlimefunGuide; -import io.github.thebusybiscuit.slimefun4.implementation.guide.ChestSlimefunGuide; import me.mrCookieSlime.Slimefun.Objects.Category; import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; @@ -199,9 +197,6 @@ public class Research implements Keyed { * Handle what to do when a {@link Player} clicks on an un-researched item in * a {@link SlimefunGuideImplementation}. * - * @author TheBusyBiscuit - * @author uiytt - * * @param guide The {@link SlimefunGuideImplementation} used. * @param player The {@link Player} who clicked on the item. * @param profile The {@link PlayerProfile} of that {@link Player}. @@ -209,16 +204,14 @@ public class Research implements Keyed { * @param category The {@link Category} where the {@link Player} was. * @param page The page number of where the {@link Player} was in the {@link Category}; * - * @see ChestSlimefunGuide - * @see BookSlimefunGuide */ @ParametersAreNonnullByDefault - public void guideClickInteraction(SlimefunGuideImplementation guide, Player player, PlayerProfile profile, SlimefunItem sfItem, Category category, int page) { + public void unlockFromGuide(SlimefunGuideImplementation guide, Player player, PlayerProfile profile, SlimefunItem sfItem, Category category, int page) { if (!SlimefunPlugin.getRegistry().getCurrentlyResearchingPlayers().contains(player.getUniqueId())) { if (profile.hasUnlocked(this)) { guide.openCategory(profile, category, page); } else { - PreCanUnlockResearchEvent event = new PreCanUnlockResearchEvent(player, this, sfItem); + PlayerPreResearchEvent event = new PlayerPreResearchEvent(player, this, sfItem); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/BookSlimefunGuide.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/BookSlimefunGuide.java index 8246532c4..57eae8b76 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/BookSlimefunGuide.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/BookSlimefunGuide.java @@ -5,8 +5,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Locale; -import io.github.thebusybiscuit.slimefun4.api.events.PreCanUnlockResearchEvent; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; @@ -218,9 +216,9 @@ public class BookSlimefunGuide implements SlimefunGuideImplementation { ChatComponent component = new ChatComponent(ChatUtils.crop(ChatColor.RED, item.getItemName()) + "\n"); component.setHoverEvent(new HoverEvent(ChatColor.RESET + item.getItemName(), ChatColor.DARK_RED.toString() + ChatColor.BOLD + SlimefunPlugin.getLocalization().getMessage(p, "guide.locked"), "", ChatColor.GREEN + "> Click to unlock", "", ChatColor.GRAY + "Cost: " + ChatColor.AQUA.toString() + research.getCost() + " Level(s)")); component.setClickEvent(new ClickEvent(key, player -> - SlimefunPlugin.runSync(() -> { - research.guideClickInteraction(this, player, profile, item, category, page); - }) + SlimefunPlugin.runSync(() -> + research.unlockFromGuide(this, player, profile, item, category, page) + ) )); items.add(component); diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/researches/TestResearches.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/researches/TestResearches.java index 2a5cb1399..fde341e3d 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/researches/TestResearches.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/researches/TestResearches.java @@ -2,8 +2,7 @@ package io.github.thebusybiscuit.slimefun4.testing.tests.researches; import java.util.Optional; -import io.github.thebusybiscuit.slimefun4.api.events.PreCanUnlockResearchEvent; -import io.github.thebusybiscuit.slimefun4.api.events.ResearchUnlockEvent; +import io.github.thebusybiscuit.slimefun4.api.events.PlayerPreResearchEvent; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation; import org.bukkit.GameMode; @@ -188,7 +187,7 @@ class TestResearches { } @Test - @DisplayName("Test PreCanUnlockResearchEvent") + @DisplayName("Test PlayerPreResearchEvent") void testPreCanUnlockResearchEvent() throws InterruptedException { SlimefunPlugin.getRegistry().setResearchingEnabled(true); @@ -201,9 +200,9 @@ class TestResearches { PlayerProfile profile = TestUtilities.awaitProfile(player); SlimefunItem sfItem = TestUtilities.mockSlimefunItem(plugin, "RESEARCH_TEST", new CustomItem(Material.TORCH, "&bResearch Test")); - research.guideClickInteraction(guide,player,profile,sfItem,sfItem.getCategory(),0); + research.unlockFromGuide(guide, player, profile, sfItem, sfItem.getCategory(), 0); - server.getPluginManager().assertEventFired(PreCanUnlockResearchEvent.class, event -> { + server.getPluginManager().assertEventFired(PlayerPreResearchEvent.class, event -> { Assertions.assertEquals(player, event.getPlayer()); Assertions.assertEquals(research, event.getResearch()); Assertions.assertEquals(sfItem,event.getSlimefunItem());