From a38678f0fac8364df5dbed5e3504a74d7f53c996 Mon Sep 17 00:00:00 2001 From: Robin Date: Fri, 22 Nov 2024 04:42:15 +0000 Subject: [PATCH] 1.21 + Menu Support --- build.gradle | 10 +- gradle.properties | 2 +- .../xyz/oribuin/fishing/FishingPlugin.java | 17 +- .../fishing/api/config/Configurable.java | 22 ++- .../fishing/api/event/FishContext.java | 3 - .../xyz/oribuin/fishing/api/gui/GuiItem.java | 147 ++++++++++++++++ .../oribuin/fishing/api/gui/PluginMenu.java | 164 ++++++++++++++++++ .../oribuin/fishing/command/FishCommand.java | 4 +- .../fishing/command/impl/MenuCommand.java | 37 ++++ .../xyz/oribuin/fishing/gui/ExampleMenu.java | 32 ++++ .../fishing/listener/FishListener.java | 5 +- .../fishing/listener/PlayerListeners.java | 2 +- .../oribuin/fishing/manager/MenuManager.java | 55 ++++++ .../manager/{ => base}/CommandManager.java | 2 +- .../{ => base}/ConfigurationManager.java | 2 +- .../manager/{ => base}/DataManager.java | 2 +- .../manager/{ => base}/LocaleManager.java | 2 +- .../java/xyz/oribuin/fishing/skill/Skill.java | 6 +- .../xyz/oribuin/fishing/storage/Fisher.java | 2 +- .../java/xyz/oribuin/fishing/totem/Totem.java | 23 ++- .../oribuin/fishing/util/ItemConstruct.java | 1 + .../oribuin/fishing/util/nms/SkullUtils.java | 1 + 22 files changed, 508 insertions(+), 33 deletions(-) create mode 100644 src/main/java/xyz/oribuin/fishing/api/gui/GuiItem.java create mode 100644 src/main/java/xyz/oribuin/fishing/api/gui/PluginMenu.java create mode 100644 src/main/java/xyz/oribuin/fishing/command/impl/MenuCommand.java create mode 100644 src/main/java/xyz/oribuin/fishing/gui/ExampleMenu.java create mode 100644 src/main/java/xyz/oribuin/fishing/manager/MenuManager.java rename src/main/java/xyz/oribuin/fishing/manager/{ => base}/CommandManager.java (93%) rename src/main/java/xyz/oribuin/fishing/manager/{ => base}/ConfigurationManager.java (97%) rename src/main/java/xyz/oribuin/fishing/manager/{ => base}/DataManager.java (99%) rename src/main/java/xyz/oribuin/fishing/manager/{ => base}/LocaleManager.java (99%) diff --git a/build.gradle b/build.gradle index 93e93a2..a3c24ad 100644 --- a/build.gradle +++ b/build.gradle @@ -8,13 +8,15 @@ plugins { group = 'xyz.oribuin' version = '1.0-SNAPSHOT' +sourceCompatibility = JavaVersion.VERSION_17 +targetCompatibility = JavaVersion.VERSION_17 java { - toolchain { - languageVersion = JavaLanguageVersion.of(17) - } + toolchain.languageVersion.set(JavaLanguageVersion.of(21)) + disableAutoTargetJvm() } + compileJava { options.compilerArgs += ['-parameters'] options.fork = true @@ -54,7 +56,7 @@ shadowJar { archiveClassifier.set(null) relocate("dev.rosewood.rosegarden", "${project.group}.fishing.libs.rosegarden") - relocate("com.jeff_media.morepersistentdatatypes", "${project.group}.fishing.libs.persistentdatatypes") + relocate("com.jeff_media.morepersistentdatatypes", "${project.group}.fishing.libs.pdt") relocate("net.objecthunter.exp4j", "${project.group}.fishing.libs.exp4j") relocate("dev.triumphteam.gui", "${project.group}.fishing.libs.triumphgui") } diff --git a/gradle.properties b/gradle.properties index 46cc994..ce364c5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ org.gradle.jvmargs='-Dfile.encoding=UTF-8' # API Versions -spigotVersion=1.20.4 +spigotVersion=1.21.1 gardenVersion=1.3.1 vaultVersion=1.7 authLibVersion=1.5.21 diff --git a/src/main/java/xyz/oribuin/fishing/FishingPlugin.java b/src/main/java/xyz/oribuin/fishing/FishingPlugin.java index b046f99..5aac15b 100644 --- a/src/main/java/xyz/oribuin/fishing/FishingPlugin.java +++ b/src/main/java/xyz/oribuin/fishing/FishingPlugin.java @@ -7,12 +7,14 @@ import xyz.oribuin.fishing.augment.AugmentRegistry; import xyz.oribuin.fishing.listener.FishListener; import xyz.oribuin.fishing.listener.PlayerListeners; -import xyz.oribuin.fishing.manager.CommandManager; -import xyz.oribuin.fishing.manager.ConfigurationManager; -import xyz.oribuin.fishing.manager.DataManager; import xyz.oribuin.fishing.manager.FishManager; -import xyz.oribuin.fishing.manager.LocaleManager; +import xyz.oribuin.fishing.manager.MenuManager; import xyz.oribuin.fishing.manager.TierManager; +import xyz.oribuin.fishing.manager.TotemManager; +import xyz.oribuin.fishing.manager.base.CommandManager; +import xyz.oribuin.fishing.manager.base.ConfigurationManager; +import xyz.oribuin.fishing.manager.base.DataManager; +import xyz.oribuin.fishing.manager.base.LocaleManager; import xyz.oribuin.fishing.skill.SkillRegistry; import java.util.List; @@ -58,7 +60,12 @@ public void disable() { @Override protected @NotNull List> getManagerLoadPriority() { - return List.of(TierManager.class, FishManager.class); + return List.of( + TierManager.class, + FishManager.class, + MenuManager.class, + TotemManager.class + ); } } diff --git a/src/main/java/xyz/oribuin/fishing/api/config/Configurable.java b/src/main/java/xyz/oribuin/fishing/api/config/Configurable.java index 1abab6c..7f699cd 100644 --- a/src/main/java/xyz/oribuin/fishing/api/config/Configurable.java +++ b/src/main/java/xyz/oribuin/fishing/api/config/Configurable.java @@ -4,6 +4,7 @@ import dev.rosewood.rosegarden.config.CommentedFileConfiguration; import org.bukkit.Bukkit; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import xyz.oribuin.fishing.FishingPlugin; import java.io.File; @@ -54,8 +55,10 @@ default List comments() { * * @return The path */ - @NotNull - Path configPath(); + @Nullable + default Path configPath() { + return null; + } /** * The parent folder of the configuration file, this should be the starting point for every config path @@ -72,6 +75,7 @@ default File parentFolder() { */ default void reload() { FishingPlugin plugin = FishingPlugin.get(); + if (this.configPath() == null) return; File targetFile = new File(this.parentFolder(), this.configPath().toString()); try { @@ -118,4 +122,18 @@ private void createFile(File target) throws IOException { target.createNewFile(); } + /** + * Pull a section from the configuration file and save the settings + * + * @param base The base section to pull from + * @param name The name of the section + */ + @NotNull + default CommentedConfigurationSection pullSection(CommentedConfigurationSection base, String name) { + CommentedConfigurationSection section = base.getConfigurationSection(name); + if (section == null) section = base.createSection(name); + + return section; + } + } diff --git a/src/main/java/xyz/oribuin/fishing/api/event/FishContext.java b/src/main/java/xyz/oribuin/fishing/api/event/FishContext.java index 8beac1a..517a65b 100644 --- a/src/main/java/xyz/oribuin/fishing/api/event/FishContext.java +++ b/src/main/java/xyz/oribuin/fishing/api/event/FishContext.java @@ -13,7 +13,4 @@ * @param level The level of the augment/skill/upgrade that was used */ public record FishContext(Player player, ItemStack itemStack, FishHook hook, int level) { - - // Unused - } diff --git a/src/main/java/xyz/oribuin/fishing/api/gui/GuiItem.java b/src/main/java/xyz/oribuin/fishing/api/gui/GuiItem.java new file mode 100644 index 0000000..4785f50 --- /dev/null +++ b/src/main/java/xyz/oribuin/fishing/api/gui/GuiItem.java @@ -0,0 +1,147 @@ +package xyz.oribuin.fishing.api.gui; + +import dev.rosewood.rosegarden.config.CommentedConfigurationSection; +import dev.triumphteam.gui.components.GuiAction; +import dev.triumphteam.gui.guis.BaseGui; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import xyz.oribuin.fishing.api.config.Configurable; +import xyz.oribuin.fishing.util.ItemConstruct; + +import java.util.ArrayList; +import java.util.List; + +public class GuiItem implements Configurable { + + protected boolean enabled = true; + protected String name = "item"; + protected List slot = List.of(0); + protected ItemConstruct item = ItemConstruct.EMPTY; + + /** + * Place the item in the specified slot in the GUI + * + * @param gui The GUI to place the item in + * @param function The function to run when the item is clicked + */ + public void place(BaseGui gui, GuiAction function) { + if (gui == null) return; + if (!this.enabled) return; + + int guiSize = gui.getRows() * 9; + this.slot.forEach(x -> { + if (x < 0 || x >= guiSize) return; + + ItemStack item = this.item.build(); + if (item == null) return; + + gui.setItem(slot, new dev.triumphteam.gui.guis.GuiItem(item, function)); + }); + } + + /** + * Load the settings from the configuration file + * I would recommend always super calling this method to save any settings that could be implemented + * + * @param config The configuration file to load + */ + @Override + public void loadSettings(@NotNull CommentedConfigurationSection config) { + this.enabled = config.getBoolean("enabled", true); + this.name = config.getString("name"); + + int slot = config.getInt("slot", -1); + if (slot > 0) this.slot = List.of(slot); + + List slots = config.getStringList("slots"); + if (!slots.isEmpty()) this.slot = this.parseSlotList(slots); + + CommentedConfigurationSection item = config.getConfigurationSection("item"); + if (item != null) { + this.item = ItemConstruct.deserialize(item); + } + + System.out.println("Loaded item: " + this.name); + } + + /** + * Save the configuration file for the configurable class + * I would recommend always super calling this method to save any settings that could be implemented + * + * @param config The configuration file to save + */ + @Override + public void saveSettings(@NotNull CommentedConfigurationSection config) { + config.set("enabled", this.enabled); + config.set("name", this.name); + + if (this.slot.size() == 1) config.set("slot", this.slot.get(0)); + else config.set("slots", this.slot.stream().map(String::valueOf).toList()); + + CommentedConfigurationSection item = config.getConfigurationSection("item"); + if (item == null) item = config.createSection("item"); + + this.item.serialize(item); + } + + /** + * Parse the slots from the configuration file to a list of integers + * + * @param lines The lines to parse + * + * @return The list of integers + */ + private List parseSlotList(List lines) { + List slots = new ArrayList<>(); + for (String line : lines) { + slots.addAll(this.parseSlots(line)); + } + return slots; + } + + /** + * Parse the slots from the configuration file to a list of integers + * + * @param line The line to parse + * + * @return The list of integers + */ + private List parseSlots(String line) { + try { + String[] split = line.split("-"); + if (split.length == 2) { + int start = Integer.parseInt(split[0]); + int end = Integer.parseInt(split[1]); + + List results = new ArrayList<>(); + for (int i = start; i <= end; i++) { + results.add(i); + } + + return results; + } + + return List.of(Integer.parseInt(line)); + } catch (NumberFormatException e) { + return List.of(0); + } + } + + public boolean enabled() { + return enabled; + } + + public String name() { + return name; + } + + public List slot() { + return slot; + } + + public ItemConstruct item() { + return item; + } + +} diff --git a/src/main/java/xyz/oribuin/fishing/api/gui/PluginMenu.java b/src/main/java/xyz/oribuin/fishing/api/gui/PluginMenu.java new file mode 100644 index 0000000..2165de7 --- /dev/null +++ b/src/main/java/xyz/oribuin/fishing/api/gui/PluginMenu.java @@ -0,0 +1,164 @@ +package xyz.oribuin.fishing.api.gui; + +import dev.rosewood.rosegarden.config.CommentedConfigurationSection; +import dev.triumphteam.gui.components.GuiAction; +import dev.triumphteam.gui.guis.BaseGui; +import dev.triumphteam.gui.guis.Gui; +import dev.triumphteam.gui.guis.PaginatedGui; +import net.kyori.adventure.text.Component; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.jetbrains.annotations.NotNull; +import xyz.oribuin.fishing.FishingPlugin; +import xyz.oribuin.fishing.api.config.Configurable; + +import java.nio.file.Path; +import java.util.HashMap; +import java.util.Map; + +public abstract class PluginMenu implements Configurable { + + protected final GuiAction EMPTY = event -> { + // :33333333 + }; + + protected final String name; + protected String title; + protected int rows; + protected Map items; + protected Map extraItems; + protected int pageSize; + + public PluginMenu(String name) { + this.name = name; + this.title = name; + this.rows = 6; + this.items = new HashMap<>(); + this.extraItems = new HashMap<>(); + this.pageSize = 0; + } + + /** + * Open the GUI for the specified player + * + * @param player The player to open the GUI for + */ + public abstract void open(Player player); + + /** + * Create the menu for the GUI with the specified settings + * + * @return The created GUI + */ + public Gui createRegular() { + return Gui.gui().disableAllInteractions().title(Component.text(this.title)).rows(this.rows).create(); + } + + /** + * Create the menu for the GUI with the specified settings + * + * @return The created GUI + */ + public PaginatedGui createPaginated() { + return Gui.paginated().disableAllInteractions() + .title(Component.text(this.title)) + .rows(this.rows) + .create(); + } + + /** + * Place the items in the GUI + * + * @param gui The GUI to place the items in + */ + public void placeExtras(BaseGui gui) { + this.extraItems.forEach((key, value) -> value.place(gui, EMPTY)); + } + + /** + * Place the item in the GUI + * + * @param gui The GUI to place the item in + * @param key The key of the item to place + * @param function The function to run when the item is clicked + */ + public void placeItem(BaseGui gui, String key, GuiAction function) { + GuiItem item = this.items.get(key.toLowerCase()); + if (item == null) { + FishingPlugin.get().getLogger().warning("Failed to place item with key: " + key + " in menu: " + this.name + ". Item not found."); + return; + } + + item.place(gui, function); + } + + /** + * Load the settings from the configuration file + * I would recommend always super calling this method to save any settings that could be implemented + * + * @param config The configuration file to load + */ + @Override + public void loadSettings(@NotNull CommentedConfigurationSection config) { + this.title = config.getString("title", this.name); + this.rows = config.getInt("rows", 6); + this.pageSize = config.getInt("page-size", 0); + + CommentedConfigurationSection items = config.getConfigurationSection("items"); + if (items != null) { + items.getKeys(false).forEach(key -> { + CommentedConfigurationSection item = this.pullSection(items, key); + + GuiItem guiItem = new GuiItem(); + guiItem.loadSettings(item); + this.items.put(guiItem.name().toLowerCase(), guiItem); + }); + } + + CommentedConfigurationSection extraItems = config.getConfigurationSection("extra-items"); + if (extraItems != null) { + extraItems.getKeys(false).forEach(key -> { + CommentedConfigurationSection item = this.pullSection(extraItems, key); + GuiItem guiItem = new GuiItem(); + guiItem.loadSettings(item); + + this.extraItems.put(key, guiItem); + }); + } + } + + /** + * Save the configuration file for the configurable class + * I would recommend always super calling this method to save any settings that could be implemented + * + * @param config The configuration file to save + */ + @Override + public void saveSettings(@NotNull CommentedConfigurationSection config) { + config.set("title", this.title); + config.set("rows", this.rows); + config.set("page-size", this.pageSize); + + // Save the items + CommentedConfigurationSection items = this.pullSection(config, "items"); + this.items.forEach((key, value) -> { + CommentedConfigurationSection item = this.pullSection(items, key); + value.saveSettings(item); + }); + + // Save the extra items + CommentedConfigurationSection extraItems = this.pullSection(config, "extra-items"); + this.extraItems.forEach((key, value) -> { + CommentedConfigurationSection item = this.pullSection(extraItems, key); + value.saveSettings(item); + }); + } + + /** + * @return The path to the configuration file + */ + public @NotNull Path configPath() { + return Path.of("menus", this.name + ".yml"); + } + +} diff --git a/src/main/java/xyz/oribuin/fishing/command/FishCommand.java b/src/main/java/xyz/oribuin/fishing/command/FishCommand.java index 792a39c..cacb5cd 100644 --- a/src/main/java/xyz/oribuin/fishing/command/FishCommand.java +++ b/src/main/java/xyz/oribuin/fishing/command/FishCommand.java @@ -7,6 +7,7 @@ import dev.rosewood.rosegarden.command.framework.BaseRoseCommand; import dev.rosewood.rosegarden.command.framework.CommandInfo; import xyz.oribuin.fishing.command.impl.ApplyCommand; +import xyz.oribuin.fishing.command.impl.MenuCommand; public class FishCommand extends BaseRoseCommand { @@ -28,7 +29,8 @@ private ArgumentsDefinition createArguments() { .requiredSub( new HelpCommand(this.rosePlugin, this), new ReloadCommand(this.rosePlugin), - new ApplyCommand(this.rosePlugin) + new ApplyCommand(this.rosePlugin), + new MenuCommand(this.rosePlugin) ); } diff --git a/src/main/java/xyz/oribuin/fishing/command/impl/MenuCommand.java b/src/main/java/xyz/oribuin/fishing/command/impl/MenuCommand.java new file mode 100644 index 0000000..393ac04 --- /dev/null +++ b/src/main/java/xyz/oribuin/fishing/command/impl/MenuCommand.java @@ -0,0 +1,37 @@ +package xyz.oribuin.fishing.command.impl; + +import dev.rosewood.rosegarden.RosePlugin; +import dev.rosewood.rosegarden.command.framework.BaseRoseCommand; +import dev.rosewood.rosegarden.command.framework.CommandContext; +import dev.rosewood.rosegarden.command.framework.CommandInfo; +import dev.rosewood.rosegarden.command.framework.annotation.RoseExecutable; +import org.bukkit.entity.Player; +import xyz.oribuin.fishing.gui.ExampleMenu; +import xyz.oribuin.fishing.manager.MenuManager; + +public class MenuCommand extends BaseRoseCommand { + + public MenuCommand(RosePlugin rosePlugin) { + super(rosePlugin); + } + + @RoseExecutable + public void execute(CommandContext context) { + Player player = (Player) context.getSender(); + + // Open the menu for the player + ExampleMenu menu = MenuManager.from(ExampleMenu.class); + if (menu == null) return; + + menu.open(player); + } + + @Override + protected CommandInfo createCommandInfo() { + return CommandInfo.builder("menu") + .permission("fishing.menu") + .playerOnly() + .build(); + } + +} diff --git a/src/main/java/xyz/oribuin/fishing/gui/ExampleMenu.java b/src/main/java/xyz/oribuin/fishing/gui/ExampleMenu.java new file mode 100644 index 0000000..b411dff --- /dev/null +++ b/src/main/java/xyz/oribuin/fishing/gui/ExampleMenu.java @@ -0,0 +1,32 @@ +package xyz.oribuin.fishing.gui; + +import dev.triumphteam.gui.guis.PaginatedGui; +import org.bukkit.entity.Player; +import xyz.oribuin.fishing.api.gui.PluginMenu; + +public class ExampleMenu extends PluginMenu { + + protected final PaginatedGui gui = this.createPaginated(); + + public ExampleMenu() { + super("example"); + } + + /** + * Open the GUI for the specified player + * + * @param player The player to open the GUI for + */ + @Override + public void open(Player player) { + this.placeExtras(this.gui); + + // Place the example item in the GUI + this.placeItem(this.gui, "example-item", x -> player.sendMessage("You clicked the example item!")); + + this.gui.update(); // Update the GUI + this.gui.open(player); // Open the GUI for the player + } + + +} diff --git a/src/main/java/xyz/oribuin/fishing/listener/FishListener.java b/src/main/java/xyz/oribuin/fishing/listener/FishListener.java index 7c9eab9..48507dd 100644 --- a/src/main/java/xyz/oribuin/fishing/listener/FishListener.java +++ b/src/main/java/xyz/oribuin/fishing/listener/FishListener.java @@ -1,6 +1,5 @@ package xyz.oribuin.fishing.listener; -import dev.rosewood.rosegarden.utils.StringPlaceholders; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerFishEvent; @@ -9,9 +8,9 @@ import xyz.oribuin.fishing.FishingPlugin; import xyz.oribuin.fishing.api.event.FishCatchEvent; import xyz.oribuin.fishing.fish.Fish; -import xyz.oribuin.fishing.manager.DataManager; +import xyz.oribuin.fishing.manager.base.DataManager; import xyz.oribuin.fishing.manager.FishManager; -import xyz.oribuin.fishing.manager.LocaleManager; +import xyz.oribuin.fishing.manager.base.LocaleManager; import xyz.oribuin.fishing.storage.Fisher; import java.util.List; diff --git a/src/main/java/xyz/oribuin/fishing/listener/PlayerListeners.java b/src/main/java/xyz/oribuin/fishing/listener/PlayerListeners.java index f2c074b..87bdb37 100644 --- a/src/main/java/xyz/oribuin/fishing/listener/PlayerListeners.java +++ b/src/main/java/xyz/oribuin/fishing/listener/PlayerListeners.java @@ -6,7 +6,7 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import xyz.oribuin.fishing.FishingPlugin; -import xyz.oribuin.fishing.manager.DataManager; +import xyz.oribuin.fishing.manager.base.DataManager; import xyz.oribuin.fishing.storage.Fisher; public class PlayerListeners implements Listener { diff --git a/src/main/java/xyz/oribuin/fishing/manager/MenuManager.java b/src/main/java/xyz/oribuin/fishing/manager/MenuManager.java new file mode 100644 index 0000000..5d4f8d4 --- /dev/null +++ b/src/main/java/xyz/oribuin/fishing/manager/MenuManager.java @@ -0,0 +1,55 @@ +package xyz.oribuin.fishing.manager; + +import dev.rosewood.rosegarden.RosePlugin; +import dev.rosewood.rosegarden.manager.Manager; +import xyz.oribuin.fishing.FishingPlugin; +import xyz.oribuin.fishing.api.gui.PluginMenu; +import xyz.oribuin.fishing.gui.ExampleMenu; + +import java.util.HashMap; +import java.util.Map; + +public class MenuManager extends Manager { + + private static final Map, PluginMenu> menus = new HashMap<>(); + + public MenuManager(RosePlugin rosePlugin) { + super(rosePlugin); + } + + @Override + public void reload() { + menus.clear(); + + // Register the menus + menus.put(ExampleMenu.class, new ExampleMenu()); + + // Load all the menus + menus.values().forEach(PluginMenu::reload); + } + + + /** + * Get a registered menu + * + * @param clazz The class of the menu + * @param The type of the menu + * + * @return The menu + */ + @SuppressWarnings("unchecked") + public static T from(Class clazz) { + try { + return (T) menus.get(clazz); + } catch (Exception e) { + FishingPlugin.get().getLogger().severe("Failed to get menu from class: " + clazz.getSimpleName()); + return null; + } + } + + @Override + public void disable() { + + } + +} diff --git a/src/main/java/xyz/oribuin/fishing/manager/CommandManager.java b/src/main/java/xyz/oribuin/fishing/manager/base/CommandManager.java similarity index 93% rename from src/main/java/xyz/oribuin/fishing/manager/CommandManager.java rename to src/main/java/xyz/oribuin/fishing/manager/base/CommandManager.java index 7ff5684..535da9d 100644 --- a/src/main/java/xyz/oribuin/fishing/manager/CommandManager.java +++ b/src/main/java/xyz/oribuin/fishing/manager/base/CommandManager.java @@ -1,4 +1,4 @@ -package xyz.oribuin.fishing.manager; +package xyz.oribuin.fishing.manager.base; import dev.rosewood.rosegarden.RosePlugin; import dev.rosewood.rosegarden.command.framework.BaseRoseCommand; diff --git a/src/main/java/xyz/oribuin/fishing/manager/ConfigurationManager.java b/src/main/java/xyz/oribuin/fishing/manager/base/ConfigurationManager.java similarity index 97% rename from src/main/java/xyz/oribuin/fishing/manager/ConfigurationManager.java rename to src/main/java/xyz/oribuin/fishing/manager/base/ConfigurationManager.java index fca2528..49b3b7f 100644 --- a/src/main/java/xyz/oribuin/fishing/manager/ConfigurationManager.java +++ b/src/main/java/xyz/oribuin/fishing/manager/base/ConfigurationManager.java @@ -1,4 +1,4 @@ -package xyz.oribuin.fishing.manager; +package xyz.oribuin.fishing.manager.base; import dev.rosewood.rosegarden.RosePlugin; import dev.rosewood.rosegarden.config.CommentedFileConfiguration; diff --git a/src/main/java/xyz/oribuin/fishing/manager/DataManager.java b/src/main/java/xyz/oribuin/fishing/manager/base/DataManager.java similarity index 99% rename from src/main/java/xyz/oribuin/fishing/manager/DataManager.java rename to src/main/java/xyz/oribuin/fishing/manager/base/DataManager.java index 4e103fc..d121a00 100644 --- a/src/main/java/xyz/oribuin/fishing/manager/DataManager.java +++ b/src/main/java/xyz/oribuin/fishing/manager/base/DataManager.java @@ -1,4 +1,4 @@ -package xyz.oribuin.fishing.manager; +package xyz.oribuin.fishing.manager.base; import com.google.gson.Gson; import dev.rosewood.rosegarden.RosePlugin; diff --git a/src/main/java/xyz/oribuin/fishing/manager/LocaleManager.java b/src/main/java/xyz/oribuin/fishing/manager/base/LocaleManager.java similarity index 99% rename from src/main/java/xyz/oribuin/fishing/manager/LocaleManager.java rename to src/main/java/xyz/oribuin/fishing/manager/base/LocaleManager.java index fdfd6f9..c2b179c 100644 --- a/src/main/java/xyz/oribuin/fishing/manager/LocaleManager.java +++ b/src/main/java/xyz/oribuin/fishing/manager/base/LocaleManager.java @@ -1,4 +1,4 @@ -package xyz.oribuin.fishing.manager; +package xyz.oribuin.fishing.manager.base; import dev.rosewood.rosegarden.RosePlugin; import dev.rosewood.rosegarden.manager.AbstractLocaleManager; diff --git a/src/main/java/xyz/oribuin/fishing/skill/Skill.java b/src/main/java/xyz/oribuin/fishing/skill/Skill.java index 5a126c1..6d69685 100644 --- a/src/main/java/xyz/oribuin/fishing/skill/Skill.java +++ b/src/main/java/xyz/oribuin/fishing/skill/Skill.java @@ -2,18 +2,16 @@ import dev.rosewood.rosegarden.config.CommentedConfigurationSection; -import dev.rosewood.rosegarden.config.CommentedFileConfiguration; import dev.rosewood.rosegarden.utils.StringPlaceholders; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import xyz.oribuin.fishing.api.config.Configurable; import xyz.oribuin.fishing.api.event.FishEventHandler; +import xyz.oribuin.fishing.manager.base.DataManager; import java.nio.file.Path; -import java.util.ArrayList; import java.util.List; import java.util.Objects; -import java.util.stream.Collectors; public abstract class Skill extends FishEventHandler implements Configurable { @@ -66,7 +64,7 @@ public StringPlaceholders placeholders(@NotNull Player player) { } /** - * The name of the skill, this is used to store what skills player has in {@link xyz.oribuin.fishing.manager.DataManager} + * The name of the skill, this is used to store what skills player has in {@link DataManager} * * @return The skill name */ diff --git a/src/main/java/xyz/oribuin/fishing/storage/Fisher.java b/src/main/java/xyz/oribuin/fishing/storage/Fisher.java index b2f1535..b71f680 100644 --- a/src/main/java/xyz/oribuin/fishing/storage/Fisher.java +++ b/src/main/java/xyz/oribuin/fishing/storage/Fisher.java @@ -1,7 +1,7 @@ package xyz.oribuin.fishing.storage; import dev.rosewood.rosegarden.utils.StringPlaceholders; -import xyz.oribuin.fishing.manager.ConfigurationManager.Setting; +import xyz.oribuin.fishing.manager.base.ConfigurationManager.Setting; import xyz.oribuin.fishing.util.FishUtils; import java.util.HashMap; diff --git a/src/main/java/xyz/oribuin/fishing/totem/Totem.java b/src/main/java/xyz/oribuin/fishing/totem/Totem.java index 566fc63..c2dfa27 100644 --- a/src/main/java/xyz/oribuin/fishing/totem/Totem.java +++ b/src/main/java/xyz/oribuin/fishing/totem/Totem.java @@ -7,6 +7,7 @@ import org.bukkit.Location; import org.bukkit.Particle; import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Fish; import org.bukkit.entity.Player; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.inventory.EquipmentSlot; @@ -37,6 +38,7 @@ public class Totem implements AsyncTicker { private long thetaTicks; // The ticks for the totem to spin private double heightOffset; // The height offset for the totem + public Totem(UUID owner, String ownerName) { this.owner = owner; this.ownerName = ownerName; @@ -48,7 +50,7 @@ public Totem(UUID owner, String ownerName) { } /** - * Create a new totem owner with all the requires values + * Create a new totem owner with all the required values * * @param owner The owner of the totem * @param center The block the totem lives @@ -76,7 +78,7 @@ public void tickAsync() { List bounds = this.bounds(); Particle.DustOptions options = new Particle.DustOptions(Color.LIME, 1f); bounds.forEach(x -> this.center.getWorld().spawnParticle( - FishUtils.getEnum(Particle.class, "DUST", Particle.REDSTONE), + FishUtils.getEnum(Particle.class, "REDSTONE", Particle.DUST), x, 2, 0, 0, 0, 0, @@ -147,7 +149,7 @@ public void spawn(Location location) { // Spawn totem particles around the totem results.forEach(x -> this.center.getWorld().spawnParticle( - Particle.TOTEM, + FishUtils.getEnum(Particle.class, "TOTEM", Particle.TOTEM_OF_UNDYING), x, 2, 0, 0, 0, 0 @@ -156,7 +158,7 @@ public void spawn(Location location) { // Spawn dust particles to display the totem radius Particle.DustOptions options = new Particle.DustOptions(Color.LIME, 1f); results.forEach(x -> this.center.getWorld().spawnParticle( - FishUtils.getEnum(Particle.class, "DUST", Particle.REDSTONE), + FishUtils.getEnum(Particle.class, "DUST", FishUtils.getEnum(Particle.class, "REDSTONE", Particle.DUST)), x, 2, 0, 0, 0, 0, @@ -165,6 +167,8 @@ public void spawn(Location location) { }); } + + /** * Save all the totem values to the container * @@ -180,6 +184,13 @@ public void saveToContainer(PersistentDataContainer container) { container.set(PersistKeys.TOTEM_LASTACTIVE, DataType.LONG, this.lastActive); } + /** + * Create a new totem from a container with all the required values + * + * @param container The container to get the values from + * + * @return The totem object + */ public static Totem fromContainer(PersistentDataContainer container) { UUID owner = container.get(PersistKeys.TOTEM_OWNER, DataType.UUID); String ownerName = container.getOrDefault(PersistKeys.TOTEM_OWNERNAME, DataType.STRING, "N/A"); @@ -196,6 +207,10 @@ public static Totem fromContainer(PersistentDataContainer container) { Totem totem = new Totem(owner, ownerName); totem.active(active); + totem.radius(radius); + totem.duration(Duration.ofMillis(duration)); + totem.cooldown(Duration.ofMillis(cooldown)); + totem.lastActive(lastActive); return null; } diff --git a/src/main/java/xyz/oribuin/fishing/util/ItemConstruct.java b/src/main/java/xyz/oribuin/fishing/util/ItemConstruct.java index 13a4b10..4c33792 100644 --- a/src/main/java/xyz/oribuin/fishing/util/ItemConstruct.java +++ b/src/main/java/xyz/oribuin/fishing/util/ItemConstruct.java @@ -16,6 +16,7 @@ import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import xyz.oribuin.fishing.api.config.Configurable; import xyz.oribuin.fishing.util.nms.SkullUtils; import java.util.ArrayList; diff --git a/src/main/java/xyz/oribuin/fishing/util/nms/SkullUtils.java b/src/main/java/xyz/oribuin/fishing/util/nms/SkullUtils.java index f63922a..8d1431e 100644 --- a/src/main/java/xyz/oribuin/fishing/util/nms/SkullUtils.java +++ b/src/main/java/xyz/oribuin/fishing/util/nms/SkullUtils.java @@ -14,6 +14,7 @@ import java.util.Base64; import java.util.UUID; +@SuppressWarnings({"unused", "deprecation"}) public final class SkullUtils { private static Method method_SkullMeta_setProfile;