diff --git a/.github/workflows/discord-webhook.yml b/.github/workflows/discord-webhook.yml index d6edc5e08..5ff92bfd4 100644 --- a/.github/workflows/discord-webhook.yml +++ b/.github/workflows/discord-webhook.yml @@ -6,6 +6,8 @@ on: - 'src/**' - '!src/main/resources/languages/**' - 'pom.xml' + tags-ignore: + - 'RC.*' jobs: report: diff --git a/CHANGELOG.md b/CHANGELOG.md index c1c9ab610..a46e67173 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ **Table of contents** -- [Release Candidate 19 (TBD)](#release-candidate-19-tbd) +- [Release Candidate 19 (11 Jan 2021)](#release-candidate-19-11-jan-2021) - [Release Candidate 18 (03 Dec 2020)](#release-candidate-18-03-dec-2020) - [Release Candidate 17 (17 Oct 2020)](#release-candidate-17-17-oct-2020) - [Release Candidate 16 (07 Sep 2020)](#release-candidate-16-07-sep-2020) @@ -24,7 +24,19 @@ -## Release Candidate 19 (TBD) +## Release Candidate 20 (TBD) + +#### Additions + +#### Changes +* (API) Improvements to the BlockBreakHandler + +#### Fixes +* Fixed elevator floor order +* Fixed "block-explosions" (e.g. beds in Nether) not properly respecting explosion-resistant blocks +* Fixed #2560 + +## Release Candidate 19 (11 Jan 2021) #### Additions * Added Bee Armor (1.15+ only) @@ -36,7 +48,8 @@ * General performance improvements * CraftBukkit is officially no longer supported, Slimefun will now be disabled on old builds of CraftBukkit * Removed the deprecated ItemManipulationAPI for BlockMenus -* (API) Improvements to the BlockBreakHandler +* Removed the "Written Book" variant of the Slimefun Guide +* The Elevator has an Inventory menu now #### Fixes * Fixed a couple of compatibility issues with ItemsAdder @@ -47,8 +60,7 @@ * Fixed #2664 * Fixed #2655 * Fixed /sf timings --verbose not working correctly -* Fixed "block-explosions" (e.g. beds in Nether) not properly respecting explosion-resistant blocks -* Fixed #2560 +* Fixed #2675 ## Release Candidate 18 (03 Dec 2020) diff --git a/pom.xml b/pom.xml index 0b0c8f43a..dba2fecb3 100644 --- a/pom.xml +++ b/pom.xml @@ -336,7 +336,7 @@ com.github.TheBusyBiscuit CS-CoreLib2 - 0.28 + 0.29 compile diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/PlayerPreResearchEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/PlayerPreResearchEvent.java index d80efd9b1..9edcb48a0 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/PlayerPreResearchEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/PlayerPreResearchEvent.java @@ -3,16 +3,16 @@ package io.github.thebusybiscuit.slimefun4.api.events; import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; +import org.apache.commons.lang.Validate; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import org.apache.commons.lang.Validate; -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; +import io.github.thebusybiscuit.slimefun4.implementation.guide.SurvivalSlimefunGuide; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; /** * This {@link Event} is called whenever a {@link Player} clicks to unlock a {@link Research}. @@ -21,8 +21,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.guide.CheatSheetSlimefu * * @author uiytt * - * @see ChestSlimefunGuide - * @see BookSlimefunGuide + * @see SurvivalSlimefunGuide * */ public class PlayerPreResearchEvent extends Event implements Cancellable { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunGuideOpenEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunGuideOpenEvent.java index 2fdbe469a..f4892242a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunGuideOpenEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/SlimefunGuideOpenEvent.java @@ -9,14 +9,14 @@ import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.bukkit.inventory.ItemStack; -import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; +import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode; /** * This {@link Event} is called whenever a {@link Player} tries to open the Slimefun Guide book. * * @author Linox * - * @see SlimefunGuideLayout + * @see SlimefunGuideMode */ public class SlimefunGuideOpenEvent extends Event implements Cancellable { @@ -24,10 +24,10 @@ public class SlimefunGuideOpenEvent extends Event implements Cancellable { private final Player player; private final ItemStack guide; - private SlimefunGuideLayout layout; + private SlimefunGuideMode layout; private boolean cancelled; - public SlimefunGuideOpenEvent(@Nonnull Player p, @Nonnull ItemStack guide, @Nonnull SlimefunGuideLayout layout) { + public SlimefunGuideOpenEvent(@Nonnull Player p, @Nonnull ItemStack guide, @Nonnull SlimefunGuideMode layout) { Validate.notNull(p, "The Player cannot be null"); Validate.notNull(guide, "Guide cannot be null"); Validate.notNull(layout, "Layout cannot be null"); @@ -59,23 +59,23 @@ public class SlimefunGuideOpenEvent extends Event implements Cancellable { } /** - * This returns the {@link SlimefunGuideLayout} of the Slimefun Guide + * This returns the {@link SlimefunGuideMode} of the Slimefun Guide * that {@link Player} tries to open. * - * @return The {@link SlimefunGuideLayout} + * @return The {@link SlimefunGuideMode} */ @Nonnull - public SlimefunGuideLayout getGuideLayout() { + public SlimefunGuideMode getGuideLayout() { return layout; } /** - * Changes the {@link SlimefunGuideLayout} that was tried to be opened with. + * Changes the {@link SlimefunGuideMode} that was tried to be opened with. * * @param layout - * The new {@link SlimefunGuideLayout} + * The new {@link SlimefunGuideMode} */ - public void setGuideLayout(@Nonnull SlimefunGuideLayout layout) { + public void setGuideLayout(@Nonnull SlimefunGuideMode layout) { Validate.notNull(layout, "You must specify a layout that is not-null!"); this.layout = layout; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java index 76ba7e998..044b7a84e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/SlimefunRegistry.java @@ -26,13 +26,13 @@ import io.github.thebusybiscuit.cscorelib2.config.Config; import io.github.thebusybiscuit.slimefun4.api.geo.GEOResource; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation; -import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; +import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode; import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlock; import io.github.thebusybiscuit.slimefun4.core.researching.Research; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; -import io.github.thebusybiscuit.slimefun4.implementation.guide.BookSlimefunGuide; + import io.github.thebusybiscuit.slimefun4.implementation.guide.CheatSheetSlimefunGuide; -import io.github.thebusybiscuit.slimefun4.implementation.guide.ChestSlimefunGuide; +import io.github.thebusybiscuit.slimefun4.implementation.guide.SurvivalSlimefunGuide; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; @@ -75,13 +75,14 @@ public final class SlimefunRegistry { private NamespacedKey soulboundKey; private NamespacedKey itemChargeKey; + private NamespacedKey guideKey; private final KeyMap geoResources = new KeyMap<>(); private final Map profiles = new ConcurrentHashMap<>(); private final Map worlds = new ConcurrentHashMap<>(); private final Map chunks = new HashMap<>(); - private final Map layouts = new EnumMap<>(SlimefunGuideLayout.class); + private final Map layouts = new EnumMap<>(SlimefunGuideMode.class); private final Map> mobDrops = new EnumMap<>(EntityType.class); private final Map blockMenuPresets = new HashMap<>(); @@ -95,12 +96,11 @@ public final class SlimefunRegistry { soulboundKey = new NamespacedKey(plugin, "soulbound"); itemChargeKey = new NamespacedKey(plugin, "item_charge"); + guideKey = new NamespacedKey(plugin, "slimefun_guide_mode"); boolean showVanillaRecipes = cfg.getBoolean("guide.show-vanilla-recipes"); - - layouts.put(SlimefunGuideLayout.CHEST, new ChestSlimefunGuide(showVanillaRecipes)); - layouts.put(SlimefunGuideLayout.CHEAT_SHEET, new CheatSheetSlimefunGuide()); - layouts.put(SlimefunGuideLayout.BOOK, new BookSlimefunGuide()); + layouts.put(SlimefunGuideMode.SURVIVAL_MODE, new SurvivalSlimefunGuide(showVanillaRecipes)); + layouts.put(SlimefunGuideMode.CHEAT_MODE, new CheatSheetSlimefunGuide()); researchRanks.addAll(cfg.getStringList("research-ranks")); @@ -199,7 +199,7 @@ public final class SlimefunRegistry { return multiblocks; } - public SlimefunGuideImplementation getGuideLayout(SlimefunGuideLayout layout) { + public SlimefunGuideImplementation getGuideLayout(SlimefunGuideMode layout) { return layouts.get(layout); } @@ -282,4 +282,9 @@ public final class SlimefunRegistry { return itemChargeKey; } + @Nonnull + public NamespacedKey getGuideDataKey() { + return guideKey; + } + } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/categories/FlexCategory.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/categories/FlexCategory.java index 28a05cfa9..896a23730 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/categories/FlexCategory.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/categories/FlexCategory.java @@ -11,7 +11,7 @@ import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide; -import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; +import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; @@ -45,12 +45,12 @@ public abstract class FlexCategory extends Category { * @param profile * The {@link PlayerProfile} of the {@link Player} * @param layout - * The {@link SlimefunGuideLayout} in which this {@link FlexCategory} is viewed + * The {@link SlimefunGuideMode} in which this {@link FlexCategory} is viewed * * @return Whether to display this {@link FlexCategory} */ @ParametersAreNonnullByDefault - public abstract boolean isVisible(Player p, PlayerProfile profile, SlimefunGuideLayout layout); + public abstract boolean isVisible(Player p, PlayerProfile profile, SlimefunGuideMode layout); /** * This method is called when a {@link Player} opens this {@link FlexCategory}. @@ -62,9 +62,9 @@ public abstract class FlexCategory extends Category { * @param profile * The corresponding {@link PlayerProfile} for that {@link Player} * @param layout - * The current {@link SlimefunGuideLayout} + * The current {@link SlimefunGuideMode} */ - public abstract void open(Player p, PlayerProfile profile, SlimefunGuideLayout layout); + public abstract void open(Player p, PlayerProfile profile, SlimefunGuideMode layout); @Override public final boolean isHidden(@Nonnull Player p) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/categories/LockedCategory.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/categories/LockedCategory.java index 36f8597d3..e47732c79 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/categories/LockedCategory.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/categories/LockedCategory.java @@ -14,6 +14,7 @@ import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Objects.Category; @@ -76,8 +77,8 @@ public class LockedCategory extends Category { } @Override - public void register() { - super.register(); + public void register(@Nonnull SlimefunAddon addon) { + super.register(addon); List namespacedKeys = new ArrayList<>(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GuideCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GuideCommand.java index ce0c4ea94..b25c96063 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GuideCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GuideCommand.java @@ -6,7 +6,7 @@ import org.bukkit.entity.Player; import io.github.thebusybiscuit.slimefun4.core.commands.SlimefunCommand; import io.github.thebusybiscuit.slimefun4.core.commands.SubCommand; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide; -import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; +import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; class GuideCommand extends SubCommand { @@ -19,7 +19,7 @@ class GuideCommand extends SubCommand { public void onExecute(CommandSender sender, String[] args) { if (sender instanceof Player) { if (sender.hasPermission("slimefun.command.guide")) { - SlimefunGuideLayout design = SlimefunGuide.getDefaultLayout(); + SlimefunGuideMode design = SlimefunGuide.getDefaultLayout(); ((Player) sender).getInventory().addItem(SlimefunGuide.getItem(design).clone()); } else { SlimefunPlugin.getLocalization().sendMessage(sender, "messages.no-permission", true); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/OpenGuideCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/OpenGuideCommand.java index a4af9f2bd..8947d989f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/OpenGuideCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/OpenGuideCommand.java @@ -1,12 +1,14 @@ package io.github.thebusybiscuit.slimefun4.core.commands.subcommands; +import javax.annotation.ParametersAreNonnullByDefault; + import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import io.github.thebusybiscuit.slimefun4.core.commands.SlimefunCommand; import io.github.thebusybiscuit.slimefun4.core.commands.SubCommand; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide; -import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; +import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; class OpenGuideCommand extends SubCommand { @@ -16,11 +18,11 @@ class OpenGuideCommand extends SubCommand { } @Override + @ParametersAreNonnullByDefault public void onExecute(CommandSender sender, String[] args) { if (sender instanceof Player) { if (sender.hasPermission("slimefun.command.open_guide")) { - boolean book = SlimefunPlugin.getCfg().getBoolean("guide.default-view-book"); - SlimefunGuide.openGuide((Player) sender, book ? SlimefunGuideLayout.BOOK : SlimefunGuideLayout.CHEST); + SlimefunGuide.openGuide((Player) sender, SlimefunGuideMode.SURVIVAL_MODE); } else { SlimefunPlugin.getLocalization().sendMessage(sender, "messages.no-permission", true); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuide.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuide.java index 94970ac43..662320f53 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuide.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuide.java @@ -3,14 +3,16 @@ package io.github.thebusybiscuit.slimefun4.core.guide; import java.util.Optional; import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; -import io.github.thebusybiscuit.slimefun4.implementation.guide.BookSlimefunGuide; -import io.github.thebusybiscuit.slimefun4.implementation.guide.ChestSlimefunGuide; +import io.github.thebusybiscuit.slimefun4.implementation.guide.SurvivalSlimefunGuide; + import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; @@ -22,36 +24,35 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; * @author TheBusyBiscuit * * @see SlimefunGuideImplementation - * @see ChestSlimefunGuide - * @see BookSlimefunGuide + * @see SurvivalSlimefunGuide * */ public final class SlimefunGuide { private SlimefunGuide() {} - public static ItemStack getItem(@Nonnull SlimefunGuideLayout design) { + @Nonnull + public static ItemStack getItem(@Nonnull SlimefunGuideMode design) { return SlimefunPlugin.getRegistry().getGuideLayout(design).getItem(); } - public static void openCheatMenu(Player p) { - openMainMenuAsync(p, SlimefunGuideLayout.CHEAT_SHEET, 1); + public static void openCheatMenu(@Nonnull Player p) { + openMainMenuAsync(p, SlimefunGuideMode.CHEAT_MODE, 1); } - public static void openGuide(Player p, ItemStack guide) { - if (SlimefunUtils.isItemSimilar(guide, getItem(SlimefunGuideLayout.CHEST), true)) { - openGuide(p, SlimefunGuideLayout.CHEST); - } else if (SlimefunUtils.isItemSimilar(guide, getItem(SlimefunGuideLayout.BOOK), true)) { - openGuide(p, SlimefunGuideLayout.BOOK); - } else if (SlimefunUtils.isItemSimilar(guide, getItem(SlimefunGuideLayout.CHEAT_SHEET), true)) { - openGuide(p, SlimefunGuideLayout.CHEAT_SHEET); + public static void openGuide(@Nonnull Player p, @Nullable ItemStack guide) { + if (getItem(SlimefunGuideMode.CHEAT_MODE).equals(guide)) { + openGuide(p, SlimefunGuideMode.CHEAT_MODE); } else { - // When using /sf cheat or /sf open_guide, ItemStack is null. - openGuide(p, SlimefunGuideLayout.CHEST); + /* + * When using /sf cheat or /sf open_guide the ItemStack is null anyway, + * so we don't even need to check here at this point. + */ + openGuide(p, SlimefunGuideMode.SURVIVAL_MODE); } } - public static void openGuide(Player p, SlimefunGuideLayout layout) { + public static void openGuide(@Nonnull Player p, @Nonnull SlimefunGuideMode layout) { if (!SlimefunPlugin.getWorldSettingsService().isWorldEnabled(p.getWorld())) { return; } @@ -67,51 +68,60 @@ public final class SlimefunGuide { } } - private static void openMainMenuAsync(Player player, SlimefunGuideLayout layout, int selectedPage) { + @ParametersAreNonnullByDefault + private static void openMainMenuAsync(Player player, SlimefunGuideMode layout, int selectedPage) { if (!PlayerProfile.get(player, profile -> SlimefunPlugin.runSync(() -> openMainMenu(profile, layout, selectedPage)))) { SlimefunPlugin.getLocalization().sendMessage(player, "messages.opening-guide"); } } - public static void openMainMenu(PlayerProfile profile, SlimefunGuideLayout layout, int selectedPage) { + @ParametersAreNonnullByDefault + public static void openMainMenu(PlayerProfile profile, SlimefunGuideMode layout, int selectedPage) { SlimefunPlugin.getRegistry().getGuideLayout(layout).openMainMenu(profile, selectedPage); } - public static void openCategory(PlayerProfile profile, Category category, SlimefunGuideLayout layout, int selectedPage) { - if (category == null) { - return; - } - + @ParametersAreNonnullByDefault + public static void openCategory(PlayerProfile profile, Category category, SlimefunGuideMode layout, int selectedPage) { SlimefunPlugin.getRegistry().getGuideLayout(layout).openCategory(profile, category, selectedPage); } + @ParametersAreNonnullByDefault public static void openSearch(PlayerProfile profile, String input, boolean survival, boolean addToHistory) { - SlimefunGuideImplementation layout = SlimefunPlugin.getRegistry().getGuideLayout(SlimefunGuideLayout.CHEST); + SlimefunGuideImplementation layout = SlimefunPlugin.getRegistry().getGuideLayout(SlimefunGuideMode.SURVIVAL_MODE); if (!survival) { - layout = SlimefunPlugin.getRegistry().getGuideLayout(SlimefunGuideLayout.CHEAT_SHEET); + layout = SlimefunPlugin.getRegistry().getGuideLayout(SlimefunGuideMode.CHEAT_MODE); } layout.openSearch(profile, input, addToHistory); } + @ParametersAreNonnullByDefault public static void displayItem(PlayerProfile profile, ItemStack item, boolean addToHistory) { - SlimefunPlugin.getRegistry().getGuideLayout(SlimefunGuideLayout.CHEST).displayItem(profile, item, 0, addToHistory); + SlimefunPlugin.getRegistry().getGuideLayout(SlimefunGuideMode.SURVIVAL_MODE).displayItem(profile, item, 0, addToHistory); } + @ParametersAreNonnullByDefault public static void displayItem(PlayerProfile profile, SlimefunItem item, boolean addToHistory) { - SlimefunPlugin.getRegistry().getGuideLayout(SlimefunGuideLayout.CHEST).displayItem(profile, item, addToHistory); + SlimefunPlugin.getRegistry().getGuideLayout(SlimefunGuideMode.SURVIVAL_MODE).displayItem(profile, item, addToHistory); } - public static boolean isGuideItem(ItemStack item) { - return SlimefunUtils.isItemSimilar(item, getItem(SlimefunGuideLayout.CHEST), true) || SlimefunUtils.isItemSimilar(item, getItem(SlimefunGuideLayout.BOOK), true) || SlimefunUtils.isItemSimilar(item, getItem(SlimefunGuideLayout.CHEAT_SHEET), true); - } - - public static SlimefunGuideLayout getDefaultLayout() { - if (SlimefunPlugin.getCfg().getBoolean("guide.default-view-book")) { - return SlimefunGuideLayout.BOOK; + public static boolean isGuideItem(@Nullable ItemStack item) { + if (item == null) { + return false; } else { - return SlimefunGuideLayout.CHEST; + return SlimefunUtils.isItemSimilar(item, getItem(SlimefunGuideMode.SURVIVAL_MODE), true) || SlimefunUtils.isItemSimilar(item, getItem(SlimefunGuideMode.CHEAT_MODE), true); } } + + /** + * Get the default layout for the Slimefun guide. + * Currently this is only {@link SlimefunGuideMode#SURVIVAL_MODE}. + * + * @return The default {@link SlimefunGuideLayout}. + */ + @Nonnull + public static SlimefunGuideMode getDefaultLayout() { + return SlimefunGuideMode.SURVIVAL_MODE; + } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuideImplementation.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuideImplementation.java index 5ed728760..873ce5105 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuideImplementation.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuideImplementation.java @@ -11,8 +11,7 @@ import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; import io.github.thebusybiscuit.slimefun4.core.researching.Research; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; -import io.github.thebusybiscuit.slimefun4.implementation.guide.BookSlimefunGuide; -import io.github.thebusybiscuit.slimefun4.implementation.guide.ChestSlimefunGuide; +import io.github.thebusybiscuit.slimefun4.implementation.guide.SurvivalSlimefunGuide; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; @@ -22,21 +21,20 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; * * @author TheBusyBiscuit * - * @see SlimefunGuideLayout - * @see ChestSlimefunGuide - * @see BookSlimefunGuide + * @see SlimefunGuideMode + * @see SurvivalSlimefunGuide * */ public interface SlimefunGuideImplementation { /** * Every {@link SlimefunGuideImplementation} can be associated with a - * {@link SlimefunGuideLayout}. + * {@link SlimefunGuideMode}. * - * @return The layout this {@link SlimefunGuideImplementation} represents + * @return The mode this {@link SlimefunGuideImplementation} represents */ @Nonnull - SlimefunGuideLayout getLayout(); + SlimefunGuideMode getMode(); /** * Returns the {@link ItemStack} representation for this {@link SlimefunGuideImplementation}. @@ -48,14 +46,6 @@ public interface SlimefunGuideImplementation { @Nonnull ItemStack getItem(); - /** - * This method returns whether this {@link SlimefunGuideImplementation} is meant - * for Survival Mode. - * - * @return Whether this is a survival mode implementation - */ - boolean isSurvivalMode(); - void openMainMenu(PlayerProfile profile, int page); void openCategory(PlayerProfile profile, Category category, int page); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuideLayout.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuideMode.java similarity index 74% rename from src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuideLayout.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuideMode.java index 562fe5981..8c439f436 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuideLayout.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuideMode.java @@ -13,24 +13,17 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; * @see SlimefunGuideImplementation * */ -public enum SlimefunGuideLayout { - - /** - * This design is a book representation of the {@link SlimefunGuide} - */ - BOOK, +public enum SlimefunGuideMode { /** * This design is the standard layout, it uses a {@link ChestMenu} */ - CHEST, + SURVIVAL_MODE, /** * This is an admin-only design which creates a {@link SlimefunGuide} that allows * you to spawn in any {@link SlimefunItem} */ - CHEAT_SHEET; - - public static final SlimefunGuideLayout[] valuesCache = values(); + CHEAT_MODE; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/GuideLayoutOption.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/GuideModeOption.java similarity index 55% rename from src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/GuideLayoutOption.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/GuideModeOption.java index 38564d077..007a1d3cc 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/GuideLayoutOption.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/GuideModeOption.java @@ -4,6 +4,9 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; + import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.NamespacedKey; @@ -13,35 +16,41 @@ import org.bukkit.inventory.meta.ItemMeta; import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide; -import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; +import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.utils.ChatUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; -class GuideLayoutOption implements SlimefunGuideOption { +class GuideModeOption implements SlimefunGuideOption { + @Nonnull @Override public SlimefunAddon getAddon() { return SlimefunPlugin.instance(); } + @Nonnull @Override public NamespacedKey getKey() { return new NamespacedKey(SlimefunPlugin.instance(), "guide_layout"); } + @Nonnull @Override public Optional getDisplayItem(Player p, ItemStack guide) { - Optional current = getSelectedOption(p, guide); + if (!p.hasPermission("slimefun.cheat.items")) { + // Only Players with the appropriate permission can access the cheat sheet + return Optional.empty(); + } + + Optional current = getSelectedOption(p, guide); if (current.isPresent()) { - SlimefunGuideLayout layout = current.get(); + SlimefunGuideMode layout = current.get(); ItemStack item = new ItemStack(Material.AIR); - if (layout == SlimefunGuideLayout.CHEST) { + if (layout == SlimefunGuideMode.SURVIVAL_MODE) { item.setType(Material.CHEST); - } else if (layout == SlimefunGuideLayout.BOOK) { - item.setType(Material.BOOK); } else { item.setType(Material.COMMAND_BLOCK); } @@ -50,12 +59,9 @@ class GuideLayoutOption implements SlimefunGuideOption { meta.setDisplayName(ChatColor.GRAY + "Slimefun Guide Design: " + ChatColor.YELLOW + ChatUtils.humanize(layout.name())); List lore = new ArrayList<>(); lore.add(""); - lore.add((layout == SlimefunGuideLayout.CHEST ? ChatColor.GREEN : ChatColor.GRAY) + "Chest"); - lore.add((layout == SlimefunGuideLayout.BOOK ? ChatColor.GREEN : ChatColor.GRAY) + "Book"); + lore.add((layout == SlimefunGuideMode.SURVIVAL_MODE ? ChatColor.GREEN : ChatColor.GRAY) + "Chest"); - if (p.hasPermission("slimefun.cheat.items")) { - lore.add((layout == SlimefunGuideLayout.CHEAT_SHEET ? ChatColor.GREEN : ChatColor.GRAY) + "Cheat Sheet"); - } + lore.add((layout == SlimefunGuideMode.CHEAT_MODE ? ChatColor.GREEN : ChatColor.GRAY) + "Cheat Sheet"); lore.add(""); lore.add(ChatColor.GRAY + "\u21E8 " + ChatColor.YELLOW + "Click to change your layout"); @@ -69,47 +75,44 @@ class GuideLayoutOption implements SlimefunGuideOption { } @Override - public void onClick(Player p, ItemStack guide) { - Optional current = getSelectedOption(p, guide); + public void onClick(@Nonnull Player p, @Nonnull ItemStack guide) { + Optional current = getSelectedOption(p, guide); if (current.isPresent()) { - SlimefunGuideLayout next = getNextLayout(p, current.get()); + SlimefunGuideMode next = getNextMode(p, current.get()); setSelectedOption(p, guide, next); } SlimefunGuideSettings.openSettings(p, guide); } - private SlimefunGuideLayout getNextLayout(Player p, SlimefunGuideLayout layout) { + @Nonnull + private SlimefunGuideMode getNextMode(@Nonnull Player p, @Nonnull SlimefunGuideMode mode) { if (p.hasPermission("slimefun.cheat.items")) { - if (layout == SlimefunGuideLayout.CHEST) { - return SlimefunGuideLayout.BOOK; + if (mode == SlimefunGuideMode.SURVIVAL_MODE) { + return SlimefunGuideMode.CHEAT_MODE; + } else { + return SlimefunGuideMode.SURVIVAL_MODE; } - - if (layout == SlimefunGuideLayout.BOOK) { - return SlimefunGuideLayout.CHEAT_SHEET; - } - - return SlimefunGuideLayout.CHEST; } else { - return layout == SlimefunGuideLayout.CHEST ? SlimefunGuideLayout.BOOK : SlimefunGuideLayout.CHEST; + return SlimefunGuideMode.SURVIVAL_MODE; + } + } + + @Nonnull + @Override + public Optional getSelectedOption(@Nonnull Player p, @Nonnull ItemStack guide) { + if (SlimefunUtils.isItemSimilar(guide, SlimefunGuide.getItem(SlimefunGuideMode.CHEAT_MODE), true, false)) { + return Optional.of(SlimefunGuideMode.CHEAT_MODE); + } else { + return Optional.of(SlimefunGuideMode.SURVIVAL_MODE); } } @Override - public Optional getSelectedOption(Player p, ItemStack guide) { - for (SlimefunGuideLayout layout : SlimefunGuideLayout.valuesCache) { - if (SlimefunUtils.isItemSimilar(guide, SlimefunGuide.getItem(layout), true, false)) { - return Optional.of(layout); - } - } - - return Optional.empty(); - } - - @Override - public void setSelectedOption(Player p, ItemStack guide, SlimefunGuideLayout value) { + @ParametersAreNonnullByDefault + public void setSelectedOption(Player p, ItemStack guide, SlimefunGuideMode value) { guide.setItemMeta(SlimefunGuide.getItem(value).getItemMeta()); } -} +} \ No newline at end of file diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/SlimefunGuideSettings.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/SlimefunGuideSettings.java index 1ed862a13..310271e2b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/SlimefunGuideSettings.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/SlimefunGuideSettings.java @@ -13,7 +13,7 @@ import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide; -import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; +import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode; import io.github.thebusybiscuit.slimefun4.core.services.localization.Language; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.utils.ChatUtils; @@ -39,7 +39,7 @@ public final class SlimefunGuideSettings { private static final List> options = new ArrayList<>(); static { - options.add(new GuideLayoutOption()); + options.add(new GuideModeOption()); options.add(new FireworksOption()); options.add(new PlayerLanguageOption()); } @@ -65,7 +65,7 @@ public final class SlimefunGuideSettings { } private static void addHeader(Player p, ChestMenu menu, ItemStack guide) { - menu.addItem(0, new CustomItem(SlimefunGuide.getItem(SlimefunGuideLayout.CHEST), "&e\u21E6 " + SlimefunPlugin.getLocalization().getMessage(p, "guide.back.title"), "", "&7" + SlimefunPlugin.getLocalization().getMessage(p, "guide.back.guide")), (pl, slot, item, action) -> { + menu.addItem(0, new CustomItem(SlimefunGuide.getItem(SlimefunGuideMode.SURVIVAL_MODE), "&e\u21E6 " + SlimefunPlugin.getLocalization().getMessage(p, "guide.back.title"), "", "&7" + SlimefunPlugin.getLocalization().getMessage(p, "guide.back.guide")), (pl, slot, item, action) -> { SlimefunGuide.openGuide(pl, guide); return false; }); @@ -141,7 +141,7 @@ public final class SlimefunGuideSettings { for (SlimefunGuideOption option : options) { if (option instanceof FireworksOption) { FireworksOption fireworks = (FireworksOption) option; - return fireworks.getSelectedOption(p, SlimefunGuide.getItem(SlimefunGuideLayout.CHEST)).orElse(true); + return fireworks.getSelectedOption(p, SlimefunGuide.getItem(SlimefunGuideMode.SURVIVAL_MODE)).orElse(true); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java index 67fca5634..295b3312d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java @@ -393,19 +393,6 @@ final class CargoUtils { } } - /** - * Get the whitelist/blacklist slots in a Cargo Input Node. If you wish to access the items - * in the cargo (without hardcoding the slots in case of change) then you can use this method. - * - * @deprecated Renamed to {@link #getFilteringSlots()} - * - * @return The slot indexes for the whitelist/blacklist section. - */ - @Deprecated - public static int[] getWhitelistBlacklistSlots() { - return getFilteringSlots(); - } - /** * Gets the {@link ItemFilter} slots for a Cargo Node. If you wish to access the items * in the cargo (without hardcoding the slots in case of change) then you can use this method. diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MinecraftRecipeService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MinecraftRecipeService.java index 9366dcb27..694f1b352 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MinecraftRecipeService.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MinecraftRecipeService.java @@ -20,14 +20,14 @@ import org.bukkit.plugin.Plugin; import io.github.thebusybiscuit.cscorelib2.recipes.MinecraftRecipe; import io.github.thebusybiscuit.cscorelib2.recipes.RecipeSnapshot; -import io.github.thebusybiscuit.slimefun4.implementation.guide.ChestSlimefunGuide; +import io.github.thebusybiscuit.slimefun4.implementation.guide.SurvivalSlimefunGuide; /** * This Service is responsible for accessing a {@link RecipeSnapshot}. * This snapshot contains a compiled list of all recipes that could be found on the * Server at the time the Service was loaded. * - * This Service is primarily used by the {@link ChestSlimefunGuide}. + * This Service is primarily used by the {@link SurvivalSlimefunGuide}. * * @author TheBusyBiscuit * diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/ThirdPartyPluginService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/ThirdPartyPluginService.java deleted file mode 100644 index d5b59882f..000000000 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/ThirdPartyPluginService.java +++ /dev/null @@ -1,59 +0,0 @@ -package io.github.thebusybiscuit.slimefun4.core.services.plugins; - -import java.util.Optional; -import java.util.function.Function; - -import javax.annotation.Nonnull; - -import org.bukkit.block.Block; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.Plugin; - -import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon; -import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; -import io.github.thebusybiscuit.slimefun4.integrations.IntegrationsManager; - -/** - * This Service holds all interactions and hooks with third-party {@link Plugin Plugins} - * that are not necessarily a dependency or a {@link SlimefunAddon}. - * - * Integration with these plugins happens inside Slimefun itself. - * - * @author TheBusyBiscuit - * - * @deprecated Renamed to {@link IntegrationsManager} - * - * @see SlimefunPlugin - * - */ -@Deprecated -public class ThirdPartyPluginService extends IntegrationsManager { - - /** - * This gets overridden if ExoticGarden is loaded - */ - private Function> exoticGardenIntegration = b -> Optional.empty(); - - /** - * This initializes the {@link ThirdPartyPluginService} - * - * @param plugin - * Our instance of {@link SlimefunPlugin} - */ - public ThirdPartyPluginService(@Nonnull SlimefunPlugin plugin) { - super(plugin); - } - - @Deprecated - public void loadExoticGarden(Plugin plugin, Function> method) { - if (plugin.getName().equals("ExoticGarden")) { - exoticGardenIntegration = method; - } - } - - @Deprecated - public Optional harvestExoticGardenPlant(Block block) { - return exoticGardenIntegration.apply(block); - } - -} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/package-info.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/package-info.java deleted file mode 100644 index 572feaade..000000000 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/plugins/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * This package contains all hooks to external plugins - */ -package io.github.thebusybiscuit.slimefun4.core.services.plugins; \ No newline at end of file diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/inspectors/ConsolePerformanceInspector.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/inspectors/ConsolePerformanceInspector.java index 6acb35a44..4520e0ec1 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/inspectors/ConsolePerformanceInspector.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/inspectors/ConsolePerformanceInspector.java @@ -33,6 +33,8 @@ public class ConsolePerformanceInspector implements PerformanceInspector { * * @param console * The {@link CommandSender}, preferabbly a {@link ConsoleCommandSender} + * @param verbose + * Whether the summary will be verbose or not */ public ConsolePerformanceInspector(@Nonnull CommandSender console, boolean verbose) { Validate.notNull(console, "CommandSender cannot be null"); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java index a5ac4e2d6..102ca7e3c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunPlugin.java @@ -50,7 +50,6 @@ import io.github.thebusybiscuit.slimefun4.core.services.PerWorldSettingsService; import io.github.thebusybiscuit.slimefun4.core.services.PermissionsService; import io.github.thebusybiscuit.slimefun4.core.services.UpdaterService; import io.github.thebusybiscuit.slimefun4.core.services.github.GitHubService; -import io.github.thebusybiscuit.slimefun4.core.services.plugins.ThirdPartyPluginService; import io.github.thebusybiscuit.slimefun4.core.services.profiler.SlimefunProfiler; import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientAltar; import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientPedestal; @@ -152,7 +151,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon { private final PerWorldSettingsService worldSettingsService = new PerWorldSettingsService(this); private final MinecraftRecipeService recipeService = new MinecraftRecipeService(this); - private final IntegrationsManager integrations = new ThirdPartyPluginService(this); + private final IntegrationsManager integrations = new IntegrationsManager(this); private final SlimefunProfiler profiler = new SlimefunProfiler(); private LocalizationService local; @@ -204,7 +203,6 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon { if (minecraftVersion == MinecraftVersion.UNIT_TEST) { // We handle Unit Tests seperately. setInstance(this); - getLogger().log(Level.INFO, "This is a UNIT TEST Environment."); onUnitTestStart(); } else if (isVersionUnsupported()) { // We wanna ensure that the Server uses a compatible version of Minecraft. @@ -832,18 +830,6 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon { return instance.worldSettingsService; } - /** - * This method has been renamed. - * - * @deprecated Please use {@link #getIntegrations()} instead. - * - * @return the {@link ThirdPartyPluginService} - */ - @Deprecated - public static ThirdPartyPluginService getThirdPartySupportService() { - return (ThirdPartyPluginService) instance.integrations; - } - /** * This returns our instance of {@link IntegrationsManager}. * This is responsible for managing any integrations with third party {@link Plugin plugins}. @@ -903,18 +889,24 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon { return instance.gitHubService; } - @Nonnull - public static SlimefunRegistry getRegistry() { - validateInstance(); - return instance.registry; - } - + /** + * This returns our {@link NetworkManager} which is responsible + * for handling the Cargo and Energy networks. + * + * @return Our {@link NetworkManager} instance + */ @Nonnull public static NetworkManager getNetworkManager() { validateInstance(); return instance.networkManager; } + @Nonnull + public static SlimefunRegistry getRegistry() { + validateInstance(); + return instance.registry; + } + @Nonnull public static GrapplingHookListener getGrapplingHookListener() { validateInstance(); 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 deleted file mode 100644 index a5c7c1d29..000000000 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/BookSlimefunGuide.java +++ /dev/null @@ -1,253 +0,0 @@ -package io.github.thebusybiscuit.slimefun4.implementation.guide; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; - -import org.bukkit.ChatColor; -import org.bukkit.NamespacedKey; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; - -import io.github.thebusybiscuit.cscorelib2.chat.ChatColors; -import io.github.thebusybiscuit.cscorelib2.chat.ChatInput; -import io.github.thebusybiscuit.cscorelib2.chat.json.ChatComponent; -import io.github.thebusybiscuit.cscorelib2.chat.json.ClickEvent; -import io.github.thebusybiscuit.cscorelib2.chat.json.CustomBookInterface; -import io.github.thebusybiscuit.cscorelib2.chat.json.HoverEvent; -import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils; -import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; -import io.github.thebusybiscuit.slimefun4.core.categories.FlexCategory; -import io.github.thebusybiscuit.slimefun4.core.categories.LockedCategory; -import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide; -import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation; -import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; -import io.github.thebusybiscuit.slimefun4.core.researching.Research; -import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; -import io.github.thebusybiscuit.slimefun4.utils.ChatUtils; -import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; -import io.github.thebusybiscuit.slimefun4.utils.itemstack.SlimefunGuideItem; -import me.mrCookieSlime.Slimefun.Objects.Category; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.api.Slimefun; - -/** - * The {@link BookSlimefunGuide} is a {@link SlimefunGuideImplementation} which - * uses a {@link CustomBookInterface} to display the contents of the {@link SlimefunGuide}. - * {@link Player Players} have the option to choose this Written Book layout over the - * standard {@link Inventory} variant. - * - * @author TheBusyBiscuit - * - * @see SlimefunGuide - * @see SlimefunGuideImplementation - * @see ChestSlimefunGuide - * @see CheatSheetSlimefunGuide - * - */ -public class BookSlimefunGuide implements SlimefunGuideImplementation { - - private final NamespacedKey guideSearch = new NamespacedKey(SlimefunPlugin.instance(), "search"); - private final ItemStack item; - - public BookSlimefunGuide() { - item = new SlimefunGuideItem(this, "&aSlimefun Guide &7(Book GUI)"); - } - - @Override - public SlimefunGuideLayout getLayout() { - return SlimefunGuideLayout.BOOK; - } - - @Override - public boolean isSurvivalMode() { - return true; - } - - @Override - public ItemStack getItem() { - return item; - } - - private void openBook(Player p, PlayerProfile profile, List lines, boolean backButton) { - CustomBookInterface book = new CustomBookInterface(SlimefunPlugin.instance()); - book.setTitle(SlimefunPlugin.getLocalization().getMessage(p, "guide.title.main")); - - for (int i = 0; i < lines.size(); i = i + 10) { - ChatComponent page = new ChatComponent(""); - ChatComponent header = new ChatComponent(ChatColors.color("&b&l- " + SlimefunPlugin.getLocalization().getMessage(p, "guide.title.main") + " -\n\n")); - header.setHoverEvent(new HoverEvent(ChestMenuUtils.getSearchButton(p))); - - header.setClickEvent(new ClickEvent(guideSearch, player -> SlimefunPlugin.runSync(() -> { - SlimefunPlugin.getLocalization().sendMessage(player, "guide.search.message"); - ChatInput.waitForPlayer(SlimefunPlugin.instance(), player, msg -> SlimefunGuide.openSearch(profile, msg, true, true)); - }, 1))); - - page.append(header); - - for (int j = i; j < lines.size() && j < i + 10; j++) { - page.append(lines.get(j)); - } - - page.append(new ChatComponent("\n")); - - if (backButton) { - ChatComponent button = new ChatComponent(ChatColor.DARK_BLUE + "\u21E6 " + SlimefunPlugin.getLocalization().getMessage(p, "guide.back.title")); - button.setHoverEvent(new HoverEvent(ChatColor.DARK_BLUE + "\u21E6 " + SlimefunPlugin.getLocalization().getMessage(p, "guide.back.title"), "", ChatColor.GRAY + SlimefunPlugin.getLocalization().getMessage(p, "guide.back.guide"))); - button.setClickEvent(new ClickEvent(new NamespacedKey(SlimefunPlugin.instance(), "slimefun_guide"), pl -> openMainMenu(profile, 1))); - page.append(button); - } - - book.addPage(page); - } - - book.open(p); - } - - @Override - public void openMainMenu(PlayerProfile profile, int page) { - Player p = profile.getPlayer(); - - if (p == null) { - return; - } - - List lines = new LinkedList<>(); - int tier = 0; - - for (Category category : SlimefunPlugin.getRegistry().getCategories()) { - if (!category.isHidden(p) && (!(category instanceof FlexCategory) || ((FlexCategory) category).isVisible(p, profile, getLayout()))) { - if (tier < category.getTier()) { - tier = category.getTier(); - - if (tier > 1) { - for (int i = 0; i < 10 && lines.size() % 10 != 0; i++) { - lines.add(new ChatComponent("\n")); - } - } - - lines.add(new ChatComponent(ChatColor.DARK_GRAY + "\u21E8" + ChatColor.DARK_BLUE + " Tier " + tier + "\n")); - } - - addCategory(p, profile, category, lines); - } - } - - openBook(p, profile, lines, false); - } - - private void addCategory(Player p, PlayerProfile profile, Category category, List lines) { - if (category instanceof LockedCategory && !((LockedCategory) category).hasUnlocked(p, profile)) { - List lore = new LinkedList<>(); - lore.add(ChatColor.DARK_RED + SlimefunPlugin.getLocalization().getMessage(p, "guide.locked") + " " + ChatColor.GRAY + "- " + ChatColor.RESET + category.getItem(p).getItemMeta().getDisplayName()); - lore.add(""); - - for (String line : SlimefunPlugin.getLocalization().getMessages(p, "guide.locked-category")) { - lore.add(ChatColor.RESET + line); - } - - lore.add(""); - - for (Category parent : ((LockedCategory) category).getParents()) { - lore.add(parent.getItem(p).getItemMeta().getDisplayName()); - } - - ChatComponent chatComponent = new ChatComponent(ChatUtils.crop(ChatColor.RED, ItemUtils.getItemName(category.getItem(p))) + "\n"); - chatComponent.setHoverEvent(new HoverEvent(lore)); - lines.add(chatComponent); - } else { - ChatComponent chatComponent = new ChatComponent(ChatUtils.crop(ChatColor.DARK_GREEN, ItemUtils.getItemName(category.getItem(p))) + "\n"); - chatComponent.setHoverEvent(new HoverEvent(ItemUtils.getItemName(category.getItem(p)), "", ChatColor.GRAY + "\u21E8 " + ChatColor.GREEN + SlimefunPlugin.getLocalization().getMessage(p, "guide.tooltips.open-category"))); - chatComponent.setClickEvent(new ClickEvent(category.getKey(), pl -> openCategory(profile, category, 1))); - lines.add(chatComponent); - } - } - - @Override - public void openCategory(PlayerProfile profile, Category category, int page) { - Player p = profile.getPlayer(); - - if (p == null) { - return; - } - - if (category instanceof FlexCategory) { - ((FlexCategory) category).open(p, profile, getLayout()); - } else if (category.getItems().size() < 250) { - profile.getGuideHistory().add(category, page); - - List items = new LinkedList<>(); - - for (SlimefunItem slimefunItem : category.getItems()) { - if (Slimefun.hasPermission(p, slimefunItem, false)) { - if (Slimefun.isEnabled(p, slimefunItem, false)) { - addSlimefunItem(category, page, p, profile, slimefunItem, items); - } - } else { - ChatComponent component = new ChatComponent(ChatUtils.crop(ChatColor.DARK_RED, ItemUtils.getItemName(slimefunItem.getItem())) + "\n"); - - List lore = new ArrayList<>(); - lore.add(ChatColor.DARK_RED + ChatColor.stripColor(ItemUtils.getItemName(slimefunItem.getItem()))); - lore.add(""); - - for (String line : SlimefunPlugin.getPermissionsService().getLore(slimefunItem)) { - lore.add(ChatColors.color(line)); - } - - component.setHoverEvent(new HoverEvent(lore)); - items.add(component); - } - } - - openBook(p, profile, items, true); - } else { - p.sendMessage(ChatColor.RED + "That Category is too big to open :/"); - } - } - - private void addSlimefunItem(Category category, int page, Player p, PlayerProfile profile, SlimefunItem item, List items) { - NamespacedKey key = new NamespacedKey(SlimefunPlugin.instance(), item.getId().toLowerCase(Locale.ROOT)); - - if (!Slimefun.hasUnlocked(p, item, false) && item.getResearch() != null) { - Research research = item.getResearch(); - - 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.unlockFromGuide(this, player, profile, item, category, page)))); - - items.add(component); - } else { - ChatComponent component = new ChatComponent(ChatUtils.crop(ChatColor.DARK_GREEN, item.getItemName()) + "\n"); - - List lore = new ArrayList<>(); - lore.add(item.getItemName()); - - if (item.getItem().hasItemMeta() && item.getItem().getItemMeta().hasLore()) { - lore.addAll(item.getItem().getItemMeta().getLore()); - } - - component.setHoverEvent(new HoverEvent(lore)); - component.setClickEvent(new ClickEvent(key, player -> SlimefunPlugin.runSync(() -> displayItem(profile, item, true)))); - items.add(component); - } - } - - @Override - public void openSearch(PlayerProfile profile, String input, boolean addToHistory) { - // We need to write a book implementation for this at some point - SlimefunGuide.openSearch(profile, input, true, addToHistory); - } - - @Override - public void displayItem(PlayerProfile profile, ItemStack item, int index, boolean addToHistory) { - SlimefunGuide.displayItem(profile, item, addToHistory); - } - - @Override - public void displayItem(PlayerProfile profile, SlimefunItem item, boolean addToHistory) { - SlimefunGuide.displayItem(profile, item, addToHistory); - } - -} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/CheatSheetSlimefunGuide.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/CheatSheetSlimefunGuide.java index d02c04c7e..f45f47272 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/CheatSheetSlimefunGuide.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/CheatSheetSlimefunGuide.java @@ -12,7 +12,7 @@ import org.bukkit.inventory.Recipe; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; import io.github.thebusybiscuit.slimefun4.core.categories.FlexCategory; -import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; +import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; import io.github.thebusybiscuit.slimefun4.utils.itemstack.SlimefunGuideItem; @@ -21,13 +21,13 @@ import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; /** - * This is an admin-variant of the {@link ChestSlimefunGuide} which allows a {@link Player} + * This is an admin-variant of the {@link SurvivalSlimefunGuide} which allows a {@link Player} * to spawn in a {@link SlimefunItem} via click rather than showing their {@link Recipe}. * * @author TheBusyBiscuit * */ -public class CheatSheetSlimefunGuide extends ChestSlimefunGuide { +public class CheatSheetSlimefunGuide extends SurvivalSlimefunGuide { private final ItemStack item; @@ -37,11 +37,6 @@ public class CheatSheetSlimefunGuide extends ChestSlimefunGuide { item = new SlimefunGuideItem(this, "&cSlimefun Guide &4(Cheat Sheet)"); } - @Override - public boolean isSurvivalMode() { - return false; - } - /** * Returns a {@link List} of visible {@link Category} instances that the {@link SlimefunGuide} would display. * @@ -65,11 +60,13 @@ public class CheatSheetSlimefunGuide extends ChestSlimefunGuide { return categories; } + @Nonnull @Override - public SlimefunGuideLayout getLayout() { - return SlimefunGuideLayout.CHEAT_SHEET; + public SlimefunGuideMode getMode() { + return SlimefunGuideMode.CHEAT_MODE; } + @Nonnull @Override public ItemStack getItem() { return item; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/RecipeChoiceTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/RecipeChoiceTask.java index 51917a37e..acb1b57f9 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/RecipeChoiceTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/RecipeChoiceTask.java @@ -21,7 +21,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; * A {@link RecipeChoiceTask} is an asynchronously repeating task that cycles * through the different variants of {@link Material} that a {@link MaterialChoice} or {@link Tag} can represent. * - * It is used in the {@link ChestSlimefunGuide} for any {@link ItemStack} from Minecraft + * It is used in the {@link SurvivalSlimefunGuide} for any {@link ItemStack} from Minecraft * that accepts more than one {@link Material} in its {@link Recipe}. * * @author TheBusyBiscuit diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/ChestSlimefunGuide.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java similarity index 95% rename from src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/ChestSlimefunGuide.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java index ed9468473..760fee545 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/ChestSlimefunGuide.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java @@ -27,6 +27,7 @@ import io.github.thebusybiscuit.cscorelib2.chat.ChatInput; import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.cscorelib2.recipes.MinecraftRecipe; +import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon; import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem; import io.github.thebusybiscuit.slimefun4.core.categories.FlexCategory; @@ -34,7 +35,7 @@ import io.github.thebusybiscuit.slimefun4.core.categories.LockedCategory; import io.github.thebusybiscuit.slimefun4.core.guide.GuideHistory; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation; -import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; +import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode; import io.github.thebusybiscuit.slimefun4.core.guide.options.SlimefunGuideSettings; import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlock; import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine; @@ -51,18 +52,17 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.api.Slimefun; /** - * The {@link ChestSlimefunGuide} is the standard version of our {@link SlimefunGuide}. + * The {@link SurvivalSlimefunGuide} is the standard version of our {@link SlimefunGuide}. * It uses an {@link Inventory} to display {@link SlimefunGuide} contents. * * @author TheBusyBiscuit * * @see SlimefunGuide * @see SlimefunGuideImplementation - * @see BookSlimefunGuide * @see CheatSheetSlimefunGuide * */ -public class ChestSlimefunGuide implements SlimefunGuideImplementation { +public class SurvivalSlimefunGuide implements SlimefunGuideImplementation { private static final int CATEGORY_SIZE = 36; private static final Sound sound = Sound.ITEM_BOOK_PAGE_TURN; @@ -71,14 +71,14 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation { private final ItemStack item; private final boolean showVanillaRecipes; - public ChestSlimefunGuide(boolean showVanillaRecipes) { + public SurvivalSlimefunGuide(boolean showVanillaRecipes) { this.showVanillaRecipes = showVanillaRecipes; item = new SlimefunGuideItem(this, "&aSlimefun Guide &7(Chest GUI)"); } @Override - public SlimefunGuideLayout getLayout() { - return SlimefunGuideLayout.CHEST; + public SlimefunGuideMode getMode() { + return SlimefunGuideMode.SURVIVAL_MODE; } @Override @@ -86,9 +86,8 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation { return item; } - @Override - public boolean isSurvivalMode() { - return true; + protected final boolean isSurvivalMode() { + return getMode() != SlimefunGuideMode.CHEAT_MODE; } /** @@ -105,8 +104,18 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation { List categories = new LinkedList<>(); for (Category category : SlimefunPlugin.getRegistry().getCategories()) { - if (!category.isHidden(p) && (!(category instanceof FlexCategory) || ((FlexCategory) category).isVisible(p, profile, getLayout()))) { - categories.add(category); + try { + if (!category.isHidden(p) && (!(category instanceof FlexCategory) || ((FlexCategory) category).isVisible(p, profile, getMode()))) { + categories.add(category); + } + } catch (Exception | LinkageError x) { + SlimefunAddon addon = category.getAddon(); + + if (addon != null) { + addon.getLogger().log(Level.SEVERE, x, () -> "Could not display Category: " + category); + } else { + SlimefunPlugin.logger().log(Level.SEVERE, x, () -> "Could not display Category: " + category); + } } } @@ -204,7 +213,7 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation { } if (category instanceof FlexCategory) { - ((FlexCategory) category).open(p, profile, getLayout()); + ((FlexCategory) category).open(p, profile, getMode()); return; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/AndroidType.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/AndroidType.java index 732c998a3..fbbbdb108 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/AndroidType.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/AndroidType.java @@ -29,7 +29,7 @@ public enum AndroidType { FARMER, /** - * The {@link AdvancedFarmerAndroid} is an extension of the {@link FarmerAndroid}, + * The Advanced Farmer is an extension of the {@link FarmerAndroid}, * it can also harvest plants from ExoticGarden. */ ADVANCED_FARMER, diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/FarmerAndroid.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/FarmerAndroid.java index 45c2ea829..44948ab4b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/FarmerAndroid.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/FarmerAndroid.java @@ -1,6 +1,5 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.androids; -import java.util.Optional; import java.util.Random; import java.util.concurrent.ThreadLocalRandom; @@ -12,11 +11,9 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.data.Ageable; import org.bukkit.block.data.BlockData; -import org.bukkit.event.EventHandler; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.api.events.AndroidFarmEvent; -import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; @@ -49,8 +46,6 @@ public class FarmerAndroid extends ProgrammableAndroid { AndroidFarmEvent event = new AndroidFarmEvent(block, instance, isAdvanced, drop); Bukkit.getPluginManager().callEvent(event); - handleExoticGarden(event); - if (!event.isCancelled()) { drop = event.getDrop(); @@ -65,24 +60,6 @@ public class FarmerAndroid extends ProgrammableAndroid { } } - /** - * Deprecated method. - * - * @deprecated This will be moved into an {@link EventHandler} inside exoticgarden itself on the next update. - * - * @param event - * the event - * @param isAdvanced - * is advanced - */ - @Deprecated - private void handleExoticGarden(AndroidFarmEvent event) { - if (event.isAdvanced() && SlimefunPlugin.getIntegrations().isExoticGardenInstalled()) { - Optional result = SlimefunPlugin.getThirdPartySupportService().harvestExoticGardenPlant(event.getBlock()); - result.ifPresent(event::setDrop); - } - } - private ItemStack getDropFromCrop(Material crop) { Random random = ThreadLocalRandom.current(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/elevator/ElevatorFloor.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/elevator/ElevatorFloor.java new file mode 100644 index 000000000..24e6f2b9c --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/elevator/ElevatorFloor.java @@ -0,0 +1,93 @@ +package io.github.thebusybiscuit.slimefun4.implementation.items.elevator; + +import javax.annotation.Nonnull; + +import org.apache.commons.lang.Validate; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; + +/** + * This represents an {@link ElevatorFloor} to which a {@link Player} + * can travel to using an {@link ElevatorPlate}. + * + * @author TheBusyBiscuit + * + */ +class ElevatorFloor { + + /** + * The name of this floor. + */ + private final String name; + + /** + * The floor number. + */ + private final int number; + + /** + * The {@link Location} of this floor. + */ + private final Location location; + + /** + * This constructs a new {@link ElevatorFloor} with the given name + * and the {@link Location} of the provided {@link Block}. + * + * @param name + * The name of this {@link ElevatorFloor} + * @param block + * The {@link Block} of this floor + */ + public ElevatorFloor(@Nonnull String name, int number, @Nonnull Block block) { + Validate.notNull(name, "An ElevatorFloor must have a name"); + Validate.notNull(block, "An ElevatorFloor must have a block"); + + this.name = name; + this.number = number; + this.location = block.getLocation(); + } + + /** + * This returns the name of this {@link ElevatorFloor}. + * + * @return The name of this floor + */ + @Nonnull + public String getName() { + return name; + } + + /** + * This returns the {@link Location} of this {@link ElevatorFloor}. + * + * @return The {@link Location} of this floor + */ + @Nonnull + public Location getLocation() { + return location; + } + + /** + * This returns the "altitude" of this floor. + * This is equivalent to the Y level of {@link #getLocation()}. + * + * @return The altitude of this floor + */ + public int getAltitude() { + return location.getBlockY(); + } + + /** + * This returns the number of this floor. + * The lowest floor will have the number 0 and it + * increments from there. + * + * @return The number of this floor. + */ + public int getNumber() { + return number; + } + +} \ No newline at end of file diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/ElevatorPlate.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/elevator/ElevatorPlate.java similarity index 59% rename from src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/ElevatorPlate.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/elevator/ElevatorPlate.java index 1d7dc7ae0..59e6dab5c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/ElevatorPlate.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/elevator/ElevatorPlate.java @@ -1,4 +1,4 @@ -package io.github.thebusybiscuit.slimefun4.implementation.items.gps; +package io.github.thebusybiscuit.slimefun4.implementation.items.elevator; import java.util.HashSet; import java.util.LinkedList; @@ -12,22 +12,19 @@ import javax.annotation.ParametersAreNonnullByDefault; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.NamespacedKey; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.chat.ChatColors; -import io.github.thebusybiscuit.cscorelib2.chat.json.ChatComponent; -import io.github.thebusybiscuit.cscorelib2.chat.json.ClickEvent; -import io.github.thebusybiscuit.cscorelib2.chat.json.CustomBookInterface; -import io.github.thebusybiscuit.cscorelib2.chat.json.HoverEvent; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler; import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; +import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; import io.github.thebusybiscuit.slimefun4.utils.ChatUtils; import io.papermc.lib.PaperLib; import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu; @@ -40,9 +37,9 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; * The {@link ElevatorPlate} is a quick way of teleportation. * You can place multiple {@link ElevatorPlate ElevatorPlates} along the y axis * to teleport between them. - * - * @author TheBusyBiscuit * + * @author TheBusyBiscuit + * @author Walshy */ public class ElevatorPlate extends SimpleSlimefunItem { @@ -51,6 +48,11 @@ public class ElevatorPlate extends SimpleSlimefunItem { */ private static final String DATA_KEY = "floor"; + /** + * This is the size of our {@link Inventory}. + */ + private static final int GUI_SIZE = 27; + /** * This is our {@link Set} of currently teleporting {@link Player Players}. * It is used to prevent them from triggering the {@link ElevatorPlate} they land on. @@ -77,6 +79,7 @@ public class ElevatorPlate extends SimpleSlimefunItem { }; } + @Nonnull @Override public BlockUseHandler getItemHandler() { return e -> { @@ -89,19 +92,24 @@ public class ElevatorPlate extends SimpleSlimefunItem { } @Nonnull - public List getFloors(@Nonnull Block b) { - List floors = new LinkedList<>(); + public List getFloors(@Nonnull Block b) { + LinkedList floors = new LinkedList<>(); + int index = 0; - for (int y = b.getWorld().getMaxHeight(); y > 0; y--) { + for (int y = 0; y < b.getWorld().getMaxHeight(); y++) { if (y == b.getY()) { - floors.add(b); + String name = ChatColors.color(BlockStorage.getLocationInfo(b.getLocation(), DATA_KEY)); + floors.addFirst(new ElevatorFloor(name, index, b)); + index++; continue; } Block block = b.getWorld().getBlockAt(b.getX(), y, b.getZ()); if (block.getType() == getItem().getType() && BlockStorage.check(block, getId())) { - floors.add(block); + String name = ChatColors.color(BlockStorage.getLocationInfo(block.getLocation(), DATA_KEY)); + floors.addFirst(new ElevatorFloor(name, index, block)); + index++; } } @@ -114,54 +122,69 @@ public class ElevatorPlate extends SimpleSlimefunItem { return; } - List floors = getFloors(b); + List floors = getFloors(b); if (floors.size() < 2) { SlimefunPlugin.getLocalization().sendMessage(p, "machines.ELEVATOR.no-destinations", true); } else { - openFloorSelector(b, floors, p); + openFloorSelector(b, floors, p, 1); } } @ParametersAreNonnullByDefault - private void openFloorSelector(Block b, List floors, Player p) { - CustomBookInterface book = new CustomBookInterface(SlimefunPlugin.instance()); - ChatComponent page = null; + private void openFloorSelector(Block b, List floors, Player p, int page) { + ChestMenu menu = new ChestMenu(SlimefunPlugin.getLocalization().getMessage(p, "machines.ELEVATOR.pick-a-floor")); + menu.setEmptySlotsClickable(false); - for (int i = 0; i < floors.size(); i++) { - if (i % 10 == 0) { - if (page != null) { - book.addPage(page); - } + int index = GUI_SIZE * (page - 1); - page = new ChatComponent(ChatColors.color(SlimefunPlugin.getLocalization().getMessage(p, "machines.ELEVATOR.pick-a-floor")) + "\n"); - } + for (int i = 0; i < Math.min(GUI_SIZE, floors.size() - index); i++) { + ElevatorFloor floor = floors.get(index + i); - Block block = floors.get(i); - String floor = ChatColors.color(BlockStorage.getLocationInfo(block.getLocation(), DATA_KEY)); - ChatComponent line; - - if (block.getY() == b.getY()) { - line = new ChatComponent("\n" + ChatColor.GRAY + "> " + (floors.size() - i) + ". " + ChatColor.BLACK + floor); - line.setHoverEvent(new HoverEvent(ChatColors.color(SlimefunPlugin.getLocalization().getMessage(p, "machines.ELEVATOR.current-floor")), "", ChatColor.WHITE + floor, "")); + // @formatter:off + if (floor.getAltitude() == b.getY()) { + menu.addItem(i, new CustomItem( + Material.COMPASS, + ChatColor.GRAY.toString() + floor.getNumber() + ". " + ChatColor.BLACK + floor.getName(), + SlimefunPlugin.getLocalization().getMessage(p, "machines.ELEVATOR.current-floor") + ' ' + ChatColor.WHITE + floor.getName() + ), ChestMenuUtils.getEmptyClickHandler()); } else { - line = new ChatComponent("\n" + ChatColor.GRAY + (floors.size() - i) + ". " + ChatColor.BLACK + floor); - line.setHoverEvent(new HoverEvent(ChatColors.color(SlimefunPlugin.getLocalization().getMessage(p, "machines.ELEVATOR.click-to-teleport")), "", ChatColor.WHITE + floor, "")); - line.setClickEvent(new ClickEvent(new NamespacedKey(SlimefunPlugin.instance(), DATA_KEY + i), player -> teleport(player, floor, block))); + menu.addItem(i, new CustomItem( + Material.PAPER, + ChatColor.GRAY.toString() + floor.getNumber() + ". " + ChatColor.BLACK + floor.getName(), + SlimefunPlugin.getLocalization().getMessage(p, "machines.ELEVATOR.click-to-teleport") + ' ' + ChatColor.WHITE + floor.getName() + ), (player, slot, itemStack, clickAction) -> { + teleport(player, floor); + return false; + }); } - - page.append(line); + // @formatter:on } - if (page != null) { - book.addPage(page); + int pages = 1 + (floors.size() / GUI_SIZE); + + // 0 index so size is the first slot of the last row. + for (int i = GUI_SIZE; i < GUI_SIZE + 9; i++) { + if (i == GUI_SIZE + 2 && pages > 1 && page != 1) { + menu.addItem(i, ChestMenuUtils.getPreviousButton(p, page, pages), (player, i1, itemStack, clickAction) -> { + openFloorSelector(b, floors, p, page - 1); + return false; + }); + } else if (i == GUI_SIZE + 6 && pages > 1 && page != pages) { + menu.addItem(i, ChestMenuUtils.getNextButton(p, page, pages), (player, i1, itemStack, clickAction) -> { + openFloorSelector(b, floors, p, page + 1); + return false; + }); + } else { + menu.addItem(i, ChestMenuUtils.getBackground(), (player, i1, itemStack, clickAction) -> false); + } } - book.open(p); + menu.open(p); } @ParametersAreNonnullByDefault - private void teleport(Player player, String floorName, Block target) { + private void teleport(Player player, ElevatorFloor floor) { SlimefunPlugin.runSync(() -> { users.add(player.getUniqueId()); @@ -171,11 +194,12 @@ public class ElevatorPlate extends SimpleSlimefunItem { yaw = -180 + (yaw - 180); } - Location destination = new Location(player.getWorld(), target.getX() + 0.5, target.getY() + 0.4, target.getZ() + 0.5, yaw, player.getEyeLocation().getPitch()); + Location loc = floor.getLocation(); + Location destination = new Location(player.getWorld(), loc.getX() + 0.5, loc.getY() + 0.4, loc.getZ() + 0.5, yaw, player.getEyeLocation().getPitch()); PaperLib.teleportAsync(player, destination).thenAccept(teleported -> { if (teleported.booleanValue()) { - player.sendTitle(ChatColor.WHITE + ChatColors.color(floorName), null, 20, 60, 20); + player.sendTitle(ChatColor.WHITE + ChatColors.color(floor.getName()), null, 20, 60, 20); } }); }); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/elevator/package-info.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/elevator/package-info.java new file mode 100644 index 000000000..46e84ac6f --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/elevator/package-info.java @@ -0,0 +1,5 @@ +/** + * This package holds the {@link io.github.thebusybiscuit.slimefun4.implementation.items.elevator.ElevatorPlate} and any + * related classes to making the elevator work. + */ +package io.github.thebusybiscuit.slimefun4.implementation.items.elevator; \ No newline at end of file diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunGuideListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunGuideListener.java index 5575ce2aa..79c319c3b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunGuideListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/SlimefunGuideListener.java @@ -12,10 +12,10 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.inventory.ItemStack; -import io.github.thebusybiscuit.slimefun4.api.events.SlimefunGuideOpenEvent; import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent; +import io.github.thebusybiscuit.slimefun4.api.events.SlimefunGuideOpenEvent; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide; -import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; +import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode; import io.github.thebusybiscuit.slimefun4.core.guide.options.SlimefunGuideSettings; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; @@ -38,7 +38,7 @@ public class SlimefunGuideListener implements Listener { return; } - SlimefunGuideLayout type = SlimefunGuide.getDefaultLayout(); + SlimefunGuideMode type = SlimefunGuide.getDefaultLayout(); p.getInventory().addItem(SlimefunGuide.getItem(type).clone()); } } @@ -47,31 +47,27 @@ public class SlimefunGuideListener implements Listener { public void onInteract(PlayerRightClickEvent e) { Player p = e.getPlayer(); - if (tryOpenGuide(p, e, SlimefunGuideLayout.BOOK) == Result.ALLOW) { + if (tryOpenGuide(p, e, SlimefunGuideMode.SURVIVAL_MODE) == Result.ALLOW) { if (p.isSneaking()) { SlimefunGuideSettings.openSettings(p, e.getItem()); } else { - openGuide(p, e, SlimefunGuideLayout.BOOK); + openGuide(p, e, SlimefunGuideMode.SURVIVAL_MODE); } - } else if (tryOpenGuide(p, e, SlimefunGuideLayout.CHEST) == Result.ALLOW) { + } else if (tryOpenGuide(p, e, SlimefunGuideMode.CHEAT_MODE) == Result.ALLOW) { if (p.isSneaking()) { SlimefunGuideSettings.openSettings(p, e.getItem()); } else { - openGuide(p, e, SlimefunGuideLayout.CHEST); - } - } else if (tryOpenGuide(p, e, SlimefunGuideLayout.CHEAT_SHEET) == Result.ALLOW) { - if (p.isSneaking()) { - SlimefunGuideSettings.openSettings(p, e.getItem()); - } else { - // We rather just run the command here, - // all necessary permission checks will be handled there. + /* + * We rather just run the command here, all + * necessary permission checks will be handled there. + */ p.chat("/sf cheat"); } } } @ParametersAreNonnullByDefault - private void openGuide(Player p, PlayerRightClickEvent e, SlimefunGuideLayout layout) { + private void openGuide(Player p, PlayerRightClickEvent e, SlimefunGuideMode layout) { SlimefunGuideOpenEvent event = new SlimefunGuideOpenEvent(p, e.getItem(), layout); Bukkit.getPluginManager().callEvent(event); @@ -83,7 +79,7 @@ public class SlimefunGuideListener implements Listener { @Nonnull @ParametersAreNonnullByDefault - private Result tryOpenGuide(Player p, PlayerRightClickEvent e, SlimefunGuideLayout layout) { + private Result tryOpenGuide(Player p, PlayerRightClickEvent e, SlimefunGuideMode layout) { ItemStack item = e.getItem(); if (SlimefunUtils.isItemSimilar(item, SlimefunGuide.getItem(layout), true, false)) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TeleporterListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TeleporterListener.java index 158d38092..b10f1cdbe 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TeleporterListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TeleporterListener.java @@ -15,7 +15,7 @@ import org.bukkit.event.player.PlayerInteractEvent; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; -import io.github.thebusybiscuit.slimefun4.implementation.items.gps.ElevatorPlate; +import io.github.thebusybiscuit.slimefun4.implementation.items.elevator.ElevatorPlate; import io.github.thebusybiscuit.slimefun4.implementation.items.gps.Teleporter; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.api.BlockStorage; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java index d20ada89d..d285c9758 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java @@ -109,6 +109,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.XPCollector; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.reactors.NetherStarReactor; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.reactors.NuclearReactor; +import io.github.thebusybiscuit.slimefun4.implementation.items.elevator.ElevatorPlate; import io.github.thebusybiscuit.slimefun4.implementation.items.food.BirthdayCake; import io.github.thebusybiscuit.slimefun4.implementation.items.food.DietCookie; import io.github.thebusybiscuit.slimefun4.implementation.items.food.FortuneCookie; @@ -121,7 +122,6 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.geo.GEOMiner; import io.github.thebusybiscuit.slimefun4.implementation.items.geo.GEOScanner; import io.github.thebusybiscuit.slimefun4.implementation.items.geo.OilPump; import io.github.thebusybiscuit.slimefun4.implementation.items.geo.PortableGEOScanner; -import io.github.thebusybiscuit.slimefun4.implementation.items.gps.ElevatorPlate; import io.github.thebusybiscuit.slimefun4.implementation.items.gps.GPSControlPanel; import io.github.thebusybiscuit.slimefun4.implementation.items.gps.GPSMarkerTool; import io.github.thebusybiscuit.slimefun4.implementation.items.gps.GPSTransmitter; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/IntegrationsManager.java b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/IntegrationsManager.java index 37c88ad6b..92ef1ec56 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/IntegrationsManager.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/IntegrationsManager.java @@ -55,7 +55,6 @@ public class IntegrationsManager { // Addon support private boolean isChestTerminalInstalled = false; - private boolean isExoticGardenInstalled = false; /** * This initializes the {@link IntegrationsManager} @@ -140,7 +139,6 @@ public class IntegrationsManager { } isChestTerminalInstalled = isAddonInstalled("ChestTerminal"); - isExoticGardenInstalled = isAddonInstalled("ExoticGarden"); } /** @@ -249,8 +247,4 @@ public class IntegrationsManager { return isChestTerminalInstalled; } - public boolean isExoticGardenInstalled() { - return isExoticGardenInstalled; - } - } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/itemstack/SlimefunGuideItem.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/itemstack/SlimefunGuideItem.java index 2cb93cf15..ded9609c3 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/itemstack/SlimefunGuideItem.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/itemstack/SlimefunGuideItem.java @@ -1,6 +1,6 @@ package io.github.thebusybiscuit.slimefun4.utils.itemstack; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import javax.annotation.Nonnull; @@ -10,10 +10,11 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import io.github.thebusybiscuit.cscorelib2.chat.ChatColors; +import io.github.thebusybiscuit.cscorelib2.data.PersistentDataAPI; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation; +import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; -import io.github.thebusybiscuit.slimefun4.implementation.guide.CheatSheetSlimefunGuide; /** * This is just a helper {@link ItemStack} class for the {@link SlimefunGuide} {@link ItemStack}. @@ -32,12 +33,15 @@ public class SlimefunGuideItem extends ItemStack { ItemMeta meta = getItemMeta(); meta.setDisplayName(ChatColors.color(name)); - List lore = new LinkedList<>(); - lore.add(implementation instanceof CheatSheetSlimefunGuide ? ChatColors.color("&4&lOnly openable by Admins") : ""); + List lore = new ArrayList<>(); + SlimefunGuideMode type = implementation.getMode(); + lore.add(type == SlimefunGuideMode.CHEAT_MODE ? ChatColors.color("&4&lOnly openable by Admins") : ""); lore.add(ChatColors.color("&eRight Click &8\u21E8 &7Browse Items")); lore.add(ChatColors.color("&eShift + Right Click &8\u21E8 &7Open Settings / Credits")); meta.setLore(lore); + + PersistentDataAPI.setString(meta, SlimefunPlugin.getRegistry().getGuideDataKey(), type.name()); SlimefunPlugin.getItemTextureService().setTexture(meta, "SLIMEFUN_GUIDE"); setItemMeta(meta); diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/Category.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/Category.java index 8c788e94f..7f174deea 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/Category.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/Category.java @@ -7,6 +7,7 @@ import java.util.Comparator; import java.util.List; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; import org.apache.commons.lang.Validate; @@ -19,6 +20,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; +import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon; import io.github.thebusybiscuit.slimefun4.core.categories.LockedCategory; import io.github.thebusybiscuit.slimefun4.core.categories.SeasonalCategory; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide; @@ -37,6 +39,8 @@ import me.mrCookieSlime.Slimefun.api.Slimefun; */ public class Category implements Keyed { + private SlimefunAddon addon; + protected final List items = new ArrayList<>(); protected final NamespacedKey key; protected final ItemStack item; @@ -94,12 +98,40 @@ public class Category implements Keyed { * Registers this category. *

* By default, a category is automatically registered when a {@link SlimefunItem} was added to it. + * + * @param addon + * The {@link SlimefunAddon} that wants to register this {@link Category} */ + public void register(@Nonnull SlimefunAddon addon) { + Validate.notNull(addon, "The Addon cannot be null"); + this.addon = addon; + + SlimefunPlugin.getRegistry().getCategories().add(this); + Collections.sort(SlimefunPlugin.getRegistry().getCategories(), Comparator.comparingInt(Category::getTier)); + } + + /** + * Old way of registering categories, do not call this manually. + * + * @deprecated Please use {@link #register(SlimefunAddon)} instead. + */ + @Deprecated public void register() { SlimefunPlugin.getRegistry().getCategories().add(this); Collections.sort(SlimefunPlugin.getRegistry().getCategories(), Comparator.comparingInt(Category::getTier)); } + /** + * This returns the {@link SlimefunAddon} which has registered this {@link Category}. + * Or null if it has not been registered yet. + * + * @return The {@link SlimefunAddon} or null if unregistered + */ + @Nullable + public final SlimefunAddon getAddon() { + return addon; + } + /** * Adds the given {@link SlimefunItem} to this {@link Category}. * diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java index 9f487f678..c23fbdc17 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java @@ -477,7 +477,7 @@ public class SlimefunItem implements Placeable { private final void onEnable() { // Register the Category too if it hasn't been registered yet if (!category.isRegistered()) { - category.register(); + category.register(addon); } // Send out deprecation warnings for any classes or interfaces diff --git a/src/main/java/me/mrCookieSlime/Slimefun/api/Slimefun.java b/src/main/java/me/mrCookieSlime/Slimefun/api/Slimefun.java index 1161fa5f1..6b843802c 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/api/Slimefun.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/api/Slimefun.java @@ -1,9 +1,6 @@ package me.mrCookieSlime.Slimefun.api; import java.util.Optional; -import java.util.logging.Logger; - -import javax.annotation.Nonnull; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -25,17 +22,6 @@ public final class Slimefun { private Slimefun() {} - /** - * This returns the {@link Logger} for Slimefun. - * - * @deprecated Use {@link SlimefunPlugin#logger()} instead - */ - @Deprecated - @Nonnull - public static Logger getLogger() { - return SlimefunPlugin.logger(); - } - /** * Checks if this player can use this item. * diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 9413104e2..84aff21b3 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -20,7 +20,6 @@ options: drop-excess-sf-give-items: false guide: - default-view-book: false show-vanilla-recipes: true receive-on-first-join: true diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 692b065ca..fa3936eaa 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -23,7 +23,6 @@ softdepend: # We hook into these plugins too, but they depend on Slimefun. loadBefore: - ChestTerminal -- ExoticGarden # Our commands commands: diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/commands/TestGuideCommand.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/commands/TestGuideCommand.java index 663d1e1bc..cd1055a5b 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/commands/TestGuideCommand.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/commands/TestGuideCommand.java @@ -12,7 +12,7 @@ import org.junit.jupiter.params.provider.ValueSource; import be.seeseemelk.mockbukkit.MockBukkit; import be.seeseemelk.mockbukkit.ServerMock; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide; -import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; +import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; @@ -39,7 +39,7 @@ class TestGuideCommand { player.setOp(op); server.execute("slimefun", player, "guide").assertSucceeded(); - ItemStack guide = SlimefunGuide.getItem(SlimefunGuideLayout.CHEST); + ItemStack guide = SlimefunGuide.getItem(SlimefunGuideMode.SURVIVAL_MODE); Assertions.assertEquals(op, SlimefunUtils.containsSimilarItem(player.getInventory(), guide, true)); } } diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/guide/TestBookSlimefunGuide.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/guide/TestBookSlimefunGuide.java deleted file mode 100644 index 6d56a54e6..000000000 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/guide/TestBookSlimefunGuide.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.thebusybiscuit.slimefun4.testing.tests.guide; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import be.seeseemelk.mockbukkit.MockBukkit; -import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; -import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; -import io.github.thebusybiscuit.slimefun4.implementation.guide.BookSlimefunGuide; - -class TestBookSlimefunGuide { - - @BeforeAll - public static void load() { - MockBukkit.mock(); - MockBukkit.load(SlimefunPlugin.class); - } - - @AfterAll - public static void unload() { - MockBukkit.unmock(); - } - - @Test - @DisplayName("Test Getters for Chest Slimefun Guide") - void testBasicGetters() { - BookSlimefunGuide guide = new BookSlimefunGuide(); - - Assertions.assertEquals(SlimefunGuideLayout.BOOK, guide.getLayout()); - Assertions.assertTrue(guide.isSurvivalMode()); - } - -} diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/guide/TestChestSlimefunGuide.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/guide/TestChestSlimefunGuide.java deleted file mode 100644 index 5880e650f..000000000 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/guide/TestChestSlimefunGuide.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.thebusybiscuit.slimefun4.testing.tests.guide; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import be.seeseemelk.mockbukkit.MockBukkit; -import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; -import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; -import io.github.thebusybiscuit.slimefun4.implementation.guide.ChestSlimefunGuide; - -class TestChestSlimefunGuide { - - @BeforeAll - public static void load() { - MockBukkit.mock(); - MockBukkit.load(SlimefunPlugin.class); - } - - @AfterAll - public static void unload() { - MockBukkit.unmock(); - } - - @Test - @DisplayName("Test Getters for Chest Slimefun Guide") - void testBasicGetters() { - ChestSlimefunGuide guide = new ChestSlimefunGuide(false); - - Assertions.assertEquals(SlimefunGuideLayout.CHEST, guide.getLayout()); - Assertions.assertTrue(guide.isSurvivalMode()); - } - -} diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/listeners/TestGrindstoneListener.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/listeners/TestGrindstoneListener.java index 19a74a5dc..b171f1570 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/listeners/TestGrindstoneListener.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/listeners/TestGrindstoneListener.java @@ -22,7 +22,7 @@ import be.seeseemelk.mockbukkit.MockBukkit; import be.seeseemelk.mockbukkit.ServerMock; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide; -import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; +import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.items.VanillaItem; import io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting.GrindstoneListener; @@ -82,8 +82,8 @@ public class TestGrindstoneListener { } @ParameterizedTest - @EnumSource(SlimefunGuideLayout.class) - public void testGrindStoneWithSlimefunGuide(SlimefunGuideLayout layout) { + @EnumSource(SlimefunGuideMode.class) + public void testGrindStoneWithSlimefunGuide(SlimefunGuideMode layout) { InventoryClickEvent event = mockGrindStoneEvent(SlimefunGuide.getItem(layout)); Assertions.assertEquals(Result.DENY, event.getResult()); } diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/registration/TestCategories.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/registration/TestCategories.java index 5a6d87450..bb0aadca7 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/registration/TestCategories.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/registration/TestCategories.java @@ -10,6 +10,7 @@ import org.bukkit.inventory.ItemStack; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import be.seeseemelk.mockbukkit.MockBukkit; @@ -19,7 +20,7 @@ import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; import io.github.thebusybiscuit.slimefun4.core.categories.FlexCategory; import io.github.thebusybiscuit.slimefun4.core.categories.LockedCategory; import io.github.thebusybiscuit.slimefun4.core.categories.SeasonalCategory; -import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; +import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideMode; import io.github.thebusybiscuit.slimefun4.core.researching.Research; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.testing.TestUtilities; @@ -28,7 +29,7 @@ import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -public class TestCategories { +class TestCategories { private static ServerMock server; private static SlimefunPlugin plugin; @@ -45,17 +46,23 @@ public class TestCategories { } @Test - public void testCategoryGetters() { + @DisplayName("Test the Getters for Category") + void testCategoryGetters() { Category category = new Category(new NamespacedKey(plugin, "getter_test"), new CustomItem(Material.DIAMOND_AXE, "&6Testing")); Assertions.assertEquals(3, category.getTier()); Assertions.assertEquals(new NamespacedKey(SlimefunPlugin.instance(), "getter_test"), category.getKey()); Assertions.assertEquals("Testing", category.getUnlocalizedName()); Assertions.assertEquals(0, category.getItems().size()); + + Assertions.assertNull(category.getAddon()); + category.register(plugin); + Assertions.assertEquals(plugin, category.getAddon()); } @Test - public void testAddItem() { + @DisplayName("Test adding an item to a Category") + void testAddItem() { Category category = new Category(new NamespacedKey(plugin, "items_test"), new CustomItem(Material.DIAMOND_AXE, "&6Testing")); SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "CATEGORY_ITEMS_TEST_ITEM", new CustomItem(Material.BAMBOO, "&6Test Bamboo")); item.setCategory(category); @@ -73,7 +80,8 @@ public class TestCategories { } @Test - public void testHidden() { + @DisplayName("Test hidden Categories") + void testHidden() { Category category = new Category(new NamespacedKey(plugin, "hiddenCategory"), new ItemStack(Material.BEACON)); Player player = server.addPlayer(); @@ -103,7 +111,8 @@ public class TestCategories { } @Test - public void testContains() { + @DisplayName("Test Category#contains") + void testContains() { SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "CATEGORY_TEST_ITEM_2", new CustomItem(Material.BOW, "&6Test Bow")); item.register(plugin); item.load(); @@ -118,16 +127,17 @@ public class TestCategories { } @Test - public void testLockedCategoriesParents() { + @DisplayName("Test LockedCategory parental locking") + void testLockedCategoriesParents() { Assertions.assertThrows(IllegalArgumentException.class, () -> new LockedCategory(new NamespacedKey(plugin, "locked"), new CustomItem(Material.GOLD_NUGGET, "&6Locked Test"), (NamespacedKey) null)); Category category = new Category(new NamespacedKey(plugin, "unlocked"), new CustomItem(Material.EMERALD, "&5I am SHERlocked")); - category.register(); + category.register(plugin); Category unregistered = new Category(new NamespacedKey(plugin, "unregistered"), new CustomItem(Material.EMERALD, "&5I am unregistered")); LockedCategory locked = new LockedCategory(new NamespacedKey(plugin, "locked"), new CustomItem(Material.GOLD_NUGGET, "&6Locked Test"), category.getKey(), unregistered.getKey()); - locked.register(); + locked.register(plugin); Assertions.assertTrue(locked.getParents().contains(category)); Assertions.assertFalse(locked.getParents().contains(unregistered)); @@ -143,17 +153,18 @@ public class TestCategories { } @Test - public void testLockedCategoriesUnlocking() throws InterruptedException { + @DisplayName("Test an unlocked LockedCategory") + void testLockedCategoriesUnlocking() throws InterruptedException { Player player = server.addPlayer(); PlayerProfile profile = TestUtilities.awaitProfile(player); Assertions.assertThrows(IllegalArgumentException.class, () -> new LockedCategory(new NamespacedKey(plugin, "locked"), new CustomItem(Material.GOLD_NUGGET, "&6Locked Test"), (NamespacedKey) null)); Category category = new Category(new NamespacedKey(plugin, "parent"), new CustomItem(Material.EMERALD, "&5I am SHERlocked")); - category.register(); + category.register(plugin); LockedCategory locked = new LockedCategory(new NamespacedKey(plugin, "locked"), new CustomItem(Material.GOLD_NUGGET, "&6Locked Test"), category.getKey()); - locked.register(); + locked.register(plugin); // No Items, so it should be unlocked Assertions.assertTrue(locked.hasUnlocked(player, profile)); @@ -176,7 +187,8 @@ public class TestCategories { } @Test - public void testSeasonalCategories() { + @DisplayName("Test a seasonal Category") + void testSeasonalCategories() { // Category with current Month Month month = LocalDate.now().getMonth(); SeasonalCategory category = new SeasonalCategory(new NamespacedKey(plugin, "seasonal"), month, 1, new CustomItem(Material.NETHER_STAR, "&cSeasonal Test")); @@ -196,16 +208,17 @@ public class TestCategories { } @Test - public void testFlexCategory() { + @DisplayName("Test the FlexCategory") + void testFlexCategory() { FlexCategory category = new FlexCategory(new NamespacedKey(plugin, "flex"), new CustomItem(Material.REDSTONE, "&4Weird flex but ok")) { @Override - public void open(Player p, PlayerProfile profile, SlimefunGuideLayout layout) { + public void open(Player p, PlayerProfile profile, SlimefunGuideMode layout) { // Nothing } @Override - public boolean isVisible(Player p, PlayerProfile profile, SlimefunGuideLayout layout) { + public boolean isVisible(Player p, PlayerProfile profile, SlimefunGuideMode layout) { return true; } };