1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Again Formatting fix

I will never see the end of these things  ...
This commit is contained in:
uiytt 2020-10-23 17:31:27 +02:00
parent 95a2dc08d4
commit c56a55dd69
4 changed files with 15 additions and 24 deletions

View File

@ -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");

View File

@ -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()) {

View File

@ -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);

View File

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