From 274055dfce93ce8c2b30b0594c165a28320cfe25 Mon Sep 17 00:00:00 2001 From: XiaoMoMi <972454774@qq.com> Date: Thu, 4 Jul 2024 00:15:44 +0800 Subject: [PATCH] checkpoint - 22 --- .../api/event/FishingLootSpawnEvent.java | 9 +- .../api/event/FishingResultEvent.java | 98 +-- .../mechanic/competition/CompetitionGoal.java | 13 +- .../api/mechanic/config/ConfigManager.java | 10 + .../api/mechanic/config/ConfigType.java | 8 +- .../api/mechanic/context/ContextKeys.java | 1 + .../mechanic/fishing/CustomFishingHook.java | 93 ++- .../api/mechanic/fishing/FishingGears.java | 8 +- .../mechanic/item/CustomFishingItemImpl.java | 3 +- .../customfishing/api/mechanic/loot/Loot.java | 11 +- .../api/mechanic/loot/LootImpl.java | 8 +- .../common/locale/MessageConstants.java | 15 + .../MiniMessageTranslationRegistry.java | 2 + .../MiniMessageTranslationRegistryImpl.java | 11 +- .../common/locale/StandardLocales.java | 128 ---- .../common/locale/TranslationManager.java | 17 + .../bukkit/BukkitCustomFishingPluginImpl.java | 7 - .../bukkit/bag/BukkitBagManager.java | 7 - .../bukkit/command/BukkitCommandManager.java | 1 - .../command/feature/GUIEditorCommand.java | 33 - .../bukkit/competition/Competition.java | 13 +- .../actionbar/ActionBarSender.java | 5 +- .../competition/bossbar/BossBarSender.java | 5 +- .../bukkit/config/BukkitConfigManager.java | 15 + .../bukkit/fishing/BukkitFishingManager.java | 7 + .../bukkit/gui/ChatCatcherManager.java | 77 --- .../customfishing/bukkit/gui/Icon.java | 21 - .../customfishing/bukkit/gui/ParentPage.java | 31 - .../customfishing/bukkit/gui/SectionPage.java | 25 - .../customfishing/bukkit/gui/YamlPage.java | 23 - .../bukkit/gui/icon/BackGroundItem.java | 41 -- .../bukkit/gui/icon/BackToFolderItem.java | 64 -- .../bukkit/gui/icon/BackToPageItem.java | 51 -- .../bukkit/gui/icon/NextPageItem.java | 50 -- .../bukkit/gui/icon/PreviousPageItem.java | 49 -- .../bukkit/gui/icon/ScrollDownItem.java | 48 -- .../bukkit/gui/icon/ScrollUpItem.java | 48 -- .../gui/icon/property/item/AmountItem.java | 73 -- .../gui/icon/property/item/CMDItem.java | 74 -- .../icon/property/item/DisplayNameItem.java | 70 -- .../icon/property/item/DurabilityItem.java | 70 -- .../icon/property/item/EnchantmentItem.java | 78 --- .../gui/icon/property/item/Head64Item.java | 91 --- .../gui/icon/property/item/ItemFlagItem.java | 72 -- .../gui/icon/property/item/LoreItem.java | 73 -- .../gui/icon/property/item/MaterialItem.java | 76 --- .../gui/icon/property/item/NBTItem.java | 76 --- .../icon/property/item/PreventGrabItem.java | 62 -- .../gui/icon/property/item/PriceItem.java | 72 -- .../property/item/RandomDurabilityItem.java | 64 -- .../gui/icon/property/item/SizeItem.java | 72 -- .../gui/icon/property/item/StackableItem.java | 62 -- .../property/item/StoredEnchantmentItem.java | 77 --- .../gui/icon/property/item/TagItem.java | 62 -- .../icon/property/item/UnbreakableItem.java | 57 -- .../icon/property/loot/DisableGameItem.java | 61 -- .../icon/property/loot/DisableStatsItem.java | 61 -- .../icon/property/loot/InstantGameItem.java | 57 -- .../gui/icon/property/loot/NickItem.java | 69 -- .../gui/icon/property/loot/ScoreItem.java | 74 -- .../icon/property/loot/ShowInFinderItem.java | 66 -- .../bukkit/gui/page/file/FileSelector.java | 140 ---- .../gui/page/item/AbstractSectionEditor.java | 122 ---- .../bukkit/gui/page/item/BaitEditor.java | 54 -- .../bukkit/gui/page/item/HookEditor.java | 54 -- .../bukkit/gui/page/item/ItemSelector.java | 290 -------- .../bukkit/gui/page/item/RodEditor.java | 51 -- .../bukkit/gui/page/item/SectionEditor.java | 64 -- .../gui/page/property/AmountEditor.java | 132 ---- .../page/property/CustomModelDataEditor.java | 147 ---- .../gui/page/property/DisplayNameEditor.java | 121 ---- .../gui/page/property/DurabilityEditor.java | 130 ---- .../gui/page/property/EnchantmentEditor.java | 219 ------ .../gui/page/property/ItemFlagEditor.java | 136 ---- .../bukkit/gui/page/property/LoreEditor.java | 187 ----- .../gui/page/property/MaterialEditor.java | 151 ---- .../bukkit/gui/page/property/NBTEditor.java | 643 ------------------ .../bukkit/gui/page/property/NickEditor.java | 113 --- .../bukkit/gui/page/property/PriceEditor.java | 172 ----- .../bukkit/gui/page/property/ScoreEditor.java | 125 ---- .../bukkit/gui/page/property/SizeEditor.java | 173 ----- .../integration/BukkitIntegrationManager.java | 6 +- .../bukkit/item/BukkitItemManager.java | 18 +- .../bukkit/loot/BukkitLootManager.java | 4 +- .../requirement/BukkitRequirementManager.java | 276 ++++---- .../requirement/ConditionalElement.java | 62 -- .../bukkit/scheduler/impl/BukkitExecutor.java | 8 + .../bukkit/scheduler/impl/FoliaExecutor.java | 12 +- .../{ItemUtils.java => ItemStackUtils.java} | 29 +- core/src/main/resources/config.yml | 10 + gradle.properties | 2 +- 91 files changed, 420 insertions(+), 5956 deletions(-) delete mode 100644 common/src/main/java/net/momirealms/customfishing/common/locale/StandardLocales.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/command/feature/GUIEditorCommand.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/ChatCatcherManager.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/Icon.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/ParentPage.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/SectionPage.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/YamlPage.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/BackGroundItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/BackToFolderItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/BackToPageItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/NextPageItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/PreviousPageItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/ScrollDownItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/ScrollUpItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/AmountItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/CMDItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/DisplayNameItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/DurabilityItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/EnchantmentItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/Head64Item.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/ItemFlagItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/LoreItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/MaterialItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/NBTItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/PreventGrabItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/PriceItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/RandomDurabilityItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/SizeItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/StackableItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/StoredEnchantmentItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/TagItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/UnbreakableItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/DisableGameItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/DisableStatsItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/InstantGameItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/NickItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/ScoreItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/ShowInFinderItem.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/file/FileSelector.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/AbstractSectionEditor.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/BaitEditor.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/HookEditor.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/ItemSelector.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/RodEditor.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/SectionEditor.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/AmountEditor.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/CustomModelDataEditor.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/DisplayNameEditor.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/DurabilityEditor.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/EnchantmentEditor.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/ItemFlagEditor.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/LoreEditor.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/MaterialEditor.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/NBTEditor.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/NickEditor.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/PriceEditor.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/ScoreEditor.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/SizeEditor.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/bukkit/requirement/ConditionalElement.java rename core/src/main/java/net/momirealms/customfishing/bukkit/util/{ItemUtils.java => ItemStackUtils.java} (67%) diff --git a/api/src/main/java/net/momirealms/customfishing/api/event/FishingLootSpawnEvent.java b/api/src/main/java/net/momirealms/customfishing/api/event/FishingLootSpawnEvent.java index 0e067137..7532b2f7 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/event/FishingLootSpawnEvent.java +++ b/api/src/main/java/net/momirealms/customfishing/api/event/FishingLootSpawnEvent.java @@ -17,6 +17,7 @@ package net.momirealms.customfishing.api.event; +import net.momirealms.customfishing.api.mechanic.loot.Loot; import org.bukkit.Location; import org.bukkit.entity.Item; import org.bukkit.entity.Player; @@ -30,11 +31,13 @@ public class FishingLootSpawnEvent extends PlayerEvent implements Cancellable { private static final HandlerList handlerList = new HandlerList(); private final Location location; private final Item item; + private final Loot loot; private boolean isCancelled; - public FishingLootSpawnEvent(@NotNull Player who, Location location, Item item) { + public FishingLootSpawnEvent(@NotNull Player who, Location location, Loot loot, Item item) { super(who); this.item = item; + this.loot = loot; this.location = location; this.isCancelled = false; } @@ -57,6 +60,10 @@ public class FishingLootSpawnEvent extends PlayerEvent implements Cancellable { return item; } + public Loot getLoot() { + return loot; + } + @Override public @NotNull HandlerList getHandlers() { return handlerList; diff --git a/api/src/main/java/net/momirealms/customfishing/api/event/FishingResultEvent.java b/api/src/main/java/net/momirealms/customfishing/api/event/FishingResultEvent.java index 2b2b96ee..2dd64e43 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/event/FishingResultEvent.java +++ b/api/src/main/java/net/momirealms/customfishing/api/event/FishingResultEvent.java @@ -17,6 +17,8 @@ package net.momirealms.customfishing.api.event; +import net.momirealms.customfishing.api.mechanic.context.Context; +import net.momirealms.customfishing.api.mechanic.context.ContextKeys; import net.momirealms.customfishing.api.mechanic.loot.Loot; import org.bukkit.entity.FishHook; import org.bukkit.entity.Player; @@ -24,14 +26,9 @@ import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; import org.bukkit.event.player.PlayerEvent; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.util.Map; import java.util.Optional; -/** - * This class represents an event that occurs when a player gets a result from fishing. - */ public class FishingResultEvent extends PlayerEvent implements Cancellable { private static final HandlerList handlerList = new HandlerList(); @@ -39,21 +36,12 @@ public class FishingResultEvent extends PlayerEvent implements Cancellable { private final Result result; private final Loot loot; private final FishHook fishHook; - private final Map args; + private Context context; - /** - * Constructs a new FishingResultEvent. - * - * @param who The player who triggered the event. - * @param result The result of the fishing action (SUCCESS or FAILURE). - * @param loot The loot received from fishing. - * @param args A map of placeholders and their corresponding values. - */ - public FishingResultEvent(@NotNull Player who, Result result, FishHook fishHook, Loot loot, Map args) { - super(who); + public FishingResultEvent(@NotNull Context context, Result result, FishHook fishHook, Loot loot) { + super(context.getHolder()); this.result = result; this.loot = loot; - this.args = args; this.fishHook = fishHook; } @@ -77,87 +65,31 @@ public class FishingResultEvent extends PlayerEvent implements Cancellable { isCancelled = cancel; } - /** - * Gets the value associated with a specific argument key. - * Usage example event.getArg("{x}") - * - * @param key The argument key enclosed in curly braces, e.g., "{amount}". - * @return The value associated with the argument key, or null if not found. - */ - public String getArg(String key) { - return args.get(key); - } - - /** - * Set the value associated with a specific argument key. - * @param key key - * @param value value - * @return previous value - */ - @Nullable - public String setArg(String key, String value) { - return args.put(key, value); - } - - /** - * Gets the result of the fishing action. - * - * @return The fishing result, which can be either SUCCESS or FAILURE. - */ public Result getResult() { return result; } - /** - * Get the fish hook entity. - * - * @return fish hook - */ public FishHook getFishHook() { return fishHook; } - /** - * Gets the loot received from fishing. - * - * @return The loot obtained from the fishing action. - */ public Loot getLoot() { return loot; } - /** - * Gets the amount of loot received. - * This value is determined by the "multiple-loot" effect. - * If you want to get the amount of item spawned, listen to FishingLootSpawnEvent - * - * @return The amount of loot received, or 1 if the loot is block or entity - */ - public int getAmount() { - return Integer.parseInt(Optional.ofNullable(getArg("{amount}")).orElse("1")); - } - - /** - * Set the loot amount (Only works for items) - * - * @param amount amount - */ - public void setAmount(int amount) { - setArg("{amount}", String.valueOf(amount)); - } - - /** - * Set the score to get in competition - * - * @param score score - */ public void setScore(double score) { - setArg("{SCORE}", String.valueOf(score)); + context.arg(ContextKeys.CUSTOM_SCORE, score); + } + + public Context getContext() { + return context; + } + + public int getAmount() { + if (result == Result.FAILURE) return 0; + return Optional.ofNullable(context.arg(ContextKeys.AMOUNT)).orElse(1); } - /** - * An enumeration representing possible fishing results (SUCCESS or FAILURE). - */ public enum Result { SUCCESS, FAILURE diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/competition/CompetitionGoal.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/competition/CompetitionGoal.java index 699e9286..7560c7c4 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/competition/CompetitionGoal.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/competition/CompetitionGoal.java @@ -18,7 +18,8 @@ package net.momirealms.customfishing.api.mechanic.competition; import net.kyori.adventure.util.Index; -import net.momirealms.customfishing.common.locale.StandardLocales; +import net.momirealms.customfishing.common.locale.MessageConstants; +import net.momirealms.customfishing.common.locale.TranslationManager; import net.momirealms.customfishing.common.util.RandomUtils; import org.apache.logging.log4j.util.Supplier; import org.apache.logging.log4j.util.TriConsumer; @@ -31,12 +32,12 @@ public final class CompetitionGoal { public static final CompetitionGoal CATCH_AMOUNT = new CompetitionGoal( "catch_amount", ((rankingProvider, player, score) -> rankingProvider.refreshData(player, 1)), - () -> Optional.ofNullable(StandardLocales.GOAL_CATCH_AMOUNT).orElse("catch_amount") + () -> Optional.ofNullable(TranslationManager.miniMessageTranslation(MessageConstants.GOAL_CATCH_AMOUNT.build().key())).orElse("catch_amount") ); public static final CompetitionGoal TOTAL_SCORE = new CompetitionGoal( "total_score", (RankingProvider::refreshData), - () -> Optional.ofNullable(StandardLocales.GOAL_TOTAL_SCORE).orElse("total_score") + () -> Optional.ofNullable(TranslationManager.miniMessageTranslation(MessageConstants.GOAL_TOTAL_SCORE.build().key())).orElse("total_score") ); public static final CompetitionGoal MAX_SIZE = new CompetitionGoal( "max_size", @@ -45,7 +46,7 @@ public final class CompetitionGoal { rankingProvider.setData(player, score); } }), - () -> Optional.ofNullable(StandardLocales.GOAL_MAX_SIZE).orElse("max_size") + () -> Optional.ofNullable(TranslationManager.miniMessageTranslation(MessageConstants.GOAL_MAX_SIZE.build().key())).orElse("max_size") ); public static final CompetitionGoal MIN_SIZE = new CompetitionGoal( "min_size", @@ -54,12 +55,12 @@ public final class CompetitionGoal { rankingProvider.setData(player, score); } }), - () -> Optional.ofNullable(StandardLocales.GOAL_MIN_SIZE).orElse("min_size") + () -> Optional.ofNullable(TranslationManager.miniMessageTranslation(MessageConstants.GOAL_MIN_SIZE.build().key())).orElse("min_size") ); public static final CompetitionGoal TOTAL_SIZE = new CompetitionGoal( "total_size", (RankingProvider::refreshData), - () -> Optional.ofNullable(StandardLocales.GOAL_TOTAL_SIZE).orElse("total_size") + () -> Optional.ofNullable(TranslationManager.miniMessageTranslation(MessageConstants.GOAL_TOTAL_SIZE.build().key())).orElse("total_size") ); public static final CompetitionGoal RANDOM = new CompetitionGoal( "random", diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/config/ConfigManager.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/config/ConfigManager.java index 4cef39a1..73e72b80 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/config/ConfigManager.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/config/ConfigManager.java @@ -73,6 +73,8 @@ public abstract class ConfigManager implements ConfigLoader, Reloadable { protected boolean allowSameTotemType; protected EventPriority eventPriority; protected Requirement[] mechanicRequirements; + protected Requirement[] skipGameRequirements; + protected Requirement[] autoFishingRequirements; protected boolean enableBag; protected List, Integer>> globalEffects; @@ -193,6 +195,14 @@ public abstract class ConfigManager implements ConfigLoader, Reloadable { return instance.mechanicRequirements; } + public static Requirement[] autoFishingRequirements() { + return instance.autoFishingRequirements; + } + + public static Requirement[] skipGameRequirements() { + return instance.skipGameRequirements; + } + public static List, Integer>> globalEffects() { return instance.globalEffects; } diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/config/ConfigType.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/config/ConfigType.java index d27803b7..aaa66efe 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/config/ConfigType.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/config/ConfigType.java @@ -50,7 +50,7 @@ public class ConfigType { MechanicType.register(id, MechanicType.ROD); RodConfigParser config = new RodConfigParser(id, section, functions); BukkitCustomFishingPlugin.getInstance().getItemManager().registerItem(config.getItem()); - BukkitCustomFishingPlugin.getInstance().getLootManager().registerLoot(config.getLoot()); + //BukkitCustomFishingPlugin.getInstance().getLootManager().registerLoot(config.getLoot()); BukkitCustomFishingPlugin.getInstance().getEffectManager().registerEffectModifier(config.getEffectModifier(), MechanicType.ROD); BukkitCustomFishingPlugin.getInstance().getEventManager().registerEventCarrier(config.getEventCarrier()); } @@ -62,7 +62,7 @@ public class ConfigType { MechanicType.register(id, MechanicType.BAIT); BaitConfigParser config = new BaitConfigParser(id, section, functions); BukkitCustomFishingPlugin.getInstance().getItemManager().registerItem(config.getItem()); - BukkitCustomFishingPlugin.getInstance().getLootManager().registerLoot(config.getLoot()); + //BukkitCustomFishingPlugin.getInstance().getLootManager().registerLoot(config.getLoot()); BukkitCustomFishingPlugin.getInstance().getEffectManager().registerEffectModifier(config.getEffectModifier(), MechanicType.BAIT); BukkitCustomFishingPlugin.getInstance().getEventManager().registerEventCarrier(config.getEventCarrier()); } @@ -74,7 +74,7 @@ public class ConfigType { MechanicType.register(id, MechanicType.HOOK); HookConfigParser config = new HookConfigParser(id, section, functions); BukkitCustomFishingPlugin.getInstance().getItemManager().registerItem(config.getItem()); - BukkitCustomFishingPlugin.getInstance().getLootManager().registerLoot(config.getLoot()); + //BukkitCustomFishingPlugin.getInstance().getLootManager().registerLoot(config.getLoot()); BukkitCustomFishingPlugin.getInstance().getEffectManager().registerEffectModifier(config.getEffectModifier(), MechanicType.HOOK); BukkitCustomFishingPlugin.getInstance().getEventManager().registerEventCarrier(config.getEventCarrier()); BukkitCustomFishingPlugin.getInstance().getHookManager().registerHook(config.getHook()); @@ -87,7 +87,7 @@ public class ConfigType { MechanicType.register(id, MechanicType.UTIL); UtilConfigParser config = new UtilConfigParser(id, section, functions); BukkitCustomFishingPlugin.getInstance().getItemManager().registerItem(config.getItem()); - BukkitCustomFishingPlugin.getInstance().getLootManager().registerLoot(config.getLoot()); + //BukkitCustomFishingPlugin.getInstance().getLootManager().registerLoot(config.getLoot()); BukkitCustomFishingPlugin.getInstance().getEffectManager().registerEffectModifier(config.getEffectModifier(), MechanicType.UTIL); BukkitCustomFishingPlugin.getInstance().getEventManager().registerEventCarrier(config.getEventCarrier()); } diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/context/ContextKeys.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/context/ContextKeys.java index cf13229b..c478e8ea 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/context/ContextKeys.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/context/ContextKeys.java @@ -64,6 +64,7 @@ public class ContextKeys { public static final ContextKeys REST = of("rest", String.class); public static final ContextKeys REST_FORMATTED = of("rest_formatted", String.class); public static final ContextKeys SOLD_ITEM_AMOUNT = of("sold_item_amount", Integer.class); + public static final ContextKeys AMOUNT = of("amount", Integer.class); public static final ContextKeys WEIGHT = of("0", Double.class); public static final ContextKeys TIME_LEFT = of("time_left", String.class); diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/CustomFishingHook.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/CustomFishingHook.java index 8384df19..7232beb2 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/CustomFishingHook.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/CustomFishingHook.java @@ -1,6 +1,7 @@ package net.momirealms.customfishing.api.mechanic.fishing; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; +import net.momirealms.customfishing.api.event.FishingResultEvent; import net.momirealms.customfishing.api.mechanic.action.ActionTrigger; import net.momirealms.customfishing.api.mechanic.competition.CompetitionGoal; import net.momirealms.customfishing.api.mechanic.competition.FishingCompetition; @@ -17,10 +18,12 @@ import net.momirealms.customfishing.api.mechanic.item.MechanicType; import net.momirealms.customfishing.api.mechanic.loot.Loot; import net.momirealms.customfishing.api.mechanic.loot.LootType; import net.momirealms.customfishing.api.mechanic.requirement.RequirementManager; +import net.momirealms.customfishing.api.util.EventUtils; import net.momirealms.customfishing.common.helper.AdventureHelper; import net.momirealms.customfishing.common.plugin.scheduler.SchedulerTask; import net.momirealms.customfishing.common.util.TriConsumer; import net.momirealms.customfishing.common.util.TriFunction; +import net.momirealms.sparrow.heart.SparrowHeart; import org.bukkit.Statistic; import org.bukkit.entity.FishHook; import org.bukkit.entity.Item; @@ -141,7 +144,7 @@ public class CustomFishingHook { } public void destroy() { - task.cancel(); + if (task != null) task.cancel(); if (hook.isValid()) hook.remove(); if (hookMechanic != null) hookMechanic.destroy(); } @@ -165,24 +168,42 @@ public class CustomFishingHook { if (hookMechanic != null) { if (!hookMechanic.isHooked()) { gears.trigger(ActionTrigger.REEL, context); - destroy(); + end(); } else { - if (nextLoot.disableGame()) { + if (nextLoot.disableGame() || RequirementManager.isSatisfied(context, ConfigManager.skipGameRequirements())) { handleSuccessfulFishing(); - destroy(); + end(); } else { handleSuccessfulFishing(); - destroy(); + end(); } } } else { gears.trigger(ActionTrigger.REEL, context); - destroy(); + end(); } } + private void end() { + plugin.getFishingManager().destroy(context.getHolder().getUniqueId()); + } + public void onBite() { + plugin.getEventManager().trigger(context, nextLoot.id(), MechanicType.getTypeByID(nextLoot.id()), ActionTrigger.BITE); gears.trigger(ActionTrigger.BITE, context); + if (RequirementManager.isSatisfied(context, ConfigManager.autoFishingRequirements())) { + handleSuccessfulFishing(); + SparrowHeart.getInstance().swingHand(context.getHolder(), gears.getRodSlot()); + end(); + scheduleNextFishing(); + } + if (nextLoot.instantGame()) { + + } + } + + private void scheduleNextFishing() { + } public void onLand() { @@ -190,10 +211,12 @@ public class CustomFishingHook { } public void onEscape() { + plugin.getEventManager().trigger(context, nextLoot.id(), MechanicType.getTypeByID(nextLoot.id()), ActionTrigger.ESCAPE); gears.trigger(ActionTrigger.ESCAPE, context); } public void onLure() { + plugin.getEventManager().trigger(context, nextLoot.id(), MechanicType.getTypeByID(nextLoot.id()), ActionTrigger.LURE); gears.trigger(ActionTrigger.LURE, context); } @@ -206,9 +229,7 @@ public class CustomFishingHook { context.arg(ContextKeys.HOOK_Z, hook.getLocation().getBlockZ()); gears.trigger(ActionTrigger.FAILURE, context); - - String id = context.arg(ContextKeys.ID); - BukkitCustomFishingPlugin.getInstance().getEventManager().trigger(context, id, MechanicType.getTypeByID(id), ActionTrigger.FAILURE); + plugin.getEventManager().trigger(context, nextLoot.id(), MechanicType.getTypeByID(nextLoot.id()), ActionTrigger.FAILURE); } private void handleSuccessfulFishing() { @@ -222,43 +243,55 @@ public class CustomFishingHook { LootType lootType = context.arg(ContextKeys.LOOT); Objects.requireNonNull(lootType, "Missing loot type"); Objects.requireNonNull(tempFinalEffect, "Missing final effects"); + + int amount; + if (lootType == LootType.ITEM) { + amount = (int) tempFinalEffect.multipleLootChance(); + amount += Math.random() < (tempFinalEffect.multipleLootChance() - amount) ? 2 : 1; + } else { + amount = 1; + } + // set the amount of loot + context.arg(ContextKeys.AMOUNT, amount); + + FishingResultEvent event = new FishingResultEvent(context, FishingResultEvent.Result.SUCCESS, hook, nextLoot); + if (EventUtils.fireAndCheckCancel(event)) { + return; + } + switch (lootType) { case ITEM -> { - int amount = (int) tempFinalEffect.multipleLootChance(); - amount += Math.random() < (tempFinalEffect.multipleLootChance() - amount) ? 2 : 1; for (int i = 0; i < amount; i++) { plugin.getScheduler().sync().runLater(() -> { Item item = plugin.getItemManager().dropItemLoot(context, gears.getItem(FishingGears.GearType.ROD).stream().findAny().orElseThrow().right(), hook); - if (item != null) { - if (Objects.equals(context.arg(ContextKeys.NICK), "UNDEFINED")) { - ItemStack stack = item.getItemStack(); - Optional displayName = plugin.getItemManager().wrap(stack).displayName(); - if (displayName.isPresent()) { - context.arg(ContextKeys.NICK, AdventureHelper.jsonToMiniMessage(displayName.get())); - } else { - context.arg(ContextKeys.NICK, ""); - } + if (item != null && Objects.equals(context.arg(ContextKeys.NICK), "UNDEFINED")) { + ItemStack stack = item.getItemStack(); + Optional displayName = plugin.getItemManager().wrap(stack).displayName(); + if (displayName.isPresent()) { + context.arg(ContextKeys.NICK, AdventureHelper.jsonToMiniMessage(displayName.get())); + } else { + context.arg(ContextKeys.NICK, ""); } } - handleSuccess(); + doSuccessActions(); }, (long) ConfigManager.multipleLootSpawnDelay() * i, hook.getLocation()); } } case BLOCK -> { - BukkitCustomFishingPlugin.getInstance().getBlockManager().summonBlockLoot(context); - handleSuccess(); + plugin.getBlockManager().summonBlockLoot(context); + doSuccessActions(); } case ENTITY -> { - BukkitCustomFishingPlugin.getInstance().getEntityManager().summonEntityLoot(context); - handleSuccess(); + plugin.getEntityManager().summonEntityLoot(context); + doSuccessActions(); } } gears.trigger(ActionTrigger.SUCCESS, context); } - private void handleSuccess() { - FishingCompetition competition = BukkitCustomFishingPlugin.getInstance().getCompetitionManager().getOnGoingCompetition(); + private void doSuccessActions() { + FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition(); if (competition != null && RequirementManager.isSatisfied(context, competition.getConfig().joinRequirements())) { Double customScore = context.arg(ContextKeys.CUSTOM_SCORE); if (customScore != null) { @@ -292,15 +325,15 @@ public class CustomFishingHook { String id = context.arg(ContextKeys.ID); Player player = context.getHolder(); MechanicType type = MechanicType.getTypeByID(id); - BukkitCustomFishingPlugin.getInstance().getEventManager().trigger(context, id, type, ActionTrigger.SUCCESS); + plugin.getEventManager().trigger(context, id, type, ActionTrigger.SUCCESS); player.setStatistic(Statistic.FISH_CAUGHT, player.getStatistic(Statistic.FISH_CAUGHT) + 1); if (!nextLoot.disableStats()) { - BukkitCustomFishingPlugin.getInstance().getStorageManager().getOnlineUser(player.getUniqueId()).ifPresent( + plugin.getStorageManager().getOnlineUser(player.getUniqueId()).ifPresent( userData -> { userData.statistics().addAmount(id, 1); Optional.ofNullable(context.arg(ContextKeys.SIZE)).ifPresent(size -> { if (userData.statistics().updateSize(id, size)) { - BukkitCustomFishingPlugin.getInstance().getEventManager().trigger(context, id, type, ActionTrigger.NEW_SIZE_RECORD); + plugin.getEventManager().trigger(context, id, type, ActionTrigger.NEW_SIZE_RECORD); } }); } diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/FishingGears.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/FishingGears.java index 43cb902b..f2d18aae 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/FishingGears.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/FishingGears.java @@ -11,9 +11,9 @@ import net.momirealms.customfishing.api.mechanic.requirement.RequirementManager; import net.momirealms.customfishing.api.storage.user.UserData; import net.momirealms.customfishing.common.util.Pair; import net.momirealms.customfishing.common.util.TriConsumer; +import net.momirealms.sparrow.heart.feature.inventory.HandSlot; import org.bukkit.GameMode; import org.bukkit.Material; -import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; @@ -42,6 +42,7 @@ public class FishingGears { private final HashMap>> gears = new HashMap<>(); private final ArrayList modifiers = new ArrayList<>(); private boolean canFish = true; + private HandSlot rodSlot; public static void fishingGearsConsumers(BiConsumer, FishingGears> fishingGearsConsumers) { FishingGears.fishingGearsConsumers = fishingGearsConsumers; @@ -70,6 +71,10 @@ public class FishingGears { return modifiers; } + public HandSlot getRodSlot() { + return rodSlot; + } + @NotNull public Collection> getItem(GearType type) { return gears.getOrDefault(type, List.of()); @@ -86,6 +91,7 @@ public class FishingGears { String rodID = BukkitCustomFishingPlugin.getInstance().getItemManager().getItemID(rodOnMainHand ? mainHandItem : offHandItem); fishingGears.gears.put(GearType.ROD, List.of(Pair.of(rodID, rodOnMainHand ? mainHandItem : offHandItem))); context.arg(ContextKeys.ROD, rodID); + fishingGears.rodSlot = rodOnMainHand ? HandSlot.MAIN : HandSlot.OFF; BukkitCustomFishingPlugin.getInstance().getEffectManager().getEffectModifier(rodID, MechanicType.ROD).ifPresent(fishingGears.modifiers::add); // set enchantments diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/item/CustomFishingItemImpl.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/item/CustomFishingItemImpl.java index b3358401..1701aa4f 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/item/CustomFishingItemImpl.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/item/CustomFishingItemImpl.java @@ -7,6 +7,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import java.util.List; +import java.util.Optional; import java.util.TreeSet; import java.util.function.BiConsumer; @@ -27,7 +28,7 @@ public class CustomFishingItemImpl implements CustomFishingItem { @Override public String material() { - return material; + return Optional.ofNullable(material).orElse("AIR"); } @Override diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/loot/Loot.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/loot/Loot.java index ad5ad2c5..b32fd6ee 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/loot/Loot.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/loot/Loot.java @@ -25,10 +25,13 @@ import org.jetbrains.annotations.NotNull; public interface Loot { - boolean DEFAULT_INSTANT_GAME = false; - boolean DEFAULT_DISABLE_GAME = false; - boolean DEFAULT_DISABLE_STATS = false; - boolean DEFAULT_SHOW_IN_FINDER = false; + class DefaultProperties { + public static boolean DEFAULT_INSTANT_GAME = false; + public static boolean DEFAULT_DISABLE_GAME = false; + public static boolean DEFAULT_DISABLE_STATS = false; + public static boolean DEFAULT_SHOW_IN_FINDER = false; + } + LootType DEFAULT_TYPE = LootType.ITEM; MathValue DEFAULT_SCORE = MathValue.plain(0); diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/loot/LootImpl.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/loot/LootImpl.java index 4e0491dc..44858298 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/loot/LootImpl.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/loot/LootImpl.java @@ -97,10 +97,10 @@ public class LootImpl implements Loot { public static class BuilderImpl implements Builder { private LootType type = DEFAULT_TYPE; - private boolean instantGame = DEFAULT_INSTANT_GAME; - private boolean disableGame = DEFAULT_DISABLE_GAME; - private boolean disableStatistics = DEFAULT_DISABLE_STATS; - private boolean showInFinder = DEFAULT_SHOW_IN_FINDER; + private boolean instantGame = Loot.DefaultProperties.DEFAULT_INSTANT_GAME; + private boolean disableGame = Loot.DefaultProperties.DEFAULT_DISABLE_GAME; + private boolean disableStatistics = Loot.DefaultProperties.DEFAULT_DISABLE_STATS; + private boolean showInFinder = Loot.DefaultProperties.DEFAULT_SHOW_IN_FINDER; private String id = null; private String nick = "UNDEFINED"; private StatisticsKeys statisticsKeys = null; diff --git a/common/src/main/java/net/momirealms/customfishing/common/locale/MessageConstants.java b/common/src/main/java/net/momirealms/customfishing/common/locale/MessageConstants.java index 10f5f76f..aa598731 100644 --- a/common/src/main/java/net/momirealms/customfishing/common/locale/MessageConstants.java +++ b/common/src/main/java/net/momirealms/customfishing/common/locale/MessageConstants.java @@ -5,6 +5,21 @@ import net.kyori.adventure.text.TranslatableComponent; public interface MessageConstants { + TranslatableComponent.Builder COMPETITION_NO_PLAYER = Component.translatable().key("competition.no_player");; + TranslatableComponent.Builder COMPETITION_NO_SCORE = Component.translatable().key("competition.no_score"); + TranslatableComponent.Builder COMPETITION_NO_RANK = Component.translatable().key("competition.no_rank"); + + TranslatableComponent.Builder GOAL_TOTAL_SIZE = Component.translatable().key("competition.goal.total_size"); + TranslatableComponent.Builder GOAL_CATCH_AMOUNT = Component.translatable().key("competition.goal.catch_amount"); + TranslatableComponent.Builder GOAL_TOTAL_SCORE = Component.translatable().key("competition.goal.total_score"); + TranslatableComponent.Builder GOAL_MAX_SIZE = Component.translatable().key("competition.goal.max_size"); + TranslatableComponent.Builder GOAL_MIN_SIZE = Component.translatable().key("competition.goal.min_size"); + + TranslatableComponent.Builder FORMAT_SECOND = Component.translatable().key("format.second"); + TranslatableComponent.Builder FORMAT_MINUTE = Component.translatable().key("format.minute"); + TranslatableComponent.Builder FORMAT_HOUR = Component.translatable().key("format.hour"); + TranslatableComponent.Builder FORMAT_DAY = Component.translatable().key("format.day"); + TranslatableComponent.Builder COMMAND_PREFIX = Component.translatable().key("command.prefix"); TranslatableComponent.Builder COMMAND_RELOAD_SUCCESS = Component.translatable().key("command.reload.success"); TranslatableComponent.Builder COMMAND_ITEM_FAILURE_NOT_EXIST = Component.translatable().key("command.item.failure.not_exist"); diff --git a/common/src/main/java/net/momirealms/customfishing/common/locale/MiniMessageTranslationRegistry.java b/common/src/main/java/net/momirealms/customfishing/common/locale/MiniMessageTranslationRegistry.java index fe1dfa58..f6eb877c 100644 --- a/common/src/main/java/net/momirealms/customfishing/common/locale/MiniMessageTranslationRegistry.java +++ b/common/src/main/java/net/momirealms/customfishing/common/locale/MiniMessageTranslationRegistry.java @@ -24,6 +24,8 @@ public interface MiniMessageTranslationRegistry extends Translator { boolean contains(@NotNull String key); + String miniMessageTranslation(@NotNull String key, @NotNull Locale locale); + void defaultLocale(@NotNull Locale defaultLocale); default void registerAll(final @NotNull Locale locale, final @NotNull Map bundle) { diff --git a/common/src/main/java/net/momirealms/customfishing/common/locale/MiniMessageTranslationRegistryImpl.java b/common/src/main/java/net/momirealms/customfishing/common/locale/MiniMessageTranslationRegistryImpl.java index bed2824d..811a96b4 100644 --- a/common/src/main/java/net/momirealms/customfishing/common/locale/MiniMessageTranslationRegistryImpl.java +++ b/common/src/main/java/net/momirealms/customfishing/common/locale/MiniMessageTranslationRegistryImpl.java @@ -74,7 +74,7 @@ public class MiniMessageTranslationRegistryImpl implements Examinable, MiniMessa if (miniMessageString == null) { return null; } - if (miniMessageString.equals("")) { + if (miniMessageString.isEmpty()) { return Component.empty(); } final Component resultingComponent; @@ -90,6 +90,15 @@ public class MiniMessageTranslationRegistryImpl implements Examinable, MiniMessa } } + @Override + public String miniMessageTranslation(@NotNull String key, @NotNull Locale locale) { + Translation translation = translations.get(key); + if (translation == null) { + return null; + } + return translation.translate(locale); + } + @Override public @NotNull TriState hasAnyTranslations() { if (!this.translations.isEmpty()) { diff --git a/common/src/main/java/net/momirealms/customfishing/common/locale/StandardLocales.java b/common/src/main/java/net/momirealms/customfishing/common/locale/StandardLocales.java deleted file mode 100644 index 54e61596..00000000 --- a/common/src/main/java/net/momirealms/customfishing/common/locale/StandardLocales.java +++ /dev/null @@ -1,128 +0,0 @@ -package net.momirealms.customfishing.common.locale; - -public class StandardLocales { - - public static String COMPETITION_NO_PLAYER = "No Player"; - public static String COMPETITION_NO_SCORE = "No Score"; - public static String COMPETITION_NO_RANK = "No Rank"; - - public static String GOAL_TOTAL_SIZE; - public static String GOAL_CATCH_AMOUNT; - public static String GOAL_TOTAL_SCORE; - public static String GOAL_MAX_SIZE; - public static String GOAL_MIN_SIZE; - - public static String FORMAT_SECOND = "s"; - public static String FORMAT_MINUTE = "m"; - public static String FORMAT_HOUR = "h"; - - public static String COMMAND_PREFIX; - public static String COMMAND_RELOAD; - public static String COMMAND_COMPETITION_NOT_EXISTS; - public static String COMMAND_N0_COMPETITION_ONGOING; - public static String COMMAND_END_COMPETITION; - public static String COMMAND_STOP_COMPETITION; - public static String COMMAND_ITEM_NOT_EXISTS; - public static String COMMAND_GET_ITEM; - public static String COMMAND_GIVE_ITEM; - public static String COMMAND_NEVER_PLAYED; - public static String COMMAND_UNSAFE_MODIFICATION; - public static String COMMAND_DATA_NOT_LOAD; - public static String COMMAND_MARKET_OPEN; - public static String COMMAND_FISHING_BAG_OPEN; - public static String COMMAND_POSSIBLE_LOOTS_SPLIT_CHAR; - public static String COMMAND_POSSIBLE_LOOTS; - - public static String GUI_SCROLL_DOWN; - public static String GUI_SCROLL_UP; - public static String GUI_CANNOT_SCROLL_UP; - public static String GUI_CANNOT_SCROLL_DOWN; - public static String GUI_NEXT_PAGE; - public static String GUI_GOTO_NEXT_PAGE; - public static String GUI_CANNOT_GOTO_NEXT_PAGE; - public static String GUI_PREVIOUS_PAGE; - public static String GUI_GOTO_PREVIOUS_PAGE; - public static String GUI_CANNOT_GOTO_PREVIOUS_PAGE; - public static String GUI_BACK_TO_PARENT_PAGE; - public static String GUI_BACK_TO_PARENT_FOLDER; - public static String GUI_CURRENT_VALUE; - public static String GUI_CLICK_TO_TOGGLE; - public static String GUI_LEFT_CLICK_EDIT; - public static String GUI_RIGHT_CLICK_RESET; - public static String GUI_RIGHT_CLICK_DELETE; - public static String GUI_LOOT_SHOW_IN_FINDER; - public static String GUI_LOOT_SCORE; - public static String GUI_LOOT_NICK; - public static String GUI_LOOT_INSTANT_GAME; - public static String GUI_LOOT_DISABLE_STATS; - public static String GUI_LOOT_DISABLE_GAME; - public static String GUI_ITEM_AMOUNT; - public static String GUI_ITEM_MODEL_DATA; - public static String GUI_ITEM_DISPLAY_NAME; - public static String GUI_ITEM_DURABILITY; - public static String GUI_ITEM_ENCHANTMENT; - public static String GUI_ITEM_HEAD64; - public static String GUI_ITEM_FLAG; - public static String GUI_ITEM_LORE; - public static String GUI_ITEM_MATERIAL; - public static String GUI_ITEM_NBT; - public static String GUI_ITEM_PREVENT_GRAB; - public static String GUI_ITEM_PRICE; - public static String GUI_ITEM_PRICE_BASE; - public static String GUI_ITEM_PRICE_BONUS; - public static String GUI_ITEM_RANDOM_DURABILITY; - public static String GUI_ITEM_SIZE; - public static String GUI_ITEM_STACKABLE; - public static String GUI_ITEM_STORED_ENCHANTMENT; - public static String GUI_ITEM_TAG; - public static String GUI_ITEM_UNBREAKABLE; - public static String GUI_DELETE_PROPERTY; - public static String GUI_NEW_VALUE; - public static String GUI_CLICK_CONFIRM; - public static String GUI_INVALID_NUMBER; - public static String GUI_ILLEGAL_FORMAT; - public static String GUI_TITLE_AMOUNT; - public static String GUI_TITLE_MODEL_DATA; - public static String GUI_TITLE_DISPLAY_NAME; - public static String GUI_NEW_DISPLAY_NAME; - public static String GUI_TITLE_CUSTOM_DURABILITY; - public static String GUI_TITLE_ENCHANTMENT; - public static String GUI_TITLE_STORED_ENCHANTMENT; - public static String GUI_SELECT_ONE_ENCHANTMENT; - public static String GUI_ADD_NEW_ENCHANTMENT; - public static String GUI_TITLE_ITEM_FLAG; - public static String GUI_TITLE_LORE; - public static String GUI_ADD_NEW_LORE; - public static String GUI_SELECT_ONE_LORE; - public static String GUI_TITLE_MATERIAL; - public static String GUI_TITLE_NBT_COMPOUND; - public static String GUI_TITLE_NBT_LIST; - public static String GUI_TITLE_NBT_KEY; - public static String GUI_NBT_INVALID_KEY; - public static String GUI_RIGHT_CLICK_CANCEL; - public static String GUI_NBT_ADD_COMPOUND; - public static String GUI_NBT_ADD_LIST; - public static String GUI_NBT_ADD_VALUE; - public static String GUI_NBT_PREVIEW; - public static String GUI_NBT_BACK_TO_COMPOUND; - public static String GUI_NBT_SET_VALUE_TITLE; - public static String GUI_NBT_EDIT_TITLE; - public static String GUI_NICK_TITLE; - public static String GUI_NICK_NEW; - public static String GUI_PRICE_TITLE; - public static String GUI_PRICE_BASE; - public static String GUI_PRICE_BONUS; - public static String GUI_SCORE_TITLE; - public static String GUI_SIZE_TITLE; - public static String GUI_SIZE_MIN; - public static String GUI_SIZE_MAX; - public static String GUI_SIZE_MAX_NO_LESS; - public static String GUI_SELECT_FILE; - public static String GUI_SELECT_ITEM; - public static String GUI_ADD_NEW_KEY; - public static String GUI_DUPE_INVALID_KEY; - public static String GUI_SEARCH; - public static String GUI_TEMP_NEW_KEY; - public static String GUI_SET_NEW_KEY; - public static String GUI_EDIT_KEY; -} diff --git a/common/src/main/java/net/momirealms/customfishing/common/locale/TranslationManager.java b/common/src/main/java/net/momirealms/customfishing/common/locale/TranslationManager.java index 72ecd42b..6fb29a56 100644 --- a/common/src/main/java/net/momirealms/customfishing/common/locale/TranslationManager.java +++ b/common/src/main/java/net/momirealms/customfishing/common/locale/TranslationManager.java @@ -21,6 +21,7 @@ public class TranslationManager { public static final Locale DEFAULT_LOCALE = Locale.ENGLISH; private static final List locales = List.of("en"); + private static TranslationManager instance; private final CustomFishingPlugin plugin; private final Set installed = ConcurrentHashMap.newKeySet(); @@ -30,6 +31,7 @@ public class TranslationManager { public TranslationManager(CustomFishingPlugin plugin) { this.plugin = plugin; this.translationsDirectory = this.plugin.getConfigDirectory().resolve("translations"); + instance = this; } public void reload() { @@ -49,6 +51,20 @@ public class TranslationManager { MiniMessageTranslator.translator().addSource(this.registry); } + public static String miniMessageTranslation(String key) { + return miniMessageTranslation(key, null); + } + + public static String miniMessageTranslation(String key, @Nullable Locale locale) { + if (locale == null) { + locale = Locale.getDefault(); + if (locale == null) { + locale = DEFAULT_LOCALE; + } + } + return instance.registry.miniMessageTranslation(key, locale); + } + public static Component render(Component component) { return render(component, null); } @@ -113,6 +129,7 @@ public class TranslationManager { return e instanceof IllegalArgumentException && (e.getMessage().startsWith("Invalid key") || e.getMessage().startsWith("Translation already exists")); } + @SuppressWarnings("unchecked") private Pair> loadTranslationFile(Path translationFile) { String fileName = translationFile.getFileName().toString(); String localeString = fileName.substring(0, fileName.length() - ".yml".length()); diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/BukkitCustomFishingPluginImpl.java b/core/src/main/java/net/momirealms/customfishing/bukkit/BukkitCustomFishingPluginImpl.java index 7e907c4b..04747a70 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/BukkitCustomFishingPluginImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/BukkitCustomFishingPluginImpl.java @@ -17,7 +17,6 @@ import net.momirealms.customfishing.bukkit.effect.BukkitEffectManager; import net.momirealms.customfishing.bukkit.entity.BukkitEntityManager; import net.momirealms.customfishing.bukkit.event.BukkitEventManager; import net.momirealms.customfishing.bukkit.fishing.BukkitFishingManager; -import net.momirealms.customfishing.bukkit.gui.ChatCatcherManager; import net.momirealms.customfishing.bukkit.hook.BukkitHookManager; import net.momirealms.customfishing.bukkit.integration.BukkitIntegrationManager; import net.momirealms.customfishing.bukkit.item.BukkitItemManager; @@ -51,7 +50,6 @@ public class BukkitCustomFishingPluginImpl extends BukkitCustomFishingPlugin { private final ClassPathAppender classPathAppender; private final PluginLogger logger; - private ChatCatcherManager chatCatcherManager; private BukkitCommandManager commandManager; private Consumer debugger; @@ -110,7 +108,6 @@ public class BukkitCustomFishingPluginImpl extends BukkitCustomFishingPlugin { this.bagManager = new BukkitBagManager(this); this.totemManager = new BukkitTotemManager(this); this.translationManager = new TranslationManager(this); - this.chatCatcherManager = new ChatCatcherManager(this); this.commandManager = new BukkitCommandManager(this); this.commandManager.registerDefaultFeatures(); @@ -224,8 +221,4 @@ public class BukkitCustomFishingPluginImpl extends BukkitCustomFishingPlugin { public void debug(Object message) { this.debugger.accept(message); } - - public ChatCatcherManager getChatCatcherManager() { - return chatCatcherManager; - } } diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/bag/BukkitBagManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/bag/BukkitBagManager.java index 8e158df8..d5b014a4 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/bag/BukkitBagManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/bag/BukkitBagManager.java @@ -135,33 +135,26 @@ public class BukkitBagManager implements BagManager, Listener { public void onInvClick(InventoryClickEvent event) { if (!(event.getInventory().getHolder() instanceof FishingBagHolder)) return; - ItemStack movedItem = event.getCurrentItem(); Inventory clicked = event.getClickedInventory(); - if (clicked != event.getWhoClicked().getInventory()) { if (event.getAction() != InventoryAction.HOTBAR_SWAP && event.getAction() != InventoryAction.HOTBAR_MOVE_AND_READD) { return; } movedItem = event.getWhoClicked().getInventory().getItem(event.getHotbarButton()); } - if (movedItem == null || movedItem.getType() == Material.AIR || bagWhiteListItems.contains(movedItem.getType())) return; - String id = plugin.getItemManager().getItemID(movedItem); MechanicType type = MechanicType.getTypeByID(id); if (type == null) { event.setCancelled(true); return; } - if (type == MechanicType.LOOT && bagStoreLoots) return; - if (type == MechanicType.BAIT || type == MechanicType.ROD || type == MechanicType.UTIL || type == MechanicType.HOOK) return; - event.setCancelled(true); } diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/command/BukkitCommandManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/command/BukkitCommandManager.java index 3c70a3bc..d5931a85 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/command/BukkitCommandManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/command/BukkitCommandManager.java @@ -28,7 +28,6 @@ public class BukkitCommandManager extends AbstractCommandManager new OpenMarketCommand(this), new OpenBagCommand(this), new FishingBagCommand(this), - new GUIEditorCommand(this), new EditOnlineBagCommand(this), new EditOfflineBagCommand(this) ); diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/command/feature/GUIEditorCommand.java b/core/src/main/java/net/momirealms/customfishing/bukkit/command/feature/GUIEditorCommand.java deleted file mode 100644 index 17a9ed13..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/command/feature/GUIEditorCommand.java +++ /dev/null @@ -1,33 +0,0 @@ -package net.momirealms.customfishing.bukkit.command.feature; - -import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.bukkit.command.BukkitCommandFeature; -import net.momirealms.customfishing.bukkit.gui.page.file.FileSelector; -import net.momirealms.customfishing.common.command.CustomFishingCommandManager; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.incendo.cloud.Command; -import org.incendo.cloud.CommandManager; - -import java.io.File; - -public class GUIEditorCommand extends BukkitCommandFeature { - - public GUIEditorCommand(CustomFishingCommandManager commandManager) { - super(commandManager); - } - - @Override - public Command.Builder assembleCommand(CommandManager manager, Command.Builder builder) { - return builder - .senderType(Player.class) - .handler(context -> { - new FileSelector(context.sender(), new File(BukkitCustomFishingPlugin.getInstance().getDataFolder(), "contents")); - }); - } - - @Override - public String getFeatureID() { - return "browser"; - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/competition/Competition.java b/core/src/main/java/net/momirealms/customfishing/bukkit/competition/Competition.java index 792c76b8..b3daf267 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/competition/Competition.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/competition/Competition.java @@ -32,7 +32,8 @@ import net.momirealms.customfishing.bukkit.competition.actionbar.ActionBarManage import net.momirealms.customfishing.bukkit.competition.bossbar.BossBarManager; import net.momirealms.customfishing.bukkit.competition.ranking.LocalRankingProvider; import net.momirealms.customfishing.bukkit.competition.ranking.RedisRankingProvider; -import net.momirealms.customfishing.common.locale.StandardLocales; +import net.momirealms.customfishing.common.locale.MessageConstants; +import net.momirealms.customfishing.common.locale.TranslationManager; import net.momirealms.customfishing.common.plugin.scheduler.SchedulerTask; import net.momirealms.customfishing.common.util.Pair; import org.bukkit.Bukkit; @@ -188,13 +189,13 @@ public class Competition implements FishingCompetition { this.publicContext.arg(ContextKeys.of(i + "_player", String.class), player.get()); this.publicContext.arg(ContextKeys.of(i + "_score", String.class), String.format("%.2f", this.rankingProvider.getScoreAt(i))); } else { - this.publicContext.arg(ContextKeys.of(i + "_player", String.class), StandardLocales.COMPETITION_NO_PLAYER); - this.publicContext.arg(ContextKeys.of(i + "_score", String.class), StandardLocales.COMPETITION_NO_SCORE); + this.publicContext.arg(ContextKeys.of(i + "_player", String.class), TranslationManager.miniMessageTranslation(MessageConstants.COMPETITION_NO_PLAYER.build().key())); + this.publicContext.arg(ContextKeys.of(i + "_score", String.class), TranslationManager.miniMessageTranslation(MessageConstants.COMPETITION_NO_SCORE.build().key())); } } - this.publicContext.arg(ContextKeys.HOUR, remainingTime < 3600 ? "" : (remainingTime / 3600) + StandardLocales.FORMAT_HOUR); - this.publicContext.arg(ContextKeys.MINUTE, remainingTime < 60 ? "" : (remainingTime % 3600) / 60 + StandardLocales.FORMAT_MINUTE); - this.publicContext.arg(ContextKeys.SECOND, remainingTime == 0 ? "" : remainingTime % 60 + StandardLocales.FORMAT_SECOND); + this.publicContext.arg(ContextKeys.HOUR, remainingTime < 3600 ? "" : (remainingTime / 3600) + TranslationManager.miniMessageTranslation(MessageConstants.FORMAT_HOUR.build().key())); + this.publicContext.arg(ContextKeys.MINUTE, remainingTime < 60 ? "" : (remainingTime % 3600) / 60 + TranslationManager.miniMessageTranslation(MessageConstants.FORMAT_MINUTE.build().key())); + this.publicContext.arg(ContextKeys.SECOND, remainingTime == 0 ? "" : remainingTime % 60 + TranslationManager.miniMessageTranslation(MessageConstants.FORMAT_SECOND.build().key())); this.publicContext.arg(ContextKeys.SECONDS, remainingTime); } diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/competition/actionbar/ActionBarSender.java b/core/src/main/java/net/momirealms/customfishing/bukkit/competition/actionbar/ActionBarSender.java index fae38ebf..1dc3e3fa 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/competition/actionbar/ActionBarSender.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/competition/actionbar/ActionBarSender.java @@ -25,7 +25,8 @@ import net.momirealms.customfishing.api.mechanic.context.ContextKeys; import net.momirealms.customfishing.api.mechanic.misc.value.DynamicText; import net.momirealms.customfishing.bukkit.competition.Competition; import net.momirealms.customfishing.common.helper.AdventureHelper; -import net.momirealms.customfishing.common.locale.StandardLocales; +import net.momirealms.customfishing.common.locale.MessageConstants; +import net.momirealms.customfishing.common.locale.TranslationManager; import net.momirealms.customfishing.common.plugin.scheduler.SchedulerTask; import org.bukkit.entity.Player; @@ -65,7 +66,7 @@ public class ActionBarSender { private void updatePrivatePlaceholders() { this.privateContext.arg(ContextKeys.SCORE_FORMATTED, String.format("%.2f", competition.getRanking().getPlayerScore(player.getName()))); int rank = competition.getRanking().getPlayerRank(player.getName()); - this.privateContext.arg(ContextKeys.RANK, rank != -1 ? String.valueOf(rank) : StandardLocales.COMPETITION_NO_RANK); + this.privateContext.arg(ContextKeys.RANK, rank != -1 ? String.valueOf(rank) : TranslationManager.miniMessageTranslation(MessageConstants.COMPETITION_NO_RANK.build().key())); this.privateContext.combine(competition.getPublicContext()); } diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/competition/bossbar/BossBarSender.java b/core/src/main/java/net/momirealms/customfishing/bukkit/competition/bossbar/BossBarSender.java index 1ce345a4..c6489877 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/competition/bossbar/BossBarSender.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/competition/bossbar/BossBarSender.java @@ -26,7 +26,8 @@ import net.momirealms.customfishing.api.mechanic.context.ContextKeys; import net.momirealms.customfishing.api.mechanic.misc.value.DynamicText; import net.momirealms.customfishing.bukkit.competition.Competition; import net.momirealms.customfishing.common.helper.AdventureHelper; -import net.momirealms.customfishing.common.locale.StandardLocales; +import net.momirealms.customfishing.common.locale.MessageConstants; +import net.momirealms.customfishing.common.locale.TranslationManager; import net.momirealms.customfishing.common.plugin.scheduler.SchedulerTask; import org.bukkit.entity.Player; @@ -75,7 +76,7 @@ public class BossBarSender { private void updatePrivatePlaceholders() { this.privateContext.arg(ContextKeys.SCORE_FORMATTED, String.format("%.2f", competition.getRanking().getPlayerScore(player.getName()))); int rank = competition.getRanking().getPlayerRank(player.getName()); - this.privateContext.arg(ContextKeys.RANK, rank != -1 ? String.valueOf(rank) : StandardLocales.COMPETITION_NO_RANK); + this.privateContext.arg(ContextKeys.RANK, rank != -1 ? String.valueOf(rank) : TranslationManager.miniMessageTranslation(MessageConstants.COMPETITION_NO_RANK.build().key())); this.privateContext.combine(competition.getPublicContext()); } diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/config/BukkitConfigManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/config/BukkitConfigManager.java index 140440ab..56ac879d 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/config/BukkitConfigManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/config/BukkitConfigManager.java @@ -18,6 +18,7 @@ import net.momirealms.customfishing.api.mechanic.effect.Effect; import net.momirealms.customfishing.api.mechanic.effect.EffectProperties; import net.momirealms.customfishing.api.mechanic.event.EventManager; import net.momirealms.customfishing.api.mechanic.item.MechanicType; +import net.momirealms.customfishing.api.mechanic.loot.Loot; import net.momirealms.customfishing.api.mechanic.misc.value.MathValue; import net.momirealms.customfishing.api.mechanic.misc.value.TextValue; import net.momirealms.customfishing.api.mechanic.requirement.Requirement; @@ -92,10 +93,17 @@ public class BukkitConfigManager extends ConfigManager { .builder() .setVersioning(new BasicVersioning("config-version")) .addIgnoredRoute(configVersion, "mechanics.mechanic-requirements", '.') + .addIgnoredRoute(configVersion, "mechanics.skip-game-requirements", '.') + .addIgnoredRoute(configVersion, "mechanics.auto-fishing-requirements", '.') .addIgnoredRoute(configVersion, "mechanics.global-events", '.') .addIgnoredRoute(configVersion, "mechanics.global-effects", '.') + .addIgnoredRoute(configVersion, "mechanics.fishing-bag.collect-requirements", '.') .addIgnoredRoute(configVersion, "mechanics.fishing-bag.collect-actions", '.') .addIgnoredRoute(configVersion, "mechanics.fishing-bag.full-actions", '.') + .addIgnoredRoute(configVersion, "mechanics.market.item-price", '.') + .addIgnoredRoute(configVersion, "mechanics.market.sell-all-icons", '.') + .addIgnoredRoute(configVersion, "mechanics.market.sell-icons", '.') + .addIgnoredRoute(configVersion, "mechanics.market.decorative-icons", '.') .addIgnoredRoute(configVersion, "other-settings.placeholder-register", '.') .build() ); @@ -147,11 +155,18 @@ public class BukkitConfigManager extends ConfigManager { eventPriority = EventPriority.valueOf(config.getString("other-settings.event-priority", "NORMAL").toUpperCase(Locale.ENGLISH)); mechanicRequirements = plugin.getRequirementManager().parseRequirements(config.getSection("mechanics.mechanic-requirements"), true); + skipGameRequirements = plugin.getRequirementManager().parseRequirements(config.getSection("mechanics.skip-game-requirements"), true); + autoFishingRequirements = plugin.getRequirementManager().parseRequirements(config.getSection("mechanics.auto-fishing-requirements"), true); enableBag = config.getBoolean("mechanics.fishing-bag.enable", true); multipleLootSpawnDelay = config.getInt("mechanics.multiple-loot-spawn-delay", 4); + Loot.DefaultProperties.DEFAULT_DISABLE_GAME = config.getBoolean("mechanics.global-loot-property.disable-game", false); + Loot.DefaultProperties.DEFAULT_DISABLE_STATS = config.getBoolean("mechanics.global-loot-property.disable-stat", false); + Loot.DefaultProperties.DEFAULT_INSTANT_GAME = config.getBoolean("mechanics.global-loot-property.instant-game", false); + Loot.DefaultProperties.DEFAULT_SHOW_IN_FINDER = config.getBoolean("mechanics.global-loot-property.show-in-fishfinder", true); + Section placeholderSection = config.getSection("other-settings.placeholder-register"); if (placeholderSection != null) { for (Map.Entry entry : placeholderSection.getStringRouteMappedValues(false).entrySet()) { diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/fishing/BukkitFishingManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/fishing/BukkitFishingManager.java index 915813d1..f874e717 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/fishing/BukkitFishingManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/fishing/BukkitFishingManager.java @@ -25,6 +25,7 @@ import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerFishEvent; import org.bukkit.event.player.PlayerItemHeldEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerSwapHandItemsEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.persistence.PersistentDataType; @@ -121,6 +122,11 @@ public class BukkitFishingManager implements FishingManager, Listener { } } + @EventHandler + public void onQuit(PlayerQuitEvent event) { + this.destroy(event.getPlayer().getUniqueId()); + } + private void selectState(PlayerFishEvent event) { switch (event.getState()) { case FISHING -> onCastRod(event); @@ -130,6 +136,7 @@ public class BukkitFishingManager implements FishingManager, Listener { case BITE -> onBite(event); case IN_GROUND -> onInGround(event); case FAILED_ATTEMPT -> onFailedAttempt(event); + // case LURED 1.20.5+ } } diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/ChatCatcherManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/ChatCatcherManager.java deleted file mode 100644 index 8c0c32c5..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/ChatCatcherManager.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui; - -import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.common.util.Pair; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerQuitEvent; - -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; - -public class ChatCatcherManager implements Listener { - - private final BukkitCustomFishingPlugin plugin; - private final ConcurrentHashMap> pageMap; - - public ChatCatcherManager(BukkitCustomFishingPlugin plugin) { - this.pageMap = new ConcurrentHashMap<>(); - this.plugin = plugin; - } - - public void load() { - Bukkit.getPluginManager().registerEvents(this, plugin.getBoostrap()); - } - - public void unload() { - this.pageMap.clear(); - HandlerList.unregisterAll(this); - } - - public void disable() { - unload(); - } - - public void catchMessage(Player player, String key, SectionPage page) { - this.pageMap.put(player.getUniqueId(), Pair.of(key, page)); - } - - @EventHandler - public void onQuit(PlayerQuitEvent event) { - pageMap.remove(event.getPlayer().getUniqueId()); - } - - @EventHandler - public void onChat(AsyncPlayerChatEvent event) { - final Player player = event.getPlayer(); - var uuid = player.getUniqueId(); - var pair = pageMap.remove(uuid); - if (pair == null) return; - event.setCancelled(true); - plugin.getScheduler().sync().run(() -> { - pair.right().getSection().set(pair.left(), event.getMessage()); - pair.right().reOpen(); - }, player.getLocation()); - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/Icon.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/Icon.java deleted file mode 100644 index a9626e38..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/Icon.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui; - -public interface Icon { -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/ParentPage.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/ParentPage.java deleted file mode 100644 index 2a58b566..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/ParentPage.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui; - - -import net.momirealms.customfishing.bukkit.gui.icon.BackToPageItem; -import xyz.xenondevs.invui.item.Item; - -public interface ParentPage { - - void reOpen(); - - default Item getBackItem() { - return new BackToPageItem(this); - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/SectionPage.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/SectionPage.java deleted file mode 100644 index ecbca963..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/SectionPage.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui; - -import dev.dejvokep.boostedyaml.block.implementation.Section; - -public interface SectionPage extends YamlPage { - - Section getSection(); -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/YamlPage.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/YamlPage.java deleted file mode 100644 index 76d3490d..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/YamlPage.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui; - -public interface YamlPage extends ParentPage { - - void save(); -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/BackGroundItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/BackGroundItem.java deleted file mode 100644 index 1c9fe237..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/BackGroundItem.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon; - -import net.momirealms.customfishing.bukkit.gui.Icon; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -public class BackGroundItem extends AbstractItem implements Icon { - - @Override - public ItemProvider getItemProvider() { - return new ItemBuilder(Material.BLACK_STAINED_GLASS_PANE).setDisplayName(""); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - - } -} \ No newline at end of file diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/BackToFolderItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/BackToFolderItem.java deleted file mode 100644 index 77d60480..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/BackToFolderItem.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon; - -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.Icon; -import net.momirealms.customfishing.bukkit.gui.page.file.FileSelector; -import net.momirealms.customfishing.common.helper.AdventureHelper; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -import java.io.File; -import java.util.List; - -public class BackToFolderItem extends AbstractItem implements Icon { - - private final File file; - - public BackToFolderItem(File file) { - this.file = file; - } - - @Override - public ItemProvider getItemProvider() { - if (file != null && (file.getPath().startsWith("plugins\\CustomFishing\\contents") || file.getPath().startsWith("plugins/CustomFishing/contents"))) { - return new ItemBuilder(Material.ORANGE_STAINED_GLASS_PANE) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_BACK_TO_PARENT_FOLDER.build()))) - .setLore(List.of(new ShadedAdventureComponentWrapper(AdventureHelper.miniMessage( - "<#FFA500>-> " + file.getName() - )))); - } else { - return new ItemBuilder(Material.BLACK_STAINED_GLASS_PANE); - } - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (file != null && (file.getPath().startsWith("plugins\\CustomFishing\\contents") || file.getPath().startsWith("plugins/CustomFishing/contents"))) - new FileSelector(player, file); - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/BackToPageItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/BackToPageItem.java deleted file mode 100644 index b0968aad..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/BackToPageItem.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon; - -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.ParentPage; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -public class BackToPageItem extends AbstractItem { - - private final ParentPage parentPage; - - public BackToPageItem(ParentPage parentPage) { - this.parentPage = parentPage; - } - - @Override - public ItemProvider getItemProvider() { - return new ItemBuilder(Material.ORANGE_STAINED_GLASS_PANE) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_BACK_TO_PARENT_PAGE.build()))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - parentPage.reOpen(); - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/NextPageItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/NextPageItem.java deleted file mode 100644 index b92457b6..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/NextPageItem.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon; - -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.Icon; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import xyz.xenondevs.invui.gui.PagedGui; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.controlitem.PageItem; - -public class NextPageItem extends PageItem implements Icon { - - public NextPageItem() { - super(true); - } - - @Override - public ItemProvider getItemProvider(PagedGui gui) { - ItemBuilder builder = new ItemBuilder(Material.GREEN_STAINED_GLASS_PANE); - builder.setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_NEXT_PAGE.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render( gui.hasNextPage() - ? MessageConstants.GUI_GOTO_NEXT_PAGE.arguments( - Component.text(gui.getCurrentPage() + 2), - Component.text(gui.getPageAmount()) - ).build() : - MessageConstants.GUI_CANNOT_GOTO_NEXT_PAGE.build() - ))); - return builder; - } -} \ No newline at end of file diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/PreviousPageItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/PreviousPageItem.java deleted file mode 100644 index e5ea43cf..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/PreviousPageItem.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon; - -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.Icon; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import xyz.xenondevs.invui.gui.PagedGui; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.controlitem.PageItem; - -public class PreviousPageItem extends PageItem implements Icon { - - public PreviousPageItem() { - super(false); - } - - @Override - public ItemProvider getItemProvider(PagedGui gui) { - ItemBuilder builder = new ItemBuilder(Material.RED_STAINED_GLASS_PANE); - builder.setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PREVIOUS_PAGE.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render( gui.hasPreviousPage() - ? MessageConstants.GUI_GOTO_PREVIOUS_PAGE.arguments( - Component.text(gui.getCurrentPage()), - Component.text(gui.getPageAmount()) - ).build() - : MessageConstants.GUI_CANNOT_GOTO_PREVIOUS_PAGE.build()))); - return builder; - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/ScrollDownItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/ScrollDownItem.java deleted file mode 100644 index 67a010e9..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/ScrollDownItem.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon; - -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.Icon; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import xyz.xenondevs.invui.gui.ScrollGui; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.controlitem.ScrollItem; - -public class ScrollDownItem extends ScrollItem implements Icon { - - public ScrollDownItem() { - super(1); - } - - @Override - public ItemProvider getItemProvider(ScrollGui gui) { - ItemBuilder builder = new ItemBuilder(Material.GREEN_STAINED_GLASS_PANE); - builder.setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_SCROLL_DOWN.build() - ))); - if (!gui.canScroll(1)) - builder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_CANNOT_SCROLL_DOWN.build() - ))); - return builder; - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/ScrollUpItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/ScrollUpItem.java deleted file mode 100644 index e50abc95..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/ScrollUpItem.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon; - -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.Icon; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import xyz.xenondevs.invui.gui.ScrollGui; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.controlitem.ScrollItem; - -public class ScrollUpItem extends ScrollItem implements Icon { - - public ScrollUpItem() { - super(-1); - } - - @Override - public ItemProvider getItemProvider(ScrollGui gui) { - ItemBuilder builder = new ItemBuilder(Material.RED_STAINED_GLASS_PANE); - builder.setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_SCROLL_UP.build() - ))); - if (!gui.canScroll(-1)) - builder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_CANNOT_SCROLL_UP.build() - ))); - return builder; - } -} \ No newline at end of file diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/AmountItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/AmountItem.java deleted file mode 100644 index 85464cdb..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/AmountItem.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon.property.item; - -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.page.property.AmountEditor; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -public class AmountItem extends AbstractItem { - - private final SectionPage itemPage; - - public AmountItem(SectionPage itemPage) { - this.itemPage = itemPage; - } - - @Override - public ItemProvider getItemProvider() { - ItemBuilder itemBuilder = new ItemBuilder(Material.IRON_NUGGET) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_ITEM_AMOUNT.build()))) - .setAmount(itemPage.getSection().getInt("amount", 1)); - if (itemPage.getSection().contains("amount")) { - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_CURRENT_VALUE.arguments( - Component.text(itemPage.getSection().getInt("amount")) - ).build() - ))) - .addLoreLines(""); - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_RESET.build()))); - } else { - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))); - } - return itemBuilder; - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (clickType.isLeftClick()) { - new AmountEditor(player, itemPage); - } else if (clickType.isRightClick()) { - itemPage.getSection().set("amount", null); - itemPage.save(); - itemPage.reOpen(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/CMDItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/CMDItem.java deleted file mode 100644 index 57a135ba..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/CMDItem.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon.property.item; - -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.page.property.CustomModelDataEditor; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -public class CMDItem extends AbstractItem { - - private final SectionPage itemPage; - - public CMDItem(SectionPage itemPage) { - this.itemPage = itemPage; - } - - @Override - public ItemProvider getItemProvider() { - ItemBuilder itemBuilder = new ItemBuilder(Material.GLOW_INK_SAC) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_ITEM_CUSTOM_MODEL_DATA.build() - ))); - if (itemPage.getSection().contains("custom-model-data")) { - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_CURRENT_VALUE.arguments( - Component.text(itemPage.getSection().getInt("custom-model-data")) - ).build() - ))) - .addLoreLines(""); - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_RESET.build()))); - } else { - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))); - } - return itemBuilder; - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (clickType.isLeftClick()) { - new CustomModelDataEditor(player, itemPage); - } else if (clickType.isRightClick()) { - itemPage.getSection().set("custom-model-data", null); - itemPage.save(); - itemPage.reOpen(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/DisplayNameItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/DisplayNameItem.java deleted file mode 100644 index 8d7b8a8e..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/DisplayNameItem.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon.property.item; - -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.page.property.DisplayNameEditor; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -public class DisplayNameItem extends AbstractItem { - - private final SectionPage itemPage; - - public DisplayNameItem(SectionPage itemPage) { - this.itemPage = itemPage; - } - - @Override - public ItemProvider getItemProvider() { - ItemBuilder itemBuilder = new ItemBuilder(Material.NAME_TAG) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_ITEM_DISPLAY_NAME.build()))); - if (itemPage.getSection().contains("display.name")) { - itemBuilder - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CURRENT_VALUE.arguments(Component.text(itemPage.getSection().getString("display.name", ""))).build()))) - .addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_RESET.build()))); - } else { - itemBuilder - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))); - } - return itemBuilder; - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (clickType.isLeftClick()) { - new DisplayNameEditor(player, itemPage); - } else if (clickType.isRightClick()) { - itemPage.getSection().set("display.name", null); - itemPage.save(); - itemPage.reOpen(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/DurabilityItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/DurabilityItem.java deleted file mode 100644 index 2c363084..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/DurabilityItem.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon.property.item; - -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.page.property.DurabilityEditor; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -public class DurabilityItem extends AbstractItem { - - private final SectionPage itemPage; - - public DurabilityItem(SectionPage itemPage) { - this.itemPage = itemPage; - } - - @Override - public ItemProvider getItemProvider() { - ItemBuilder itemBuilder = new ItemBuilder(Material.DIAMOND_CHESTPLATE) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_ITEM_CUSTOM_DURABILITY.build()))); - if (itemPage.getSection().contains("max-durability")) { - itemBuilder - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CURRENT_VALUE.arguments(Component.text(itemPage.getSection().getInt("max-durability"))).build()))) - .addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_RESET.build()))); - } else { - itemBuilder - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))); - } - return itemBuilder; - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (clickType.isLeftClick()) { - new DurabilityEditor(player, itemPage); - } else if (clickType.isRightClick()) { - itemPage.getSection().set("max-durability", null); - itemPage.save(); - itemPage.reOpen(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/EnchantmentItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/EnchantmentItem.java deleted file mode 100644 index e40113ce..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/EnchantmentItem.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon.property.item; - -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.page.property.EnchantmentEditor; -import net.momirealms.customfishing.common.helper.AdventureHelper; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemFlag; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -import java.util.Map; - -public class EnchantmentItem extends AbstractItem { - - private final SectionPage itemPage; - - public EnchantmentItem(SectionPage itemPage) { - this.itemPage = itemPage; - } - - @Override - public ItemProvider getItemProvider() { - ItemBuilder itemBuilder = new ItemBuilder(Material.IRON_HOE) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_ITEM_ENCHANTMENT.build()))) - .addEnchantment(Enchantment.ARROW_FIRE,1,true) - .addItemFlags(ItemFlag.HIDE_ENCHANTS); - if (itemPage.getSection().contains("enchantments")) { - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CURRENT_VALUE.build()))); - for (Map.Entry entry : itemPage.getSection().getSection("enchantments").getStringRouteMappedValues(false).entrySet()) { - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.miniMessage(" - " + entry.getKey() + ":" + entry.getValue()))); - } - itemBuilder - .addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_RESET.build()))); - } else { - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))); - } - return itemBuilder; - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (clickType.isLeftClick()) { - new EnchantmentEditor(player, itemPage, false); - } else if (clickType.isRightClick()) { - itemPage.getSection().set("enchantments", null); - itemPage.save(); - itemPage.reOpen(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/Head64Item.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/Head64Item.java deleted file mode 100644 index 15bbc83d..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/Head64Item.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon.property.item; - -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.bukkit.BukkitCustomFishingPluginImpl; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.common.helper.AdventureHelper; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -import java.util.ArrayList; - -public class Head64Item extends AbstractItem { - - private final SectionPage itemPage; - - public Head64Item(SectionPage itemPage) { - this.itemPage = itemPage; - } - - @Override - public ItemProvider getItemProvider() { - ItemBuilder itemBuilder = new ItemBuilder(Material.PLAYER_HEAD) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_ITEM_HEAD64.build()))); - if (itemPage.getSection().contains("head64")) { - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CURRENT_VALUE.build()))); - String head64 = itemPage.getSection().getString("head64", ""); - ArrayList list = new ArrayList<>(); - for (int i = 0; i < head64.length(); i += 16) { - if (i + 16 > head64.length()) { - list.add(head64.substring(i)); - } else { - list.add(head64.substring(i, i + 16)); - } - } - for (String line : list) { - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.miniMessage( - "" + line - ))); - } - itemBuilder - .addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_RESET.build()))); - } else { - itemBuilder - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))); - } - return itemBuilder; - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (clickType.isLeftClick()) { - player.closeInventory(); - BukkitCustomFishingPlugin.getInstance().getSenderFactory().wrap(player) - .sendMessage(Component.text("Input the head64 value in chat")); - ((BukkitCustomFishingPluginImpl) BukkitCustomFishingPlugin.getInstance()).getChatCatcherManager().catchMessage(player, "head64", itemPage); - } else if (clickType.isRightClick()) { - itemPage.getSection().set("head64", null); - itemPage.save(); - itemPage.reOpen(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/ItemFlagItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/ItemFlagItem.java deleted file mode 100644 index bfab7064..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/ItemFlagItem.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon.property.item; - -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.page.property.ItemFlagEditor; -import net.momirealms.customfishing.common.helper.AdventureHelper; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -public class ItemFlagItem extends AbstractItem { - - private final SectionPage itemPage; - - public ItemFlagItem(SectionPage itemPage) { - this.itemPage = itemPage; - } - - @Override - public ItemProvider getItemProvider() { - ItemBuilder itemBuilder = new ItemBuilder(Material.CYAN_BANNER) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_ITEM_FLAG.build()))); - if (itemPage.getSection().contains("item-flags")) { - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CURRENT_VALUE.build()))); - for (String lore : itemPage.getSection().getStringList("item-flags")) { - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.miniMessage(" - " + lore))); - } - itemBuilder - .addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_RESET.build()))); - } else { - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))); - } - return itemBuilder; - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (clickType.isLeftClick()) { - new ItemFlagEditor(player, itemPage); - } else if (clickType.isRightClick()) { - itemPage.getSection().set("item-flags", null); - itemPage.save(); - itemPage.reOpen(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/LoreItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/LoreItem.java deleted file mode 100644 index d7ac521a..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/LoreItem.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon.property.item; - -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.page.property.LoreEditor; -import net.momirealms.customfishing.common.helper.AdventureHelper; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -public class LoreItem extends AbstractItem { - - private final SectionPage itemPage; - - public LoreItem(SectionPage itemPage) { - this.itemPage = itemPage; - } - - @Override - public ItemProvider getItemProvider() { - ItemBuilder itemBuilder = new ItemBuilder(Material.BIRCH_SIGN) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_ITEM_LORE.build()))); - if (itemPage.getSection().contains("display.lore")) { - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CURRENT_VALUE.build()))); - for (String lore : itemPage.getSection().getStringList("display.lore")) { - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.miniMessage(" - " + lore))); - } - itemBuilder - .addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_RESET.build()))); - } else { - itemBuilder - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))); - } - return itemBuilder; - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (clickType.isLeftClick()) { - new LoreEditor(player, itemPage); - } else if (clickType.isRightClick()) { - itemPage.getSection().set("display.lore", null); - itemPage.save(); - itemPage.reOpen(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/MaterialItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/MaterialItem.java deleted file mode 100644 index d9a37cff..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/MaterialItem.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon.property.item; - -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.page.property.MaterialEditor; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -public class MaterialItem extends AbstractItem { - - private final SectionPage itemPage; - - public MaterialItem(SectionPage itemPage) { - this.itemPage = itemPage; - } - - @Override - public ItemProvider getItemProvider() { - ItemBuilder itemBuilder = new ItemBuilder(Material.COD) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_ITEM_MATERIAL.build() - ))); - if (itemPage.getSection().contains("material")) { - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_CURRENT_VALUE - .arguments(Component.text(itemPage.getSection().getString("material", "paper"))) - .build() - ))) - .addLoreLines(""); - itemBuilder - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_RESET.build()))); - } else { - itemBuilder - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))); - } - return itemBuilder; - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (clickType.isLeftClick()) { - new MaterialEditor(player, itemPage); - } else if (clickType.isRightClick()) { - itemPage.getSection().set("material", null); - itemPage.save(); - itemPage.reOpen(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/NBTItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/NBTItem.java deleted file mode 100644 index e858cce1..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/NBTItem.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon.property.item; - -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.page.property.NBTEditor; -import net.momirealms.customfishing.common.helper.AdventureHelper; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -import java.util.List; - -public class NBTItem extends AbstractItem { - - private final SectionPage itemPage; - - public NBTItem(SectionPage itemPage) { - this.itemPage = itemPage; - } - - @Override - public ItemProvider getItemProvider() { - ItemBuilder itemBuilder = new ItemBuilder(Material.COMMAND_BLOCK) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_ITEM_NBT.build()))); - var section = itemPage.getSection().getSection("nbt"); - if (section != null) { - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CURRENT_VALUE.build()))); - //TODO ConfigUtils.getReadableSection(section.getValues(false)); - for (String line : List.of("")) { - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.miniMessage(line))); - } - itemBuilder - .addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_RESET.build()))); - } else { - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))); - } - return itemBuilder; - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (clickType.isLeftClick()) { - new NBTEditor(player, itemPage); - } else if (clickType.isRightClick()) { - itemPage.getSection().set("nbt", null); - itemPage.save(); - itemPage.reOpen(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/PreventGrabItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/PreventGrabItem.java deleted file mode 100644 index 691a8476..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/PreventGrabItem.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon.property.item; - -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -public class PreventGrabItem extends AbstractItem { - - private final SectionPage itemPage; - - public PreventGrabItem(SectionPage itemPage) { - this.itemPage = itemPage; - } - - @Override - public ItemProvider getItemProvider() { - ItemBuilder itemBuilder = new ItemBuilder(Material.DRAGON_EGG) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_ITEM_PREVENT_GRAB.build()))); - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_CURRENT_VALUE.arguments( - Component.text(itemPage.getSection().getBoolean("prevent-grabbing", false)) - ).build() - ))) - .addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CLICK_TO_TOGGLE.build()))); - return itemBuilder; - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - itemPage.getSection().set("prevent-grabbing", !itemPage.getSection().getBoolean("prevent-grabbing", false)); - itemPage.save(); - itemPage.reOpen(); - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/PriceItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/PriceItem.java deleted file mode 100644 index a5eea022..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/PriceItem.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon.property.item; - -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.page.property.PriceEditor; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -public class PriceItem extends AbstractItem { - - private final SectionPage itemPage; - - public PriceItem(SectionPage itemPage) { - this.itemPage = itemPage; - } - - @Override - public ItemProvider getItemProvider() { - ItemBuilder itemBuilder = new ItemBuilder(Material.GOLD_INGOT) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_ITEM_PRICE.build()))); - if (itemPage.getSection().contains("price")) { - itemBuilder - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CURRENT_VALUE.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_ITEM_PRICE_BASE.arguments(Component.text(itemPage.getSection().getDouble("price.base"))).build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_ITEM_PRICE_BONUS.arguments(Component.text(itemPage.getSection().getDouble("price.bonus"))).build()))) - .addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_RESET.build()))); - } else { - itemBuilder - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))); - } - return itemBuilder; - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (clickType.isLeftClick()) { - new PriceEditor(player, itemPage); - } else if (clickType.isRightClick()) { - itemPage.getSection().set("price", null); - itemPage.save(); - itemPage.reOpen(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/RandomDurabilityItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/RandomDurabilityItem.java deleted file mode 100644 index 6f3c9550..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/RandomDurabilityItem.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon.property.item; - -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -public class RandomDurabilityItem extends AbstractItem { - - private final SectionPage itemPage; - - public RandomDurabilityItem(SectionPage itemPage) { - this.itemPage = itemPage; - } - - @Override - public ItemProvider getItemProvider() { - return new ItemBuilder(Material.LEATHER_BOOTS) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_ITEM_RANDOM_DURABILITY.build() - ))) - .setDamage(15) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_CURRENT_VALUE - .arguments(Component.text(itemPage.getSection().getBoolean("random-durability", false))) - .build() - ))) - .addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CLICK_TO_TOGGLE.build()))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - itemPage.getSection().set("random-durability", !itemPage.getSection().getBoolean("random-durability", false)); - itemPage.save(); - itemPage.reOpen(); - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/SizeItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/SizeItem.java deleted file mode 100644 index 3a72dc7f..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/SizeItem.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon.property.item; - -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.page.property.SizeEditor; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -public class SizeItem extends AbstractItem { - - private final SectionPage itemPage; - - public SizeItem(SectionPage itemPage) { - this.itemPage = itemPage; - } - - @Override - public ItemProvider getItemProvider() { - ItemBuilder itemBuilder = new ItemBuilder(Material.PUFFERFISH) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_ITEM_SIZE.build()))); - if (itemPage.getSection().contains("size")) { - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_CURRENT_VALUE.arguments( - Component.text(itemPage.getSection().getString("size", "")) - ).build() - ))) - .addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))).addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_RESET.build()))); - } else { - itemBuilder - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))); - } - return itemBuilder; - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (clickType.isLeftClick()) { - new SizeEditor(player, itemPage); - } else if (clickType.isRightClick()) { - itemPage.getSection().set("size", null); - itemPage.save(); - itemPage.reOpen(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/StackableItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/StackableItem.java deleted file mode 100644 index 8cfe94e6..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/StackableItem.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon.property.item; - -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -public class StackableItem extends AbstractItem { - - private final SectionPage itemPage; - - public StackableItem(SectionPage itemPage) { - this.itemPage = itemPage; - } - - @Override - public ItemProvider getItemProvider() { - ItemBuilder itemBuilder = new ItemBuilder(Material.CHEST_MINECART) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_ITEM_STACKABLE.build()))); - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_CURRENT_VALUE.arguments( - Component.text(itemPage.getSection().getBoolean("stackable", true)) - ).build() - ))) - .addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CLICK_TO_TOGGLE.build()))); - return itemBuilder; - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - itemPage.getSection().set("stackable", !itemPage.getSection().getBoolean("stackable", true)); - itemPage.save(); - itemPage.reOpen(); - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/StoredEnchantmentItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/StoredEnchantmentItem.java deleted file mode 100644 index 7e26a553..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/StoredEnchantmentItem.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon.property.item; - -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.page.property.EnchantmentEditor; -import net.momirealms.customfishing.common.helper.AdventureHelper; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemFlag; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -import java.util.Map; - -public class StoredEnchantmentItem extends AbstractItem { - - private final SectionPage itemPage; - - public StoredEnchantmentItem(SectionPage itemPage) { - this.itemPage = itemPage; - } - - @Override - public ItemProvider getItemProvider() { - ItemBuilder itemBuilder = new ItemBuilder(Material.ENCHANTED_BOOK) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_ITEM_STORED_ENCHANTMENT.build()))) - .addEnchantment(Enchantment.ARROW_FIRE,1,true) - .addItemFlags(ItemFlag.HIDE_ENCHANTS); - if (itemPage.getSection().contains("stored-enchantments")) { - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CURRENT_VALUE.build()))); - for (Map.Entry entry : itemPage.getSection().getSection("stored-enchantments").getStringRouteMappedValues(false).entrySet()) { - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.miniMessage(" - " + entry.getKey() + ":" + entry.getValue()))); - } - itemBuilder.addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_RESET.build()))); - } else { - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))); - } - return itemBuilder; - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (clickType.isLeftClick()) { - new EnchantmentEditor(player, itemPage, true); - } else if (clickType.isRightClick()) { - itemPage.getSection().set("stored-enchantments", null); - itemPage.save(); - itemPage.reOpen(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/TagItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/TagItem.java deleted file mode 100644 index 3d063bbd..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/TagItem.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon.property.item; - -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -public class TagItem extends AbstractItem { - - private final SectionPage itemPage; - - public TagItem(SectionPage itemPage) { - this.itemPage = itemPage; - } - - @Override - public ItemProvider getItemProvider() { - ItemBuilder itemBuilder = new ItemBuilder(Material.TOTEM_OF_UNDYING) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_ITEM_TAG.build()))); - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_CURRENT_VALUE.arguments( - Component.text(itemPage.getSection().getBoolean("tag", true)) - ).build() - ))) - .addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CLICK_TO_TOGGLE.build()))); - return itemBuilder; - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - itemPage.getSection().set("tag", !itemPage.getSection().getBoolean("tag", true)); - itemPage.save(); - itemPage.reOpen(); - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/UnbreakableItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/UnbreakableItem.java deleted file mode 100644 index 272ed93c..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/UnbreakableItem.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon.property.item; - -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -public class UnbreakableItem extends AbstractItem { - - private final SectionPage itemPage; - - public UnbreakableItem(SectionPage itemPage) { - this.itemPage = itemPage; - } - - @Override - public ItemProvider getItemProvider() { - return new ItemBuilder(Material.BEDROCK) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_ITEM_UNBREAKABLE.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CURRENT_VALUE.arguments(Component.text(itemPage.getSection().getBoolean("unbreakable", false))).build()))) - .addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CLICK_TO_TOGGLE.build()))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - itemPage.getSection().set("unbreakable", !itemPage.getSection().getBoolean("unbreakable", false)); - itemPage.save(); - itemPage.reOpen(); - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/DisableGameItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/DisableGameItem.java deleted file mode 100644 index 01b29381..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/DisableGameItem.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon.property.loot; - -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -public class DisableGameItem extends AbstractItem { - - private final SectionPage itemPage; - - public DisableGameItem(SectionPage itemPage) { - this.itemPage = itemPage; - } - - @Override - public ItemProvider getItemProvider() { - return new ItemBuilder(Material.LEAD) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LOOT_DISABLE_GAME.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_CURRENT_VALUE.arguments( - Component.text(itemPage.getSection().getBoolean("disable-game", false)) - ).build() - ))) - .addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CLICK_TO_TOGGLE.build()))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - itemPage.getSection().set("disable-game", !itemPage.getSection().getBoolean("disable-game", false)); - itemPage.save(); - itemPage.reOpen(); - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/DisableStatsItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/DisableStatsItem.java deleted file mode 100644 index f0176f97..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/DisableStatsItem.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon.property.loot; - -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -public class DisableStatsItem extends AbstractItem { - - private final SectionPage itemPage; - - public DisableStatsItem(SectionPage itemPage) { - this.itemPage = itemPage; - } - - @Override - public ItemProvider getItemProvider() { - return new ItemBuilder(Material.WRITTEN_BOOK) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LOOT_DISABLE_STATISTICS.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_CURRENT_VALUE.arguments( - Component.text(itemPage.getSection().getBoolean("disable-stat", false)) - ).build() - ))) - .addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CLICK_TO_TOGGLE.build()))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - itemPage.getSection().set("disable-game", !itemPage.getSection().getBoolean("disable-stat", false)); - itemPage.save(); - itemPage.reOpen(); - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/InstantGameItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/InstantGameItem.java deleted file mode 100644 index 7f8af6d2..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/InstantGameItem.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon.property.loot; - -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -public class InstantGameItem extends AbstractItem { - - private final SectionPage itemPage; - - public InstantGameItem(SectionPage itemPage) { - this.itemPage = itemPage; - } - - @Override - public ItemProvider getItemProvider() { - return new ItemBuilder(Material.FISHING_ROD) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LOOT_INSTANT_GAME.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CURRENT_VALUE.arguments(Component.text(itemPage.getSection().getBoolean("instant-game", false))).build()))) - .addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CLICK_TO_TOGGLE.build()))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - itemPage.getSection().set("instant-game", !itemPage.getSection().getBoolean("instant-game", false)); - itemPage.save(); - itemPage.reOpen(); - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/NickItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/NickItem.java deleted file mode 100644 index 7fb51778..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/NickItem.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon.property.loot; - -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.page.property.NickEditor; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -public class NickItem extends AbstractItem { - - private final SectionPage itemPage; - - public NickItem(SectionPage itemPage) { - this.itemPage = itemPage; - } - - @Override - public ItemProvider getItemProvider() { - ItemBuilder itemBuilder = new ItemBuilder(Material.WRITABLE_BOOK) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LOOT_NICK.build()))); - if (itemPage.getSection().contains("nick")) { - itemBuilder - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CURRENT_VALUE.arguments(Component.text(itemPage.getSection().getString("nick"))).build()))) - .addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_RESET.build()))); - } else { - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))); - } - return itemBuilder; - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (clickType.isLeftClick()) { - new NickEditor(player, itemPage); - } else if (clickType.isRightClick()) { - itemPage.getSection().set("nick", null); - itemPage.save(); - itemPage.reOpen(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/ScoreItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/ScoreItem.java deleted file mode 100644 index 9b43abfb..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/ScoreItem.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon.property.loot; - -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.page.property.ScoreEditor; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -public class ScoreItem extends AbstractItem { - - private final SectionPage itemPage; - - public ScoreItem(SectionPage itemPage) { - this.itemPage = itemPage; - } - - @Override - public ItemProvider getItemProvider() { - ItemBuilder itemBuilder = new ItemBuilder(Material.NETHER_STAR) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_LOOT_SCORE.build() - ))); - if (itemPage.getSection().contains("score")) { - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_CURRENT_VALUE - .arguments(Component.text(itemPage.getSection().getDouble("score"))) - .build() - ))) - .addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_RESET.build()))); - } else { - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))); - } - return itemBuilder; - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (clickType.isLeftClick()) { - new ScoreEditor(player, itemPage); - } else if (clickType.isRightClick()) { - itemPage.getSection().set("score", null); - itemPage.save(); - itemPage.reOpen(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/ShowInFinderItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/ShowInFinderItem.java deleted file mode 100644 index fe90dcaa..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/ShowInFinderItem.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.icon.property.loot; - -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; - -public class ShowInFinderItem extends AbstractItem { - - private final SectionPage itemPage; - - public ShowInFinderItem(SectionPage itemPage) { - this.itemPage = itemPage; - } - - @Override - public ItemProvider getItemProvider() { - ItemBuilder itemBuilder = new ItemBuilder(Material.COMPASS) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_LOOT_SHOW_IN_FINDER.build() - ))); - itemBuilder.addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_CURRENT_VALUE - .arguments(Component.text(itemPage.getSection().getBoolean("show-in-fishfinder", true))) - .build() - ))) - .addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_CLICK_TO_TOGGLE.build() - ))); - return itemBuilder; - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - itemPage.getSection().set("show-in-fishfinder", !itemPage.getSection().getBoolean("show-in-fishfinder", true)); - itemPage.save(); - itemPage.reOpen(); - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/file/FileSelector.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/file/FileSelector.java deleted file mode 100644 index 73dc68fb..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/file/FileSelector.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.page.file; - -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; -import net.momirealms.customfishing.bukkit.gui.icon.BackToFolderItem; -import net.momirealms.customfishing.bukkit.gui.icon.ScrollDownItem; -import net.momirealms.customfishing.bukkit.gui.icon.ScrollUpItem; -import net.momirealms.customfishing.bukkit.gui.page.item.ItemSelector; -import net.momirealms.customfishing.common.helper.AdventureHelper; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.gui.Gui; -import xyz.xenondevs.invui.gui.ScrollGui; -import xyz.xenondevs.invui.gui.structure.Markers; -import xyz.xenondevs.invui.item.Item; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; -import xyz.xenondevs.invui.window.Window; - -import java.io.File; -import java.util.ArrayDeque; -import java.util.Deque; - -public class FileSelector { - - public FileSelector(Player player, File folder) { - File[] files = folder.listFiles(); - Deque items = new ArrayDeque<>(); - if (files != null) { - for (File file : files) { - if (file.isFile() && file.getName().endsWith(".yml")) { - items.addLast(new FileItem(file)); - } else if (file.isDirectory()) { - String path = file.getPath().replace("/", "\\"); - String[] split = path.split("\\\\"); - String type = split[3]; - switch (type) { - case "item", "rod", "bait", "util", "hook" -> items.addFirst(new FolderItem(file)); - } - } - } - } - - Gui gui = ScrollGui.items() - .setStructure( - "x x x x x x x x u", - "x x x x x x x x #", - "x x x x x x x x b", - "x x x x x x x x #", - "x x x x x x x x d" - ) - .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL) - .addIngredient('#', new BackGroundItem()) - .addIngredient('u', new ScrollUpItem()) - .addIngredient('d', new ScrollDownItem()) - .addIngredient('b', new BackToFolderItem(folder.getParentFile())) - .setContent(items.stream().toList()) - .build(); - - Window window = Window.single() - .setViewer(player) - .setTitle(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_SELECT_FILE.build()))) - .setGui(gui) - .build(); - - window.open(); - } - - public static class FileItem extends AbstractItem { - - private final File file; - - public FileItem(File file) { - this.file = file; - } - - @Override - public ItemProvider getItemProvider() { - return new ItemBuilder(Material.PAPER).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.miniMessage( - "<#FDF5E6>" + file.getName() - ))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - String path = file.getPath().replace("/", "\\"); - String[] split = path.split("\\\\"); - String type = split[3]; - switch (type) { - case "item", "rod", "bait", "util", "hook" -> { - new ItemSelector(player, file, type); - } - } - } - } - - public static class FolderItem extends AbstractItem { - - private final File file; - - public FolderItem(File file) { - this.file = file; - } - - @Override - public ItemProvider getItemProvider() { - return new ItemBuilder(Material.BOOK).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.miniMessage( - "<#D2B48C>" + file.getName() - ))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - new FileSelector(player, file); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/AbstractSectionEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/AbstractSectionEditor.java deleted file mode 100644 index 39d999f9..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/AbstractSectionEditor.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.page.item; - -import dev.dejvokep.boostedyaml.block.implementation.Section; -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; -import net.momirealms.customfishing.bukkit.gui.icon.BackToPageItem; -import net.momirealms.customfishing.bukkit.gui.icon.NextPageItem; -import net.momirealms.customfishing.bukkit.gui.icon.PreviousPageItem; -import net.momirealms.customfishing.common.locale.MessageConstants; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.gui.Gui; -import xyz.xenondevs.invui.gui.PagedGui; -import xyz.xenondevs.invui.gui.structure.Markers; -import xyz.xenondevs.invui.item.Item; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; -import xyz.xenondevs.invui.item.impl.SimpleItem; -import xyz.xenondevs.invui.window.AnvilWindow; - -import java.util.List; - -public abstract class AbstractSectionEditor implements SectionPage { - - protected final Player player; - protected final ItemSelector itemSelector; - protected final Section section; - protected final String key; - - public AbstractSectionEditor(Player player, ItemSelector itemSelector, Section section, String key) { - this.player = player; - this.itemSelector = itemSelector; - this.section = section; - this.key = key; - this.reOpen(); - } - - @Override - public Section getSection() { - return section; - } - - @Override - public void reOpen() { - Item border = new SimpleItem(new ItemBuilder(Material.AIR)); - Gui upperGui = Gui.normal() - .setStructure( - "# a #" - ) - .addIngredient('a', new RefreshExample()) - .addIngredient('#', border) - .build(); - - var gui = PagedGui.items() - .setStructure( - "x x x x x x x x x", - "x x x x x x x x x", - "x x x x x x x x x", - "# # a # c # b # #" - ) - .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL) - .addIngredient('#', new BackGroundItem()) - .addIngredient('a', new PreviousPageItem()) - .addIngredient('b', new NextPageItem()) - .addIngredient('c', new BackToPageItem(itemSelector)) - .setContent(getItemList()) - .build(); - - var window = AnvilWindow.split() - .setViewer(player) - .setTitle(new ShadedAdventureComponentWrapper(MessageConstants.GUI_EDIT_KEY.arguments(Component.text(key)).build())) - .setUpperGui(upperGui) - .setLowerGui(gui) - .build(); - - window.open(); - } - - @Override - public void save() { - itemSelector.save(); - } - - public class RefreshExample extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - return null; - //return new ItemBuilder(BukkitCustomFishingPlugin.getInstance().getItemManager().getItemBuilder(section, "bait", key).build(player)); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - notifyWindows(); - } - } - - public abstract List getItemList(); -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/BaitEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/BaitEditor.java deleted file mode 100644 index 2e5b0832..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/BaitEditor.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.page.item; - -import dev.dejvokep.boostedyaml.block.implementation.Section; -import net.momirealms.customfishing.bukkit.gui.icon.property.item.*; -import org.bukkit.entity.Player; -import xyz.xenondevs.invui.item.Item; - -import java.util.ArrayList; -import java.util.List; - -@SuppressWarnings("DuplicatedCode") -public class BaitEditor extends AbstractSectionEditor { - - public BaitEditor(Player player, String key, ItemSelector itemSelector, Section section) { - super(player, itemSelector, section, key); - } - - @Override - public List getItemList() { - ArrayList items = new ArrayList<>(); - items.add(new MaterialItem(this)); - items.add(new DisplayNameItem(this)); - items.add(new LoreItem(this)); - items.add(new CMDItem(this)); - items.add(new TagItem(this)); - items.add(new UnbreakableItem(this)); - items.add(new DurabilityItem(this)); - items.add(new RandomDurabilityItem(this)); - items.add(new StackableItem(this)); - items.add(new ItemFlagItem(this)); - items.add(new Head64Item(this)); - items.add(new NBTItem(this)); - items.add(new EnchantmentItem(this)); - items.add(new StoredEnchantmentItem(this)); - return items; - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/HookEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/HookEditor.java deleted file mode 100644 index 05994374..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/HookEditor.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.page.item; - -import dev.dejvokep.boostedyaml.block.implementation.Section; -import net.momirealms.customfishing.bukkit.gui.icon.property.item.*; -import org.bukkit.entity.Player; -import xyz.xenondevs.invui.item.Item; - -import java.util.ArrayList; -import java.util.List; - -@SuppressWarnings("DuplicatedCode") -public class HookEditor extends AbstractSectionEditor { - - public HookEditor(Player player, String key, ItemSelector itemSelector, Section section) { - super(player, itemSelector, section, key); - } - - @Override - public List getItemList() { - ArrayList items = new ArrayList<>(); - items.add(new MaterialItem(this)); - items.add(new DisplayNameItem(this)); - items.add(new LoreItem(this)); - items.add(new CMDItem(this)); - items.add(new TagItem(this)); - items.add(new UnbreakableItem(this)); - items.add(new DurabilityItem(this)); - items.add(new RandomDurabilityItem(this)); - items.add(new StackableItem(this)); - items.add(new ItemFlagItem(this)); - items.add(new Head64Item(this)); - items.add(new NBTItem(this)); - items.add(new EnchantmentItem(this)); - items.add(new StoredEnchantmentItem(this)); - return items; - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/ItemSelector.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/ItemSelector.java deleted file mode 100644 index a7931fa9..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/ItemSelector.java +++ /dev/null @@ -1,290 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.page.item; - -import dev.dejvokep.boostedyaml.YamlDocument; -import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.YamlPage; -import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; -import net.momirealms.customfishing.bukkit.gui.icon.BackToFolderItem; -import net.momirealms.customfishing.bukkit.gui.icon.NextPageItem; -import net.momirealms.customfishing.bukkit.gui.icon.PreviousPageItem; -import net.momirealms.customfishing.common.helper.AdventureHelper; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.gui.Gui; -import xyz.xenondevs.invui.gui.PagedGui; -import xyz.xenondevs.invui.gui.structure.Markers; -import xyz.xenondevs.invui.item.Item; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; -import xyz.xenondevs.invui.item.impl.SimpleItem; -import xyz.xenondevs.invui.window.AnvilWindow; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public class ItemSelector implements YamlPage { - - private final String SEARCH; - private final Player player; - private final YamlDocument yaml; - private String prefix; - private final File file; - private long coolDown; - private final String type; - - public ItemSelector(Player player, File file, String type) { - this.yaml = BukkitCustomFishingPlugin.getInstance().getConfigManager().loadData(file); - this.player = player; - this.file = file; - this.type = type; - this.SEARCH = "Search"; - this.prefix = SEARCH; - this.reOpenWithFilter(SEARCH); - } - - @Override - public void reOpen() { - reOpenWithFilter(prefix); - } - - public void reOpenWithFilter(String filter) { - Item border = new SimpleItem(new ItemBuilder(Material.AIR)); - Gui upperGui = Gui.normal() - .setStructure("a # #") - .addIngredient('a', new SimpleItem(new ItemBuilder(Material.NAME_TAG).setDisplayName(filter))) - .addIngredient('#', border) - .build(); - - var gui = PagedGui.items() - .setStructure( - "x x x x x x x x x", - "x x x x x x x x x", - "x x x x x x x x x", - "# # a # c # b # #" - ) - .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL) - .addIngredient('#', new BackGroundItem()) - .addIngredient('a', new PreviousPageItem()) - .addIngredient('b', new NextPageItem()) - .addIngredient('c', new BackToFolderItem(file.getParentFile())) - .setContent(getItemList()) - .build(); - - var window = AnvilWindow.split() - .setViewer(player) - .setTitle(new ShadedAdventureComponentWrapper( - TranslationManager.render( - MessageConstants.GUI_SELECT_ITEM.build() - ) - )) - .addRenameHandler(s -> { - long current = System.currentTimeMillis(); - if (current - coolDown < 100) return; - if (s.equals(filter)) return; - prefix = s; - coolDown = current; - reOpenWithFilter(s); - }) - .setUpperGui(upperGui) - .setLowerGui(gui) - .build(); - - window.open(); - } - - public void reOpenWithNewKey() { - String tempKey = "ID"; - prefix = tempKey; - var confirmIcon = new ConfirmIcon(); - Item border = new SimpleItem(new ItemBuilder(Material.AIR)); - Gui upperGui = Gui.normal() - .setStructure("a # b") - .addIngredient('a', new SimpleItem(new ItemBuilder(Material.NAME_TAG).setDisplayName(tempKey))) - .addIngredient('b', confirmIcon) - .addIngredient('#', border) - .build(); - - var gui = PagedGui.items() - .setStructure( - "x x x x x x x x x", - "x x x x x x x x x", - "x x x x x x x x x", - "# # a # c # b # #" - ) - .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL) - .addIngredient('#', new BackGroundItem()) - .addIngredient('a', new PreviousPageItem()) - .addIngredient('b', new NextPageItem()) - .addIngredient('c', new BackToFolderItem(file.getParentFile())) - .build(); - - var window = AnvilWindow.split() - .setViewer(player) - .setTitle(new ShadedAdventureComponentWrapper( - TranslationManager.render( - MessageConstants.GUI_SET_NEW_KEY.build() - ) - )) - .addRenameHandler(s -> { - long current = System.currentTimeMillis(); - if (current - coolDown < 100) return; - if (s.equals(tempKey)) return; - prefix = s; - coolDown = current; - confirmIcon.notifyWindows(); - }) - .setUpperGui(upperGui) - .setLowerGui(gui) - .build(); - - window.open(); - } - - public List getItemList() { - List itemList = new ArrayList<>(); - for (Map.Entry entry : this.yaml.getStringRouteMappedValues(false).entrySet()) { - String key = entry.getKey(); - if (entry.getValue() instanceof ConfigurationSection section) { - if (!prefix.equals(SEARCH) && !entry.getKey().startsWith(prefix)) continue; - String material = section.getString("material"); - if (material != null) { - - continue; - } - } - itemList.add(new ItemInList(key, new ItemBuilder(Material.STRUCTURE_VOID), this)); - } - itemList.add(new AddKey()); - return itemList; - } - - public void removeKey(String key) { - yaml.set(key, null); - } - - public void openEditor(String key) { - switch (type) { - case "item" -> new SectionEditor(player, key, this, yaml.getSection(key)); - case "rod" -> new RodEditor(player, key, this, yaml.getSection(key)); - case "bait" -> new BaitEditor(player, key, this, yaml.getSection(key)); - case "hook" -> new HookEditor(player, key, this, yaml.getSection(key)); - } - } - - @Override - public void save() { - try { - yaml.save(file); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public static class ItemInList extends AbstractItem { - - private final String key; - private final ItemBuilder itemBuilder; - private final ItemSelector itemSelector; - - public ItemInList(String key, ItemBuilder itemBuilder, ItemSelector itemSelector) { - this.key = key; - this.itemBuilder = itemBuilder - .setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.miniMessage(key))) - .addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_DELETE.build()))); - this.itemSelector = itemSelector; - } - - @Override - public ItemProvider getItemProvider() { - return itemBuilder; - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (clickType.isLeftClick()) { - this.itemSelector.openEditor(key); - } else if (clickType.isRightClick()) { - this.itemSelector.removeKey(key); - this.itemSelector.save(); - this.itemSelector.reOpenWithFilter(itemSelector.prefix); - } - } - } - - public class AddKey extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - return new ItemBuilder(Material.ANVIL).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_PAGE_ADD_NEW_KEY.build() - ))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - reOpenWithNewKey(); - } - } - - public class ConfirmIcon extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - if (prefix != null && !yaml.contains(prefix) && prefix.matches("^[a-zA-Z0-9_]+$")) { - return new ItemBuilder(Material.NAME_TAG) - .setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.miniMessage(prefix))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CLICK_CONFIRM.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_CANCEL.build()))); - } else { - return new ItemBuilder(Material.BARRIER) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_INVALID_KEY.build() - ))); - } - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (clickType.isLeftClick()) { - if (prefix != null && !yaml.contains(prefix) && prefix.matches("^[a-zA-Z0-9_]+$")) { - yaml.createSection(prefix); - save(); - } else { - return; - } - } - prefix = SEARCH; - reOpenWithFilter(SEARCH); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/RodEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/RodEditor.java deleted file mode 100644 index 8dadda5b..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/RodEditor.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.page.item; - -import dev.dejvokep.boostedyaml.block.implementation.Section; -import net.momirealms.customfishing.bukkit.gui.icon.property.item.*; -import org.bukkit.entity.Player; -import xyz.xenondevs.invui.item.Item; - -import java.util.ArrayList; -import java.util.List; - -@SuppressWarnings("DuplicatedCode") -public class RodEditor extends AbstractSectionEditor { - - public RodEditor(Player player, String key, ItemSelector itemSelector, Section section) { - super(player, itemSelector, section, key); - } - - @Override - public List getItemList() { - ArrayList items = new ArrayList<>(); - items.add(new MaterialItem(this)); - items.add(new DisplayNameItem(this)); - items.add(new LoreItem(this)); - items.add(new CMDItem(this)); - items.add(new TagItem(this)); - items.add(new UnbreakableItem(this)); - items.add(new DurabilityItem(this)); - items.add(new RandomDurabilityItem(this)); - items.add(new ItemFlagItem(this)); - items.add(new NBTItem(this)); - items.add(new EnchantmentItem(this)); - return items; - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/SectionEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/SectionEditor.java deleted file mode 100644 index c2267385..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/SectionEditor.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.page.item; - -import dev.dejvokep.boostedyaml.block.implementation.Section; -import net.momirealms.customfishing.bukkit.gui.icon.property.item.*; -import net.momirealms.customfishing.bukkit.gui.icon.property.loot.*; -import org.bukkit.entity.Player; -import xyz.xenondevs.invui.item.Item; - -import java.util.ArrayList; -import java.util.List; - -public class SectionEditor extends AbstractSectionEditor { - - public SectionEditor(Player player, String key, ItemSelector itemSelector, Section section) { - super(player, itemSelector, section, key); - } - - @Override - public List getItemList() { - ArrayList items = new ArrayList<>(); - items.add(new MaterialItem(this)); - items.add(new NickItem(this)); - items.add(new DisplayNameItem(this)); - items.add(new LoreItem(this)); - items.add(new CMDItem(this)); - items.add(new AmountItem(this)); - items.add(new TagItem(this)); - items.add(new UnbreakableItem(this)); - items.add(new DurabilityItem(this)); - items.add(new RandomDurabilityItem(this)); - items.add(new StackableItem(this)); - items.add(new PreventGrabItem(this)); - items.add(new PriceItem(this)); - items.add(new ShowInFinderItem(this)); - items.add(new DisableStatsItem(this)); - items.add(new DisableGameItem(this)); - items.add(new InstantGameItem(this)); - items.add(new ScoreItem(this)); - items.add(new SizeItem(this)); - items.add(new ItemFlagItem(this)); - items.add(new Head64Item(this)); - items.add(new NBTItem(this)); - items.add(new EnchantmentItem(this)); - items.add(new StoredEnchantmentItem(this)); - return items; - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/AmountEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/AmountEditor.java deleted file mode 100644 index 04b15e2b..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/AmountEditor.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.page.property; - -import dev.dejvokep.boostedyaml.block.implementation.Section; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.gui.Gui; -import xyz.xenondevs.invui.gui.PagedGui; -import xyz.xenondevs.invui.item.Item; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; -import xyz.xenondevs.invui.item.impl.SimpleItem; -import xyz.xenondevs.invui.window.AnvilWindow; - -public class AmountEditor { - - private final SectionPage parentPage; - private String amount; - private final Section section; - - public AmountEditor(Player player, SectionPage parentPage) { - this.parentPage = parentPage; - this.section = parentPage.getSection(); - - Item border = new SimpleItem(new ItemBuilder(Material.AIR)); - var confirm = new ConfirmIcon(); - Gui upperGui = Gui.normal() - .setStructure("a # b") - .addIngredient('a', new ItemBuilder(Material.IRON_NUGGET).setDisplayName(String.valueOf(section.getInt("amount", 1)))) - .addIngredient('#', border) - .addIngredient('b', confirm) - .build(); - - var gui = PagedGui.items() - .setStructure( - "x x x x x x x x x", - "x x x x x x x x x", - "x x x x x x x x x", - "# # # # c # # # #" - ) - .addIngredient('x', new ItemStack(Material.AIR)) - .addIngredient('c', parentPage.getBackItem()) - .addIngredient('#', new BackGroundItem()) - .build(); - - var window = AnvilWindow.split() - .setViewer(player) - .setTitle(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_AMOUNT_TITLE.build()))) - .addRenameHandler(s -> { - amount = s; - confirm.notifyWindows(); - }) - .setUpperGui(upperGui) - .setLowerGui(gui) - .build(); - - window.open(); - } - - public class ConfirmIcon extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - if (amount == null || amount.isEmpty()) { - return new ItemBuilder(Material.STRUCTURE_VOID).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_DELETE_PROPERTY.build() - ))); - } else { - try { - int m = Integer.parseInt(amount); - if (m >= 1) { - return new ItemBuilder(Material.IRON_NUGGET) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_CLICK_CONFIRM.build() - ))) - .setAmount(m); - } else { - return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_INVALID_NUMBER.build()))); - } - } catch (NumberFormatException e) { - return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_INVALID_NUMBER.build()))); - } - } - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (amount == null || amount.isEmpty()) { - section.set("amount", null); - } else { - try { - int value = Integer.parseInt(amount); - if (value >= 1) { - section.set("amount", value); - } else { - return; - } - } catch (NumberFormatException e) { - return; - } - } - parentPage.reOpen(); - parentPage.save(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/CustomModelDataEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/CustomModelDataEditor.java deleted file mode 100644 index a5e61a77..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/CustomModelDataEditor.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.page.property; - -import dev.dejvokep.boostedyaml.block.implementation.Section; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.gui.Gui; -import xyz.xenondevs.invui.gui.PagedGui; -import xyz.xenondevs.invui.item.Item; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; -import xyz.xenondevs.invui.item.impl.SimpleItem; -import xyz.xenondevs.invui.window.AnvilWindow; - -public class CustomModelDataEditor { - - private final Player player; - private final SectionPage parentPage; - private String cmd; - private final Section section; - private final String material; - - public CustomModelDataEditor(Player player, SectionPage parentPage) { - this.player = player; - this.parentPage = parentPage; - this.section = parentPage.getSection(); - this.material = section.getString("material"); - - Item border = new SimpleItem(new ItemBuilder(Material.AIR)); - var confirm = new ConfirmIcon(); - Gui upperGui = Gui.normal() - .setStructure( - "a # b" - ) - .addIngredient('#', border) - .addIngredient('b', confirm) -// .addIngredient('a', new ItemBuilder(BukkitCustomFishingPlugin.getInstance() -// .getItemManager() -// .getItemStackAppearance(player, material)) -// .setCustomModelData(section.getInt("custom-model-data", 0)) -// .setDisplayName(String.valueOf(section.getInt("custom-model-data", 0))) -// ) - .build(); - - var gui = PagedGui.items() - .setStructure( - "x x x x x x x x x", - "x x x x x x x x x", - "x x x x x x x x x", - "# # # # c # # # #" - ) - .addIngredient('x', new ItemStack(Material.AIR)) - .addIngredient('c', parentPage.getBackItem()) - .addIngredient('#', new BackGroundItem()) - .build(); - - var window = AnvilWindow.split() - .setViewer(player) - .setTitle(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_MODEL_DATA_TITLE.build()))) - .addRenameHandler(s -> { - cmd = s; - confirm.notifyWindows(); - }) - .setUpperGui(upperGui) - .setLowerGui(gui) - .build(); - - window.open(); - } - - public class ConfirmIcon extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - if (cmd == null || cmd.isEmpty()) { - return new ItemBuilder(Material.STRUCTURE_VOID).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_DELETE_PROPERTY.build() - ))); - } else { - try { - int value = Integer.parseInt(cmd); - if (value >= 0) { - return null; -// return new ItemBuilder( -// BukkitCustomFishingPlugin.getInstance() -// .getItemManager() -// .getItemStackAppearance(player, material) -// ) -// .setCustomModelData(value) -// .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_NEW_VALUE.arguments(Component.text(value)).build()))) -// .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CLICK_CONFIRM.build()))); - } else { - return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_INVALID_NUMBER.build()))); - } - } catch (NumberFormatException e) { - return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_INVALID_NUMBER.build()))); - } - } - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (cmd == null || cmd.isEmpty()) { - section.set("custom-model-data", null); - } else { - try { - int value = Integer.parseInt(cmd); - if (value >= 0) { - section.set("custom-model-data", value); - } else { - return; - } - } catch (NumberFormatException e) { - return; - } - } - parentPage.reOpen(); - parentPage.save(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/DisplayNameEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/DisplayNameEditor.java deleted file mode 100644 index 8452129b..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/DisplayNameEditor.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.page.property; - -import dev.dejvokep.boostedyaml.block.implementation.Section; -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; -import net.momirealms.customfishing.common.helper.AdventureHelper; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.gui.Gui; -import xyz.xenondevs.invui.gui.PagedGui; -import xyz.xenondevs.invui.item.Item; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; -import xyz.xenondevs.invui.item.impl.SimpleItem; -import xyz.xenondevs.invui.window.AnvilWindow; - -public class DisplayNameEditor { - - private final SectionPage parentPage; - private String name; - private final Section section; - - public DisplayNameEditor(Player player, SectionPage parentPage) { - this.parentPage = parentPage; - this.section = parentPage.getSection(); - - Item border = new SimpleItem(new ItemBuilder(Material.AIR)); - var confirm = new ConfirmIcon(); - Gui upperGui = Gui.normal() - .setStructure("a # b") - .addIngredient('a', new ItemBuilder(Material.NAME_TAG).setDisplayName( - new ShadedAdventureComponentWrapper( - section.contains("display.name") ? - Component.text(section.getString("display.name")) : MessageConstants.GUI_PAGE_NEW_DISPLAY_NAME.build() - ) - )) - .addIngredient('#', border) - .addIngredient('b', confirm) - .build(); - - var gui = PagedGui.items() - .setStructure( - "x x x x x x x x x", - "x x x x x x x x x", - "x x x x x x x x x", - "# # # # c # # # #" - ) - .addIngredient('x', new ItemStack(Material.AIR)) - .addIngredient('c', parentPage.getBackItem()) - .addIngredient('#', new BackGroundItem()) - .build(); - - var window = AnvilWindow.split() - .setViewer(player) - .setTitle(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_DISPLAY_NAME_TITLE.build()))) - .addRenameHandler(s -> { - name = s; - confirm.notifyWindows(); - }) - .setUpperGui(upperGui) - .setLowerGui(gui) - .build(); - - window.open(); - } - - public class ConfirmIcon extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - if (name == null || name.isEmpty()) { - return new ItemBuilder(Material.STRUCTURE_VOID).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_DELETE_PROPERTY.build()))); - } else { - return new ItemBuilder(Material.NAME_TAG) - .setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.miniMessage( - "" + name - ))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_CLICK_CONFIRM.build() - ))); - } - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (name == null || name.isEmpty()) { - section.set("display.name", null); - } else { - section.set("display.name", name); - } - parentPage.reOpen(); - parentPage.save(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/DurabilityEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/DurabilityEditor.java deleted file mode 100644 index 30dfd988..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/DurabilityEditor.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.page.property; - -import dev.dejvokep.boostedyaml.block.implementation.Section; -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.gui.Gui; -import xyz.xenondevs.invui.gui.PagedGui; -import xyz.xenondevs.invui.item.Item; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; -import xyz.xenondevs.invui.item.impl.SimpleItem; -import xyz.xenondevs.invui.window.AnvilWindow; - -public class DurabilityEditor { - - private final SectionPage parentPage; - private String dur; - private final Section section; - - public DurabilityEditor(Player player, SectionPage parentPage) { - this.parentPage = parentPage; - this.section = parentPage.getSection(); - - Item border = new SimpleItem(new ItemBuilder(Material.AIR)); - var confirm = new ConfirmIcon(); - Gui upperGui = Gui.normal() - .setStructure("a # b") - .addIngredient('a', new ItemBuilder(Material.NETHERITE_PICKAXE).setDisplayName(String.valueOf(section.getInt("max-durability", 64)))) - .addIngredient('#', border) - .addIngredient('b', confirm) - .build(); - - var gui = PagedGui.items() - .setStructure( - "x x x x x x x x x", - "x x x x x x x x x", - "x x x x x x x x x", - "# # # # c # # # #" - ) - .addIngredient('x', new ItemStack(Material.AIR)) - .addIngredient('c', parentPage.getBackItem()) - .addIngredient('#', new BackGroundItem()) - .build(); - - var window = AnvilWindow.split() - .setViewer(player) - .setTitle(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_CUSTOM_DURABILITY_TITLE.build()))) - .addRenameHandler(s -> { - dur = s; - confirm.notifyWindows(); - }) - .setUpperGui(upperGui) - .setLowerGui(gui) - .build(); - - window.open(); - } - - public class ConfirmIcon extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - if (dur == null || dur.isEmpty()) { - return new ItemBuilder(Material.STRUCTURE_VOID).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_DELETE_PROPERTY.build()))); - } else { - try { - int m = Integer.parseInt(dur); - if (m >= 1) { - return new ItemBuilder(Material.NETHERITE_PICKAXE) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_NEW_VALUE.arguments(Component.text(dur)).build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CLICK_CONFIRM.build()))) - .setDamage(Math.max(0, Material.NETHERITE_PICKAXE.getMaxDurability() - m)); - } else { - return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_INVALID_NUMBER.build()))); - } - } catch (NumberFormatException e) { - return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_INVALID_NUMBER.build()))); - } - } - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (dur == null || dur.isEmpty()) { - section.set("max-durability", null); - } else { - try { - int value = Integer.parseInt(dur); - if (value >= 1) { - section.set("max-durability", value); - } else { - return; - } - } catch (NumberFormatException e) { - return; - } - } - parentPage.reOpen(); - parentPage.save(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/EnchantmentEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/EnchantmentEditor.java deleted file mode 100644 index 5b03334f..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/EnchantmentEditor.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.page.property; - -import dev.dejvokep.boostedyaml.block.implementation.Section; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; -import net.momirealms.customfishing.common.helper.AdventureHelper; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.gui.Gui; -import xyz.xenondevs.invui.gui.PagedGui; -import xyz.xenondevs.invui.gui.structure.Markers; -import xyz.xenondevs.invui.item.Item; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; -import xyz.xenondevs.invui.item.impl.SimpleItem; -import xyz.xenondevs.invui.window.AnvilWindow; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public class EnchantmentEditor { - - private final Player player; - private final SectionPage parentPage; - private final ArrayList enchantments; - private final Section section; - private int index; - private final boolean store; - - public EnchantmentEditor(Player player, SectionPage parentPage, boolean store) { - this.player = player; - this.parentPage = parentPage; - this.section = parentPage.getSection(); - this.store = store; - this.index = 0; - this.enchantments = new ArrayList<>(); - this.enchantments.add("Select one enchantment"); - Section eSection = section.getSection(store ? "stored-enchantments" : "enchantments"); - if (eSection != null) - for (Map.Entry entry : eSection.getStringRouteMappedValues(false).entrySet()) { - this.enchantments.add(entry.getKey() + ":" + entry.getValue()); - } - reOpen(0); - } - - public void reOpen(int idx) { - Item border = new SimpleItem(new ItemBuilder(Material.AIR)); - var confirm = new ConfirmIcon(); - Gui upperGui = Gui.normal() - .setStructure("a # b") - .addIngredient('a', new ItemBuilder(Material.NAME_TAG).setDisplayName(enchantments.get(idx))) - .addIngredient('#', border) - .addIngredient('b', confirm) - .build(); - - var gui = PagedGui.items() - .setStructure( - "x x x x x x x x x", - "x x x x x x x x x", - "x x x x x x x x x", - "# # # # c # # # #" - ) - .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL) - .addIngredient('c', parentPage.getBackItem()) - .addIngredient('#', new BackGroundItem()) - .setContent(getContents()) - .build(); - - var window = AnvilWindow.split() - .setViewer(player) - .setTitle(new ShadedAdventureComponentWrapper( - TranslationManager.render(store ? MessageConstants.GUI_PAGE_STORED_ENCHANTMENT_TITLE.build() : MessageConstants.GUI_PAGE_ENCHANTMENT_TITLE.build()) - )) - .addRenameHandler(s -> { - if (index == 0) return; - enchantments.set(index, s); - confirm.notifyWindows(); - }) - .setUpperGui(upperGui) - .setLowerGui(gui) - .build(); - - window.open(); - } - - public List getContents() { - ArrayList items = new ArrayList<>(); - int i = 1; - List subList = enchantments.subList(1, enchantments.size()); - for (String lore : subList) { - items.add(new EnchantmentElement(lore, i++)); - } - items.add(new AddEnchantment()); - return items; - } - - public class AddEnchantment extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - return new ItemBuilder(Material.ANVIL).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_PAGE_ADD_NEW_ENCHANTMENT.build() - ))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - enchantments.add("namespace:enchantment:level"); - index = enchantments.size() - 1; - reOpen(index); - } - } - - public class EnchantmentElement extends AbstractItem { - - private final String line; - private final int idx; - - public EnchantmentElement(String line, int idx) { - this.line = line; - this.idx = idx; - } - - @Override - public ItemProvider getItemProvider() { - return new ItemBuilder(Material.ENCHANTED_BOOK) - .setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.miniMessage(line))) - .addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_DELETE.build()))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (clickType == ClickType.LEFT) { - index = idx; - reOpen(idx); - } else if (clickType == ClickType.RIGHT) { - enchantments.remove(idx); - index = Math.min(index, enchantments.size() - 1); - reOpen(index); - } - } - } - - public class ConfirmIcon extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - List subList = enchantments.subList(1, enchantments.size()); - if (subList.isEmpty()) { - return new ItemBuilder(Material.STRUCTURE_VOID).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_DELETE_PROPERTY.build()))); - } else { - var builder = new ItemBuilder(Material.NAME_TAG).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CLICK_CONFIRM.build()))); - for (String enchantment : subList) { - String[] split = enchantment.split(":"); - if (split.length != 3) { - return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_ILLEGAL_FORMAT.build()))); - } - try { - Integer.parseInt(split[2]); - builder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.miniMessage(" - " + enchantment))); - } catch (NumberFormatException e) { - return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_ILLEGAL_FORMAT.build()))); - } - } - return builder; - } - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - List subList = enchantments.subList(1, enchantments.size()); - for (String line : subList) { - String[] split = line.split(":"); - if (split.length != 3) { - return; - } - try { - Integer.parseInt(split[2]); - } catch (NumberFormatException e) { - return; - } - } - section.set(store ? "stored-enchantments" : "enchantments", null); - for (String line : subList) { - String[] split = line.split(":"); - section.set((store ? "stored-enchantments" : "enchantments") + "." + split[0] + ":" + split[1], Integer.parseInt(split[2])); - } - parentPage.reOpen(); - parentPage.save(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/ItemFlagEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/ItemFlagEditor.java deleted file mode 100644 index 061d5338..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/ItemFlagEditor.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.page.property; - -import dev.dejvokep.boostedyaml.block.implementation.Section; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; -import net.momirealms.customfishing.common.helper.AdventureHelper; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemFlag; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.gui.Gui; -import xyz.xenondevs.invui.gui.PagedGui; -import xyz.xenondevs.invui.gui.structure.Markers; -import xyz.xenondevs.invui.item.Item; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; -import xyz.xenondevs.invui.item.impl.SimpleItem; -import xyz.xenondevs.invui.window.AnvilWindow; - -import java.util.ArrayList; -import java.util.List; - -public class ItemFlagEditor { - - private final Player player; - private final SectionPage parentPage; - private final List flags; - private final Section section; - - public ItemFlagEditor(Player player, SectionPage parentPage) { - this.player = player; - this.parentPage = parentPage; - this.section = parentPage.getSection(); - this.flags = section.getStringList("item-flags"); - reOpen(); - } - - public void reOpen() { - Gui upperGui = Gui.normal() - .setStructure( - "# a #" - ) - //.addIngredient('a', new ItemBuilder(BukkitCustomFishingPlugin.getInstance().getItemManager().getItemBuilder(section, "item", "id").build(player))) - .addIngredient('#', new SimpleItem(new ItemBuilder(Material.AIR))) - .build(); - - var gui = PagedGui.items() - .setStructure( - "x x x x x x x x x", - "x x x x x x x x x", - "x x x x x x x x x", - "# # # # c # # # #" - ) - .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL) - .addIngredient('c', parentPage.getBackItem()) - .addIngredient('#', new BackGroundItem()) - .setContent(getContents()) - .build(); - - var window = AnvilWindow.split() - .setViewer(player) - .setTitle(new ShadedAdventureComponentWrapper( - TranslationManager.render(MessageConstants.GUI_PAGE_ITEM_FLAG_TITLE.build()) - )) - .setUpperGui(upperGui) - .setLowerGui(gui) - .build(); - - window.open(); - } - - public List getContents() { - ArrayList items = new ArrayList<>(); - for (ItemFlag itemFlag : ItemFlag.values()) { - items.add(new ItemFlagToggleItem(itemFlag.name())); - } - return items; - } - - public class ItemFlagToggleItem extends AbstractItem { - - private final String flag; - - public ItemFlagToggleItem(String flag) { - this.flag = flag; - } - - @Override - public ItemProvider getItemProvider() { - if (flags.contains(flag)) { - return new ItemBuilder(Material.GREEN_BANNER).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.miniMessage("" + flag))); - } else { - return new ItemBuilder(Material.RED_BANNER).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.miniMessage("" + flag))); - } - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (flags.contains(flag)) { - flags.remove(flag); - } else { - flags.add(flag); - } - if (!flags.isEmpty()) { - section.set("item-flags", flags); - } else { - section.set("item-flags", null); - } - parentPage.save(); - reOpen(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/LoreEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/LoreEditor.java deleted file mode 100644 index 61846ef9..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/LoreEditor.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.page.property; - -import dev.dejvokep.boostedyaml.block.implementation.Section; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; -import net.momirealms.customfishing.common.helper.AdventureHelper; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.gui.Gui; -import xyz.xenondevs.invui.gui.PagedGui; -import xyz.xenondevs.invui.gui.structure.Markers; -import xyz.xenondevs.invui.item.Item; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; -import xyz.xenondevs.invui.item.impl.SimpleItem; -import xyz.xenondevs.invui.window.AnvilWindow; - -import java.util.ArrayList; -import java.util.List; - -public class LoreEditor { - - private final Player player; - private final SectionPage parentPage; - private final ArrayList lore; - private final Section section; - private int index; - - public LoreEditor(Player player, SectionPage parentPage) { - this.player = player; - this.parentPage = parentPage; - this.section = parentPage.getSection(); - this.index = 0; - this.lore = new ArrayList<>(section.getStringList("display.lore")); - this.lore.add(0, "Select one lore"); - reOpen(0); - } - - public void reOpen(int idx) { - Item border = new SimpleItem(new ItemBuilder(Material.AIR)); - var confirm = new ConfirmIcon(); - Gui upperGui = Gui.normal() - .setStructure("a # b") - .addIngredient('a', new ItemBuilder(Material.NAME_TAG).setDisplayName(lore.get(idx))) - .addIngredient('#', border) - .addIngredient('b', confirm) - .build(); - - var gui = PagedGui.items() - .setStructure( - "x x x x x x x x x", - "x x x x x x x x x", - "x x x x x x x x x", - "# # # # c # # # #" - ) - .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL) - .addIngredient('c', parentPage.getBackItem()) - .addIngredient('#', new BackGroundItem()) - .setContent(getContents()) - .build(); - - var window = AnvilWindow.split() - .setViewer(player) - .setTitle(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_LORE_TITLE.build()))) - .addRenameHandler(s -> { - if (index == 0) return; - lore.set(index, s); - confirm.notifyWindows(); - }) - .setUpperGui(upperGui) - .setLowerGui(gui) - .build(); - - window.open(); - } - - public List getContents() { - ArrayList items = new ArrayList<>(); - int i = 1; - List subList = lore.subList(1, lore.size()); - for (String lore : subList) { - items.add(new LoreElement(lore, i++)); - } - items.add(new AddLore()); - return items; - } - - public class AddLore extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - return new ItemBuilder(Material.ANVIL).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_ADD_NEW_LORE.build()))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - lore.add("Text"); - index = lore.size() - 1; - reOpen(index); - } - } - - public class LoreElement extends AbstractItem { - - private final String line; - private final int idx; - - public LoreElement(String line, int idx) { - this.line = line; - this.idx = idx; - } - - @Override - public ItemProvider getItemProvider() { - return new ItemBuilder(Material.PAPER) - .setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.miniMessage(line))).addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_DELETE.build()))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (clickType == ClickType.LEFT) { - index = idx; - reOpen(idx); - } else if (clickType == ClickType.RIGHT) { - lore.remove(idx); - index = Math.min(index, lore.size() - 1); - reOpen(index); - } - } - } - - public class ConfirmIcon extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - List subList = lore.subList(1, lore.size()); - if (subList.isEmpty()) { - return new ItemBuilder(Material.STRUCTURE_VOID).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_DELETE_PROPERTY.build()))); - } else { - var builder = new ItemBuilder(Material.NAME_TAG) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CLICK_CONFIRM.build()))); - for (String lore : subList) { - builder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.miniMessage(" - " + lore))); - } - return builder; - } - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - List subList = lore.subList(1, lore.size()); - if (lore.isEmpty()) { - section.set("display.lore", null); - } else { - section.set("display.lore", subList); - } - parentPage.reOpen(); - parentPage.save(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/MaterialEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/MaterialEditor.java deleted file mode 100644 index 059fdec0..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/MaterialEditor.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.page.property; - -import dev.dejvokep.boostedyaml.block.implementation.Section; -import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.gui.Gui; -import xyz.xenondevs.invui.gui.PagedGui; -import xyz.xenondevs.invui.gui.structure.Markers; -import xyz.xenondevs.invui.item.Item; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; -import xyz.xenondevs.invui.item.impl.SimpleItem; -import xyz.xenondevs.invui.window.AnvilWindow; - -import java.util.ArrayList; -import java.util.List; - -public class MaterialEditor { - - private final Player player; - private final SectionPage parentPage; - private String material; - private final Section section; - - public MaterialEditor(Player player, SectionPage parentPage) { - this.player = player; - this.parentPage = parentPage; - this.section = parentPage.getSection(); - this.material = section.getString("material"); - - Item border = new SimpleItem(new ItemBuilder(Material.AIR)); - var confirm = new ConfirmIcon(); -// var itemBuilder = new ItemBuilder(BukkitCustomFishingPlugin.get() -// .getItemManager() -// .getItemStackAppearance(player, material) -// ) -// .setDisplayName(section.getString("material", "")); -// -// if (section.contains("custom-model-data")) -// itemBuilder.setCustomModelData(section.getInt("custom-model-data", 0)); - - Gui upperGui = Gui.normal() - .setStructure("a # b") -// .addIngredient('a', itemBuilder) - .addIngredient('#', border) - .addIngredient('b', confirm) - .build(); - - var gui = PagedGui.items() - .setStructure( - "x x x x x x x x x", - "x x x x x x x x x", - "x x x x x x x x x", - "# # # # c # # # #" - ) - .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL) - .addIngredient('c', parentPage.getBackItem()) - .addIngredient('#', new BackGroundItem()) - .setContent(getCompatibilityItemList()) - .build(); - - var window = AnvilWindow.split() - .setViewer(player) - .setTitle(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_MATERIAL_TITLE.build()))) - .addRenameHandler(s -> { - material = s; - confirm.notifyWindows(); - }) - .setUpperGui(upperGui) - .setLowerGui(gui) - .build(); - - window.open(); - } - - public List getCompatibilityItemList() { - ArrayList items = new ArrayList<>(); - for (net.momirealms.customfishing.api.integration.ItemProvider lib : BukkitCustomFishingPlugin.getInstance().getItemManager().getItemProviders()) { - switch (lib.identifier()) { - case "MMOItems" -> items.add(new SimpleItem(new ItemBuilder(Material.BELL).setDisplayName(lib + ":TYPE:ID"))); - case "ItemsAdder" -> items.add(new SimpleItem(new ItemBuilder(Material.BELL).setDisplayName(lib + ":namespace:id"))); - case "vanilla", "CustomFishing" -> {} - default -> items.add(new SimpleItem(new ItemBuilder(Material.BELL).setDisplayName(lib + ":ID"))); - } - } - return items; - } - - public class ConfirmIcon extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - if (material == null || material.isEmpty()) { - return new ItemBuilder(Material.STRUCTURE_VOID).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_DELETE_PROPERTY.build()))); - } else { -// var builder = new ItemBuilder( -// BukkitCustomFishingPlugin.get() -// .getItemManager() -// .getItemStackAppearance(player, material) -// ).setDisplayName(CFLocale.GUI_NEW_VALUE + material) -// .addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.getInstance().getComponentFromMiniMessage( -// CFLocale.GUI_CLICK_CONFIRM -// ))); -// if (section.contains("custom-model-data")) -// builder.setCustomModelData(section.getInt("custom-model-data")); -// return builder; - return null; - } - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { -// if (material == null || material.isEmpty()) { -// section.set("material", null); -// } else if (BukkitCustomFishingPlugin.get().getItemManager().getItemStackAppearance(player, material).getType() == Material.BARRIER) { -// return; -// } else { -// section.set("material", material); -// } - parentPage.reOpen(); - parentPage.save(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/NBTEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/NBTEditor.java deleted file mode 100644 index aaa89c19..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/NBTEditor.java +++ /dev/null @@ -1,643 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.page.property; - -import dev.dejvokep.boostedyaml.block.implementation.Section; -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; -import net.momirealms.customfishing.common.helper.AdventureHelper; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.gui.Gui; -import xyz.xenondevs.invui.gui.PagedGui; -import xyz.xenondevs.invui.gui.structure.Markers; -import xyz.xenondevs.invui.item.Item; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; -import xyz.xenondevs.invui.window.AnvilWindow; - -import java.util.*; - -@SuppressWarnings("DuplicatedCode") -public class NBTEditor { - - private final Player player; - private final SectionPage parentPage; - private Section nbtSection; - private Section currentSection; - private String value; - private String currentNode; - - public NBTEditor(Player player, SectionPage parentPage) { - this.player = player; - this.parentPage = parentPage; - this.nbtSection = parentPage.getSection().getSection("nbt"); - if (this.nbtSection == null) - this.nbtSection = parentPage.getSection().createSection("nbt"); - this.currentSection = nbtSection; - this.currentNode = ""; - reOpenMain(); - } - - public List getNBTContents() { - Deque deque = new ArrayDeque<>(); - for (Map.Entry entry : currentSection.getStringRouteMappedValues(false).entrySet()) { - String path = Objects.equals(currentNode, "") ? entry.getKey() : currentNode + "." + entry.getKey(); - if (entry.getValue() instanceof List list) { - deque.addLast(new InvListIcon(path)); - } else if (entry.getValue() instanceof String str) { - deque.addLast(new InvValueIcon(path, str)); - } else if (entry.getValue() instanceof Section inner) { - deque.addFirst(new InvCompoundIcon(path, inner)); - } else if (entry.getValue() instanceof Map map) { - deque.addLast(new InvMapIcon(path)); - } - } - deque.addLast(new NewCompoundIcon()); - deque.addLast(new NewListIcon()); - deque.addLast(new NewValueIcon()); - if (currentSection.getParent() != null && !currentSection.getName().equals("nbt")) { - deque.addLast(new BackToParentIcon()); - } - return new ArrayList<>(deque); - } - - public void reOpenMain() { - Gui upperGui = Gui.normal() - .setStructure("b b c") - .addIngredient('b', new ItemStack(Material.AIR)) - .addIngredient('c', new SaveIcon()) - .build(); - - var gui = PagedGui.items() - .setStructure( - "x x x x x x x x x", - "x x x x x x x x x", - "x x x x x x x x x", - "# # # # c # # # #" - ) - .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL) - .addIngredient('c', parentPage.getBackItem()) - .addIngredient('#', new BackGroundItem()) - .setContent(getNBTContents()) - .build(); - - var window = AnvilWindow.split() - .setViewer(player) - .setTitle(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_NBT_EDIT_TITLE.build()))) - .setUpperGui(upperGui) - .setLowerGui(gui) - .build(); - - window.open(); - } - - public void reOpenAddCompound() { - var confirm = new ConfirmCompoundItem(); - Gui upperGui = Gui.normal() - .setStructure("a b c") - .addIngredient('a', new ItemBuilder(Material.COMMAND_BLOCK_MINECART).setDisplayName("")) - .addIngredient('b', new ItemStack(Material.AIR)) - .addIngredient('c', confirm) - .build(); - - value = ""; - - var gui = PagedGui.items() - .setStructure( - "x x x x x x x x x", - "x x x x x x x x x", - "x x x x x x x x x", - "# # # # c # # # #" - ) - .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL) - .addIngredient('c', parentPage.getBackItem()) - .addIngredient('#', new BackGroundItem()) - .setContent(getNBTContents()) - .build(); - - var window = AnvilWindow.split() - .setViewer(player) - .setTitle(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_NBT_COMPOUND_KEY_TITLE.build()))) - .addRenameHandler(s -> { - value = s; - confirm.notifyWindows(); - }) - .setUpperGui(upperGui) - .setLowerGui(gui) - .build(); - - window.open(); - } - - public void reOpenAddList() { - var confirm = new ConfirmListItem(); - Gui upperGui = Gui.normal() - .setStructure("a b c") - .addIngredient('a', new ItemBuilder(Material.CHAIN_COMMAND_BLOCK).setDisplayName("")) - .addIngredient('b', new ItemStack(Material.AIR)) - .addIngredient('c', confirm) - .build(); - - value = ""; - - var gui = PagedGui.items() - .setStructure( - "x x x x x x x x x", - "x x x x x x x x x", - "x x x x x x x x x", - "# # # # c # # # #" - ) - .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL) - .addIngredient('c', parentPage.getBackItem()) - .addIngredient('#', new BackGroundItem()) - .setContent(getNBTContents()) - .build(); - - var window = AnvilWindow.split() - .setViewer(player) - .setTitle(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_NBT_LIST_KEY_TITLE.build()))) - .addRenameHandler(s -> { - value = s; - confirm.notifyWindows(); - }) - .setUpperGui(upperGui) - .setLowerGui(gui) - .build(); - - window.open(); - } - - public void reOpenAddValue() { - var confirm =new ConfirmValueItem(); - Gui upperGui = Gui.normal() - .setStructure("a b c") - .addIngredient('a', new ItemBuilder(Material.COMMAND_BLOCK).setDisplayName("")) - .addIngredient('b', new ItemStack(Material.AIR)) - .addIngredient('c', confirm) - .build(); - - value = ""; - - var gui = PagedGui.items() - .setStructure( - "x x x x x x x x x", - "x x x x x x x x x", - "x x x x x x x x x", - "# # # # c # # # #" - ) - .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL) - .addIngredient('c', parentPage.getBackItem()) - .addIngredient('#', new BackGroundItem()) - .setContent(getNBTContents()) - .build(); - - var window = AnvilWindow.split() - .setViewer(player) - .setTitle(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_NBT_KEY_TITLE.build()))) - .addRenameHandler(s -> { - value = s; - confirm.notifyWindows(); - }) - .setUpperGui(upperGui) - .setLowerGui(gui) - .build(); - - window.open(); - } - - public void reOpenSetValue(String key, String type) { - var save = new SaveValueIcon(key); - Gui upperGui = Gui.normal() - .setStructure("a b c") - .addIngredient('a', new ItemBuilder(Material.COMMAND_BLOCK).setDisplayName(type == null ? "" : "(" + type + ") ")) - .addIngredient('b', new ItemStack(Material.AIR)) - .addIngredient('c', save) - .build(); - - value = ""; - - var gui = PagedGui.items() - .setStructure( - "x x x x x x x x x", - "x x x x x x x x x", - "x x x x x x x x x", - "# # # # c # # # #" - ) - .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL) - .addIngredient('c', parentPage.getBackItem()) - .addIngredient('#', new BackGroundItem()) - .setContent(getTypeContents(key)) - .build(); - - var window = AnvilWindow.split() - .setViewer(player) - .setTitle(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_NBT_SET_VALUE_TITLE.build()))) - .addRenameHandler(s -> { - value = s; - save.notifyWindows(); - }) - .setUpperGui(upperGui) - .setLowerGui(gui) - .build(); - - window.open(); - } - - public void removeByNode(String node) { - nbtSection.set(node, null); - parentPage.save(); - } - - public List getTypeContents(String key) { - ArrayList list = new ArrayList<>(); - for (Map.Entry entry : Map.of( - "String","some text", - "Byte","1", - "Short","123", - "Int","123456", - "Long","123456789", - "Double", "1.2345", - "Float", "1.23", - "Boolean", "true", - "IntArray", "[111,222,333,444]", - "ByteArray","[1,2,3,4]" - ).entrySet()) { - list.add(new TypeItem(key, entry.getKey(), entry.getValue())); - } - return list; - } - - public class TypeItem extends AbstractItem { - - private final String type; - private final String tip; - private final String key; - - public TypeItem(String key, String type, String tip) { - this.type = type; - this.tip = tip; - this.key = key; - } - - @Override - public ItemProvider getItemProvider() { - return new ItemBuilder(Material.BELL).setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.miniMessage("(" + type + ") " + tip))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - reOpenSetValue(key, type); - } - } - - public class ConfirmCompoundItem extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - if (value == null || value.isEmpty() || value.contains(".") || currentSection.contains(value)) { - return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_NBT_INVALID_KEY.build()))); - } - - return new ItemBuilder(Material.COMMAND_BLOCK_MINECART) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_NEW_VALUE.arguments(Component.text(value)).build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CLICK_CONFIRM.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_CANCEL.build()))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (clickType.isLeftClick()) { - if (value == null || value.isEmpty() || value.contains(".")) { - return; - } - if (currentSection.contains(value)) { - return; - } - currentSection.createSection(value); - parentPage.save(); - } - reOpenMain(); - } - } - - public class ConfirmListItem extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - if (value == null || value.isEmpty() || value.contains(".") || currentSection.contains(value)) { - return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_NBT_INVALID_KEY.build()))); - } - return new ItemBuilder(Material.CHAIN_COMMAND_BLOCK) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_NEW_VALUE.arguments(Component.text(value)).build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CLICK_CONFIRM.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_CANCEL.build()))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (clickType.isLeftClick()) { - if (value == null || value.isEmpty() || value.contains(".")) { - return; - } - if (currentSection.contains(value)) { - return; - } - currentSection.set(value, new ArrayList<>()); - parentPage.save(); - } - reOpenMain(); - } - } - - public class ConfirmValueItem extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - if (value == null || value.isEmpty() || value.contains(".") || currentSection.contains(value)) { - return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_NBT_INVALID_KEY.build()))); - } - - return new ItemBuilder(Material.COMMAND_BLOCK) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_NEW_VALUE.arguments(Component.text(value)).build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CLICK_CONFIRM.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_CANCEL.build()))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (clickType.isLeftClick()) { - if (value == null || value.isEmpty() || value.contains(".")) { - return; - } - if (currentSection.contains(value)) { - return; - } - reOpenSetValue(value, null); - } else if (clickType.isRightClick()) { - reOpenMain(); - } - } - } - - public class NewCompoundIcon extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - return new ItemBuilder(Material.OAK_SIGN).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_NBT_ADD_NEW_COMPOUND.build()))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - reOpenAddCompound(); - } - } - - public class NewListIcon extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - return new ItemBuilder(Material.SPRUCE_SIGN).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_NBT_ADD_NEW_LIST.build()))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - reOpenAddList(); - } - } - - public class NewValueIcon extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - return new ItemBuilder(Material.ACACIA_SIGN).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_NBT_ADD_NEW_VALUE.build()))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - reOpenAddValue(); - } - } - - public class InvCompoundIcon extends AbstractItem { - - private final String node; - private final Section compound; - - public InvCompoundIcon(String node, Section compound) { - this.compound = compound; - this.node = node; - } - - @Override - public ItemProvider getItemProvider() { - String[] splits = node.split("\\."); - return new ItemBuilder(Material.COMMAND_BLOCK_MINECART) - .setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.miniMessage("Compound: " + splits[splits.length -1]))) - .addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_DELETE.build()))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (clickType.isLeftClick()) { - currentSection = compound; - currentNode = node; - } else if (clickType.isRightClick()) { - removeByNode(node); - } - reOpenMain(); - } - } - - public class InvValueIcon extends AbstractItem { - - private final String node; - private final String value; - - public InvValueIcon(String node, String value) { - this.node = node; - this.value = value; - } - - @Override - public ItemProvider getItemProvider() { - String[] splits = node.split("\\."); - return new ItemBuilder(Material.REPEATING_COMMAND_BLOCK) - .setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.miniMessage(splits[splits.length -1] + ": " + value))) - .addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_DELETE.build()))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - String[] split = node.split("\\."); - if (clickType.isLeftClick()) { - //reOpenSetValue(split[split.length-1], NBTUtils.getTypeAndData(value)[0]); - } else if (clickType.isRightClick()) { - removeByNode(node); - reOpenMain(); - } - } - } - - public class InvListIcon extends AbstractItem { - - private final String node; - - public InvListIcon(String node) { - this.node = node; - } - - @Override - public ItemProvider getItemProvider() { - String[] splits = node.split("\\."); - return new ItemBuilder(Material.CHAIN_COMMAND_BLOCK) - .setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.miniMessage("List: " + splits[splits.length -1]))) - .addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_DELETE.build()))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (clickType.isRightClick()) { - removeByNode(node); - reOpenMain(); - } - } - } - - public class InvMapIcon extends AbstractItem { - - private final String node; - - public InvMapIcon(String node) { - this.node = node; - } - - @Override - public ItemProvider getItemProvider() { - String[] splits = node.split("\\."); - return new ItemBuilder(Material.COMMAND_BLOCK) - .setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.miniMessage("Map: " + splits[splits.length -1]))) - .addLoreLines("") - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_LEFT_CLICK_EDIT.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_DELETE.build()))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (clickType.isRightClick()) { - removeByNode(node); - reOpenMain(); - } - } - } - - public class SaveValueIcon extends AbstractItem { - - private final String key; - - public SaveValueIcon(String key) { - this.key = key; - } - - @Override - public ItemProvider getItemProvider() { - try { - //NBTUtils.getTypeAndData(value); - return new ItemBuilder(Material.COMMAND_BLOCK) - .setDisplayName(value) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CLICK_CONFIRM.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_RIGHT_CLICK_CANCEL.build()))); - } catch (IllegalArgumentException e) { - return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render( - MessageConstants.GUI_ILLEGAL_FORMAT.build() - ))); - } - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (clickType == ClickType.LEFT) { - try { - //NBTUtils.getTypeAndData(value); - currentSection.set(key, value); - parentPage.save(); - reOpenMain(); - } catch (IllegalArgumentException e) { - reOpenMain(); - } - } else if (clickType == ClickType.RIGHT) { - reOpenMain(); - } - } - } - - public class SaveIcon extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - if (!nbtSection.getStringRouteMappedValues(false).isEmpty()) { - var builder = new ItemBuilder(Material.ACACIA_SIGN).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_NBT_PREVIEW.build()))); -// for (String line : ConfigUtils.getReadableSection(nbtSection.getValues(false))) { -// builder.addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.miniMessage(line))); -// } - return builder; - } else { - return new ItemBuilder(Material.STRUCTURE_VOID).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_DELETE_PROPERTY.build()))); - } - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (nbtSection.getStringRouteMappedValues(false).isEmpty()) { - Objects.requireNonNull(nbtSection.getParent()).set("nbt", null); - } - parentPage.save(); - parentPage.reOpen(); - } - } - - public class BackToParentIcon extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - return new ItemBuilder(Material.MINECART).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_NBT_BACK_TO_COMPOUND.build()))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - currentSection = currentSection.getParent(); - currentNode = currentNode.lastIndexOf(".") == -1 ? "" : currentNode.substring(0, currentNode.lastIndexOf(".")); - reOpenMain(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/NickEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/NickEditor.java deleted file mode 100644 index 6172deb7..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/NickEditor.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.page.property; - -import dev.dejvokep.boostedyaml.block.implementation.Section; -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; -import net.momirealms.customfishing.common.helper.AdventureHelper; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.gui.Gui; -import xyz.xenondevs.invui.gui.PagedGui; -import xyz.xenondevs.invui.item.Item; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; -import xyz.xenondevs.invui.item.impl.SimpleItem; -import xyz.xenondevs.invui.window.AnvilWindow; - -public class NickEditor { - - private final SectionPage parentPage; - private String nick; - private final Section section; - - public NickEditor(Player player, SectionPage parentPage) { - this.parentPage = parentPage; - this.section = parentPage.getSection(); - - Item border = new SimpleItem(new ItemBuilder(Material.AIR)); - var confirm = new ConfirmIcon(); - Gui upperGui = Gui.normal() - .setStructure("a # b") - .addIngredient('a', new ItemBuilder(Material.WRITABLE_BOOK) - .setDisplayName(new ShadedAdventureComponentWrapper(section.contains("nick") ? MessageConstants.GUI_PAGE_NEW_NICK.build() : Component.text(section.getString("nick"))))) - .addIngredient('#', border) - .addIngredient('b', confirm) - .build(); - - var gui = PagedGui.items() - .setStructure( - "x x x x x x x x x", - "x x x x x x x x x", - "x x x x x x x x x", - "# # # # c # # # #" - ) - .addIngredient('x', new ItemStack(Material.AIR)) - .addIngredient('c', parentPage.getBackItem()) - .addIngredient('#', new BackGroundItem()) - .build(); - - var window = AnvilWindow.split() - .setViewer(player) - .setTitle(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_NICK_TITLE.build()))) - .addRenameHandler(s -> { - nick = s; - confirm.notifyWindows(); - }) - .setUpperGui(upperGui) - .setLowerGui(gui) - .build(); - - window.open(); - } - - public class ConfirmIcon extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - if (nick == null || nick.isEmpty()) { - return new ItemBuilder(Material.STRUCTURE_VOID).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_DELETE_PROPERTY.build()))); - } else { - return new ItemBuilder(Material.WRITABLE_BOOK) - .setDisplayName(new ShadedAdventureComponentWrapper(AdventureHelper.miniMessage("" + nick))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CLICK_CONFIRM.build()))); - } - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (nick == null || nick.isEmpty()) { - section.set("nick", null); - } else { - section.set("nick", nick); - } - parentPage.reOpen(); - parentPage.save(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/PriceEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/PriceEditor.java deleted file mode 100644 index 9ce24735..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/PriceEditor.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.page.property; - -import dev.dejvokep.boostedyaml.block.implementation.Section; -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.gui.Gui; -import xyz.xenondevs.invui.gui.PagedGui; -import xyz.xenondevs.invui.item.Item; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; -import xyz.xenondevs.invui.item.impl.SimpleItem; -import xyz.xenondevs.invui.window.AnvilWindow; - -public class PriceEditor { - - private final Player player; - private final SectionPage parentPage; - private final String[] price; - private int index; - private final Section section; - - public PriceEditor(Player player, SectionPage parentPage) { - this.player = player; - this.parentPage = parentPage; - this.section = parentPage.getSection(); - this.index = 0; - this.price = new String[]{section.getString("price.base","0"), section.getString("price.bonus","0")}; - reOpen(); - } - - public void reOpen() { - Item border = new SimpleItem(new ItemBuilder(Material.AIR)); - var confirm = new ConfirmIcon(); - Gui upperGui = Gui.normal() - .setStructure("a # b") - .addIngredient('a', new ItemBuilder(Material.GOLD_INGOT).setDisplayName(price[index])) - .addIngredient('#', border) - .addIngredient('b', confirm) - .build(); - - var gui = PagedGui.items() - .setStructure( - "a b x x x x x x x", - "x x x x x x x x x", - "x x x x x x x x x", - "# # # # c # # # #" - ) - .addIngredient('x', new ItemStack(Material.AIR)) - .addIngredient('c', parentPage.getBackItem()) - .addIngredient('#', new BackGroundItem()) - .addIngredient('a', new BaseItem()) - .addIngredient('b', new BonusItem()) - .build(); - - var window = AnvilWindow.split() - .setViewer(player) - .setTitle(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_PRICE_TITLE.build()))) - .addRenameHandler(s -> { - if (s == null || s.isEmpty()) { - price[index] = "0"; - return; - } - price[index] = s; - confirm.notifyWindows(); - }) - .setUpperGui(upperGui) - .setLowerGui(gui) - .build(); - - window.open(); - } - - public class BaseItem extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - return new ItemBuilder(Material.GOLD_BLOCK).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_ITEM_PRICE_BASE.build()))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - index = 0; - reOpen(); - } - } - - public class BonusItem extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - return new ItemBuilder(Material.GOLD_NUGGET).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_ITEM_PRICE_BONUS.build()))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - index = 1; - reOpen(); - } - } - - public class ConfirmIcon extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - if (price[0].equals("0") && price[1].equals("0")) { - return new ItemBuilder(Material.STRUCTURE_VOID).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_DELETE_PROPERTY.build()))); - } else { - try { - Double.parseDouble(price[0]); - Double.parseDouble(price[1]); - return new ItemBuilder(Material.GOLD_INGOT) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_NEW_VALUE.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_ITEM_PRICE_BASE.arguments(Component.text(price[0])).build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_ITEM_PRICE_BONUS.arguments(Component.text(price[1])).build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CLICK_CONFIRM.build()))); - } catch (NumberFormatException e) { - return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_INVALID_NUMBER.build()))); - } - } - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (price[0].equals("0") && price[1].equals("0")) { - section.set("price", null); - } else { - try { - double base = Double.parseDouble(price[0]); - double bonus = Double.parseDouble(price[1]); - if (base != 0) { - section.set("price.base", base); - } - if (bonus != 0) { - section.set("price.bonus", bonus); - } - } catch (NumberFormatException e) { - return; - } - } - parentPage.reOpen(); - parentPage.save(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/ScoreEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/ScoreEditor.java deleted file mode 100644 index fe147b8b..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/ScoreEditor.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.page.property; - -import dev.dejvokep.boostedyaml.block.implementation.Section; -import net.kyori.adventure.text.Component; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.gui.Gui; -import xyz.xenondevs.invui.gui.PagedGui; -import xyz.xenondevs.invui.item.Item; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; -import xyz.xenondevs.invui.item.impl.SimpleItem; -import xyz.xenondevs.invui.window.AnvilWindow; - -public class ScoreEditor { - - private final SectionPage parentPage; - private String score; - private final Section section; - - public ScoreEditor(Player player, SectionPage parentPage) { - this.parentPage = parentPage; - this.section = parentPage.getSection(); - - Item border = new SimpleItem(new ItemBuilder(Material.AIR)); - var confirm = new ConfirmIcon(); - Gui upperGui = Gui.normal() - .setStructure("a # b") - .addIngredient('a', new ItemBuilder(Material.NETHER_STAR).setDisplayName(String.valueOf(section.getDouble("score", 0d)))) - .addIngredient('#', border) - .addIngredient('b', confirm) - .build(); - - var gui = PagedGui.items() - .setStructure( - "x x x x x x x x x", - "x x x x x x x x x", - "x x x x x x x x x", - "# # # # c # # # #" - ) - .addIngredient('x', new ItemStack(Material.AIR)) - .addIngredient('c', parentPage.getBackItem()) - .addIngredient('#', new BackGroundItem()) - .build(); - - var window = AnvilWindow.split() - .setViewer(player) - .setTitle(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_SCORE_TITLE.build()))) - .addRenameHandler(s -> { - score = s; - confirm.notifyWindows(); - }) - .setUpperGui(upperGui) - .setLowerGui(gui) - .build(); - - window.open(); - } - - public class ConfirmIcon extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - if (score == null || score.isEmpty()) { - return new ItemBuilder(Material.STRUCTURE_VOID).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_DELETE_PROPERTY.build()))); - } else { - try { - Double.parseDouble(score); - return new ItemBuilder(Material.NETHER_STAR) - .setDisplayName(new ShadedAdventureComponentWrapper((MessageConstants.GUI_NEW_VALUE.arguments(Component.text(score)).build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CLICK_CONFIRM.build()))); - } catch (NumberFormatException e) { - return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_INVALID_NUMBER.build()))); - } - } - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (score == null || score.isEmpty()) { - section.set("score", null); - } else { - try { - double value = Double.parseDouble(score); - if (value >= 0) { - section.set("score", value); - } else { - return; - } - } catch (NumberFormatException e) { - return; - } - } - parentPage.reOpen(); - parentPage.save(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/SizeEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/SizeEditor.java deleted file mode 100644 index 4d8df950..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/SizeEditor.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.bukkit.gui.page.property; - -import dev.dejvokep.boostedyaml.block.implementation.Section; -import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.bukkit.gui.SectionPage; -import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; -import net.momirealms.customfishing.common.helper.AdventureHelper; -import net.momirealms.customfishing.common.locale.MessageConstants; -import net.momirealms.customfishing.common.locale.TranslationManager; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import xyz.xenondevs.invui.gui.Gui; -import xyz.xenondevs.invui.gui.PagedGui; -import xyz.xenondevs.invui.item.Item; -import xyz.xenondevs.invui.item.ItemProvider; -import xyz.xenondevs.invui.item.builder.ItemBuilder; -import xyz.xenondevs.invui.item.impl.AbstractItem; -import xyz.xenondevs.invui.item.impl.SimpleItem; -import xyz.xenondevs.invui.window.AnvilWindow; - -public class SizeEditor { - - private final Player player; - private final SectionPage parentPage; - private final String[] size; - private int index; - private final Section section; - - public SizeEditor(Player player, SectionPage parentPage) { - this.player = player; - this.parentPage = parentPage; - this.section = parentPage.getSection(); - this.index = 0; - this.size = section.contains("size") ? section.getString("size").split("~") : new String[]{"0","0"}; - reOpen(); - } - - public void reOpen() { - Item border = new SimpleItem(new ItemBuilder(Material.AIR)); - var confirm = new ConfirmIcon(); - Gui upperGui = Gui.normal() - .setStructure("a # b") - .addIngredient('a', new ItemBuilder(Material.PUFFERFISH).setDisplayName(size[index])) - .addIngredient('#', border) - .addIngredient('b', confirm) - .build(); - - var gui = PagedGui.items() - .setStructure( - "a b x x x x x x x", - "x x x x x x x x x", - "x x x x x x x x x", - "# # # # c # # # #" - ) - .addIngredient('x', new ItemStack(Material.AIR)) - .addIngredient('c', parentPage.getBackItem()) - .addIngredient('#', new BackGroundItem()) - .addIngredient('a', new MinItem()) - .addIngredient('b', new MaxItem()) - .build(); - - var window = AnvilWindow.split() - .setViewer(player) - .setTitle(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_SIZE_TITLE.build()))) - .addRenameHandler(s -> { - if (s == null || s.isEmpty()) { - size[index] = "0"; - return; - } - size[index] = s; - confirm.notifyWindows(); - }) - .setUpperGui(upperGui) - .setLowerGui(gui) - .build(); - - window.open(); - } - - public class MinItem extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - return new ItemBuilder(Material.IRON_INGOT).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_SIZE_MIN.build()))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - index = 0; - reOpen(); - } - } - - public class MaxItem extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - return new ItemBuilder(Material.IRON_BLOCK).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_SIZE_MAX.build()))); - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - index = 1; - reOpen(); - } - } - - public class ConfirmIcon extends AbstractItem { - - @Override - public ItemProvider getItemProvider() { - if (size[0].equals("0") && size[1].equals("0")) { - return new ItemBuilder(Material.STRUCTURE_VOID).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_DELETE_PROPERTY.build()))); - } else { - try { - double min = Double.parseDouble(size[0]); - double max = Double.parseDouble(size[1]); - - if (min <= max) { - return new ItemBuilder(Material.PUFFERFISH) - .setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_NEW_VALUE.build()))) - .addLoreLines(new ShadedAdventureComponentWrapper(AdventureHelper.miniMessage(" - " + size[0] + "~" + size[1]))) - .addLoreLines(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_CLICK_CONFIRM.build()))); - } else { - return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_PAGE_SIZE_MAX_NO_LESS_MIN.build()))); - } - } catch (NumberFormatException e) { - return new ItemBuilder(Material.BARRIER).setDisplayName(new ShadedAdventureComponentWrapper(TranslationManager.render(MessageConstants.GUI_INVALID_NUMBER.build()))); - } - } - } - - @Override - public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) { - if (size[0].equals("0") && size[1].equals("0")) { - section.set("size", null); - } else { - try { - double min = Double.parseDouble(size[0]); - double max = Double.parseDouble(size[1]); - if (min <= max) { - section.set("size", min + "~" + max); - } - } catch (NumberFormatException e) { - return; - } - } - parentPage.reOpen(); - parentPage.save(); - } - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/integration/BukkitIntegrationManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/integration/BukkitIntegrationManager.java index 536a5ccb..1c22a3c4 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/integration/BukkitIntegrationManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/integration/BukkitIntegrationManager.java @@ -49,14 +49,12 @@ import java.util.List; public class BukkitIntegrationManager implements IntegrationManager { private final BukkitCustomFishingPlugin plugin; - private final HashMap levelerProviders; - private final HashMap enchantmentProviders; + private final HashMap levelerProviders = new HashMap<>(); + private final HashMap enchantmentProviders = new HashMap<>(); private SeasonProvider seasonProvider; public BukkitIntegrationManager(BukkitCustomFishingPlugin plugin) { this.plugin = plugin; - this.levelerProviders = new HashMap<>(); - this.enchantmentProviders = new HashMap<>(); this.load(); } diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/item/BukkitItemManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/item/BukkitItemManager.java index 2b25acfd..7895ef44 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/item/BukkitItemManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/item/BukkitItemManager.java @@ -11,7 +11,7 @@ import net.momirealms.customfishing.api.mechanic.item.CustomFishingItem; import net.momirealms.customfishing.api.mechanic.item.ItemManager; import net.momirealms.customfishing.api.mechanic.item.MechanicType; import net.momirealms.customfishing.bukkit.integration.item.CustomFishingItemProvider; -import net.momirealms.customfishing.bukkit.util.ItemUtils; +import net.momirealms.customfishing.bukkit.util.ItemStackUtils; import net.momirealms.customfishing.bukkit.util.LocationUtils; import net.momirealms.customfishing.common.item.Item; import net.momirealms.sparrow.heart.SparrowHeart; @@ -100,7 +100,9 @@ public class BukkitItemManager implements ItemManager, Listener { @Nullable @Override public ItemStack buildInternal(@NotNull Context context, @NotNull String id) { - CustomFishingItem item = requireNonNull(items.get(id), () -> "No item found for " + id); +// CustomFishingItem item = requireNonNull(items.get(id), () -> "No item found for " + id); + CustomFishingItem item = items.get(id); + if (item == null) return null; return build(context, item); } @@ -108,6 +110,7 @@ public class BukkitItemManager implements ItemManager, Listener { @Override public ItemStack build(@NotNull Context context, @NotNull CustomFishingItem item) { ItemStack itemStack = getOriginalStack(context.getHolder(), item.material()); + if (itemStack.getType() == Material.AIR) return itemStack; Item wrappedItemStack = factory.wrap(itemStack); for (BiConsumer, Context> consumer : item.tagConsumers()) { consumer.accept(wrappedItemStack, context); @@ -173,15 +176,14 @@ public class BukkitItemManager implements ItemManager, Listener { double d0 = playerLocation.getX() - hookLocation.getX(); double d1 = playerLocation.getY() - hookLocation.getY(); double d2 = playerLocation.getZ() - hookLocation.getZ(); - double d3 = 0.1D; Vector vector = new Vector(d0 * 0.1D, d1 * 0.1D + Math.sqrt(Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2)) * 0.08D, d2 * 0.1D); org.bukkit.entity.Item itemEntity = hookLocation.getWorld().dropItem(hookLocation, itemStack); - FishingLootSpawnEvent spawnEvent = new FishingLootSpawnEvent(player, hookLocation, itemEntity); + FishingLootSpawnEvent spawnEvent = new FishingLootSpawnEvent(player, hookLocation, plugin.getLootManager().getLoot(id).orElseThrow(), itemEntity); Bukkit.getPluginManager().callEvent(spawnEvent); if (spawnEvent.isCancelled()) { itemEntity.remove(); - return null; + return itemEntity; } itemEntity.setInvulnerable(true); @@ -268,7 +270,7 @@ public class BukkitItemManager implements ItemManager, Listener { PersistentDataContainer pdc = block.getChunk().getPersistentDataContainer(); ItemStack cloned = itemStack.clone(); cloned.setAmount(1); - pdc.set(new NamespacedKey(plugin.getBoostrap(), LocationUtils.toChunkPosString(block.getLocation())), PersistentDataType.STRING, ItemUtils.toBase64(cloned)); + pdc.set(new NamespacedKey(plugin.getBoostrap(), LocationUtils.toChunkPosString(block.getLocation())), PersistentDataType.STRING, ItemStackUtils.toBase64(cloned)); } else { event.setCancelled(true); } @@ -282,7 +284,7 @@ public class BukkitItemManager implements ItemManager, Listener { PersistentDataContainer pdc = block.getChunk().getPersistentDataContainer(); String base64 = pdc.get(new NamespacedKey(plugin.getBoostrap(), LocationUtils.toChunkPosString(block.getLocation())), PersistentDataType.STRING); if (base64 != null) { - ItemStack itemStack = ItemUtils.fromBase64(base64); + ItemStack itemStack = ItemStackUtils.fromBase64(base64); event.setDropItems(false); block.getLocation().getWorld().dropItemNaturally(block.getLocation(), itemStack); } @@ -329,7 +331,7 @@ public class BukkitItemManager implements ItemManager, Listener { var nk = new NamespacedKey(plugin.getBoostrap(), LocationUtils.toChunkPosString(block.getLocation())); String base64 = pdc.get(nk, PersistentDataType.STRING); if (base64 != null) { - ItemStack itemStack = ItemUtils.fromBase64(base64); + ItemStack itemStack = ItemStackUtils.fromBase64(base64); block.getLocation().getWorld().dropItemNaturally(block.getLocation(), itemStack); blockToRemove.add(block); block.setType(Material.AIR); diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/loot/BukkitLootManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/loot/BukkitLootManager.java index b9ec2724..3225873c 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/loot/BukkitLootManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/loot/BukkitLootManager.java @@ -130,7 +130,9 @@ public class BukkitLootManager implements LootManager { lootWeightMap.put(pair.left(), pair.right().apply(context, previous)); } String lootID = WeightUtils.getRandom(lootWeightMap); - return getLoot(lootID).orElseThrow(() -> new RuntimeException("Could not find loot " + lootID)); + return Optional.ofNullable(lootID) + .map(id -> getLoot(lootID).orElseThrow(() -> new RuntimeException("Could not find loot " + lootID))) + .orElseThrow(() -> new RuntimeException("No loot available. " + context)); } private void modifyWeightMap(Map weightMap, Context context, ConditionalElement, Double, Double>>>, Player> conditionalElement) { diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/requirement/BukkitRequirementManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/requirement/BukkitRequirementManager.java index 9252d1a9..44e82aea 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/requirement/BukkitRequirementManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/requirement/BukkitRequirementManager.java @@ -166,10 +166,18 @@ public class BukkitRequirementManager implements RequirementManager { this.registerCompetitionRequirement(); this.registerPluginLevelRequirement(); this.registerItemInHandRequirement(); + this.registerImpossibleRequirement(); + } + + private void registerImpossibleRequirement() { + registerRequirement("impossible", ((args, actions, runActions) -> context -> { + if (runActions) ActionManager.trigger(context, actions); + return false; + })); } private void registerCompetitionRequirement() { - registerRequirement("competition", (args, actions, advanced) -> { + registerRequirement("competition", (args, actions, runActions) -> { if (args instanceof Section section) { boolean onCompetition = section.getBoolean("ongoing", true); List ids = ListUtils.toList(section.get("id")); @@ -189,7 +197,7 @@ public class BukkitRequirementManager implements RequirementManager { return true; } } - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; } else { @@ -200,19 +208,19 @@ public class BukkitRequirementManager implements RequirementManager { } private void registerInBagRequirement() { - registerRequirement("in-fishingbag", (args, actions, advanced) -> { + registerRequirement("in-fishingbag", (args, actions, runActions) -> { boolean arg = (boolean) args; return context -> { boolean inBag = Optional.ofNullable(context.arg(ContextKeys.IN_BAG)).orElse(false); if (inBag == arg) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); } private void registerItemInHandRequirement() { - registerRequirement("item-in-hand", (args, actions, advanced) -> { + registerRequirement("item-in-hand", (args, actions, runActions) -> { if (args instanceof Section section) { boolean mainOrOff = section.getString("hand","main").equalsIgnoreCase("main"); int amount = section.getInt("amount", 1); @@ -223,7 +231,7 @@ public class BukkitRequirementManager implements RequirementManager { : context.getHolder().getInventory().getItemInOffHand(); String id = plugin.getItemManager().getItemID(itemStack); if (items.contains(id) && itemStack.getAmount() >= amount) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; } else { @@ -234,7 +242,7 @@ public class BukkitRequirementManager implements RequirementManager { } private void registerPluginLevelRequirement() { - registerRequirement("plugin-level", (args, actions, advanced) -> { + registerRequirement("plugin-level", (args, actions, runActions) -> { if (args instanceof Section section) { String pluginName = section.getString("plugin"); int level = section.getInt("level"); @@ -247,7 +255,7 @@ public class BukkitRequirementManager implements RequirementManager { } if (levelerProvider.getLevel(context.getHolder(), target) >= level) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; } else { @@ -258,7 +266,7 @@ public class BukkitRequirementManager implements RequirementManager { } private void registerTimeRequirement() { - registerRequirement("time", (args, actions, advanced) -> { + registerRequirement("time", (args, actions, runActions) -> { List list = ListUtils.toList(args); List> timePairs = list.stream().map(line -> { String[] split = line.split("~"); @@ -270,14 +278,14 @@ public class BukkitRequirementManager implements RequirementManager { for (Pair pair : timePairs) if (time >= pair.left() && time <= pair.right()) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); } private void registerYRequirement() { - registerRequirement("ypos", (args, actions, advanced) -> { + registerRequirement("ypos", (args, actions, runActions) -> { List list = ListUtils.toList(args); List> posPairs = list.stream().map(line -> { String[] split = line.split("~"); @@ -289,21 +297,21 @@ public class BukkitRequirementManager implements RequirementManager { for (Pair pair : posPairs) if (y >= pair.left() && y <= pair.right()) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); } private void registerOrRequirement() { - registerRequirement("||", (args, actions, advanced) -> { + registerRequirement("||", (args, actions, runActions) -> { if (args instanceof Section section) { - Requirement[] requirements = parseRequirements(section, advanced); + Requirement[] requirements = parseRequirements(section, runActions); return context -> { for (Requirement requirement : requirements) if (requirement.isSatisfied(context)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; } else { @@ -314,9 +322,9 @@ public class BukkitRequirementManager implements RequirementManager { } private void registerAndRequirement() { - registerRequirement("&&", (args, actions, advanced) -> { + registerRequirement("&&", (args, actions, runActions) -> { if (args instanceof Section section) { - Requirement[] requirements = parseRequirements(section, advanced); + Requirement[] requirements = parseRequirements(section, runActions); return context -> { outer: { for (Requirement requirement : requirements) @@ -324,7 +332,7 @@ public class BukkitRequirementManager implements RequirementManager { break outer; return true; } - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; } else { @@ -335,24 +343,24 @@ public class BukkitRequirementManager implements RequirementManager { } private void registerInWaterRequirement() { - registerRequirement("in-water", (args, actions, advanced) -> { + registerRequirement("in-water", (args, actions, runActions) -> { boolean inWater = (boolean) args; return context -> { boolean in_water = Optional.ofNullable(context.arg(ContextKeys.SURROUNDING)).orElse("").equals(EffectProperties.WATER_FISHING.key()); if (in_water == inWater) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); } private void registerInVoidRequirement() { - registerRequirement("in-void", (args, actions, advanced) -> { + registerRequirement("in-void", (args, actions, runActions) -> { boolean inVoid = (boolean) args; return context -> { boolean in_void = Optional.ofNullable(context.arg(ContextKeys.SURROUNDING)).orElse("").equals(EffectProperties.VOID_FISHING.key()); if (in_void == inVoid) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); @@ -360,14 +368,14 @@ public class BukkitRequirementManager implements RequirementManager { private void registerInLavaRequirement() { // Deprecated requirement type - registerRequirement("lava-fishing", (args, actions, advanced) -> { + registerRequirement("lava-fishing", (args, actions, runActions) -> { boolean inLava = (boolean) args; if (!inLava) { // in water return context -> { boolean in_water = Optional.ofNullable(context.arg(ContextKeys.SURROUNDING)).orElse("").equals(EffectProperties.WATER_FISHING.key()); if (in_water) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; } @@ -375,44 +383,44 @@ public class BukkitRequirementManager implements RequirementManager { return context -> { boolean in_lava = Optional.ofNullable(context.arg(ContextKeys.SURROUNDING)).orElse("").equals(EffectProperties.LAVA_FISHING.key()); if (in_lava) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); - registerRequirement("in-lava", (args, actions, advanced) -> { + registerRequirement("in-lava", (args, actions, runActions) -> { boolean inLava = (boolean) args; return context -> { boolean in_lava = Optional.ofNullable(context.arg(ContextKeys.SURROUNDING)).orElse("").equals(EffectProperties.LAVA_FISHING.key()); if (in_lava == inLava) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); } private void registerRodRequirement() { - registerRequirement("rod", (args, actions, advanced) -> { + registerRequirement("rod", (args, actions, runActions) -> { HashSet rods = new HashSet<>(ListUtils.toList(args)); return context -> { String id = context.arg(ContextKeys.ROD); if (rods.contains(id)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); - registerRequirement("!rod", (args, actions, advanced) -> { + registerRequirement("!rod", (args, actions, runActions) -> { HashSet rods = new HashSet<>(ListUtils.toList(args)); return context -> { String id = context.arg(ContextKeys.ROD); if (!rods.contains(id)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); } private void registerGroupRequirement() { - registerRequirement("group", (args, actions, advanced) -> { + registerRequirement("group", (args, actions, runActions) -> { HashSet groups = new HashSet<>(ListUtils.toList(args)); return context -> { String lootID = context.arg(ContextKeys.ID); @@ -423,11 +431,11 @@ public class BukkitRequirementManager implements RequirementManager { for (String x : group) if (groups.contains(x)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); - registerRequirement("!group", (args, actions, advanced) -> { + registerRequirement("!group", (args, actions, runActions) -> { HashSet groups = new HashSet<>(ListUtils.toList(args)); return context -> { String lootID = context.arg(ContextKeys.ID); @@ -442,123 +450,123 @@ public class BukkitRequirementManager implements RequirementManager { break outer; return true; } - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); } private void registerLootRequirement() { - registerRequirement("loot", (args, actions, advanced) -> { + registerRequirement("loot", (args, actions, runActions) -> { HashSet arg = new HashSet<>(ListUtils.toList(args)); return context -> { String lootID = context.arg(ContextKeys.ID); if (arg.contains(lootID)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); - registerRequirement("!loot", (args, actions, advanced) -> { + registerRequirement("!loot", (args, actions, runActions) -> { HashSet arg = new HashSet<>(ListUtils.toList(args)); return context -> { String lootID = context.arg(ContextKeys.ID); if (!arg.contains(lootID)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); } private void registerHookRequirement() { - registerRequirement("hook", (args, actions, advanced) -> { + registerRequirement("hook", (args, actions, runActions) -> { HashSet hooks = new HashSet<>(ListUtils.toList(args)); return context -> { String id = context.arg(ContextKeys.HOOK); if (hooks.contains(id)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); - registerRequirement("!hook", (args, actions, advanced) -> { + registerRequirement("!hook", (args, actions, runActions) -> { HashSet hooks = new HashSet<>(ListUtils.toList(args)); return context -> { String id = context.arg(ContextKeys.HOOK); if (!hooks.contains(id)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); - registerRequirement("has-hook", (args, actions, advanced) -> { + registerRequirement("has-hook", (args, actions, runActions) -> { boolean has = (boolean) args; return context -> { String id = context.arg(ContextKeys.HOOK); if (id != null && has) return true; if (id == null && !has) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); } private void registerBaitRequirement() { - registerRequirement("bait", (args, actions, advanced) -> { + registerRequirement("bait", (args, actions, runActions) -> { HashSet arg = new HashSet<>(ListUtils.toList(args)); return context -> { String id = context.arg(ContextKeys.BAIT); if (arg.contains(id)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); - registerRequirement("!bait", (args, actions, advanced) -> { + registerRequirement("!bait", (args, actions, runActions) -> { HashSet arg = new HashSet<>(ListUtils.toList(args)); return context -> { String id = context.arg(ContextKeys.BAIT); if (!arg.contains(id)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); - registerRequirement("has-bait", (args, actions, advanced) -> { + registerRequirement("has-bait", (args, actions, runActions) -> { boolean has = (boolean) args; return context -> { String id = context.arg(ContextKeys.BAIT); if (id != null && has) return true; if (id == null && !has) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); } private void registerSizeRequirement() { - registerRequirement("has-size", (args, actions, advanced) -> { + registerRequirement("has-size", (args, actions, runActions) -> { boolean has = (boolean) args; return context -> { float size = Optional.ofNullable(context.arg(ContextKeys.SIZE)).orElse(-1f); if (size != -1 && has) return true; if (size == -1 && !has) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); } private void registerOpenWaterRequirement() { - registerRequirement("open-water", (args, actions, advanced) -> { + registerRequirement("open-water", (args, actions, runActions) -> { boolean openWater = (boolean) args; return context -> { boolean current = Optional.ofNullable(context.arg(ContextKeys.OPEN_WATER)).orElse(false); if (openWater == current) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); } private void registerHasStatsRequirement() { - registerRequirement("has-stats", (args, actions, advanced) -> { + registerRequirement("has-stats", (args, actions, runActions) -> { boolean has = (boolean) args; return context -> { String loot = context.arg(ContextKeys.ID); @@ -567,14 +575,14 @@ public class BukkitRequirementManager implements RequirementManager { if (!lootInstance.get().disableStats() && has) return true; if (lootInstance.get().disableStats() && !has) return true; } - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); } private void registerLootTypeRequirement() { - registerRequirement("loot-type", (args, actions, advanced) -> { + registerRequirement("loot-type", (args, actions, runActions) -> { List types = ListUtils.toList(args); return context -> { String loot = context.arg(ContextKeys.ID); @@ -583,11 +591,11 @@ public class BukkitRequirementManager implements RequirementManager { if (types.contains(lootInstance.get().type().name().toLowerCase(Locale.ENGLISH))) return true; } - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); - registerRequirement("!loot-type", (args, actions, advanced) -> { + registerRequirement("!loot-type", (args, actions, runActions) -> { List types = ListUtils.toList(args); return context -> { String loot = context.arg(ContextKeys.ID); @@ -596,14 +604,14 @@ public class BukkitRequirementManager implements RequirementManager { if (!types.contains(lootInstance.get().type().name().toLowerCase(Locale.ENGLISH))) return true; } - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); } private void registerListRequirement() { - registerRequirement("list", (args, actions, advanced) -> { + registerRequirement("list", (args, actions, runActions) -> { plugin.getPluginLogger().severe("It seems that you made a mistake where you put \"list\" into \"conditions\" section."); plugin.getPluginLogger().warn("list:"); for (String e : ListUtils.toList(args)) { @@ -614,30 +622,30 @@ public class BukkitRequirementManager implements RequirementManager { } private void registerEnvironmentRequirement() { - registerRequirement("environment", (args, actions, advanced) -> { + registerRequirement("environment", (args, actions, runActions) -> { List environments = ListUtils.toList(args); return context -> { Location location = requireNonNull(context.arg(ContextKeys.LOCATION)); var name = location.getWorld().getEnvironment().name().toLowerCase(Locale.ENGLISH); if (environments.contains(name)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); - registerRequirement("!environment", (args, actions, advanced) -> { + registerRequirement("!environment", (args, actions, runActions) -> { List environments = ListUtils.toList(args); return context -> { Location location = requireNonNull(context.arg(ContextKeys.LOCATION)); var name = location.getWorld().getEnvironment().name().toLowerCase(Locale.ENGLISH); if (!environments.contains(name)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); } private void registerIceFishingRequirement() { - registerRequirement("ice-fishing", (args, actions, advanced) -> { + registerRequirement("ice-fishing", (args, actions, runActions) -> { boolean iceFishing = (boolean) args; return context -> { Location location = requireNonNull(context.arg(ContextKeys.HOOK_LOCATION)); @@ -654,125 +662,125 @@ public class BukkitRequirementManager implements RequirementManager { } if ((ice >= 16 && water >= 25) == iceFishing) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); } private void registerLevelRequirement() { - registerRequirement("level", (args, actions, advanced) -> { + registerRequirement("level", (args, actions, runActions) -> { MathValue value = MathValue.auto(args); return context -> { int current = context.getHolder().getLevel(); if (current >= value.evaluate(context)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); } private void registerMoneyRequirement() { - registerRequirement("money", (args, actions, advanced) -> { + registerRequirement("money", (args, actions, runActions) -> { MathValue value = MathValue.auto(args); return context -> { double current = VaultHook.getBalance(context.getHolder()); if (current >= value.evaluate(context)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); } private void registerRandomRequirement() { - registerRequirement("random", (args, actions, advanced) -> { + registerRequirement("random", (args, actions, runActions) -> { MathValue value = MathValue.auto(args); return context -> { if (Math.random() < value.evaluate(context)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); } private void registerBiomeRequirement() { - registerRequirement("biome", (args, actions, advanced) -> { + registerRequirement("biome", (args, actions, runActions) -> { HashSet biomes = new HashSet<>(ListUtils.toList(args)); return context -> { Location location = requireNonNull(Optional.ofNullable(context.arg(ContextKeys.HOOK_LOCATION)).orElse(context.arg(ContextKeys.LOCATION))); String currentBiome = SparrowHeart.getInstance().getBiomeResourceLocation(location); if (biomes.contains(currentBiome)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); - registerRequirement("!biome", (args, actions, advanced) -> { + registerRequirement("!biome", (args, actions, runActions) -> { HashSet biomes = new HashSet<>(ListUtils.toList(args)); return context -> { Location location = requireNonNull(Optional.ofNullable(context.arg(ContextKeys.HOOK_LOCATION)).orElse(context.arg(ContextKeys.LOCATION))); String currentBiome = SparrowHeart.getInstance().getBiomeResourceLocation(location); if (!biomes.contains(currentBiome)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); } private void registerMoonPhaseRequirement() { - registerRequirement("moon-phase", (args, actions, advanced) -> { + registerRequirement("moon-phase", (args, actions, runActions) -> { HashSet moonPhases = new HashSet<>(ListUtils.toList(args)); return context -> { Location location = requireNonNull(context.arg(ContextKeys.LOCATION)); long days = location.getWorld().getFullTime() / 24_000; if (moonPhases.contains(MoonPhase.getPhase(days).name().toLowerCase(Locale.ENGLISH))) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); - registerRequirement("!moon-phase", (args, actions, advanced) -> { + registerRequirement("!moon-phase", (args, actions, runActions) -> { HashSet moonPhases = new HashSet<>(ListUtils.toList(args)); return context -> { Location location = requireNonNull(context.arg(ContextKeys.LOCATION)); long days = location.getWorld().getFullTime() / 24_000; if (!moonPhases.contains(MoonPhase.getPhase(days).name().toLowerCase(Locale.ENGLISH))) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); } private void registerWorldRequirement() { - registerRequirement("world", (args, actions, advanced) -> { + registerRequirement("world", (args, actions, runActions) -> { HashSet worlds = new HashSet<>(ListUtils.toList(args)); return context -> { Location location = requireNonNull(context.arg(ContextKeys.LOCATION)); if (worlds.contains(location.getWorld().getName())) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); - registerRequirement("!world", (args, actions, advanced) -> { + registerRequirement("!world", (args, actions, runActions) -> { HashSet worlds = new HashSet<>(ListUtils.toList(args)); return context -> { Location location = requireNonNull(context.arg(ContextKeys.LOCATION)); if (!worlds.contains(location.getWorld().getName())) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); } private void registerWeatherRequirement() { - registerRequirement("weather", (args, actions, advanced) -> { + registerRequirement("weather", (args, actions, runActions) -> { HashSet weathers = new HashSet<>(ListUtils.toList(args)); return context -> { String currentWeather; @@ -782,21 +790,21 @@ public class BukkitRequirementManager implements RequirementManager { else if (world.isThundering()) currentWeather = "thunder"; else currentWeather = "rain"; if (weathers.contains(currentWeather)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); } private void registerCoolDownRequirement() { - registerRequirement("cooldown", (args, actions, advanced) -> { + registerRequirement("cooldown", (args, actions, runActions) -> { if (args instanceof Section section) { String key = section.getString("key"); int time = section.getInt("time"); return context -> { if (!plugin.getCoolDownManager().isCoolDown(context.getHolder().getUniqueId(), key, time)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; } else { @@ -807,36 +815,36 @@ public class BukkitRequirementManager implements RequirementManager { } private void registerDateRequirement() { - registerRequirement("date", (args, actions, advanced) -> { + registerRequirement("date", (args, actions, runActions) -> { HashSet dates = new HashSet<>(ListUtils.toList(args)); return context -> { Calendar calendar = Calendar.getInstance(); String current = (calendar.get(Calendar.MONTH) + 1) + "/" + calendar.get(Calendar.DATE); if (dates.contains(current)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); } private void registerPermissionRequirement() { - registerRequirement("permission", (args, actions, advanced) -> { + registerRequirement("permission", (args, actions, runActions) -> { List perms = ListUtils.toList(args); return context -> { for (String perm : perms) if (context.getHolder().hasPermission(perm)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); - registerRequirement("!permission", (args, actions, advanced) -> { + registerRequirement("!permission", (args, actions, runActions) -> { List perms = ListUtils.toList(args); return context -> { for (String perm : perms) if (context.getHolder().hasPermission(perm)) { - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; } return true; @@ -845,7 +853,7 @@ public class BukkitRequirementManager implements RequirementManager { } private void registerSeasonRequirement() { - registerRequirement("season", (args, actions, advanced) -> { + registerRequirement("season", (args, actions, runActions) -> { List seasons = ListUtils.toList(args); return context -> { SeasonProvider seasonProvider = plugin.getIntegrationManager().getSeasonProvider(); @@ -854,20 +862,20 @@ public class BukkitRequirementManager implements RequirementManager { World world = location.getWorld(); Season season = seasonProvider.getSeason(world); if (seasons.contains(season.name().toLowerCase(Locale.ENGLISH))) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); } private void registerPAPIRequirement() { - registerRequirement("<", (args, actions, advanced) -> { + registerRequirement("<", (args, actions, runActions) -> { if (args instanceof Section section) { MathValue v1 = MathValue.auto(section.get("value1")); MathValue v2 = MathValue.auto(section.get("value2")); return context -> { if (v1.evaluate(context) < v2.evaluate(context)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; } else { @@ -875,13 +883,13 @@ public class BukkitRequirementManager implements RequirementManager { return EmptyRequirement.INSTANCE; } }); - registerRequirement("<=", (args, actions, advanced) -> { + registerRequirement("<=", (args, actions, runActions) -> { if (args instanceof Section section) { MathValue v1 = MathValue.auto(section.get("value1")); MathValue v2 = MathValue.auto(section.get("value2")); return context -> { if (v1.evaluate(context) <= v2.evaluate(context)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; } else { @@ -889,13 +897,13 @@ public class BukkitRequirementManager implements RequirementManager { return EmptyRequirement.INSTANCE; } }); - registerRequirement("!=", (args, actions, advanced) -> { + registerRequirement("!=", (args, actions, runActions) -> { if (args instanceof Section section) { MathValue v1 = MathValue.auto(section.get("value1")); MathValue v2 = MathValue.auto(section.get("value2")); return context -> { if (v1.evaluate(context) != v2.evaluate(context)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; } else { @@ -903,13 +911,13 @@ public class BukkitRequirementManager implements RequirementManager { return EmptyRequirement.INSTANCE; } }); - registerRequirement("==", (args, actions, advanced) -> { + registerRequirement("==", (args, actions, runActions) -> { if (args instanceof Section section) { MathValue v1 = MathValue.auto(section.get("value1")); MathValue v2 = MathValue.auto(section.get("value2")); return context -> { if (v1.evaluate(context) == v2.evaluate(context)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; } else { @@ -917,13 +925,13 @@ public class BukkitRequirementManager implements RequirementManager { return EmptyRequirement.INSTANCE; } }); - registerRequirement(">=", (args, actions, advanced) -> { + registerRequirement(">=", (args, actions, runActions) -> { if (args instanceof Section section) { MathValue v1 = MathValue.auto(section.get("value1")); MathValue v2 = MathValue.auto(section.get("value2")); return context -> { if (v1.evaluate(context) >= v2.evaluate(context)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; } else { @@ -931,13 +939,13 @@ public class BukkitRequirementManager implements RequirementManager { return EmptyRequirement.INSTANCE; } }); - registerRequirement(">", (args, actions, advanced) -> { + registerRequirement(">", (args, actions, runActions) -> { if (args instanceof Section section) { MathValue v1 = MathValue.auto(section.get("value1")); MathValue v2 = MathValue.auto(section.get("value2")); return context -> { if (v1.evaluate(context) > v2.evaluate(context)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; } else { @@ -945,13 +953,13 @@ public class BukkitRequirementManager implements RequirementManager { return EmptyRequirement.INSTANCE; } }); - registerRequirement("regex", (args, actions, advanced) -> { + registerRequirement("regex", (args, actions, runActions) -> { if (args instanceof Section section) { TextValue v1 = TextValue.auto(section.getString("papi", "")); String v2 = section.getString("regex", ""); return context -> { if (v1.render(context).matches(v2)) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; } else { @@ -959,13 +967,13 @@ public class BukkitRequirementManager implements RequirementManager { return EmptyRequirement.INSTANCE; } }); - registerRequirement("startsWith", (args, actions, advanced) -> { + registerRequirement("startsWith", (args, actions, runActions) -> { if (args instanceof Section section) { TextValue v1 = TextValue.auto(section.getString("value1", "")); TextValue v2 = TextValue.auto(section.getString("value2", "")); return context -> { if (v1.render(context).startsWith(v2.render(context))) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; } else { @@ -973,13 +981,13 @@ public class BukkitRequirementManager implements RequirementManager { return EmptyRequirement.INSTANCE; } }); - registerRequirement("!startsWith", (args, actions, advanced) -> { + registerRequirement("!startsWith", (args, actions, runActions) -> { if (args instanceof Section section) { TextValue v1 = TextValue.auto(section.getString("value1", "")); TextValue v2 = TextValue.auto(section.getString("value2", "")); return context -> { if (!v1.render(context).startsWith(v2.render(context))) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; } else { @@ -987,13 +995,13 @@ public class BukkitRequirementManager implements RequirementManager { return EmptyRequirement.INSTANCE; } }); - registerRequirement("endsWith", (args, actions, advanced) -> { + registerRequirement("endsWith", (args, actions, runActions) -> { if (args instanceof Section section) { TextValue v1 = TextValue.auto(section.getString("value1", "")); TextValue v2 = TextValue.auto(section.getString("value2", "")); return context -> { if (v1.render(context).endsWith(v2.render(context))) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; } else { @@ -1001,13 +1009,13 @@ public class BukkitRequirementManager implements RequirementManager { return EmptyRequirement.INSTANCE; } }); - registerRequirement("!endsWith", (args, actions, advanced) -> { + registerRequirement("!endsWith", (args, actions, runActions) -> { if (args instanceof Section section) { TextValue v1 = TextValue.auto(section.getString("value1", "")); TextValue v2 = TextValue.auto(section.getString("value2", "")); return context -> { if (!v1.render(context).endsWith(v2.render(context))) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; } else { @@ -1015,13 +1023,13 @@ public class BukkitRequirementManager implements RequirementManager { return EmptyRequirement.INSTANCE; } }); - registerRequirement("contains", (args, actions, advanced) -> { + registerRequirement("contains", (args, actions, runActions) -> { if (args instanceof Section section) { TextValue v1 = TextValue.auto(section.getString("value1", "")); TextValue v2 = TextValue.auto(section.getString("value2", "")); return context -> { if (v1.render(context).contains(v2.render(context))) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; } else { @@ -1029,13 +1037,13 @@ public class BukkitRequirementManager implements RequirementManager { return EmptyRequirement.INSTANCE; } }); - registerRequirement("!contains", (args, actions, advanced) -> { + registerRequirement("!contains", (args, actions, runActions) -> { if (args instanceof Section section) { TextValue v1 = TextValue.auto(section.getString("value1", "")); TextValue v2 = TextValue.auto(section.getString("value2", "")); return context -> { if (!v1.render(context).contains(v2.render(context))) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; } else { @@ -1043,13 +1051,13 @@ public class BukkitRequirementManager implements RequirementManager { return EmptyRequirement.INSTANCE; } }); - registerRequirement("in-list", (args, actions, advanced) -> { + registerRequirement("in-list", (args, actions, runActions) -> { if (args instanceof Section section) { TextValue papi = TextValue.auto(section.getString("papi", "")); List values = ListUtils.toList(section.get("values")); return context -> { if (values.contains(papi.render(context))) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; } else { @@ -1057,13 +1065,13 @@ public class BukkitRequirementManager implements RequirementManager { return EmptyRequirement.INSTANCE; } }); - registerRequirement("!in-list", (args, actions, advanced) -> { + registerRequirement("!in-list", (args, actions, runActions) -> { if (args instanceof Section section) { TextValue papi = TextValue.auto(section.getString("papi", "")); List values = ListUtils.toList(section.get("values")); return context -> { if (!values.contains(papi.render(context))) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; } else { @@ -1071,13 +1079,13 @@ public class BukkitRequirementManager implements RequirementManager { return EmptyRequirement.INSTANCE; } }); - registerRequirement("equals", (args, actions, advanced) -> { + registerRequirement("equals", (args, actions, runActions) -> { if (args instanceof Section section) { TextValue v1 = TextValue.auto(section.getString("value1", "")); TextValue v2 = TextValue.auto(section.getString("value2", "")); return context -> { if (v1.render(context).equals(v2.render(context))) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; } else { @@ -1085,13 +1093,13 @@ public class BukkitRequirementManager implements RequirementManager { return EmptyRequirement.INSTANCE; } }); - registerRequirement("!equals", (args, actions, advanced) -> { + registerRequirement("!equals", (args, actions, runActions) -> { if (args instanceof Section section) { TextValue v1 = TextValue.auto(section.getString("value1", "")); TextValue v2 = TextValue.auto(section.getString("value2", "")); return context -> { if (!v1.render(context).equals(v2.render(context))) return true; - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; } else { @@ -1102,7 +1110,7 @@ public class BukkitRequirementManager implements RequirementManager { } private void registerPotionEffectRequirement() { - registerRequirement("potion-effect", (args, actions, advanced) -> { + registerRequirement("potion-effect", (args, actions, runActions) -> { String potions = (String) args; String[] split = potions.split("(<=|>=|<|>|==)", 2); PotionEffectType type = PotionEffectType.getByName(split[0]); @@ -1142,7 +1150,7 @@ public class BukkitRequirementManager implements RequirementManager { if (result) { return true; } - if (advanced) ActionManager.trigger(context, actions); + if (runActions) ActionManager.trigger(context, actions); return false; }; }); diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/requirement/ConditionalElement.java b/core/src/main/java/net/momirealms/customfishing/bukkit/requirement/ConditionalElement.java deleted file mode 100644 index d27eacaa..00000000 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/requirement/ConditionalElement.java +++ /dev/null @@ -1,62 +0,0 @@ -///* -// * Copyright (C) <2022> -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see . -// */ -// -//package net.momirealms.customfishing.bukkit.requirement; -// -//import net.momirealms.customfishing.api.mechanic.requirement.Requirement; -//import org.bukkit.entity.Player; -// -//import java.util.HashMap; -//import java.util.List; -// -//public class ConditionalElement { -// -// private final List> modifierList; -// private final HashMap subLoots; -// private final Requirement[] requirements; -// -// public ConditionalElement( -// Requirement[] requirements, -// List> modifierList, -// HashMap subElements -// ) { -// this.modifierList = modifierList; -// this.requirements = requirements; -// this.subLoots = subElements; -// } -// -// /** -// * Combines the weight modifiers for this element. -// * -// * @param player The player for whom the modifiers are applied. -// * @param weightMap The map of weight modifiers. -// */ -// synchronized public void combine(Player player, HashMap weightMap) { -// for (Pair modifierPair : this.modifierList) { -// double previous = weightMap.getOrDefault(modifierPair.left(), 0d); -// weightMap.put(modifierPair.left(), modifierPair.right().modify(player, previous)); -// } -// } -// -// public Requirement[] getRequirements() { -// return requirements; -// } -// -// public HashMap getSubElements() { -// return subLoots; -// } -//} diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/scheduler/impl/BukkitExecutor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/scheduler/impl/BukkitExecutor.java index 1aff4b85..af583f14 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/scheduler/impl/BukkitExecutor.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/scheduler/impl/BukkitExecutor.java @@ -46,6 +46,14 @@ public class BukkitExecutor implements RegionExecutor { @Override public SchedulerTask runLater(Runnable r, long delayTicks, Location l) { + if (delayTicks == 0) { + if (Bukkit.isPrimaryThread()) { + r.run(); + return () -> {}; + } else { + return Bukkit.getScheduler().runTask(plugin, r)::cancel; + } + } return Bukkit.getScheduler().runTaskLater(plugin, r, delayTicks)::cancel; } diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/scheduler/impl/FoliaExecutor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/scheduler/impl/FoliaExecutor.java index 6a6804a4..29d3d4c6 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/scheduler/impl/FoliaExecutor.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/scheduler/impl/FoliaExecutor.java @@ -49,9 +49,17 @@ public class FoliaExecutor implements RegionExecutor { @Override public SchedulerTask runLater(Runnable r, long delayTicks, Location l) { if (l == null) { - return Bukkit.getGlobalRegionScheduler().runDelayed(plugin, scheduledTask -> r.run(), delayTicks)::cancel; + if (delayTicks == 0) { + return Bukkit.getGlobalRegionScheduler().runDelayed(plugin, scheduledTask -> r.run(), delayTicks)::cancel; + } else { + return Bukkit.getGlobalRegionScheduler().run(plugin, scheduledTask -> r.run())::cancel; + } } else { - return Bukkit.getRegionScheduler().runDelayed(plugin, l, scheduledTask -> r.run(), delayTicks)::cancel; + if (delayTicks == 0) { + return Bukkit.getRegionScheduler().run(plugin, l, scheduledTask -> r.run())::cancel; + } else { + return Bukkit.getRegionScheduler().runDelayed(plugin, l, scheduledTask -> r.run(), delayTicks)::cancel; + } } } diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/util/ItemUtils.java b/core/src/main/java/net/momirealms/customfishing/bukkit/util/ItemStackUtils.java similarity index 67% rename from core/src/main/java/net/momirealms/customfishing/bukkit/util/ItemUtils.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/util/ItemStackUtils.java index ef456c67..6a5aa771 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/util/ItemUtils.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/util/ItemStackUtils.java @@ -1,5 +1,8 @@ package net.momirealms.customfishing.bukkit.util; +import com.saicone.rtag.RtagMirror; +import com.saicone.rtag.item.ItemObject; +import com.saicone.rtag.tag.TagCompound; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.util.io.BukkitObjectInputStream; @@ -9,10 +12,11 @@ import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.util.Map; -public class ItemUtils { +public class ItemStackUtils { - private ItemUtils() {} + private ItemStackUtils() {} public static ItemStack fromBase64(String base64) { if (base64 == null || base64.isEmpty()) @@ -47,4 +51,25 @@ public class ItemUtils { return ""; } } + + public static Map toReadableMap(ItemStack item) { + return toMap(item); + } + + private static Map toMap(ItemStack object) { + return TagCompound.getValue(RtagMirror.INSTANCE, toCompound(object)); + } + + private static Object toCompound(ItemStack object) { + if (object == null) { + return null; + } else { + Object compound = extract(object); + return TagCompound.isTagCompound(compound) ? compound : null; + } + } + + private static Object extract(ItemStack object) { + return ItemObject.save(ItemObject.asNMSCopy(object)); + } } diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml index cd2cf471..32916cf2 100644 --- a/core/src/main/resources/config.yml +++ b/core/src/main/resources/config.yml @@ -18,6 +18,16 @@ mechanics: type: '!world' value: - blacklist_world + # If you want to let some players skip games, you can set requirements that used to skip games + # We used `impossible` requirement here, so players should play the game if there exists + skip-game-requirements: + impossible_requirement: + type: 'impossible' + # Requirements for enabling auto-fishing + auto-fishing-requirements: + impossible_requirement: + type: 'impossible' + # Configures global effects. This is useful if you want to give all the players certain effects based on certain conditions global-effects: effect_1: diff --git a/gradle.properties b/gradle.properties index 7cd04790..9cdc99b8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ # Project settings # Rule: [major update].[feature update].[bug fix] project_version=2.2.0 -config_version=32 +config_version=33 project_group=net.momirealms # Dependency settings