From c23bbc75d0ec903244dcaa5e4b7a2f585d6d5445 Mon Sep 17 00:00:00 2001 From: XiaoMoMi <972454774@qq.com> Date: Mon, 20 May 2024 04:43:41 +0800 Subject: [PATCH] checkpoint - 5 --- .../api/BukkitCustomFishingPlugin.java | 30 + .../api/integration/BlockProvider.java | 23 +- .../api/integration/EnchantmentProvider.java | 3 +- .../api/integration/IntegrationManager.java | 3 +- .../api/mechanic/action/ActionManager.java | 41 +- .../api/mechanic/block/BlockConfig.java | 74 +- .../mechanic/competition/CompetitionGoal.java | 53 +- .../competition/CompetitionManager.java | 53 +- .../competition/CompetitionPlayer.java | 2 +- .../competition/FishingCompetition.java | 23 +- .../api/mechanic/config/ConfigManager.java | 12 + .../api/mechanic/context/Context.java | 16 +- .../api/mechanic/context/ContextKeys.java | 16 +- .../mechanic/context/PlayerContextImpl.java | 22 +- .../mechanic/game/AbstractGamingPlayer.java | 8 +- .../api/mechanic/game/GameSettings.java | 18 +- .../api/mechanic/game/GamingPlayer.java | 8 +- .../misc/cooldown}/CoolDownManager.java | 12 +- .../api/mechanic/misc/value}/DynamicText.java | 8 +- .../misc/value/ExpressionMathValueImpl.java | 2 +- .../misc/value/PlaceholderTextValueImpl.java | 2 +- .../customfishing/api}/util/MoonPhase.java | 2 +- .../api}/util/SimpleLocation.java | 10 +- common/build.gradle.kts | 1 + .../common/helper/AdventureHelper.java | 15 +- .../common/helper/VersionHelper.java | 15 +- .../common/locale/MessageConstants.java | 1 - .../common/locale/StandardLocales.java | 11 + .../common}/util/CompletableFutures.java | 2 +- .../block/ItemsAdderBlockProvider.java | 5 +- .../block/OraxenBlockProvider.java | 49 + .../block/VanillaBlockProvider.java | 5 +- .../enchant/AdvancedEnchantmentsProvider.java | 3 +- .../enchant/VanillaEnchantmentsProvider.java | 3 +- .../item/MMOItemsItemProvider.java | 2 +- .../item/McMMOTreasureProvider.java | 2 +- .../compatibility/item/ZaphkielItemImpl.java | 4 +- .../level/AuraSkillsLevelerProvider.java | 5 +- .../compatibility/papi/CompetitionPapi.java | 10 +- .../BukkitCustomFishingPluginImpl.java | 140 +- .../bukkit/action/BukkitActionManager.java | 50 +- .../bag/BukkitBagManager.java} | 8 +- .../block/BukkitBlockManager.java} | 10 +- ...mpl.java => BukkitIntegrationManager.java} | 4 +- ...mpl.java => BukkitCompetitionManager.java} | 220 ++- .../bukkit/competition/Competition.java | 361 ++--- .../actionbar/ActionBarManager.java | 25 +- .../actionbar/ActionBarSender.java | 76 +- .../competition/bossbar/BossBarManager.java | 25 +- .../competition/bossbar/BossBarSender.java | 152 +- .../ranking/LocalRankingProvider.java | 1 + .../ranking/RedisRankingProvider.java | 37 +- .../effect/BukkitEffectManager.java} | 8 +- .../entity/BukkitEntityManager.java} | 6 +- .../fishing/BaitAnimationTask.java | 6 +- .../fishing/BukkitFishingManager.java} | 15 +- .../fishing/FishingPreparationImpl.java | 2 +- .../fishing/HookCheckTimerTask.java | 6 +- .../fishing/LavaEffectTask.java | 2 +- .../game/BukkitGameManager.java} | 41 +- .../customfishing/{ => bukkit}/gui/Icon.java | 2 +- .../{ => bukkit}/gui/ParentPage.java | 4 +- .../{ => bukkit}/gui/SectionPage.java | 2 +- .../{ => bukkit}/gui/YamlPage.java | 2 +- .../{ => bukkit}/gui/icon/BackGroundItem.java | 4 +- .../gui/icon/BackToFolderItem.java | 6 +- .../{ => bukkit}/gui/icon/BackToPageItem.java | 4 +- .../{ => bukkit}/gui/icon/NextPageItem.java | 4 +- .../gui/icon/PreviousPageItem.java | 4 +- .../{ => bukkit}/gui/icon/ScrollDownItem.java | 4 +- .../{ => bukkit}/gui/icon/ScrollUpItem.java | 4 +- .../gui/icon/property/item/AmountItem.java | 6 +- .../gui/icon/property/item/CMDItem.java | 6 +- .../icon/property/item/DisplayNameItem.java | 6 +- .../icon/property/item/DurabilityItem.java | 6 +- .../icon/property/item/EnchantmentItem.java | 6 +- .../gui/icon/property/item/Head64Item.java | 6 +- .../gui/icon/property/item/ItemFlagItem.java | 6 +- .../gui/icon/property/item/LoreItem.java | 6 +- .../gui/icon/property/item/MaterialItem.java | 6 +- .../gui/icon/property/item/NBTItem.java | 8 +- .../icon/property/item/PreventGrabItem.java | 4 +- .../gui/icon/property/item/PriceItem.java | 6 +- .../property/item/RandomDurabilityItem.java | 4 +- .../gui/icon/property/item/SizeItem.java | 6 +- .../gui/icon/property/item/StackableItem.java | 4 +- .../property/item/StoredEnchantmentItem.java | 6 +- .../gui/icon/property/item/TagItem.java | 4 +- .../icon/property/item/UnbreakableItem.java | 4 +- .../icon/property/loot/DisableGameItem.java | 4 +- .../icon/property/loot/DisableStatsItem.java | 4 +- .../icon/property/loot/InstantGameItem.java | 4 +- .../gui/icon/property/loot/NickItem.java | 6 +- .../gui/icon/property/loot/ScoreItem.java | 6 +- .../icon/property/loot/ShowInFinderItem.java | 4 +- .../gui/page/file/FileSelector.java | 12 +- .../gui/page/item/AbstractSectionEditor.java | 12 +- .../gui/page/item/BaitEditor.java | 4 +- .../gui/page/item/HookEditor.java | 4 +- .../gui/page/item/ItemSelector.java | 12 +- .../{ => bukkit}/gui/page/item/RodEditor.java | 4 +- .../gui/page/item/SectionEditor.java | 6 +- .../gui/page/property/AmountEditor.java | 6 +- .../page/property/CustomModelDataEditor.java | 6 +- .../gui/page/property/DisplayNameEditor.java | 6 +- .../gui/page/property/DurabilityEditor.java | 6 +- .../gui/page/property/EnchantmentEditor.java | 6 +- .../gui/page/property/ItemFlagEditor.java | 6 +- .../gui/page/property/LoreEditor.java | 6 +- .../gui/page/property/MaterialEditor.java | 8 +- .../gui/page/property/NBTEditor.java | 8 +- .../gui/page/property/NickEditor.java | 6 +- .../gui/page/property/PriceEditor.java | 6 +- .../gui/page/property/ScoreEditor.java | 6 +- .../gui/page/property/SizeEditor.java | 6 +- .../hook/BukkitHookManager.java} | 10 +- .../bukkit/item/BukkitItemManager.java | 4 +- .../item/ItemManagerImpl.java | 8 +- .../loot/BukkitLootManager.java | 2 +- .../loot/LootManagerImpl.java | 5 +- .../market/BukkitMarketManager.java} | 10 +- .../market/MarketDynamicGUIElement.java | 2 +- .../market/MarketGUI.java | 10 +- .../market/MarketGUIElement.java | 2 +- .../misc/ChatCatcherManager.java | 13 +- .../requirement/BukkitRequirementManager.java | 856 ++++++++++ .../requirement/ConditionalElement.java | 2 +- .../BukkitSchedulerAdapter.java | 2 +- .../statistic/BukkitStatisticsManager.java} | 6 +- .../storage/BukkitStorageManager.java} | 26 +- .../storage/method/AbstractStorage.java | 6 +- .../method/database/nosql/MongoDBImpl.java | 4 +- .../method/database/nosql/RedisManager.java | 93 +- .../database/sql/AbstractHikariDatabase.java | 2 +- .../database/sql/AbstractSQLDatabase.java | 4 +- .../storage/method/database/sql/H2Impl.java | 4 +- .../method/database/sql/MariaDBImpl.java | 2 +- .../method/database/sql/MySQLImpl.java | 2 +- .../method/database/sql/SQLiteImpl.java | 4 +- .../storage/method/file/JsonImpl.java | 4 +- .../storage/method/file/YAMLImpl.java | 6 +- .../storage/user/OfflineUser.java | 2 +- .../totem/ActivatedTotem.java | 2 +- .../totem/BukkitTotemManager.java} | 12 +- .../totem/particle/DustParticleSetting.java | 2 +- .../totem/particle/ParticleSetting.java | 2 +- .../{ => bukkit}/util/ArmorStandUtils.java | 4 +- .../{ => bukkit}/util/ConfigUtils.java | 2 +- .../{ => bukkit}/util/FakeItemUtils.java | 2 +- .../{ => bukkit}/util/ItemUtils.java | 2 +- .../{ => bukkit}/util/LocationUtils.java | 2 +- .../{ => bukkit}/util/NumberUtils.java | 2 +- .../mechanic/action/ActionManagerImpl.java | 1046 ------------- .../fishing/BukkitFishingManager.java | 4 - .../requirement/BukkitRequirementManager.java | 4 - .../requirement/RequirementManagerImpl.java | 1389 ----------------- gradle.properties | 1 + 157 files changed, 2025 insertions(+), 3615 deletions(-) rename {core/src/main/java/net/momirealms/customfishing/mechanic/misc => api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/cooldown}/CoolDownManager.java (89%) rename {core/src/main/java/net/momirealms/customfishing/mechanic/misc => api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/value}/DynamicText.java (85%) rename {core/src/main/java/net/momirealms/customfishing => api/src/main/java/net/momirealms/customfishing/api}/util/MoonPhase.java (96%) rename {core/src/main/java/net/momirealms/customfishing => api/src/main/java/net/momirealms/customfishing/api}/util/SimpleLocation.java (80%) rename core/src/main/java/net/momirealms/customfishing/version/VersionManagerImpl.java => common/src/main/java/net/momirealms/customfishing/common/helper/VersionHelper.java (93%) create mode 100644 common/src/main/java/net/momirealms/customfishing/common/locale/StandardLocales.java rename {core/src/main/java/net/momirealms/customfishing => common/src/main/java/net/momirealms/customfishing/common}/util/CompletableFutures.java (98%) create mode 100644 compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/block/OraxenBlockProvider.java rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/BukkitCustomFishingPluginImpl.java (64%) rename core/src/main/java/net/momirealms/customfishing/{mechanic/bag/BagManagerImpl.java => bukkit/bag/BukkitBagManager.java} (97%) rename core/src/main/java/net/momirealms/customfishing/{mechanic/block/BlockManagerImpl.java => bukkit/block/BukkitBlockManager.java} (98%) rename core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/{IntegrationManagerImpl.java => BukkitIntegrationManager.java} (98%) rename core/src/main/java/net/momirealms/customfishing/bukkit/competition/{CompetitionManagerImpl.java => BukkitCompetitionManager.java} (51%) rename core/src/main/java/net/momirealms/customfishing/{mechanic/effect/EffectManagerImpl.java => bukkit/effect/BukkitEffectManager.java} (98%) rename core/src/main/java/net/momirealms/customfishing/{mechanic/entity/EntityManagerImpl.java => bukkit/entity/BukkitEntityManager.java} (97%) rename core/src/main/java/net/momirealms/customfishing/{mechanic => bukkit}/fishing/BaitAnimationTask.java (94%) rename core/src/main/java/net/momirealms/customfishing/{mechanic/fishing/FishingManagerImpl.java => bukkit/fishing/BukkitFishingManager.java} (98%) rename core/src/main/java/net/momirealms/customfishing/{mechanic => bukkit}/fishing/FishingPreparationImpl.java (99%) rename core/src/main/java/net/momirealms/customfishing/{mechanic => bukkit}/fishing/HookCheckTimerTask.java (98%) rename core/src/main/java/net/momirealms/customfishing/{mechanic => bukkit}/fishing/LavaEffectTask.java (98%) rename core/src/main/java/net/momirealms/customfishing/{mechanic/game/GameManagerImpl.java => bukkit/game/BukkitGameManager.java} (97%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/Icon.java (93%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/ParentPage.java (88%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/SectionPage.java (94%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/YamlPage.java (93%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/BackGroundItem.java (92%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/BackToFolderItem.java (93%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/BackToPageItem.java (94%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/NextPageItem.java (94%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/PreviousPageItem.java (94%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/ScrollDownItem.java (94%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/ScrollUpItem.java (94%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/property/item/AmountItem.java (93%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/property/item/CMDItem.java (93%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/property/item/DisplayNameItem.java (93%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/property/item/DurabilityItem.java (93%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/property/item/EnchantmentItem.java (94%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/property/item/Head64Item.java (95%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/property/item/ItemFlagItem.java (94%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/property/item/LoreItem.java (94%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/property/item/MaterialItem.java (93%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/property/item/NBTItem.java (92%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/property/item/PreventGrabItem.java (95%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/property/item/PriceItem.java (94%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/property/item/RandomDurabilityItem.java (95%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/property/item/SizeItem.java (93%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/property/item/StackableItem.java (95%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/property/item/StoredEnchantmentItem.java (94%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/property/item/TagItem.java (94%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/property/item/UnbreakableItem.java (95%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/property/loot/DisableGameItem.java (95%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/property/loot/DisableStatsItem.java (95%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/property/loot/InstantGameItem.java (95%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/property/loot/NickItem.java (93%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/property/loot/ScoreItem.java (93%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/icon/property/loot/ShowInFinderItem.java (95%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/page/file/FileSelector.java (92%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/page/item/AbstractSectionEditor.java (91%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/page/item/BaitEditor.java (93%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/page/item/HookEditor.java (93%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/page/item/ItemSelector.java (96%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/page/item/RodEditor.java (93%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/page/item/SectionEditor.java (92%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/page/property/AmountEditor.java (96%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/page/property/CustomModelDataEditor.java (97%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/page/property/DisplayNameEditor.java (95%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/page/property/DurabilityEditor.java (96%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/page/property/EnchantmentEditor.java (98%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/page/property/ItemFlagEditor.java (96%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/page/property/LoreEditor.java (97%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/page/property/MaterialEditor.java (96%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/page/property/NBTEditor.java (99%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/page/property/NickEditor.java (95%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/page/property/PriceEditor.java (97%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/page/property/ScoreEditor.java (96%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/gui/page/property/SizeEditor.java (97%) rename core/src/main/java/net/momirealms/customfishing/{mechanic/hook/HookManagerImpl.java => bukkit/hook/BukkitHookManager.java} (97%) rename core/src/main/java/net/momirealms/customfishing/{mechanic => bukkit}/item/ItemManagerImpl.java (99%) rename core/src/main/java/net/momirealms/customfishing/{mechanic => bukkit}/loot/BukkitLootManager.java (97%) rename core/src/main/java/net/momirealms/customfishing/{mechanic => bukkit}/loot/LootManagerImpl.java (98%) rename core/src/main/java/net/momirealms/customfishing/{mechanic/market/MarketManagerImpl.java => bukkit/market/BukkitMarketManager.java} (98%) rename core/src/main/java/net/momirealms/customfishing/{mechanic => bukkit}/market/MarketDynamicGUIElement.java (94%) rename core/src/main/java/net/momirealms/customfishing/{mechanic => bukkit}/market/MarketGUI.java (97%) rename core/src/main/java/net/momirealms/customfishing/{mechanic => bukkit}/market/MarketGUIElement.java (96%) rename core/src/main/java/net/momirealms/customfishing/{mechanic => bukkit}/misc/ChatCatcherManager.java (87%) rename core/src/main/java/net/momirealms/customfishing/{mechanic => bukkit}/requirement/ConditionalElement.java (97%) rename core/src/main/java/net/momirealms/customfishing/bukkit/{ => scheduler}/BukkitSchedulerAdapter.java (97%) rename core/src/main/java/net/momirealms/customfishing/{mechanic/statistic/StatisticsManagerImpl.java => bukkit/statistic/BukkitStatisticsManager.java} (94%) rename core/src/main/java/net/momirealms/customfishing/{storage/StorageManagerImpl.java => bukkit/storage/BukkitStorageManager.java} (94%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/storage/method/AbstractStorage.java (95%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/storage/method/database/nosql/MongoDBImpl.java (98%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/storage/method/database/nosql/RedisManager.java (76%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/storage/method/database/sql/AbstractHikariDatabase.java (99%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/storage/method/database/sql/AbstractSQLDatabase.java (98%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/storage/method/database/sql/H2Impl.java (95%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/storage/method/database/sql/MariaDBImpl.java (93%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/storage/method/database/sql/MySQLImpl.java (93%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/storage/method/database/sql/SQLiteImpl.java (98%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/storage/method/file/JsonImpl.java (97%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/storage/method/file/YAMLImpl.java (97%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/storage/user/OfflineUser.java (98%) rename core/src/main/java/net/momirealms/customfishing/{mechanic => bukkit}/totem/ActivatedTotem.java (98%) rename core/src/main/java/net/momirealms/customfishing/{mechanic/totem/TotemManagerImpl.java => bukkit/totem/BukkitTotemManager.java} (97%) rename core/src/main/java/net/momirealms/customfishing/{mechanic => bukkit}/totem/particle/DustParticleSetting.java (97%) rename core/src/main/java/net/momirealms/customfishing/{mechanic => bukkit}/totem/particle/ParticleSetting.java (98%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/util/ArmorStandUtils.java (98%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/util/ConfigUtils.java (99%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/util/FakeItemUtils.java (99%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/util/ItemUtils.java (99%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/util/LocationUtils.java (97%) rename core/src/main/java/net/momirealms/customfishing/{ => bukkit}/util/NumberUtils.java (94%) delete mode 100644 core/src/main/java/net/momirealms/customfishing/mechanic/action/ActionManagerImpl.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/mechanic/fishing/BukkitFishingManager.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/mechanic/requirement/BukkitRequirementManager.java delete mode 100644 core/src/main/java/net/momirealms/customfishing/mechanic/requirement/RequirementManagerImpl.java diff --git a/api/src/main/java/net/momirealms/customfishing/api/BukkitCustomFishingPlugin.java b/api/src/main/java/net/momirealms/customfishing/api/BukkitCustomFishingPlugin.java index 1ba673f4..7a2f497f 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/BukkitCustomFishingPlugin.java +++ b/api/src/main/java/net/momirealms/customfishing/api/BukkitCustomFishingPlugin.java @@ -19,11 +19,16 @@ package net.momirealms.customfishing.api; import net.momirealms.customfishing.api.integration.IntegrationManager; import net.momirealms.customfishing.api.mechanic.action.ActionManager; +import net.momirealms.customfishing.api.mechanic.competition.CompetitionManager; import net.momirealms.customfishing.api.mechanic.config.ConfigManager; import net.momirealms.customfishing.api.mechanic.event.EventManager; import net.momirealms.customfishing.api.mechanic.item.ItemManager; +import net.momirealms.customfishing.api.mechanic.loot.LootManager; +import net.momirealms.customfishing.api.mechanic.market.MarketManager; +import net.momirealms.customfishing.api.mechanic.misc.cooldown.CoolDownManager; import net.momirealms.customfishing.api.mechanic.misc.placeholder.PlaceholderManager; import net.momirealms.customfishing.api.mechanic.requirement.RequirementManager; +import net.momirealms.customfishing.api.storage.StorageManager; import net.momirealms.customfishing.common.plugin.CustomFishingPlugin; import net.momirealms.customfishing.common.plugin.scheduler.AbstractJavaScheduler; import net.momirealms.customfishing.common.sender.SenderFactory; @@ -51,6 +56,11 @@ public abstract class BukkitCustomFishingPlugin implements CustomFishingPlugin { protected AbstractJavaScheduler scheduler; protected ItemManager itemManager; protected IntegrationManager integrationManager; + protected CompetitionManager competitionManager; + protected MarketManager marketManager; + protected StorageManager storageManager; + protected LootManager lootManager; + protected CoolDownManager coolDownManager; public BukkitCustomFishingPlugin() { instance = this; @@ -105,6 +115,26 @@ public abstract class BukkitCustomFishingPlugin implements CustomFishingPlugin { return scheduler; } + public CompetitionManager getCompetitionManager() { + return competitionManager; + } + + public MarketManager getMarketManager() { + return marketManager; + } + + public StorageManager getStorageManager() { + return storageManager; + } + + public LootManager getLootManager() { + return lootManager; + } + + public CoolDownManager getCoolDownManager() { + return coolDownManager; + } + public Plugin getBoostrap() { return boostrap; } diff --git a/api/src/main/java/net/momirealms/customfishing/api/integration/BlockProvider.java b/api/src/main/java/net/momirealms/customfishing/api/integration/BlockProvider.java index 514176b5..daf7b11e 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/integration/BlockProvider.java +++ b/api/src/main/java/net/momirealms/customfishing/api/integration/BlockProvider.java @@ -21,14 +21,33 @@ import net.momirealms.customfishing.api.mechanic.block.BlockDataModifier; import org.bukkit.block.Block; import org.bukkit.block.data.BlockData; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; +/** + * Interface for providing custom block data and retrieving block IDs within the CustomFishing plugin. + * Extends the ExternalProvider interface. + */ public interface BlockProvider extends ExternalProvider { - BlockData blockData(Player player, String id, List modifiers); + /** + * Generates BlockData for a given player based on a block ID and a list of modifiers. + * + * @param player The player for whom the block data is generated. + * @param id The unique identifier for the block. + * @param modifiers A list of {@link BlockDataModifier} objects to apply to the block data. + * @return The generated {@link BlockData} for the specified block ID and modifiers. + */ + BlockData blockData(@NotNull Player player, @NotNull String id, List modifiers); + /** + * Retrieves the unique block ID associated with a given block. + * + * @param block The block for which the ID is to be retrieved. + * @return The unique block ID as a string, or null if no ID is associated with the block. + */ @Nullable - String blockID(Block block); + String blockID(@NotNull Block block); } diff --git a/api/src/main/java/net/momirealms/customfishing/api/integration/EnchantmentProvider.java b/api/src/main/java/net/momirealms/customfishing/api/integration/EnchantmentProvider.java index 569665c5..d0daba40 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/integration/EnchantmentProvider.java +++ b/api/src/main/java/net/momirealms/customfishing/api/integration/EnchantmentProvider.java @@ -19,6 +19,7 @@ package net.momirealms.customfishing.api.integration; import net.momirealms.customfishing.common.util.Pair; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -30,5 +31,5 @@ public interface EnchantmentProvider extends ExternalProvider { * @param itemStack itemStack * @return enchantment list */ - List> getEnchants(ItemStack itemStack); + List> getEnchants(@NotNull ItemStack itemStack); } diff --git a/api/src/main/java/net/momirealms/customfishing/api/integration/IntegrationManager.java b/api/src/main/java/net/momirealms/customfishing/api/integration/IntegrationManager.java index 1bc3aa12..a72a9247 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/integration/IntegrationManager.java +++ b/api/src/main/java/net/momirealms/customfishing/api/integration/IntegrationManager.java @@ -100,9 +100,8 @@ public interface IntegrationManager { /** * Retrieves a registered SeasonProvider by its ID. * - * @param id the ID of the SeasonProvider to retrieve * @return the SeasonProvider if found, or null if not found */ @Nullable - SeasonProvider getSeasonProvider(String id); + SeasonProvider getSeasonProvider(); } diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/action/ActionManager.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/action/ActionManager.java index 12e44807..ce72e41a 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/action/ActionManager.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/action/ActionManager.java @@ -22,7 +22,7 @@ import net.momirealms.customfishing.api.mechanic.context.Context; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.List; +import java.util.*; /** * The ActionManager interface manages custom action types and provides methods for handling actions. @@ -91,6 +91,45 @@ public interface ActionManager { */ Action parseAction(@NotNull String type, @NotNull Object args); + /** + * Generates a map of actions triggered by specific events from a configuration section. + * + * @param section The configuration section containing event-action mappings. + * @return A map where the keys are action triggers and the values are arrays of actions associated with those triggers. + */ + default Map[]> parseEventActions(Section section) { + HashMap[]> actionMap = new HashMap<>(); + for (Map.Entry entry : section.getStringRouteMappedValues(false).entrySet()) { + if (entry.getValue() instanceof Section innerSection) { + try { + actionMap.put( + ActionTrigger.valueOf(entry.getKey().toUpperCase(Locale.ENGLISH)), + parseActions(innerSection) + ); + } catch (IllegalArgumentException e) { + throw new RuntimeException(e); + } + } + } + return actionMap; + } + + /** + * Parses a configuration section to generate a map of timed actions. + * + * @param section The configuration section containing time-action mappings. + * @return A TreeMap where the keys are time values (in integer form) and the values are arrays of actions associated with those times. + */ + default TreeMap[]> parseTimesActions(Section section) { + TreeMap[]> actionMap = new TreeMap<>(); + for (Map.Entry entry : section.getStringRouteMappedValues(false).entrySet()) { + if (entry.getValue() instanceof Section innerSection) { + actionMap.put(Integer.parseInt(entry.getKey()), parseActions(innerSection)); + } + } + return actionMap; + } + /** * Triggers a list of actions with the given context. * If the list of actions is not null, each action in the list is triggered. diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockConfig.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockConfig.java index 8ef22397..75a21a3e 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockConfig.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/block/BlockConfig.java @@ -22,34 +22,106 @@ import org.bukkit.entity.Player; import java.util.List; +/** + * Interface representing the configuration for a custom block in the CustomFishing plugin. + * Provides methods to access various block properties and modifiers. + */ public interface BlockConfig { + /** + * Gets the unique identifier for the block. + * + * @return The block's unique identifier. + */ String blockID(); + /** + * Gets the list of data modifiers applied to the block. + * + * @return A list of {@link BlockDataModifier} objects. + */ List dataModifier(); + /** + * Gets the list of state modifiers applied to the block. + * + * @return A list of {@link BlockStateModifier} objects. + */ List stateModifiers(); + /** + * Gets the horizontal vector math value associated with the block. + * + * @return A {@link MathValue} representing the horizontal vector for a player. + */ MathValue horizontalVector(); + /** + * Gets the vertical vector math value associated with the block. + * + * @return A {@link MathValue} representing the vertical vector for a player. + */ MathValue verticalVector(); + /** + * Creates a new builder instance for constructing a {@link BlockConfig}. + * + * @return A new {@link Builder} instance. + */ static Builder builder() { return new BlockConfigImpl.BuilderImpl(); } + /** + * Builder interface for constructing a {@link BlockConfig} instance. + */ interface Builder { + /** + * Sets the block ID for the configuration. + * + * @param blockID The block's unique identifier. + * @return The current {@link Builder} instance. + */ Builder blockID(String blockID); + /** + * Sets the list of data modifiers for the configuration. + * + * @param dataModifierList A list of {@link BlockDataModifier} objects. + * @return The current {@link Builder} instance. + */ Builder dataModifierList(List dataModifierList); + /** + * Sets the list of state modifiers for the configuration. + * + * @param stateModifierList A list of {@link BlockStateModifier} objects. + * @return The current {@link Builder} instance. + */ Builder stateModifierList(List stateModifierList); + /** + * Sets the horizontal vector math value for the configuration. + * + * @param horizontalVector A {@link MathValue} representing the horizontal vector for a player. + * @return The current {@link Builder} instance. + */ Builder horizontalVector(MathValue horizontalVector); + /** + * Sets the vertical vector math value for the configuration. + * + * @param verticalVector A {@link MathValue} representing the vertical vector for a player. + * @return The current {@link Builder} instance. + */ Builder verticalVector(MathValue verticalVector); + /** + * Builds and returns the configured {@link BlockConfig} instance. + * + * @return The constructed {@link BlockConfig} instance. + */ BlockConfig build(); } -} +} \ No newline at end of file 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 a9c6477c..8f24fc16 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 @@ -17,23 +17,43 @@ package net.momirealms.customfishing.api.mechanic.competition; -import net.kyori.adventure.key.Key; import net.kyori.adventure.util.Index; import net.momirealms.customfishing.common.util.RandomUtils; +import org.apache.logging.log4j.util.TriConsumer; +import org.bukkit.entity.Player; public final class CompetitionGoal { - public static final CompetitionGoal CATCH_AMOUNT = new CompetitionGoal(Key.key("customfishing", "catch_amount")); - public static final CompetitionGoal TOTAL_SCORE = new CompetitionGoal(Key.key("customfishing", "total_score")); - public static final CompetitionGoal MAX_SIZE = new CompetitionGoal(Key.key("customfishing", "max_size")); - public static final CompetitionGoal TOTAL_SIZE = new CompetitionGoal(Key.key("customfishing", "total_size")); - public static final CompetitionGoal RANDOM = new CompetitionGoal(Key.key("customfishing", "random")); + public static final CompetitionGoal CATCH_AMOUNT = new CompetitionGoal( + "catch_amount", + ((rankingProvider, player, score) -> rankingProvider.refreshData(player, 1)) + ); + public static final CompetitionGoal TOTAL_SCORE = new CompetitionGoal( + "total_score", + (RankingProvider::refreshData) + ); + public static final CompetitionGoal MAX_SIZE = new CompetitionGoal( + "max_size", + ((rankingProvider, player, score) -> { + if (rankingProvider.getPlayerScore(player) < score) { + rankingProvider.setData(player, score); + } + }) + ); + public static final CompetitionGoal TOTAL_SIZE = new CompetitionGoal( + "total_size", + (RankingProvider::refreshData) + ); + public static final CompetitionGoal RANDOM = new CompetitionGoal( + "random", + (rankingProvider, player, score) -> {} + ); private static final CompetitionGoal[] values = new CompetitionGoal[] { CATCH_AMOUNT, TOTAL_SCORE, MAX_SIZE, TOTAL_SIZE, RANDOM }; - private static final Index index = Index.create(CompetitionGoal::key, values()); + private static final Index index = Index.create(CompetitionGoal::key, values()); /** * Gets an array containing all defined competition goals. @@ -49,7 +69,7 @@ public final class CompetitionGoal { * * @return An index mapping keys to competition goals. */ - public static Index index() { + public static Index index() { return index; } @@ -62,10 +82,12 @@ public final class CompetitionGoal { return CompetitionGoal.values()[RandomUtils.generateRandomInt(0, values.length - 1)]; } - private final Key key; + private final String key; + private final TriConsumer scoreConsumer; - private CompetitionGoal(Key key) { + private CompetitionGoal(String key, TriConsumer scoreConsumer) { this.key = key; + this.scoreConsumer = scoreConsumer; } /** @@ -73,7 +95,16 @@ public final class CompetitionGoal { * * @return The key of the competition goal. */ - public Key key() { + public String key() { return key; } + + public void refreshScore(RankingProvider ranking, Player player, Double score) { + scoreConsumer.accept(ranking, player.getName(), score); + } + + @Override + public String toString() { + return super.toString(); + } } diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/competition/CompetitionManager.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/competition/CompetitionManager.java index b281496e..23705891 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/competition/CompetitionManager.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/competition/CompetitionManager.java @@ -17,60 +17,19 @@ package net.momirealms.customfishing.api.mechanic.competition; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Set; - public interface CompetitionManager { - /** - * Retrieves a set of all competition names. - * - * @return A set of competition names. - */ - @NotNull Set getAllCompetitionKeys(); - - /** - * Starts a competition with the specified name, allowing for the option to force start it or apply it to the entire server. - * - * @param competition The name of the competition to start. - * @param force Whether to force start the competition even if amount of the online players is lower than the requirement - * @param serverGroup Whether to apply the competition to the servers that connected to Redis. - * @return {@code true} if the competition was started successfully, {@code false} otherwise. - */ boolean startCompetition(String competition, boolean force, @Nullable String serverGroup); - /** - * Gets the ongoing fishing competition, if one is currently in progress. - * - * @return The ongoing fishing competition, or null if there is none. - */ - @Nullable FishingCompetition getOnGoingCompetition(); - - /** - * Starts a competition using the specified configuration. - * - * @param config The configuration of the competition to start. - * @param force Whether to force start the competition even if amount of the online players is lower than the requirement - * @param serverGroup Whether the competition should start across all servers that connected to Redis - * @return True if the competition was started successfully, false otherwise. - */ boolean startCompetition(CompetitionConfig config, boolean force, @Nullable String serverGroup); - /** - * Gets the number of seconds until the next competition. - * - * @return The number of seconds until the next competition. - */ - int getNextCompetitionSeconds(); - - /** - * Retrieves the configuration for a competition based on its key. - * - * @param key The key of the competition configuration to retrieve. - * @return The {@link CompetitionConfig} for the specified key, or {@code null} if no configuration exists with that key. - */ @Nullable - CompetitionConfig getConfig(String key); + FishingCompetition getOnGoingCompetition(); + + int getNextCompetitionInSeconds(); + + @Nullable + CompetitionConfig getCompetition(String key); } diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/competition/CompetitionPlayer.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/competition/CompetitionPlayer.java index eb673a42..7ae2597c 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/competition/CompetitionPlayer.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/competition/CompetitionPlayer.java @@ -68,7 +68,7 @@ public class CompetitionPlayer implements Comparable { * @return the last update time in milliseconds. */ public long getTime() { - return time; + return this.time; } /** diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/competition/FishingCompetition.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/competition/FishingCompetition.java index 8e984f1e..f19b46bd 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/competition/FishingCompetition.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/competition/FishingCompetition.java @@ -17,12 +17,10 @@ package net.momirealms.customfishing.api.mechanic.competition; +import net.momirealms.customfishing.api.mechanic.context.Context; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Map; public interface FishingCompetition { @@ -92,14 +90,15 @@ public interface FishingCompetition { * @return The configuration of the fishing competition. */ @NotNull - CompetitionConfigImpl getConfig(); + CompetitionConfig getConfig(); /** * Gets the goal of the fishing competition. * * @return The goal of the fishing competition. */ - @NotNull CompetitionGoal getGoal(); + @NotNull + CompetitionGoal getGoal(); /** * Gets the ranking data for the fishing competition. @@ -110,17 +109,9 @@ public interface FishingCompetition { RankingProvider getRanking(); /** - * Gets the cached placeholders for the fishing competition. + * Get the public context * - * @return A ConcurrentHashMap containing cached placeholders. + * @return public context */ - @NotNull Map getCachedPlaceholders(); - - /** - * Gets a specific cached placeholder value by its key. - * - * @param papi The key of the cached placeholder. - * @return The cached placeholder value as a string, or null if not found. - */ - @Nullable String getCachedPlaceholder(String papi); + Context getPublicContext(); } 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 58ab82ae..63a3fa04 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 @@ -39,6 +39,18 @@ public abstract class ConfigManager implements ConfigLoader { this.plugin = plugin; } + public static int placeholderLimit() { + return 0; + } + + public static boolean redisRanking() { + return false; + } + + public static String serverGroup() { + return null; + } + public void registerLootParser(Function> function, String... nodes) { registerNodeFunction(nodes, new LootParserFunction(function)); } diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/context/Context.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/context/Context.java index 46d81e71..7fd0b0ad 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/context/Context.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/context/Context.java @@ -44,7 +44,7 @@ public interface Context { * * @return a map of placeholders */ - Map toPlaceholderMap(); + Map placeholderMap(); /** * Adds or updates an argument in the context. @@ -57,6 +57,14 @@ public interface Context { */ Context arg(ContextKeys key, C value); + /** + * Combines one context with another + * + * @param other other + * @return this context + */ + Context combine(Context other); + /** * Retrieves the value of a specific argument from the context. * This method fetches the value associated with the specified ContextKeys key. @@ -82,6 +90,10 @@ public interface Context { * @return a new Context instance with the specified player as the holder. */ static Context player(@Nullable Player player) { - return new PlayerContextImpl(player); + return new PlayerContextImpl(player, false); + } + + static Context player(@Nullable Player player, boolean threadSafe) { + return new PlayerContextImpl(player, threadSafe); } } 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 a2c35771..2dbd4519 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 @@ -17,6 +17,7 @@ package net.momirealms.customfishing.api.mechanic.context; +import net.momirealms.customfishing.api.mechanic.competition.CompetitionGoal; import org.bukkit.Location; import java.util.Objects; @@ -29,16 +30,29 @@ public class ContextKeys { public static final ContextKeys Z = of("z", Integer.class); public static final ContextKeys WORLD = of("world", String.class); public static final ContextKeys ID = of("id", String.class); + public static final ContextKeys OPEN_WATER = of("open_water", Boolean.class); public static final ContextKeys TYPE = of("type", String.class); public static final ContextKeys SIZE = of("size", Float.class); public static final ContextKeys PRICE = of("price", Double.class); public static final ContextKeys SURROUNDING = of("surrounding", String.class); public static final ContextKeys TEMP_NEAR_PLAYER = of("near", String.class); + public static final ContextKeys ROD = of("rod", String.class); + public static final ContextKeys BAIT = of("bait", String.class); + public static final ContextKeys HOOK = of("hook", String.class); + public static final ContextKeys IN_BAG = of("in_bag", Boolean.class); + public static final ContextKeys GOAL = of("goal", CompetitionGoal.class); + public static final ContextKeys HOUR = of("hour", String.class); + public static final ContextKeys MINUTE = of("minute", String.class); + public static final ContextKeys SECOND = of("second", String.class); + public static final ContextKeys SECONDS = of("seconds", Integer.class); + public static final ContextKeys PLAYER = of("player", String.class); + public static final ContextKeys SCORE = of("score", String.class); + public static final ContextKeys RANK = of("rank", String.class); private final String key; private final Class type; - private ContextKeys(String key, Class type) { + protected ContextKeys(String key, Class type) { this.key = key; this.type = type; } diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/context/PlayerContextImpl.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/context/PlayerContextImpl.java index eb98e7c1..7fafc119 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/context/PlayerContextImpl.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/context/PlayerContextImpl.java @@ -23,6 +23,7 @@ import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; /** * The PlayerContextImpl class implements the Context interface specifically @@ -32,19 +33,22 @@ import java.util.Map; public final class PlayerContextImpl implements Context { private final Player player; - private final HashMap, Object> args = new HashMap<>(); - private final Map placeholderMap = new HashMap<>(); + private final Map, Object> args; + private final Map placeholderMap; /** * Constructs a new PlayerContextImpl with the specified player. * * @param player the player to be associated with this context. */ - public PlayerContextImpl(@Nullable Player player) { + public PlayerContextImpl(@Nullable Player player, boolean sync) { this.player = player; + this.args = sync ? new ConcurrentHashMap<>() : new HashMap<>(); + this.placeholderMap = sync ? new ConcurrentHashMap<>() : new HashMap<>(); if (player == null) return; final Location location = player.getLocation(); - arg(ContextKeys.LOCATION, location) + arg(ContextKeys.PLAYER, player.getName()) + .arg(ContextKeys.LOCATION, location) .arg(ContextKeys.X, location.getBlockX()) .arg(ContextKeys.Y, location.getBlockY()) .arg(ContextKeys.Z, location.getBlockZ()) @@ -57,7 +61,7 @@ public final class PlayerContextImpl implements Context { } @Override - public Map toPlaceholderMap() { + public Map placeholderMap() { return placeholderMap; } @@ -68,6 +72,14 @@ public final class PlayerContextImpl implements Context { return this; } + @Override + public Context combine(Context other) { + final PlayerContextImpl otherContext = (PlayerContextImpl) other; + this.args.putAll(otherContext.args); + this.placeholderMap.putAll(otherContext.placeholderMap); + return this; + } + @Override @SuppressWarnings("unchecked") public C arg(ContextKeys key) { diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/game/AbstractGamingPlayer.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/game/AbstractGamingPlayer.java index deb4c18f..fdf35b43 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/game/AbstractGamingPlayer.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/game/AbstractGamingPlayer.java @@ -26,6 +26,8 @@ import org.bukkit.entity.FishHook; import org.bukkit.entity.Player; import org.bukkit.inventory.PlayerInventory; +import java.util.concurrent.TimeUnit; + public abstract class AbstractGamingPlayer implements GamingPlayer, Runnable { private final FishingManager manager; @@ -41,13 +43,13 @@ public abstract class AbstractGamingPlayer implements GamingPlayer, Runnable { this.player = player; this.fishHook = hook; this.settings = settings; - this.manager = BukkitCustomFishingPlugin.get().getFishingManager(); - this.deadline = (long) (System.currentTimeMillis() + settings.getTime() * 1000L); + this.manager = BukkitCustomFishingPlugin.getFishingManager(); + this.deadline = (long) (System.currentTimeMillis() + settings.time() * 1000L); this.arrangeTask(); } public void arrangeTask() { - this.task = BukkitCustomFishingPlugin.get().getScheduler().runTaskSyncTimer(this, fishHook.getLocation(), 1, 1); + this.task = BukkitCustomFishingPlugin.getInstance().getScheduler().asyncRepeating(this, 50, 50, TimeUnit.MILLISECONDS); } @Override diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/game/GameSettings.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/game/GameSettings.java index 98bea519..1796a870 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/game/GameSettings.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/game/GameSettings.java @@ -17,21 +17,5 @@ package net.momirealms.customfishing.api.mechanic.game; -public class GameSettings { - - private final double time; - private final int difficulty; - - public GameSettings(double time, int difficulty) { - this.time = time; - this.difficulty = difficulty; - } - - public double getTime() { - return time; - } - - public int getDifficulty() { - return difficulty; - } +public record GameSettings(double time, int difficulty) { } diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/game/GamingPlayer.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/game/GamingPlayer.java index 4ca24a3c..61c88b60 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/game/GamingPlayer.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/game/GamingPlayer.java @@ -60,10 +60,16 @@ public interface GamingPlayer { */ boolean onSneak(); + /** + * Get the player + * + * @return the player + */ Player getPlayer(); /** * @return effect reward based on game results */ - @Nullable Effect getEffectReward(); + @Nullable + Effect getEffectReward(); } diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/misc/CoolDownManager.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/cooldown/CoolDownManager.java similarity index 89% rename from core/src/main/java/net/momirealms/customfishing/mechanic/misc/CoolDownManager.java rename to api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/cooldown/CoolDownManager.java index a9034c14..9c10de5d 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/misc/CoolDownManager.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/cooldown/CoolDownManager.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.mechanic.misc; +package net.momirealms.customfishing.api.mechanic.misc.cooldown; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import org.bukkit.Bukkit; @@ -24,7 +24,9 @@ import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; +import java.util.Collections; import java.util.HashMap; +import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; @@ -56,7 +58,7 @@ public class CoolDownManager implements Listener { } public void load() { - Bukkit.getPluginManager().registerEvents(this, plugin); + Bukkit.getPluginManager().registerEvents(this, plugin.getBoostrap()); } public void unload() { @@ -80,10 +82,10 @@ public class CoolDownManager implements Listener { public static class Data { - private final HashMap coolDownMap; + private final Map coolDownMap; public Data() { - this.coolDownMap = new HashMap<>(); + this.coolDownMap = Collections.synchronizedMap(new HashMap<>()); } /** @@ -93,7 +95,7 @@ public class CoolDownManager implements Listener { * @param delay The cooldown delay in milliseconds. * @return True if the player is in cooldown, false otherwise. */ - public synchronized boolean isCoolDown(String key, long delay) { + public boolean isCoolDown(String key, long delay) { long time = System.currentTimeMillis(); long last = coolDownMap.getOrDefault(key, time - delay); if (last + delay > time) { diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/misc/DynamicText.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/value/DynamicText.java similarity index 85% rename from core/src/main/java/net/momirealms/customfishing/mechanic/misc/DynamicText.java rename to api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/value/DynamicText.java index d1d19a84..356225eb 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/misc/DynamicText.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/value/DynamicText.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.mechanic.misc; +package net.momirealms.customfishing.api.mechanic.misc.value; import net.momirealms.customfishing.api.mechanic.misc.placeholder.BukkitPlaceholderManager; import org.bukkit.entity.Player; @@ -54,22 +54,20 @@ public class DynamicText { } public boolean update(Map placeholders) { - // Update the dynamic text by replacing placeholders with actual values. String string = originalValue; if (this.placeholders.length != 0) { BukkitPlaceholderManager bukkitPlaceholderManager = BukkitPlaceholderManager.getInstance(); if ("%s".equals(originalValue)) { - string = bukkitPlaceholderManager.getSingleValue(owner, this.placeholders[0], placeholders); + string = bukkitPlaceholderManager.parseSingle(owner, this.placeholders[0], placeholders); } else { Object[] values = new String[this.placeholders.length]; for (int i = 0; i < this.placeholders.length; i++) { - values[i] = bukkitPlaceholderManager.getSingleValue(owner, this.placeholders[i], placeholders); + values[i] = bukkitPlaceholderManager.parseSingle(owner, this.placeholders[i], placeholders); } string = String.format(originalValue, values); } } if (!latestValue.equals(string)) { - // If the updated value is different from the latest value, update it. latestValue = string; return true; } diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/value/ExpressionMathValueImpl.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/value/ExpressionMathValueImpl.java index fd39570b..c8c6a132 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/value/ExpressionMathValueImpl.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/value/ExpressionMathValueImpl.java @@ -17,7 +17,7 @@ public class ExpressionMathValueImpl implements MathValue { @Override public double evaluate(Context context) { - Map replacements = context.toPlaceholderMap(); + Map replacements = context.placeholderMap(); String expression; if (context.getHolder() instanceof OfflinePlayer player) expression = BukkitPlaceholderManager.getInstance().parse(player, raw, replacements); else expression = BukkitPlaceholderManager.getInstance().parse(null, raw, replacements); diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/value/PlaceholderTextValueImpl.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/value/PlaceholderTextValueImpl.java index 8fd1ab64..919478ee 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/value/PlaceholderTextValueImpl.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/value/PlaceholderTextValueImpl.java @@ -16,7 +16,7 @@ public class PlaceholderTextValueImpl implements TextValue { @Override public String render(Context context) { - Map replacements = context.toPlaceholderMap(); + Map replacements = context.placeholderMap(); String text; if (context.getHolder() instanceof OfflinePlayer player) text = BukkitPlaceholderManager.getInstance().parse(player, raw, replacements); else text = BukkitPlaceholderManager.getInstance().parse(null, raw, replacements); diff --git a/core/src/main/java/net/momirealms/customfishing/util/MoonPhase.java b/api/src/main/java/net/momirealms/customfishing/api/util/MoonPhase.java similarity index 96% rename from core/src/main/java/net/momirealms/customfishing/util/MoonPhase.java rename to api/src/main/java/net/momirealms/customfishing/api/util/MoonPhase.java index 25803379..338e2f72 100644 --- a/core/src/main/java/net/momirealms/customfishing/util/MoonPhase.java +++ b/api/src/main/java/net/momirealms/customfishing/api/util/MoonPhase.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.util; +package net.momirealms.customfishing.api.util; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/net/momirealms/customfishing/util/SimpleLocation.java b/api/src/main/java/net/momirealms/customfishing/api/util/SimpleLocation.java similarity index 80% rename from core/src/main/java/net/momirealms/customfishing/util/SimpleLocation.java rename to api/src/main/java/net/momirealms/customfishing/api/util/SimpleLocation.java index 867eb708..c83d3208 100644 --- a/core/src/main/java/net/momirealms/customfishing/util/SimpleLocation.java +++ b/api/src/main/java/net/momirealms/customfishing/api/util/SimpleLocation.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.util; +package net.momirealms.customfishing.api.util; import org.bukkit.Location; @@ -51,13 +51,13 @@ public record SimpleLocation(String worldName, int x, int y, int z) { public int hashCode() { int hash = 3; hash = 19 * hash + (worldName != null ? worldName.hashCode() : 0); - hash = 19 * hash + (int) (Double.doubleToLongBits(this.x) ^ (Double.doubleToLongBits(this.x) >>> 32)); - hash = 19 * hash + (int) (Double.doubleToLongBits(this.y) ^ (Double.doubleToLongBits(this.y) >>> 32)); - hash = 19 * hash + (int) (Double.doubleToLongBits(this.z) ^ (Double.doubleToLongBits(this.z) >>> 32)); + hash = 19 * hash + Long.hashCode(Double.doubleToLongBits(this.x)); + hash = 19 * hash + Long.hashCode(Double.doubleToLongBits(this.y)); + hash = 19 * hash + Long.hashCode(Double.doubleToLongBits(this.z)); return hash; } - public static SimpleLocation getByBukkitLocation(Location location) { + public static SimpleLocation of(Location location) { return new SimpleLocation(location.getWorld().getName(), location.getBlockX(), location.getBlockY(), location.getBlockZ()); } } \ No newline at end of file diff --git a/common/build.gradle.kts b/common/build.gradle.kts index aabdf79a..4bdcb717 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -20,6 +20,7 @@ dependencies { compileOnly("com.github.ben-manes.caffeine:caffeine:${rootProject.properties["caffeine_version"]}") compileOnly("com.saicone.rtag:rtag:${rootProject.properties["rtag_version"]}") compileOnly("net.objecthunter:exp4j:${rootProject.properties["exp4j_version"]}") + compileOnly("com.google.guava:guava:${rootProject.properties["guava_version"]}") } java { diff --git a/common/src/main/java/net/momirealms/customfishing/common/helper/AdventureHelper.java b/common/src/main/java/net/momirealms/customfishing/common/helper/AdventureHelper.java index 2f7832ab..c04d9bcb 100644 --- a/common/src/main/java/net/momirealms/customfishing/common/helper/AdventureHelper.java +++ b/common/src/main/java/net/momirealms/customfishing/common/helper/AdventureHelper.java @@ -19,6 +19,7 @@ public class AdventureHelper { private final MiniMessage miniMessageStrict; private final GsonComponentSerializer gsonComponentSerializer; private final Cache miniMessageToJsonCache = Caffeine.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).build(); + public static boolean legacySupport = false; private AdventureHelper() { this.miniMessage = MiniMessage.builder().build(); @@ -34,12 +35,16 @@ public class AdventureHelper { return SingletonHolder.INSTANCE; } - public static MiniMessage getMiniMessage() { - return getInstance().miniMessage; + public static Component miniMessage(String text) { + if (legacySupport) { + return getMiniMessage().deserialize(legacyToMiniMessage(text)); + } else { + return getMiniMessage().deserialize(text); + } } - public static MiniMessage getStrictMiniMessage() { - return getInstance().miniMessageStrict; + public static MiniMessage getMiniMessage() { + return getInstance().miniMessage; } public static GsonComponentSerializer getGson() { @@ -48,7 +53,7 @@ public class AdventureHelper { public static String miniMessageToJson(String miniMessage) { AdventureHelper instance = getInstance(); - return instance.miniMessageToJsonCache.get(miniMessage, (text) -> instance.gsonComponentSerializer.serialize(instance.miniMessage.deserialize(text))); + return instance.miniMessageToJsonCache.get(miniMessage, (text) -> instance.gsonComponentSerializer.serialize(miniMessage(text))); } public static void sendTitle(Audience audience, Component title, Component subtitle, int fadeIn, int stay, int fadeOut) { diff --git a/core/src/main/java/net/momirealms/customfishing/version/VersionManagerImpl.java b/common/src/main/java/net/momirealms/customfishing/common/helper/VersionHelper.java similarity index 93% rename from core/src/main/java/net/momirealms/customfishing/version/VersionManagerImpl.java rename to common/src/main/java/net/momirealms/customfishing/common/helper/VersionHelper.java index 95b2859f..82fabd6e 100644 --- a/core/src/main/java/net/momirealms/customfishing/version/VersionManagerImpl.java +++ b/common/src/main/java/net/momirealms/customfishing/common/helper/VersionHelper.java @@ -15,9 +15,9 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.version; +package net.momirealms.customfishing.common.helper; -import net.momirealms.customfishing.BukkitCustomFishingPluginImpl; +import net.momirealms.customfishing.bukkit.BukkitCustomFishingPluginImpl; import org.bukkit.Bukkit; import java.io.BufferedReader; @@ -30,7 +30,7 @@ import java.util.concurrent.CompletableFuture; /** * This class implements the VersionManager interface and is responsible for managing version-related information. */ -public class VersionManagerImpl implements VersionManager { +public class VersionHelper { private final boolean isNewerThan1_19_3; private final boolean isNewerThan1_19_4; @@ -38,18 +38,13 @@ public class VersionManagerImpl implements VersionManager { private final boolean isNewerThan1_20_5; private final boolean isNewerThan1_19; private final String serverVersion; - private final BukkitCustomFishingPluginImpl plugin; private final boolean isSpigot; private boolean hasRegionScheduler; private boolean isMojmap; private final String pluginVersion; - @SuppressWarnings("deprecation") - public VersionManagerImpl(BukkitCustomFishingPluginImpl plugin) { - this.plugin = plugin; - - // Get the server version - serverVersion = Bukkit.getServer().getBukkitVersion().split("-")[0]; + public VersionHelper(String serverVersion) { + this.serverVersion = serverVersion; String[] split = serverVersion.split("\\."); int main_ver = Integer.parseInt(split[0]); // Determine if the server version is newer than 1_19_R2 and 1_20_R1 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 e24e3dfc..67bab813 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 @@ -6,5 +6,4 @@ import net.kyori.adventure.text.TranslatableComponent; public interface MessageConstants { TranslatableComponent.Builder COMMAND_RELOAD = Component.translatable().key("argument.entity.notfound.player"); - } 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 new file mode 100644 index 00000000..034bd848 --- /dev/null +++ b/common/src/main/java/net/momirealms/customfishing/common/locale/StandardLocales.java @@ -0,0 +1,11 @@ +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 FORMAT_SECOND = "s"; + public static String FORMAT_MINUTE = "m"; + public static String FORMAT_HOUR = "h"; +} diff --git a/core/src/main/java/net/momirealms/customfishing/util/CompletableFutures.java b/common/src/main/java/net/momirealms/customfishing/common/util/CompletableFutures.java similarity index 98% rename from core/src/main/java/net/momirealms/customfishing/util/CompletableFutures.java rename to common/src/main/java/net/momirealms/customfishing/common/util/CompletableFutures.java index 7e9dc660..882eaa69 100644 --- a/core/src/main/java/net/momirealms/customfishing/util/CompletableFutures.java +++ b/common/src/main/java/net/momirealms/customfishing/common/util/CompletableFutures.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.util; +package net.momirealms.customfishing.common.util; import com.google.common.collect.ImmutableList; diff --git a/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/block/ItemsAdderBlockProvider.java b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/block/ItemsAdderBlockProvider.java index c35f8832..4d207327 100644 --- a/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/block/ItemsAdderBlockProvider.java +++ b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/block/ItemsAdderBlockProvider.java @@ -23,6 +23,7 @@ import net.momirealms.customfishing.api.mechanic.block.BlockDataModifier; import org.bukkit.block.Block; import org.bukkit.block.data.BlockData; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -34,7 +35,7 @@ public class ItemsAdderBlockProvider implements BlockProvider { } @Override - public BlockData blockData(Player player, String id, List modifiers) { + public BlockData blockData(@NotNull Player player, @NotNull String id, List modifiers) { BlockData blockData = CustomBlock.getBaseBlockData(id); for (BlockDataModifier modifier : modifiers) { modifier.apply(player, blockData); @@ -43,7 +44,7 @@ public class ItemsAdderBlockProvider implements BlockProvider { } @Override - public String blockID(Block block) { + public String blockID(@NotNull Block block) { CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block); return customBlock == null ? null : customBlock.getId(); } diff --git a/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/block/OraxenBlockProvider.java b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/block/OraxenBlockProvider.java new file mode 100644 index 00000000..e63a095f --- /dev/null +++ b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/block/OraxenBlockProvider.java @@ -0,0 +1,49 @@ +/* + * 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.compatibility.block; + +import io.th0rgal.oraxen.api.OraxenBlocks; +import io.th0rgal.oraxen.mechanics.Mechanic; +import net.momirealms.customfishing.api.integration.BlockProvider; +import net.momirealms.customfishing.api.mechanic.block.BlockDataModifier; +import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public class OraxenBlockProvider implements BlockProvider { + + @Override + public String identifier() { + return "Oraxen"; + } + + @Override + public BlockData blockData(@NotNull Player player, @NotNull String id, List modifiers) { + return null; + } + + @Override + public String blockID(@NotNull Block block) { + Mechanic mechanic = OraxenBlocks.getOraxenBlock(block.getBlockData()); + if (mechanic == null) return null; + return mechanic.getItemID(); + } +} diff --git a/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/block/VanillaBlockProvider.java b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/block/VanillaBlockProvider.java index 4223b18c..ac5296b2 100644 --- a/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/block/VanillaBlockProvider.java +++ b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/block/VanillaBlockProvider.java @@ -23,6 +23,7 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.data.BlockData; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; @@ -36,7 +37,7 @@ public class VanillaBlockProvider implements BlockProvider { } @Override - public BlockData blockData(Player player, String id, List modifiers) { + public BlockData blockData(@NotNull Player player, @NotNull String id, List modifiers) { BlockData blockData = Material.valueOf(id.toUpperCase(Locale.ENGLISH)).createBlockData(); for (BlockDataModifier modifier : modifiers) { modifier.apply(player, blockData); @@ -45,7 +46,7 @@ public class VanillaBlockProvider implements BlockProvider { } @Override - public @Nullable String blockID(Block block) { + public @Nullable String blockID(@NotNull Block block) { return block.getType().name(); } } diff --git a/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/enchant/AdvancedEnchantmentsProvider.java b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/enchant/AdvancedEnchantmentsProvider.java index edec18d4..afd5d741 100644 --- a/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/enchant/AdvancedEnchantmentsProvider.java +++ b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/enchant/AdvancedEnchantmentsProvider.java @@ -21,6 +21,7 @@ import net.advancedplugins.ae.api.AEAPI; import net.momirealms.customfishing.api.integration.EnchantmentProvider; import net.momirealms.customfishing.common.util.Pair; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; @@ -34,7 +35,7 @@ public class AdvancedEnchantmentsProvider implements EnchantmentProvider { } @Override - public List> getEnchants(ItemStack itemStack) { + public List> getEnchants(@NotNull ItemStack itemStack) { List> enchants = new ArrayList<>(); for (Map.Entry entry : AEAPI.getEnchantmentsOnItem(itemStack).entrySet()) { enchants.add(Pair.of("AE:" + entry.getKey(), entry.getValue().shortValue())); diff --git a/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/enchant/VanillaEnchantmentsProvider.java b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/enchant/VanillaEnchantmentsProvider.java index 3f75bb70..c74a7015 100644 --- a/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/enchant/VanillaEnchantmentsProvider.java +++ b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/enchant/VanillaEnchantmentsProvider.java @@ -21,6 +21,7 @@ import net.momirealms.customfishing.api.integration.EnchantmentProvider; import net.momirealms.customfishing.common.util.Pair; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; @@ -34,7 +35,7 @@ public class VanillaEnchantmentsProvider implements EnchantmentProvider { } @Override - public List> getEnchants(ItemStack itemStack) { + public List> getEnchants(@NotNull ItemStack itemStack) { Map enchantments = itemStack.getEnchantments(); List> enchants = new ArrayList<>(enchantments.size()); for (Map.Entry en : enchantments.entrySet()) { diff --git a/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/item/MMOItemsItemProvider.java b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/item/MMOItemsItemProvider.java index 8253dcd8..c3751d40 100644 --- a/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/item/MMOItemsItemProvider.java +++ b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/item/MMOItemsItemProvider.java @@ -40,7 +40,7 @@ public class MMOItemsItemProvider implements ItemProvider { @NotNull @Override - public ItemStack buildItem(@NotNull Player player, String id) { + public ItemStack buildItem(@NotNull Player player, @NotNull String id) { String[] split = id.split(":"); MMOItem mmoItem = MMOItems.plugin.getMMOItem(Type.get(split[0]), split[1].toUpperCase(Locale.ENGLISH)); return mmoItem == null ? new ItemStack(Material.AIR) : requireNonNull(mmoItem.newBuilder().build()); diff --git a/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/item/McMMOTreasureProvider.java b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/item/McMMOTreasureProvider.java index 003c6882..1ac7f942 100644 --- a/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/item/McMMOTreasureProvider.java +++ b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/item/McMMOTreasureProvider.java @@ -52,7 +52,7 @@ public class McMMOTreasureProvider implements ItemProvider { @NotNull @Override - public ItemStack buildItem(@NotNull Player player, String id) { + public ItemStack buildItem(@NotNull Player player, @NotNull String id) { if (!id.equals("treasure")) return new ItemStack(Material.AIR); ItemStack itemStack = null; int times = 0; diff --git a/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/item/ZaphkielItemImpl.java b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/item/ZaphkielItemImpl.java index c1035bdd..10420b43 100644 --- a/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/item/ZaphkielItemImpl.java +++ b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/item/ZaphkielItemImpl.java @@ -42,12 +42,12 @@ public class ZaphkielItemImpl implements ItemProvider { @NotNull @Override - public ItemStack buildItem(Player player, String id) { + public ItemStack buildItem(@NotNull Player player, @NotNull String id) { return Objects.requireNonNull(zapAPI.getItemManager().generateItemStack(id, player)); } @Override - public String itemID(ItemStack itemStack) { + public String itemID(@NotNull ItemStack itemStack) { if (itemStack == null || itemStack.getType() == Material.AIR) return null; return zapAPI.getItemHandler().getItemId(itemStack); } diff --git a/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/level/AuraSkillsLevelerProvider.java b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/level/AuraSkillsLevelerProvider.java index 510e55a2..de7556ee 100644 --- a/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/level/AuraSkillsLevelerProvider.java +++ b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/level/AuraSkillsLevelerProvider.java @@ -21,6 +21,7 @@ import dev.aurelium.auraskills.api.AuraSkillsApi; import dev.aurelium.auraskills.api.registry.NamespacedId; import net.momirealms.customfishing.api.integration.LevelerProvider; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; public class AuraSkillsLevelerProvider implements LevelerProvider { @@ -30,13 +31,13 @@ public class AuraSkillsLevelerProvider implements LevelerProvider { } @Override - public void addXp(Player player, String target, double amount) { + public void addXp(@NotNull Player player, @NotNull String target, double amount) { AuraSkillsApi.get().getUser(player.getUniqueId()) .addSkillXp(AuraSkillsApi.get().getGlobalRegistry().getSkill(NamespacedId.fromDefault(target)), amount); } @Override - public int getLevel(Player player, String target) { + public int getLevel(@NotNull Player player, @NotNull String target) { return AuraSkillsApi.get().getUser(player.getUniqueId()).getSkillLevel( AuraSkillsApi.get().getGlobalRegistry().getSkill(NamespacedId.fromDefault(target)) ); diff --git a/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/papi/CompetitionPapi.java b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/papi/CompetitionPapi.java index 6e21fdb2..5c54690e 100644 --- a/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/papi/CompetitionPapi.java +++ b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/compatibility/papi/CompetitionPapi.java @@ -69,23 +69,23 @@ public class CompetitionPapi extends PlaceholderExpansion { return String.valueOf(plugin.getCompetitionManager().getOnGoingCompetition() != null); } case "nextseconds" -> { - return String.valueOf(plugin.getCompetitionManager().getNextCompetitionSeconds()); + return String.valueOf(plugin.getCompetitionManager().getNextCompetitionInSeconds()); } case "nextsecond" -> { - return plugin.getCompetitionManager().getNextCompetitionSeconds() % 60 + CFLocale.FORMAT_Second; + return plugin.getCompetitionManager().getNextCompetitionInSeconds() % 60 + CFLocale.FORMAT_Second; } case "nextminute" -> { - int sec = plugin.getCompetitionManager().getNextCompetitionSeconds(); + int sec = plugin.getCompetitionManager().getNextCompetitionInSeconds(); int min = (sec % 3600) / 60; return sec < 60 ? "" : min + CFLocale.FORMAT_Minute; } case "nexthour" -> { - int sec = plugin.getCompetitionManager().getNextCompetitionSeconds(); + int sec = plugin.getCompetitionManager().getNextCompetitionInSeconds(); int h = (sec % (3600 * 24)) / 3600; return sec < 3600 ? "" : h + CFLocale.FORMAT_Hour; } case "nextday" -> { - int sec = plugin.getCompetitionManager().getNextCompetitionSeconds(); + int sec = plugin.getCompetitionManager().getNextCompetitionInSeconds(); int day = sec / (3600 * 24); return day == 0 ? "" : day + CFLocale.FORMAT_Day; } diff --git a/core/src/main/java/net/momirealms/customfishing/BukkitCustomFishingPluginImpl.java b/core/src/main/java/net/momirealms/customfishing/bukkit/BukkitCustomFishingPluginImpl.java similarity index 64% rename from core/src/main/java/net/momirealms/customfishing/BukkitCustomFishingPluginImpl.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/BukkitCustomFishingPluginImpl.java index a1c1b883..861e3270 100644 --- a/core/src/main/java/net/momirealms/customfishing/BukkitCustomFishingPluginImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/BukkitCustomFishingPluginImpl.java @@ -15,31 +15,29 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing; +package net.momirealms.customfishing.bukkit; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.event.CustomFishingReloadEvent; +import net.momirealms.customfishing.api.mechanic.misc.cooldown.CoolDownManager; import net.momirealms.customfishing.api.mechanic.misc.placeholder.BukkitPlaceholderManager; -import net.momirealms.customfishing.bukkit.compatibility.IntegrationManagerImpl; -import net.momirealms.customfishing.bukkit.competition.CompetitionManagerImpl; -import net.momirealms.customfishing.mechanic.action.ActionManagerImpl; -import net.momirealms.customfishing.mechanic.bag.BagManagerImpl; -import net.momirealms.customfishing.mechanic.block.BlockManagerImpl; -import net.momirealms.customfishing.mechanic.effect.EffectManagerImpl; -import net.momirealms.customfishing.mechanic.entity.EntityManagerImpl; -import net.momirealms.customfishing.mechanic.fishing.FishingManagerImpl; -import net.momirealms.customfishing.mechanic.game.GameManagerImpl; -import net.momirealms.customfishing.mechanic.hook.HookManagerImpl; -import net.momirealms.customfishing.mechanic.item.ItemManagerImpl; -import net.momirealms.customfishing.mechanic.loot.LootManagerImpl; -import net.momirealms.customfishing.mechanic.market.MarketManagerImpl; -import net.momirealms.customfishing.mechanic.misc.ChatCatcherManager; -import net.momirealms.customfishing.mechanic.misc.CoolDownManager; -import net.momirealms.customfishing.mechanic.requirement.RequirementManagerImpl; -import net.momirealms.customfishing.mechanic.statistic.StatisticsManagerImpl; -import net.momirealms.customfishing.mechanic.totem.TotemManagerImpl; -import net.momirealms.customfishing.storage.StorageManagerImpl; -import net.momirealms.customfishing.version.VersionManagerImpl; +import net.momirealms.customfishing.bukkit.bag.BukkitBagManager; +import net.momirealms.customfishing.bukkit.block.BukkitBlockManager; +import net.momirealms.customfishing.bukkit.compatibility.BukkitIntegrationManager; +import net.momirealms.customfishing.bukkit.competition.BukkitCompetitionManager; +import net.momirealms.customfishing.bukkit.effect.BukkitEffectManager; +import net.momirealms.customfishing.bukkit.entity.BukkitEntityManager; +import net.momirealms.customfishing.bukkit.fishing.BukkitFishingManager; +import net.momirealms.customfishing.bukkit.game.BukkitGameManager; +import net.momirealms.customfishing.bukkit.hook.BukkitHookManager; +import net.momirealms.customfishing.bukkit.item.ItemManagerImpl; +import net.momirealms.customfishing.bukkit.loot.LootManagerImpl; +import net.momirealms.customfishing.bukkit.market.BukkitMarketManager; +import net.momirealms.customfishing.bukkit.misc.ChatCatcherManager; +import net.momirealms.customfishing.bukkit.statistic.BukkitStatisticsManager; +import net.momirealms.customfishing.bukkit.storage.BukkitStorageManager; +import net.momirealms.customfishing.bukkit.totem.BukkitTotemManager; +import net.momirealms.customfishing.common.helper.VersionHelper; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; @@ -65,7 +63,7 @@ public class BukkitCustomFishingPluginImpl extends BukkitCustomFishingPlugin { @Override public void onLoad() { - this.versionManager = new VersionManagerImpl(this); + this.versionManager = new VersionHelper(this); this.dependencyManager = new DependencyManagerImpl(this, new ReflectionClassPathAppender(this.getClassLoader())); this.dependencyManager.loadDependencies(new ArrayList<>( List.of( @@ -101,26 +99,26 @@ public class BukkitCustomFishingPluginImpl extends BukkitCustomFishingPlugin { this.actionManager = new ActionManagerImpl(this); this.adventure = new AdventureHelper(this); - this.bagManager = new BagManagerImpl(this); - this.blockManager = new BlockManagerImpl(this); + this.bagManager = new BukkitBagManager(this); + this.blockManager = new BukkitBlockManager(this); this.commandManager = new CommandManagerImpl(this); - this.effectManager = new EffectManagerImpl(this); - this.fishingManager = new FishingManagerImpl(this); - this.gameManager = new GameManagerImpl(this); + this.effectManager = new BukkitEffectManager(this); + this.fishingManager = new BukkitFishingManager(this); + this.gameManager = new BukkitGameManager(this); this.itemManager = new ItemManagerImpl(this); this.lootManager = new LootManagerImpl(this); - this.marketManager = new MarketManagerImpl(this); - this.entityManager = new EntityManagerImpl(this); + this.marketManager = new BukkitMarketManager(this); + this.entityManager = new BukkitEntityManager(this); this.placeholderManager = new BukkitPlaceholderManager(this); this.requirementManager = new RequirementManagerImpl(this); this.scheduler = new SchedulerImpl(this); - this.storageManager = new StorageManagerImpl(this); - this.competitionManager = new CompetitionManagerImpl(this); - this.integrationManager = new IntegrationManagerImpl(this); - this.statisticsManager = new StatisticsManagerImpl(this); + this.storageManager = new BukkitStorageManager(this); + this.competitionManager = new BukkitCompetitionManager(this); + this.integrationManager = new BukkitIntegrationManager(this); + this.statisticsManager = new BukkitStatisticsManager(this); this.coolDownManager = new CoolDownManager(this); - this.totemManager = new TotemManagerImpl(this); - this.hookManager = new HookManagerImpl(this); + this.totemManager = new BukkitTotemManager(this); + this.hookManager = new BukkitHookManager(this); this.chatCatcherManager = new ChatCatcherManager(this); this.reload(); super.initialized = true; @@ -136,25 +134,25 @@ public class BukkitCustomFishingPluginImpl extends BukkitCustomFishingPlugin { @Override public void onDisable() { if (this.adventure != null) ((AdventureHelper) this.adventure).close(); - if (this.bagManager != null) ((BagManagerImpl) this.bagManager).disable(); - if (this.blockManager != null) ((BlockManagerImpl) this.blockManager).disable(); - if (this.effectManager != null) ((EffectManagerImpl) this.effectManager).disable(); - if (this.fishingManager != null) ((FishingManagerImpl) this.fishingManager).disable(); - if (this.gameManager != null) ((GameManagerImpl) this.gameManager).disable(); + if (this.bagManager != null) ((BukkitBagManager) this.bagManager).disable(); + if (this.blockManager != null) ((BukkitBlockManager) this.blockManager).disable(); + if (this.effectManager != null) ((BukkitEffectManager) this.effectManager).disable(); + if (this.fishingManager != null) ((BukkitFishingManager) this.fishingManager).disable(); + if (this.gameManager != null) ((BukkitGameManager) this.gameManager).disable(); if (this.itemManager != null) ((ItemManagerImpl) this.itemManager).disable(); if (this.lootManager != null) ((LootManagerImpl) this.lootManager).disable(); - if (this.marketManager != null) ((MarketManagerImpl) this.marketManager).disable(); - if (this.entityManager != null) ((EntityManagerImpl) this.entityManager).disable(); + if (this.marketManager != null) ((BukkitMarketManager) this.marketManager).disable(); + if (this.entityManager != null) ((BukkitEntityManager) this.entityManager).disable(); if (this.requirementManager != null) ((RequirementManagerImpl) this.requirementManager).disable(); if (this.scheduler != null) ((SchedulerImpl) this.scheduler).shutdown(); - if (this.integrationManager != null) ((IntegrationManagerImpl) this.integrationManager).disable(); - if (this.competitionManager != null) ((CompetitionManagerImpl) this.competitionManager).disable(); - if (this.storageManager != null) ((StorageManagerImpl) this.storageManager).disable(); + if (this.integrationManager != null) ((BukkitIntegrationManager) this.integrationManager).disable(); + if (this.competitionManager != null) ((BukkitCompetitionManager) this.competitionManager).disable(); + if (this.storageManager != null) ((BukkitStorageManager) this.storageManager).disable(); if (this.placeholderManager != null) ((BukkitPlaceholderManager) this.placeholderManager).disable(); - if (this.statisticsManager != null) ((StatisticsManagerImpl) this.statisticsManager).disable(); + if (this.statisticsManager != null) ((BukkitStatisticsManager) this.statisticsManager).disable(); if (this.actionManager != null) ((ActionManagerImpl) this.actionManager).disable(); - if (this.totemManager != null) ((TotemManagerImpl) this.totemManager).disable(); - if (this.hookManager != null) ((HookManagerImpl) this.hookManager).disable(); + if (this.totemManager != null) ((BukkitTotemManager) this.totemManager).disable(); + if (this.hookManager != null) ((BukkitHookManager) this.hookManager).disable(); if (this.coolDownManager != null) this.coolDownManager.disable(); if (this.chatCatcherManager != null) this.chatCatcherManager.disable(); if (this.commandManager != null) this.commandManager.unload(); @@ -173,35 +171,35 @@ public class BukkitCustomFishingPluginImpl extends BukkitCustomFishingPlugin { ((RequirementManagerImpl) this.requirementManager).load(); ((ActionManagerImpl) this.actionManager).unload(); ((ActionManagerImpl) this.actionManager).load(); - ((GameManagerImpl) this.gameManager).unload(); - ((GameManagerImpl) this.gameManager).load(); + ((BukkitGameManager) this.gameManager).unload(); + ((BukkitGameManager) this.gameManager).load(); ((ItemManagerImpl) this.itemManager).unload(); ((ItemManagerImpl) this.itemManager).load(); ((LootManagerImpl) this.lootManager).unload(); ((LootManagerImpl) this.lootManager).load(); - ((FishingManagerImpl) this.fishingManager).unload(); - ((FishingManagerImpl) this.fishingManager).load(); - ((TotemManagerImpl) this.totemManager).unload(); - ((TotemManagerImpl) this.totemManager).load(); - ((EffectManagerImpl) this.effectManager).unload(); - ((EffectManagerImpl) this.effectManager).load(); - ((MarketManagerImpl) this.marketManager).unload(); - ((MarketManagerImpl) this.marketManager).load(); - ((BagManagerImpl) this.bagManager).unload(); - ((BagManagerImpl) this.bagManager).load(); - ((BlockManagerImpl) this.blockManager).unload(); - ((BlockManagerImpl) this.blockManager).load(); - ((EntityManagerImpl) this.entityManager).unload(); - ((EntityManagerImpl) this.entityManager).load(); - ((CompetitionManagerImpl) this.competitionManager).unload(); - ((CompetitionManagerImpl) this.competitionManager).load(); - ((StorageManagerImpl) this.storageManager).reload(); - ((StatisticsManagerImpl) this.statisticsManager).unload(); - ((StatisticsManagerImpl) this.statisticsManager).load(); + ((BukkitFishingManager) this.fishingManager).unload(); + ((BukkitFishingManager) this.fishingManager).load(); + ((BukkitTotemManager) this.totemManager).unload(); + ((BukkitTotemManager) this.totemManager).load(); + ((BukkitEffectManager) this.effectManager).unload(); + ((BukkitEffectManager) this.effectManager).load(); + ((BukkitMarketManager) this.marketManager).unload(); + ((BukkitMarketManager) this.marketManager).load(); + ((BukkitBagManager) this.bagManager).unload(); + ((BukkitBagManager) this.bagManager).load(); + ((BukkitBlockManager) this.blockManager).unload(); + ((BukkitBlockManager) this.blockManager).load(); + ((BukkitEntityManager) this.entityManager).unload(); + ((BukkitEntityManager) this.entityManager).load(); + ((BukkitCompetitionManager) this.competitionManager).unload(); + ((BukkitCompetitionManager) this.competitionManager).load(); + ((BukkitStorageManager) this.storageManager).reload(); + ((BukkitStatisticsManager) this.statisticsManager).unload(); + ((BukkitStatisticsManager) this.statisticsManager).load(); ((BukkitPlaceholderManager) this.placeholderManager).unload(); ((BukkitPlaceholderManager) this.placeholderManager).load(); - ((HookManagerImpl) this.hookManager).unload(); - ((HookManagerImpl) this.hookManager).load(); + ((BukkitHookManager) this.hookManager).unload(); + ((BukkitHookManager) this.hookManager).load(); this.commandManager.unload(); this.commandManager.load(); this.coolDownManager.unload(); diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/action/BukkitActionManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/action/BukkitActionManager.java index cde1c742..95bd19d1 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/action/BukkitActionManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/action/BukkitActionManager.java @@ -20,8 +20,8 @@ import net.momirealms.customfishing.common.util.ClassUtils; import net.momirealms.customfishing.common.util.ListUtils; import net.momirealms.customfishing.common.util.Pair; import net.momirealms.customfishing.common.util.RandomUtils; -import net.momirealms.customfishing.util.ItemUtils; -import net.momirealms.customfishing.util.LocationUtils; +import net.momirealms.customfishing.bukkit.util.ItemUtils; +import net.momirealms.customfishing.bukkit.util.LocationUtils; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Entity; @@ -135,10 +135,10 @@ public class BukkitActionManager implements ActionManager { List messages = ListUtils.toList(args); return context -> { if (Math.random() > chance) return; - List replaced = plugin.getPlaceholderManager().parse(context.getHolder(), messages, context.toPlaceholderMap()); + List replaced = plugin.getPlaceholderManager().parse(context.getHolder(), messages, context.placeholderMap()); Audience audience = plugin.getSenderFactory().getAudience(context.getHolder()); for (String text : replaced) { - audience.sendMessage(AdventureHelper.getMiniMessage().deserialize(text)); + audience.sendMessage(AdventureHelper.miniMessage(text)); } }; }); @@ -147,20 +147,20 @@ public class BukkitActionManager implements ActionManager { return context -> { if (Math.random() > chance) return; String random = messages.get(RandomUtils.generateRandomInt(0, messages.size())); - random = BukkitPlaceholderManager.getInstance().parse(context.getHolder(), random, context.toPlaceholderMap()); + random = BukkitPlaceholderManager.getInstance().parse(context.getHolder(), random, context.placeholderMap()); Audience audience = plugin.getSenderFactory().getAudience(context.getHolder()); - audience.sendMessage(AdventureHelper.getMiniMessage().deserialize(random)); + audience.sendMessage(AdventureHelper.miniMessage(random)); }; }); registerAction("broadcast", (args, chance) -> { List messages = ListUtils.toList(args); return context -> { if (Math.random() > chance) return; - List replaced = plugin.getPlaceholderManager().parse(context.getHolder(), messages, context.toPlaceholderMap()); + List replaced = plugin.getPlaceholderManager().parse(context.getHolder(), messages, context.placeholderMap()); for (Player player : Bukkit.getOnlinePlayers()) { Audience audience = plugin.getSenderFactory().getAudience(player); for (String text : replaced) { - audience.sendMessage(AdventureHelper.getMiniMessage().deserialize(text)); + audience.sendMessage(AdventureHelper.miniMessage(text)); } } }; @@ -182,11 +182,11 @@ public class BukkitActionManager implements ActionManager { List replaced = BukkitPlaceholderManager.getInstance().parse( owner, messages, - context.toPlaceholderMap() + context.placeholderMap() ); Audience audience = plugin.getSenderFactory().getAudience(player); for (String text : replaced) { - audience.sendMessage(AdventureHelper.getMiniMessage().deserialize(text)); + audience.sendMessage(AdventureHelper.miniMessage(text)); } } } @@ -204,7 +204,7 @@ public class BukkitActionManager implements ActionManager { List commands = ListUtils.toList(args); return context -> { if (Math.random() > chance) return; - List replaced = BukkitPlaceholderManager.getInstance().parse(context.getHolder(), commands, context.toPlaceholderMap()); + List replaced = BukkitPlaceholderManager.getInstance().parse(context.getHolder(), commands, context.placeholderMap()); plugin.getScheduler().sync().run(() -> { for (String text : replaced) { Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), text); @@ -216,7 +216,7 @@ public class BukkitActionManager implements ActionManager { List commands = ListUtils.toList(args); return context -> { if (Math.random() > chance) return; - List replaced = BukkitPlaceholderManager.getInstance().parse(context.getHolder(), commands, context.toPlaceholderMap()); + List replaced = BukkitPlaceholderManager.getInstance().parse(context.getHolder(), commands, context.placeholderMap()); plugin.getScheduler().sync().run(() -> { for (String text : replaced) { context.getHolder().performCommand(text); @@ -229,7 +229,7 @@ public class BukkitActionManager implements ActionManager { return context -> { if (Math.random() > chance) return; String random = commands.get(ThreadLocalRandom.current().nextInt(commands.size())); - random = BukkitPlaceholderManager.getInstance().parse(context.getHolder(), random, context.toPlaceholderMap()); + random = BukkitPlaceholderManager.getInstance().parse(context.getHolder(), random, context.placeholderMap()); String finalRandom = random; plugin.getScheduler().sync().run(() -> { Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), finalRandom); @@ -250,7 +250,7 @@ public class BukkitActionManager implements ActionManager { double distance = LocationUtils.getDistance(player.getLocation(), location); if (distance <= realRange) { context.arg(ContextKeys.TEMP_NEAR_PLAYER, player.getName()); - List replaced = BukkitPlaceholderManager.getInstance().parse(owner, cmd, context.toPlaceholderMap()); + List replaced = BukkitPlaceholderManager.getInstance().parse(owner, cmd, context.placeholderMap()); for (String text : replaced) { Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), text); } @@ -278,7 +278,7 @@ public class BukkitActionManager implements ActionManager { return context -> { if (Math.random() > chance) return; Audience audience = plugin.getSenderFactory().getAudience(context.getHolder()); - Component component = AdventureHelper.getMiniMessage().deserialize(plugin.getPlaceholderManager().parse(context.getHolder(), text, context.toPlaceholderMap())); + Component component = AdventureHelper.miniMessage(plugin.getPlaceholderManager().parse(context.getHolder(), text, context.placeholderMap())); audience.sendActionBar(component); }; }); @@ -287,9 +287,9 @@ public class BukkitActionManager implements ActionManager { return context -> { if (Math.random() > chance) return; String random = texts.get(RandomUtils.generateRandomInt(0, texts.size())); - random = plugin.getPlaceholderManager().parse(context.getHolder(), random, context.toPlaceholderMap()); + random = plugin.getPlaceholderManager().parse(context.getHolder(), random, context.placeholderMap()); Audience audience = plugin.getSenderFactory().getAudience(context.getHolder()); - audience.sendActionBar(AdventureHelper.getMiniMessage().deserialize(random)); + audience.sendActionBar(AdventureHelper.miniMessage(random)); }; }); registerAction("actionbar-nearby", (args, chance) -> { @@ -306,9 +306,9 @@ public class BukkitActionManager implements ActionManager { double distance = LocationUtils.getDistance(player.getLocation(), location); if (distance <= realRange) { context.arg(ContextKeys.TEMP_NEAR_PLAYER, player.getName()); - String replaced = plugin.getPlaceholderManager().parse(owner, actionbar, context.toPlaceholderMap()); + String replaced = plugin.getPlaceholderManager().parse(owner, actionbar, context.placeholderMap()); Audience audience = plugin.getSenderFactory().getAudience(player); - audience.sendActionBar(AdventureHelper.getMiniMessage().deserialize(replaced)); + audience.sendActionBar(AdventureHelper.miniMessage(replaced)); } } }, location @@ -662,8 +662,8 @@ public class BukkitActionManager implements ActionManager { final Player player = context.getHolder(); Audience audience = plugin.getSenderFactory().getAudience(player); AdventureHelper.sendTitle(audience, - AdventureHelper.getMiniMessage().deserialize(title.render(context)), - AdventureHelper.getMiniMessage().deserialize(subtitle.render(context)), + AdventureHelper.miniMessage(title.render(context)), + AdventureHelper.miniMessage(subtitle.render(context)), fadeIn, stay, fadeOut ); }; @@ -688,8 +688,8 @@ public class BukkitActionManager implements ActionManager { final Player player = context.getHolder(); Audience audience = plugin.getSenderFactory().getAudience(player); AdventureHelper.sendTitle(audience, - AdventureHelper.getMiniMessage().deserialize(title.render(context)), - AdventureHelper.getMiniMessage().deserialize(subtitle.render(context)), + AdventureHelper.miniMessage(title.render(context)), + AdventureHelper.miniMessage(subtitle.render(context)), fadeIn, stay, fadeOut ); }; @@ -716,8 +716,8 @@ public class BukkitActionManager implements ActionManager { context.arg(ContextKeys.TEMP_NEAR_PLAYER, player.getName()); Audience audience = plugin.getSenderFactory().getAudience(player); AdventureHelper.sendTitle(audience, - AdventureHelper.getMiniMessage().deserialize(title.render(context)), - AdventureHelper.getMiniMessage().deserialize(subtitle.render(context)), + AdventureHelper.miniMessage(title.render(context)), + AdventureHelper.miniMessage(subtitle.render(context)), fadeIn, stay, fadeOut ); } diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/bag/BagManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/bukkit/bag/BukkitBagManager.java similarity index 97% rename from core/src/main/java/net/momirealms/customfishing/mechanic/bag/BagManagerImpl.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/bag/BukkitBagManager.java index 36a798d2..6c6b8fcc 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/bag/BagManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/bag/BukkitBagManager.java @@ -15,9 +15,9 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.mechanic.bag; +package net.momirealms.customfishing.bukkit.bag; -import net.momirealms.customfishing.BukkitCustomFishingPluginImpl; +import net.momirealms.customfishing.bukkit.BukkitCustomFishingPluginImpl; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.mechanic.action.Action; import net.momirealms.customfishing.api.mechanic.misc.placeholder.BukkitPlaceholderManager; @@ -41,7 +41,7 @@ import org.jetbrains.annotations.Nullable; import java.util.*; -public class BagManagerImpl implements BagManager, Listener { +public class BukkitBagManager implements BagManager, Listener { private final BukkitCustomFishingPlugin plugin; private final HashMap tempEditMap; @@ -52,7 +52,7 @@ public class BagManagerImpl implements BagManager, Listener { private List bagWhiteListItems; private Requirement[] collectRequirements; - public BagManagerImpl(BukkitCustomFishingPluginImpl plugin) { + public BukkitBagManager(BukkitCustomFishingPluginImpl plugin) { this.plugin = plugin; this.tempEditMap = new HashMap<>(); } diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/block/BlockManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/bukkit/block/BukkitBlockManager.java similarity index 98% rename from core/src/main/java/net/momirealms/customfishing/mechanic/block/BlockManagerImpl.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/block/BukkitBlockManager.java index f8059934..1de3199e 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/block/BlockManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/block/BukkitBlockManager.java @@ -15,9 +15,9 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.mechanic.block; +package net.momirealms.customfishing.bukkit.block; -import net.momirealms.customfishing.BukkitCustomFishingPluginImpl; +import net.momirealms.customfishing.bukkit.BukkitCustomFishingPluginImpl; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.common.Pair; import net.momirealms.customfishing.api.common.Tuple; @@ -25,7 +25,7 @@ import net.momirealms.customfishing.api.integration.BlockProvider; import net.momirealms.customfishing.api.mechanic.block.*; import net.momirealms.customfishing.api.mechanic.loot.Loot; import net.momirealms.customfishing.bukkit.compatibility.block.VanillaBlockProvider; -import net.momirealms.customfishing.util.ConfigUtils; +import net.momirealms.customfishing.bukkit.util.ConfigUtils; import org.bukkit.*; import org.bukkit.block.*; import org.bukkit.block.data.BlockData; @@ -55,7 +55,7 @@ import java.util.*; import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; -public class BlockManagerImpl implements BlockManager, Listener { +public class BukkitBlockManager implements BlockManager, Listener { private final BukkitCustomFishingPlugin plugin; private final HashMap blockLibraryMap; @@ -64,7 +64,7 @@ public class BlockManagerImpl implements BlockManager, Listener { private final HashMap dataBuilderMap; private final HashMap stateBuilderMap; - public BlockManagerImpl(BukkitCustomFishingPluginImpl plugin) { + public BukkitBlockManager(BukkitCustomFishingPluginImpl plugin) { this.plugin = plugin; this.blockLibraryMap = new HashMap<>(); this.blockConfigMap = new HashMap<>(); diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/IntegrationManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/BukkitIntegrationManager.java similarity index 98% rename from core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/IntegrationManagerImpl.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/BukkitIntegrationManager.java index 80c1f2ca..c7a6e03a 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/IntegrationManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/compatibility/BukkitIntegrationManager.java @@ -42,14 +42,14 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; -public class IntegrationManagerImpl implements IntegrationManager { +public class BukkitIntegrationManager implements IntegrationManager { private final BukkitCustomFishingPlugin plugin; private final HashMap levelPluginMap; private final HashMap enchantmentPluginMap; private SeasonProvider seasonProvider; - public IntegrationManagerImpl(BukkitCustomFishingPlugin plugin) { + public BukkitIntegrationManager(BukkitCustomFishingPlugin plugin) { this.plugin = plugin; this.levelPluginMap = new HashMap<>(); this.enchantmentPluginMap = new HashMap<>(); diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/competition/CompetitionManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/bukkit/competition/BukkitCompetitionManager.java similarity index 51% rename from core/src/main/java/net/momirealms/customfishing/bukkit/competition/CompetitionManagerImpl.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/competition/BukkitCompetitionManager.java index 7317d375..997e0e35 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/competition/CompetitionManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/competition/BukkitCompetitionManager.java @@ -17,23 +17,26 @@ package net.momirealms.customfishing.bukkit.competition; +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; +import dev.dejvokep.boostedyaml.YamlDocument; +import dev.dejvokep.boostedyaml.block.implementation.Section; +import net.kyori.adventure.bossbar.BossBar; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.common.Pair; import net.momirealms.customfishing.api.mechanic.action.Action; -import net.momirealms.customfishing.api.mechanic.competition.CompetitionConfigImpl; +import net.momirealms.customfishing.api.mechanic.action.ActionManager; +import net.momirealms.customfishing.api.mechanic.competition.CompetitionConfig; import net.momirealms.customfishing.api.mechanic.competition.CompetitionGoal; import net.momirealms.customfishing.api.mechanic.competition.CompetitionManager; import net.momirealms.customfishing.api.mechanic.competition.FishingCompetition; -import net.momirealms.customfishing.api.mechanic.competition.info.ActionBarConfigImpl; -import net.momirealms.customfishing.api.mechanic.competition.info.BossBarConfigImpl; -import net.momirealms.customfishing.api.scheduler.CancellableTask; -import net.momirealms.customfishing.storage.method.database.nosql.RedisManager; -import net.momirealms.customfishing.util.ConfigUtils; +import net.momirealms.customfishing.api.mechanic.competition.info.ActionBarConfig; +import net.momirealms.customfishing.api.mechanic.competition.info.BossBarConfig; +import net.momirealms.customfishing.api.mechanic.context.Context; +import net.momirealms.customfishing.bukkit.storage.method.database.nosql.RedisManager; +import net.momirealms.customfishing.common.plugin.scheduler.SchedulerTask; +import net.momirealms.customfishing.common.util.Pair; import org.bukkit.Bukkit; -import org.bukkit.boss.BarColor; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.YamlConfiguration; -import org.jetbrains.annotations.NotNull; +import org.bukkit.entity.Player; import org.jetbrains.annotations.Nullable; import java.io.File; @@ -41,16 +44,16 @@ import java.time.LocalDateTime; import java.util.*; import java.util.concurrent.TimeUnit; -public class CompetitionManagerImpl implements CompetitionManager { +public class BukkitCompetitionManager implements CompetitionManager { private final BukkitCustomFishingPlugin plugin; - private final HashMap timeConfigMap; - private final HashMap commandConfigMap; + private final HashMap timeConfigMap; + private final HashMap commandConfigMap; private Competition currentCompetition; - private CancellableTask timerCheckTask; + private SchedulerTask timerCheckTask; private int nextCompetitionSeconds; - public CompetitionManagerImpl(BukkitCustomFishingPlugin plugin) { + public BukkitCompetitionManager(BukkitCustomFishingPlugin plugin) { this.plugin = plugin; this.timeConfigMap = new HashMap<>(); this.commandConfigMap = new HashMap<>(); @@ -58,7 +61,7 @@ public class CompetitionManagerImpl implements CompetitionManager { public void load() { loadConfig(); - this.timerCheckTask = plugin.getScheduler().runTaskAsyncTimer( + this.timerCheckTask = plugin.getScheduler().asyncRepeating( this::timerCheck, 1, 1, @@ -67,33 +70,21 @@ public class CompetitionManagerImpl implements CompetitionManager { } public void unload() { - if (this.timerCheckTask != null && !this.timerCheckTask.isCancelled()) + if (this.timerCheckTask != null) this.timerCheckTask.cancel(); + if (currentCompetition != null && currentCompetition.isOnGoing()) + currentCompetition.stop(true); this.commandConfigMap.clear(); this.timeConfigMap.clear(); - if (currentCompetition != null && currentCompetition.isOnGoing()) { - plugin.getScheduler().runTaskAsync(() -> currentCompetition.stop(true)); - } } public void disable() { - if (this.timerCheckTask != null && !this.timerCheckTask.isCancelled()) + if (this.timerCheckTask != null) this.timerCheckTask.cancel(); - this.commandConfigMap.clear(); - this.timeConfigMap.clear(); if (currentCompetition != null && currentCompetition.isOnGoing()) currentCompetition.stop(false); - } - - /** - * Retrieves a set of all competition names. - * - * @return A set of competition names. - */ - @NotNull - @Override - public Set getAllCompetitionKeys() { - return commandConfigMap.keySet(); + this.commandConfigMap.clear(); + this.timeConfigMap.clear(); } @SuppressWarnings("DuplicatedCode") @@ -103,7 +94,7 @@ public class CompetitionManagerImpl implements CompetitionManager { File typeFolder = new File(plugin.getDataFolder() + File.separator + "contents" + File.separator + type); if (!typeFolder.exists()) { if (!typeFolder.mkdirs()) return; - plugin.saveResource("contents" + File.separator + type + File.separator + "default.yml", false); + plugin.getBoostrap().saveResource("contents" + File.separator + type + File.separator + "default.yml", false); } fileDeque.push(typeFolder); while (!fileDeque.isEmpty()) { @@ -122,55 +113,65 @@ public class CompetitionManagerImpl implements CompetitionManager { } private void loadSingleFileCompetition(File file) { - YamlConfiguration config = YamlConfiguration.loadConfiguration(file); - for (Map.Entry entry : config.getValues(false).entrySet()) { - if (entry.getValue() instanceof ConfigurationSection section) { + YamlDocument document = plugin.getConfigManager().loadData(file); + for (Map.Entry entry : document.getStringRouteMappedValues(false).entrySet()) { + if (entry.getValue() instanceof Section section) { - CompetitionConfigImpl.Builder builder = new CompetitionConfigImpl.Builder(entry.getKey()) - .goal(CompetitionGoal.valueOf(section.getString("goal", "TOTAL_SCORE").toUpperCase(Locale.ENGLISH))) + CompetitionConfig.Builder builder = CompetitionConfig.builder() + .key(entry.getKey()) + .goal(CompetitionGoal.index().value(section.getString("goal", "TOTAL_SCORE").toLowerCase(Locale.ENGLISH))) .minPlayers(section.getInt("min-players", 0)) .duration(section.getInt("duration", 300)) - .rewards(getPrizeActions(section.getConfigurationSection("rewards"))) - .requirements(plugin.getRequirementManager().parseRequirements(section.getConfigurationSection("participate-requirements"), false)) - .joinActions(plugin.getActionManager().getActions(section.getConfigurationSection("participate-actions"))) - .startActions(plugin.getActionManager().getActions(section.getConfigurationSection("start-actions"))) - .endActions(plugin.getActionManager().getActions(section.getConfigurationSection("end-actions"))) - .skipActions(plugin.getActionManager().getActions(section.getConfigurationSection("skip-actions"))); + .rewards(getPrizeActions(section.getSection("rewards"))) + .joinRequirements(plugin.getRequirementManager().parseRequirements(section.getSection("participate-requirements"), false)) + .joinActions(plugin.getActionManager().parseActions(section.getSection("participate-actions"))) + .startActions(plugin.getActionManager().parseActions(section.getSection("start-actions"))) + .endActions(plugin.getActionManager().parseActions(section.getSection("end-actions"))) + .skipActions(plugin.getActionManager().parseActions(section.getSection("skip-actions")));; if (section.getBoolean("bossbar.enable", false)) { - builder.bossbar(new BossBarConfigImpl.BuilderImpl() - .color(BarColor.valueOf(section.getString("bossbar.color", "WHITE").toUpperCase(Locale.ENGLISH))) - .overlay(BossBarConfigImpl.Overlay.valueOf(section.getString("bossbar.overlay", "PROGRESS").toUpperCase(Locale.ENGLISH))) - .refreshRate(section.getInt("bossbar.refresh-rate", 20)) - .switchInterval(section.getInt("bossbar.switch-interval", 200)) - .showToAll(!section.getBoolean("bossbar.only-show-to-participants", true)) - .text(section.getStringList("bossbar.text").toArray(new String[0])) - .build()); + builder.bossBarConfig( + BossBarConfig.builder() + .enable(true) + .color(BossBar.Color.valueOf(section.getString("bossbar.color", "WHITE").toUpperCase(Locale.ENGLISH))) + .overlay(BossBar.Overlay.valueOf(section.getString("bossbar.overlay", "PROGRESS").toUpperCase(Locale.ENGLISH))) + .refreshRate(section.getInt("bossbar.refresh-rate", 20)) + .switchInterval(section.getInt("bossbar.switch-interval", 200)) + .showToAll(!section.getBoolean("bossbar.only-show-to-participants", true)) + .text(section.getStringList("bossbar.text").toArray(new String[0])) + .build() + ); } if (section.getBoolean("actionbar.enable", false)) { - builder.actionbar(new ActionBarConfigImpl.BuilderImpl() - .refreshRate(section.getInt("actionbar.refresh-rate", 5)) - .switchInterval(section.getInt("actionbar.switch-interval", 200)) - .showToAll(!section.getBoolean("actionbar.only-show-to-participants", true)) - .text(section.getStringList("actionbar.text").toArray(new String[0])) - .build()); + builder.actionBarConfig( + ActionBarConfig.builder() + .enable(true) + .refreshRate(section.getInt("actionbar.refresh-rate", 5)) + .switchInterval(section.getInt("actionbar.switch-interval", 200)) + .showToAll(!section.getBoolean("actionbar.only-show-to-participants", true)) + .text(section.getStringList("actionbar.text").toArray(new String[0])) + .build() + ); } - CompetitionConfigImpl competitionConfigImpl = builder.build(); + CompetitionConfig competitionConfig = builder.build(); List> timePairs = section.getStringList("start-time") - .stream().map(it -> ConfigUtils.splitStringIntegerArgs(it, ":")).toList(); - List weekdays = section.getIntegerList("start-weekday"); - if (weekdays.size() == 0) { + .stream().map(it -> { + String[] split = it.split(":"); + return Pair.of(Integer.parseInt(split[0]), Integer.parseInt(split[1])); + }).toList(); + List weekdays = section.getIntList("start-weekday"); + if (weekdays.isEmpty()) { weekdays.addAll(List.of(1,2,3,4,5,6,7)); } for (Integer weekday : weekdays) { for (Pair timePair : timePairs) { CompetitionSchedule schedule = new CompetitionSchedule(weekday, timePair.left(), timePair.right(), 0); - timeConfigMap.put(schedule, competitionConfigImpl); + timeConfigMap.put(schedule, competitionConfig); } } - commandConfigMap.put(entry.getKey(), competitionConfigImpl); + commandConfigMap.put(entry.getKey(), competitionConfig); } } } @@ -181,12 +182,12 @@ public class CompetitionManagerImpl implements CompetitionManager { * @param section The configuration section containing prize actions. * @return A HashMap where keys are action names and values are arrays of Action objects. */ - public HashMap getPrizeActions(ConfigurationSection section) { - HashMap map = new HashMap<>(); + public HashMap[]> getPrizeActions(Section section) { + HashMap[]> map = new HashMap<>(); if (section == null) return map; - for (Map.Entry entry : section.getValues(false).entrySet()) { - if (entry.getValue() instanceof ConfigurationSection innerSection) { - map.put(entry.getKey(), plugin.getActionManager().getActions(innerSection)); + for (Map.Entry entry : section.getStringRouteMappedValues(false).entrySet()) { + if (entry.getValue() instanceof Section innerSection) { + map.put(entry.getKey(), plugin.getActionManager().parseActions(innerSection)); } } return map; @@ -209,43 +210,17 @@ public class CompetitionManagerImpl implements CompetitionManager { nextCompetitionTime = Math.min(nextCompetitionTime, schedule.getTimeDelta(seconds)); } this.nextCompetitionSeconds = nextCompetitionTime; - CompetitionConfigImpl config = timeConfigMap.get(competitionSchedule); + CompetitionConfig config = timeConfigMap.get(competitionSchedule); if (config != null) { startCompetition(config, false, null); } } - /** - * Retrieves the localization key for a given competition goal. - * - * @param goal The competition goal to retrieve the localization key for. - * @return The localization key for the specified competition goal. - */ - @NotNull - @Override - public String getCompetitionGoalLocale(CompetitionGoal goal) { - switch (goal) { - case MAX_SIZE -> { - return CFLocale.MSG_Max_Size; - } - case CATCH_AMOUNT -> { - return CFLocale.MSG_Catch_Amount; - } - case TOTAL_SCORE -> { - return CFLocale.MSG_Total_Score; - } - case TOTAL_SIZE -> { - return CFLocale.MSG_Total_Size; - } - } - return ""; - } - @Override public boolean startCompetition(String competition, boolean force, String serverGroup) { - CompetitionConfigImpl config = commandConfigMap.get(competition); + CompetitionConfig config = commandConfigMap.get(competition); if (config == null) { - LogUtils.warn("Competition " + competition + " doesn't exist."); + plugin.getPluginLogger().warn("Competition " + competition + " doesn't exist."); return false; } return startCompetition(config, force, serverGroup); @@ -264,17 +239,11 @@ public class CompetitionManagerImpl implements CompetitionManager { } @Override - public boolean startCompetition(CompetitionConfigImpl config, boolean force, @Nullable String serverGroup) { + public boolean startCompetition(CompetitionConfig config, boolean force, @Nullable String serverGroup) { if (!force) { int players = Bukkit.getOnlinePlayers().size(); - if (players < config.getMinPlayersToStart()) { - var actions = config.getSkipActions(); - if (actions != null) { - PlayerContext playerContext = new PlayerContext(null, null, new HashMap<>()); - for (Action action : actions) { - action.trigger(playerContext); - } - } + if (players < config.minPlayersToStart()) { + ActionManager.trigger(Context.player(null), config.skipActions()); return false; } start(config); @@ -283,25 +252,30 @@ public class CompetitionManagerImpl implements CompetitionManager { start(config); return true; } else { - RedisManager.getInstance().publishRedisMessage(serverGroup, "start;" + config.getKey()); + ByteArrayDataOutput out = ByteStreams.newDataOutput(); + out.writeUTF(serverGroup); + out.writeUTF("competition"); + out.writeUTF("start"); + out.writeUTF(config.key()); + RedisManager.getInstance().publishRedisMessage(Arrays.toString(out.toByteArray())); return true; } } - private void start(CompetitionConfigImpl config) { + private void start(CompetitionConfig config) { if (getOnGoingCompetition() != null) { // END currentCompetition.end(true); - plugin.getScheduler().runTaskAsyncLater(() -> { + plugin.getScheduler().asyncLater(() -> { // start one second later - this.currentCompetition = new Competition(config); - this.currentCompetition.start(); + this.currentCompetition = new Competition(plugin, config); + this.currentCompetition.start(true); }, 1, TimeUnit.SECONDS); } else { // start instantly - plugin.getScheduler().runTaskAsync(() -> { - this.currentCompetition = new Competition(config); - this.currentCompetition.start(); + plugin.getScheduler().async().execute(() -> { + this.currentCompetition = new Competition(plugin, config); + this.currentCompetition.start(true); }); } } @@ -312,19 +286,13 @@ public class CompetitionManagerImpl implements CompetitionManager { * @return The number of seconds until the next competition. */ @Override - public int getNextCompetitionSeconds() { + public int getNextCompetitionInSeconds() { return nextCompetitionSeconds; } - /** - * Retrieves the configuration for a competition based on its key. - * - * @param key The key of the competition configuration to retrieve. - * @return The {@link CompetitionConfigImpl} for the specified key, or {@code null} if no configuration exists with that key. - */ @Nullable @Override - public CompetitionConfigImpl getConfig(String key) { + public CompetitionConfig getCompetition(String key) { return commandConfigMap.get(key); } } 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 53bbb556..55bf387f 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 @@ -18,18 +18,23 @@ package net.momirealms.customfishing.bukkit.competition; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.common.Pair; import net.momirealms.customfishing.api.event.CompetitionEvent; import net.momirealms.customfishing.api.mechanic.action.Action; -import net.momirealms.customfishing.api.mechanic.competition.CompetitionConfigImpl; +import net.momirealms.customfishing.api.mechanic.action.ActionManager; +import net.momirealms.customfishing.api.mechanic.competition.CompetitionConfig; import net.momirealms.customfishing.api.mechanic.competition.CompetitionGoal; import net.momirealms.customfishing.api.mechanic.competition.FishingCompetition; import net.momirealms.customfishing.api.mechanic.competition.RankingProvider; -import net.momirealms.customfishing.api.scheduler.CancellableTask; +import net.momirealms.customfishing.api.mechanic.config.ConfigManager; +import net.momirealms.customfishing.api.mechanic.context.Context; +import net.momirealms.customfishing.api.mechanic.context.ContextKeys; import net.momirealms.customfishing.bukkit.competition.actionbar.ActionBarManager; 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.plugin.scheduler.SchedulerTask; +import net.momirealms.customfishing.common.util.Pair; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -38,77 +43,139 @@ import org.jetbrains.annotations.NotNull; import java.time.Instant; import java.util.HashMap; import java.util.Iterator; -import java.util.Map; import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; public class Competition implements FishingCompetition { - private final CompetitionConfigImpl config; - private CancellableTask competitionTimerTask; + private final BukkitCustomFishingPlugin plugin; + private final CompetitionConfig config; + private SchedulerTask competitionTimerTask; private final CompetitionGoal goal; - private final ConcurrentHashMap publicPlaceholders; + private final Context publicContext; private final RankingProvider rankingProvider; private float progress; - private long remainingTime; + private int remainingTime; private long startTime; private BossBarManager bossBarManager; private ActionBarManager actionBarManager; - public Competition(CompetitionConfigImpl config) { + public Competition(BukkitCustomFishingPlugin plugin, CompetitionConfig config) { this.config = config; - this.goal = config.getGoal() == CompetitionGoal.RANDOM ? CompetitionGoal.getRandom() : config.getGoal(); - if (CFConfig.redisRanking) this.rankingProvider = new RedisRankingProvider(); - else this.rankingProvider = new LocalRankingProvider(); - this.publicPlaceholders = new ConcurrentHashMap<>(); - this.publicPlaceholders.put("{goal}", BukkitCustomFishingPlugin.get().getCompetitionManager().getCompetitionGoalLocale(goal)); + this.plugin = plugin; + this.goal = config.goal() == CompetitionGoal.RANDOM ? CompetitionGoal.getRandom() : config.goal(); + if (ConfigManager.redisRanking()) this.rankingProvider = new RedisRankingProvider(); + else this.rankingProvider = new LocalRankingProvider(); + this.publicContext = Context.player(null, true); + this.publicContext.arg( + ContextKeys.GOAL, + goal + ); } - /** - * Starts the fishing competition, initializing its settings and actions. - * This method sets the initial progress, remaining time, start time, and updates public placeholders. - * It also arranges timer tasks for competition timing and initializes boss bar and action bar managers if configured. - * Additionally, it triggers the start actions defined in the competition's configuration. - */ @Override - public void start() { + public void start(boolean triggerEvent) { this.progress = 1; - this.remainingTime = config.getDurationInSeconds(); + this.remainingTime = this.config.durationInSeconds(); this.startTime = Instant.now().getEpochSecond(); this.arrangeTimerTask(); - if (config.getBossBarConfig() != null) { - this.bossBarManager = new BossBarManager(config.getBossBarConfig(), this); + if (this.config.bossBarConfig() != null && this.config.bossBarConfig().enabled()) { + this.bossBarManager = new BossBarManager(this.config.bossBarConfig(), this); this.bossBarManager.load(); } - if (config.getActionBarConfig() != null) { - this.actionBarManager = new ActionBarManager(config.getActionBarConfig(), this); + if (this.config.actionBarConfig() != null && this.config.actionBarConfig().enabled()) { + this.actionBarManager = new ActionBarManager(this.config.actionBarConfig(), this); this.actionBarManager.load(); } - Action[] actions = config.startActions(); - if (actions != null) { - PlayerContext playerContext = new PlayerContext(null, null, this.publicPlaceholders); - for (Action action : actions) { - action.trigger(playerContext); + this.updatePublicPlaceholders(); + ActionManager.trigger(this.publicContext, this.config.startActions()); + this.rankingProvider.clear(); + if (triggerEvent) { + this.plugin.getScheduler().async().execute(() -> { + CompetitionEvent competitionStartEvent = new CompetitionEvent(CompetitionEvent.State.START, this); + Bukkit.getPluginManager().callEvent(competitionStartEvent); + }); + } + } + + @Override + public void stop(boolean triggerEvent) { + if (this.competitionTimerTask != null) + this.competitionTimerTask.cancel(); + if (this.bossBarManager != null) + this.bossBarManager.unload(); + if (this.actionBarManager != null) + this.actionBarManager.unload(); + this.rankingProvider.clear(); + this.remainingTime = 0; + if (triggerEvent) { + plugin.getScheduler().async().execute(() -> { + CompetitionEvent competitionEvent = new CompetitionEvent(CompetitionEvent.State.STOP, this); + Bukkit.getPluginManager().callEvent(competitionEvent); + }); + } + } + + @Override + public void end(boolean triggerEvent) { + // mark it as ended + this.remainingTime = 0; + + // cancel some sub tasks + if (competitionTimerTask != null) + this.competitionTimerTask.cancel(); + if (this.bossBarManager != null) + this.bossBarManager.unload(); + if (this.actionBarManager != null) + this.actionBarManager.unload(); + + // give prizes + HashMap[]> rewardsMap = config.rewards(); + if (rankingProvider.getSize() != 0 && rewardsMap != null) { + Iterator> iterator = rankingProvider.getIterator(); + int i = 1; + while (iterator.hasNext()) { + Pair competitionPlayer = iterator.next(); + this.publicContext.arg(ContextKeys.of(i + "_player", String.class), competitionPlayer.left()); + this.publicContext.arg(ContextKeys.of(i + "_score", String.class), String.format("%.2f", competitionPlayer.right())); + if (i < rewardsMap.size()) { + Player player = Bukkit.getPlayer(competitionPlayer.left()); + if (player != null) { + ActionManager.trigger(Context.player(player).combine(this.publicContext), rewardsMap.get(String.valueOf(i))); + } + } else { + Action[] actions = rewardsMap.get("participation"); + if (actions != null) { + Player player = Bukkit.getPlayer(competitionPlayer.left()); { + if (player != null) { + ActionManager.trigger(Context.player(player).combine(this.publicContext), actions); + } + } + } + } + i++; } } - this.rankingProvider.clear(); - this.updatePublicPlaceholders(); + // end actions + ActionManager.trigger(publicContext, config.endActions()); - CompetitionEvent competitionStartEvent = new CompetitionEvent(CompetitionEvent.State.START, this); - Bukkit.getPluginManager().callEvent(competitionStartEvent); + // call event + if (triggerEvent) { + plugin.getScheduler().async().execute(() -> { + CompetitionEvent competitionEndEvent = new CompetitionEvent(CompetitionEvent.State.END, this); + Bukkit.getPluginManager().callEvent(competitionEndEvent); + }); + } + + // 1 seconds delay for other servers to read the redis data + plugin.getScheduler().asyncLater(this.rankingProvider::clear, 1, TimeUnit.SECONDS); } - /** - * Arranges the timer task for the fishing competition. - * This method schedules a recurring task that updates the competition's remaining time and public placeholders. - * If the remaining time reaches zero, the competition is ended. - */ private void arrangeTimerTask() { - this.competitionTimerTask = BukkitCustomFishingPlugin.get().getScheduler().runTaskAsyncTimer(() -> { + this.competitionTimerTask = this.plugin.getScheduler().asyncRepeating(() -> { if (decreaseTime()) { end(true); return; @@ -117,115 +184,23 @@ public class Competition implements FishingCompetition { }, 1, 1, TimeUnit.SECONDS); } - /** - * Update public placeholders for the fishing competition. - * This method updates placeholders representing player rankings, remaining time, and score in public messages. - * Placeholders for player rankings include {1_player}, {1_score}, {2_player}, {2_score}, and so on. - * The placeholders for time include {hour}, {minute}, {second}, and {seconds}. - */ private void updatePublicPlaceholders() { - for (int i = 1; i < CFConfig.placeholderLimit + 1; i++) { - int finalI = i; - Optional.ofNullable(rankingProvider.getPlayerAt(i)).ifPresentOrElse(player -> { - publicPlaceholders.put("{" + finalI + "_player}", player); - publicPlaceholders.put("{" + finalI + "_score}", String.format("%.2f", rankingProvider.getScoreAt(finalI))); - }, () -> { - publicPlaceholders.put("{" + finalI + "_player}", CFLocale.MSG_No_Player); - publicPlaceholders.put("{" + finalI + "_score}", CFLocale.MSG_No_Score); - }); - } - publicPlaceholders.put("{hour}", remainingTime < 3600 ? "" : (remainingTime / 3600) + CFLocale.FORMAT_Hour); - publicPlaceholders.put("{minute}", remainingTime < 60 ? "" : (remainingTime % 3600) / 60 + CFLocale.FORMAT_Minute); - publicPlaceholders.put("{second}", remainingTime == 0 ? "" : remainingTime % 60 + CFLocale.FORMAT_Second); - publicPlaceholders.put("{seconds}", String.valueOf(remainingTime)); - } - - /** - * Stop the fishing competition. - * This method cancels the competition timer task, unloads boss bars and action bars, clears the ranking, - * and sets the remaining time to zero. - */ - @Override - public void stop(boolean triggerEvent) { - if (!competitionTimerTask.isCancelled()) this.competitionTimerTask.cancel(); - if (this.bossBarManager != null) this.bossBarManager.unload(); - if (this.actionBarManager != null) this.actionBarManager.unload(); - this.rankingProvider.clear(); - this.remainingTime = 0; - - if (triggerEvent) { - CompetitionEvent competitionEvent = new CompetitionEvent(CompetitionEvent.State.STOP, this); - Bukkit.getPluginManager().callEvent(competitionEvent); - } - } - - /** - * End the fishing competition. - * This method marks the competition as ended, cancels sub-tasks such as timers and bar management, - * gives prizes to top participants and participation rewards, performs end actions, and clears the ranking. - */ - @Override - public void end(boolean triggerEvent) { - // mark it as ended - this.remainingTime = 0; - - // cancel some sub tasks - if (!competitionTimerTask.isCancelled()) this.competitionTimerTask.cancel(); - if (this.bossBarManager != null) this.bossBarManager.unload(); - if (this.actionBarManager != null) this.actionBarManager.unload(); - - // give prizes - HashMap rewardsMap = config.getRewards(); - if (rankingProvider.getSize() != 0 && rewardsMap != null) { - Iterator> iterator = rankingProvider.getIterator(); - int i = 1; - while (iterator.hasNext()) { - Pair competitionPlayer = iterator.next(); - this.publicPlaceholders.put("{" + i + "_player}", competitionPlayer.left()); - this.publicPlaceholders.put("{" + i + "_score}", String.format("%.2f", competitionPlayer.right())); - if (i < rewardsMap.size()) { - Player player = Bukkit.getPlayer(competitionPlayer.left()); - if (player != null) - for (Action action : rewardsMap.get(String.valueOf(i))) - action.trigger(new PlayerContext(player, this.publicPlaceholders)); - } else { - Action[] actions = rewardsMap.get("participation"); - if (actions != null) { - Player player = Bukkit.getPlayer(competitionPlayer.left()); { - if (player != null) - for (Action action : actions) - action.trigger(new PlayerContext(player, this.publicPlaceholders)); - } - } - } - i++; + for (int i = 1; i < ConfigManager.placeholderLimit() + 1; i++) { + Optional player = Optional.ofNullable(this.rankingProvider.getPlayerAt(i)); + if (player.isPresent()) { + 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); } } - - // do end actions - Action[] actions = config.getEndActions(); - if (actions != null) { - PlayerContext playerContext = new PlayerContext(null, null, new HashMap<>(publicPlaceholders)); - for (Action action : actions) { - action.trigger(playerContext); - } - } - - // call event - if (triggerEvent) { - CompetitionEvent competitionEndEvent = new CompetitionEvent(CompetitionEvent.State.END, this); - Bukkit.getPluginManager().callEvent(competitionEndEvent); - } - - // 1 seconds delay for other servers to read the redis data - BukkitCustomFishingPlugin.get().getScheduler().runTaskAsyncLater(this.rankingProvider::clear, 1, TimeUnit.SECONDS); + 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.SECONDS, remainingTime); } - /** - * Check if the fishing competition is ongoing. - * - * @return {@code true} if the competition is still ongoing, {@code false} if it has ended. - */ @Override public boolean isOnGoing() { return remainingTime > 0; @@ -238,141 +213,69 @@ public class Competition implements FishingCompetition { */ private boolean decreaseTime() { long current = Instant.now().getEpochSecond(); - int duration = config.getDurationInSeconds(); - remainingTime = duration - (current - startTime); + int duration = config.durationInSeconds(); + remainingTime = (int) (duration - (current - startTime)); progress = (float) remainingTime / duration; return remainingTime <= 0; } - /** - * Refreshes the data for a player in the fishing competition, including updating their score and triggering - * actions if it's their first time joining the competition. - * - * @param player The player whose data needs to be refreshed. - * @param score The player's current score in the competition. - */ @Override public void refreshData(Player player, double score) { // if player join for the first time, trigger join actions if (!hasPlayerJoined(player)) { - Action[] actions = config.getJoinActions(); - if (actions != null) { - PlayerContext playerContext = new PlayerContext(player); - for (Action action : actions) { - action.trigger(playerContext); - } - } + ActionManager.trigger(Context.player(player).combine(publicContext), config.joinActions()); } // show competition info - if (this.bossBarManager != null) this.bossBarManager.showBossBarTo(player); - if (this.actionBarManager != null) this.actionBarManager.showActionBarTo(player); + if (this.bossBarManager != null) + this.bossBarManager.showBossBarTo(player); + if (this.actionBarManager != null) + this.actionBarManager.showActionBarTo(player); // refresh data - switch (this.goal) { - case CATCH_AMOUNT -> rankingProvider.refreshData(player.getName(), 1); - case TOTAL_SIZE, TOTAL_SCORE -> rankingProvider.refreshData(player.getName(), score); - case MAX_SIZE -> { - if (score > rankingProvider.getPlayerScore(player.getName())) { - rankingProvider.setData(player.getName(), score); - } - } - } + this.goal.refreshScore(rankingProvider, player, score); } - /** - * Checks if a player has joined the fishing competition based on their name. - * - * @param player The player to check for participation. - * @return {@code true} if the player has joined the competition; {@code false} otherwise. - */ @Override public boolean hasPlayerJoined(OfflinePlayer player) { return rankingProvider.getPlayerRank(player.getName()) != -1; } - /** - * Gets the progress of the fishing competition as a float value (0~1). - * - * @return The progress of the fishing competition as a float. - */ @Override public float getProgress() { return progress; } - /** - * Gets the remaining time in seconds for the fishing competition. - * - * @return The remaining time in seconds. - */ @Override public long getRemainingTime() { return remainingTime; } - /** - * Gets the start time of the fishing competition. - * - * @return The start time of the fishing competition. - */ @Override public long getStartTime() { return startTime; } - /** - * Gets the configuration of the fishing competition. - * - * @return The configuration of the fishing competition. - */ @NotNull @Override - public CompetitionConfigImpl getConfig() { + public CompetitionConfig getConfig() { return config; } - /** - * Gets the goal of the fishing competition. - * - * @return The goal of the fishing competition. - */ @NotNull @Override public CompetitionGoal getGoal() { return goal; } - /** - * Gets the ranking data for the fishing competition. - * - * @return The ranking data for the fishing competition. - */ @NotNull @Override public RankingProvider getRanking() { return rankingProvider; } - /** - * Gets the cached placeholders for the fishing competition. - * - * @return A ConcurrentHashMap containing cached placeholders. - */ - @NotNull @Override - public Map getCachedPlaceholders() { - return publicPlaceholders; - } - - /** - * Gets a specific cached placeholder value by its key. - * - * @param papi The key of the cached placeholder. - * @return The cached placeholder value as a string, or null if not found. - */ - @Override - public String getCachedPlaceholder(String papi) { - return publicPlaceholders.get(papi); + public Context getPublicContext() { + return publicContext; } } diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/competition/actionbar/ActionBarManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/competition/actionbar/ActionBarManager.java index 378fe1d2..71cc49be 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/competition/actionbar/ActionBarManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/competition/actionbar/ActionBarManager.java @@ -18,7 +18,7 @@ package net.momirealms.customfishing.bukkit.competition.actionbar; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.mechanic.competition.info.ActionBarConfigImpl; +import net.momirealms.customfishing.api.mechanic.competition.info.ActionBarConfig; import net.momirealms.customfishing.bukkit.competition.Competition; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -35,11 +35,11 @@ import java.util.concurrent.TimeUnit; public class ActionBarManager implements Listener { private static final ConcurrentHashMap senderMap = new ConcurrentHashMap<>(); - private final ActionBarConfigImpl actionBarConfigImpl; + private final ActionBarConfig actionBarConfig; private final Competition competition; - public ActionBarManager(ActionBarConfigImpl actionBarConfigImpl, Competition competition) { - this.actionBarConfigImpl = actionBarConfigImpl; + public ActionBarManager(ActionBarConfig actionBarConfig, Competition competition) { + this.actionBarConfig = actionBarConfig; this.competition = competition; } @@ -47,10 +47,10 @@ public class ActionBarManager implements Listener { * Loads the ActionBar manager, registering events and showing ActionBar messages to online players. */ public void load() { - Bukkit.getPluginManager().registerEvents(this, BukkitCustomFishingPlugin.getInstance()); - if (actionBarConfigImpl.showToAll()) { + Bukkit.getPluginManager().registerEvents(this, BukkitCustomFishingPlugin.getInstance().getBoostrap()); + if (actionBarConfig.showToAll()) { for (Player player : Bukkit.getOnlinePlayers()) { - ActionBarSender sender = new ActionBarSender(player, actionBarConfigImpl, competition); + ActionBarSender sender = new ActionBarSender(player, actionBarConfig, competition); if (!sender.isVisible()) { sender.show(); } @@ -93,11 +93,11 @@ public class ActionBarManager implements Listener { @EventHandler public void onJoin(PlayerJoinEvent event) { final Player player = event.getPlayer(); - BukkitCustomFishingPlugin.getInstance().getScheduler().runTaskAsyncLater(() -> { + BukkitCustomFishingPlugin.getInstance().getScheduler().asyncLater(() -> { boolean hasJoined = competition.hasPlayerJoined(player); - if ((hasJoined || actionBarConfigImpl.showToAll()) + if ((hasJoined || actionBarConfig.showToAll()) && !senderMap.containsKey(player.getUniqueId())) { - ActionBarSender sender = new ActionBarSender(player, actionBarConfigImpl, competition); + ActionBarSender sender = new ActionBarSender(player, actionBarConfig, competition); if (!sender.isVisible()) { sender.show(); } @@ -114,11 +114,10 @@ public class ActionBarManager implements Listener { public void showActionBarTo(Player player) { ActionBarSender sender = senderMap.get(player.getUniqueId()); if (sender == null) { - sender = new ActionBarSender(player, actionBarConfigImpl, competition); + sender = new ActionBarSender(player, actionBarConfig, competition); senderMap.put(player.getUniqueId(), sender); } - if (!sender.isVisible()) { + if (!sender.isVisible()) sender.show(); - } } } 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 c7568af8..c1aa176a 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 @@ -17,73 +17,61 @@ package net.momirealms.customfishing.bukkit.competition.actionbar; +import net.kyori.adventure.audience.Audience; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.mechanic.competition.info.ActionBarConfigImpl; -import net.momirealms.customfishing.api.scheduler.CancellableTask; +import net.momirealms.customfishing.api.mechanic.competition.info.ActionBarConfig; +import net.momirealms.customfishing.api.mechanic.context.Context; +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.mechanic.misc.DynamicText; +import net.momirealms.customfishing.common.helper.AdventureHelper; +import net.momirealms.customfishing.common.locale.StandardLocales; +import net.momirealms.customfishing.common.plugin.scheduler.SchedulerTask; import org.bukkit.entity.Player; -import java.util.HashMap; import java.util.concurrent.TimeUnit; -/** - * Manages and updates ActionBar messages for a specific player in a competition context. - */ public class ActionBarSender { private final Player player; + private final Audience audience; private int refreshTimer; private int switchTimer; private int counter; private final DynamicText[] texts; - private CancellableTask senderTask; - private final ActionBarConfigImpl config; + private SchedulerTask senderTask; + private final ActionBarConfig config; private boolean isShown; private final Competition competition; - private final HashMap privatePlaceholders; + private final Context privateContext; - /** - * Creates a new ActionBarSender instance for a player. - * - * @param player The player to manage ActionBar messages for. - * @param config The configuration for ActionBar messages. - * @param competition The competition associated with this ActionBarSender. - */ - public ActionBarSender(Player player, ActionBarConfigImpl config, Competition competition) { + public ActionBarSender(Player player, ActionBarConfig config, Competition competition) { this.player = player; + this.audience = BukkitCustomFishingPlugin.getInstance().getSenderFactory().getAudience(player); this.config = config; + this.privateContext = Context.player(player); this.isShown = false; this.competition = competition; - this.privatePlaceholders = new HashMap<>(); - this.privatePlaceholders.put("{player}", player.getName()); this.updatePrivatePlaceholders(); - String[] str = config.texts(); texts = new DynamicText[str.length]; for (int i = 0; i < str.length; i++) { texts[i] = new DynamicText(player, str[i]); - texts[i].update(privatePlaceholders); + texts[i].update(privateContext.placeholderMap()); } } - /** - * Updates private placeholders used in ActionBar messages. - */ @SuppressWarnings("DuplicatedCode") private void updatePrivatePlaceholders() { - this.privatePlaceholders.put("{score}", String.format("%.2f", competition.getRanking().getPlayerScore(player.getName()))); + this.privateContext.arg(ContextKeys.SCORE, String.format("%.2f", competition.getRanking().getPlayerScore(player.getName()))); int rank = competition.getRanking().getPlayerRank(player.getName()); - this.privatePlaceholders.put("{rank}", rank != -1 ? String.valueOf(rank) : CFLocale.MSG_No_Rank); - this.privatePlaceholders.putAll(competition.getCachedPlaceholders()); + this.privateContext.arg(ContextKeys.RANK, rank != -1 ? String.valueOf(rank) : StandardLocales.COMPETITION_NO_RANK); + this.privateContext.combine(competition.getPublicContext()); } - /** - * Shows the ActionBar message to the player. - */ public void show() { this.isShown = true; - senderTask = BukkitCustomFishingPlugin.get().getScheduler().runTaskAsyncTimer(() -> { + senderTask = BukkitCustomFishingPlugin.getInstance().getScheduler().asyncRepeating(() -> { switchTimer++; if (switchTimer > config.switchInterval()) { switchTimer = 0; @@ -95,39 +83,23 @@ public class ActionBarSender { refreshTimer = 0; DynamicText text = texts[counter % (texts.length)]; updatePrivatePlaceholders(); - text.update(privatePlaceholders); - AdventureHelper.getInstance().sendActionbar( - player, - text.getLatestValue() - ); + text.update(this.privateContext.placeholderMap()); + audience.sendActionBar(AdventureHelper.miniMessage().deserialize(text.getLatestValue())); } }, 50, 50, TimeUnit.MILLISECONDS); } - /** - * Hides the ActionBar message from the player. - */ public void hide() { - if (senderTask != null && !senderTask.isCancelled()) + if (senderTask != null) senderTask.cancel(); this.isShown = false; } - /** - * Checks if the ActionBar message is currently visible to the player. - * - * @return True if the ActionBar message is visible, false otherwise. - */ public boolean isVisible() { return this.isShown; } - /** - * Gets the ActionBar configuration. - * - * @return The ActionBar configuration. - */ - public ActionBarConfigImpl getConfig() { + public ActionBarConfig getConfig() { return config; } } diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/competition/bossbar/BossBarManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/competition/bossbar/BossBarManager.java index e88c9156..7d26fde5 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/competition/bossbar/BossBarManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/competition/bossbar/BossBarManager.java @@ -18,7 +18,7 @@ package net.momirealms.customfishing.bukkit.competition.bossbar; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.mechanic.competition.info.BossBarConfigImpl; +import net.momirealms.customfishing.api.mechanic.competition.info.BossBarConfig; import net.momirealms.customfishing.bukkit.competition.Competition; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -35,11 +35,11 @@ import java.util.concurrent.TimeUnit; public class BossBarManager implements Listener { private static final ConcurrentHashMap senderMap = new ConcurrentHashMap<>(); - private final BossBarConfigImpl bossBarConfigImpl; + private final BossBarConfig bossBarConfig; private final Competition competition; - public BossBarManager(BossBarConfigImpl bossBarConfigImpl, Competition competition) { - this.bossBarConfigImpl = bossBarConfigImpl; + public BossBarManager(BossBarConfig bossBarConfig, Competition competition) { + this.bossBarConfig = bossBarConfig; this.competition = competition; } @@ -47,10 +47,10 @@ public class BossBarManager implements Listener { * Loads the boss bar manager, registering events and showing boss bars to online players. */ public void load() { - Bukkit.getPluginManager().registerEvents(this, BukkitCustomFishingPlugin.getInstance()); - if (bossBarConfigImpl.showToAll()) { + Bukkit.getPluginManager().registerEvents(this, BukkitCustomFishingPlugin.getInstance().getBoostrap()); + if (bossBarConfig.showToAll()) { for (Player player : Bukkit.getOnlinePlayers()) { - BossBarSender sender = new BossBarSender(player, bossBarConfigImpl, competition); + BossBarSender sender = new BossBarSender(player, bossBarConfig, competition); if (!sender.isVisible()) { sender.show(); } @@ -93,11 +93,11 @@ public class BossBarManager implements Listener { @EventHandler public void onJoin(PlayerJoinEvent event) { final Player player = event.getPlayer(); - BukkitCustomFishingPlugin.getInstance().getScheduler().runTaskAsyncLater(() -> { + BukkitCustomFishingPlugin.getInstance().getScheduler().asyncLater(() -> { boolean hasJoined = competition.hasPlayerJoined(player); - if ((hasJoined || bossBarConfigImpl.showToAll()) + if ((hasJoined || bossBarConfig.showToAll()) && !senderMap.containsKey(player.getUniqueId())) { - BossBarSender sender = new BossBarSender(player, bossBarConfigImpl, competition); + BossBarSender sender = new BossBarSender(player, bossBarConfig, competition); if (!sender.isVisible()) { sender.show(); } @@ -114,11 +114,10 @@ public class BossBarManager implements Listener { public void showBossBarTo(Player player) { BossBarSender sender = senderMap.get(player.getUniqueId()); if (sender == null) { - sender = new BossBarSender(player, bossBarConfigImpl, competition); + sender = new BossBarSender(player, bossBarConfig, competition); senderMap.put(player.getUniqueId(), sender); } - if (!sender.isVisible()) { + if (!sender.isVisible()) sender.show(); - } } } 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 957be254..81d804cf 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 @@ -17,87 +17,72 @@ package net.momirealms.customfishing.bukkit.competition.bossbar; -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.events.InternalStructure; -import com.comphenix.protocol.events.PacketContainer; -import com.comphenix.protocol.wrappers.WrappedChatComponent; -import net.kyori.adventure.text.minimessage.MiniMessage; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.momirealms.customfishing.BukkitCustomFishingPluginImpl; +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.bossbar.BossBar; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.mechanic.competition.info.BossBarConfigImpl; -import net.momirealms.customfishing.api.scheduler.CancellableTask; -import net.momirealms.customfishing.api.util.ReflectionUtils; +import net.momirealms.customfishing.api.mechanic.competition.info.BossBarConfig; +import net.momirealms.customfishing.api.mechanic.context.Context; +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.mechanic.misc.DynamicText; -import org.bukkit.boss.BarColor; +import net.momirealms.customfishing.common.helper.AdventureHelper; +import net.momirealms.customfishing.common.locale.StandardLocales; +import net.momirealms.customfishing.common.plugin.scheduler.SchedulerTask; import org.bukkit.entity.Player; -import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; -import java.util.UUID; +import java.util.Set; import java.util.concurrent.TimeUnit; -/** - * Manages and updates boss bars for a specific player in a competition context. - */ public class BossBarSender { private final Player player; + private final Audience audience; private int refreshTimer; private int switchTimer; private int counter; private final DynamicText[] texts; - private CancellableTask senderTask; - private final UUID uuid; - private final BossBarConfigImpl config; + private SchedulerTask senderTask; + private final BossBar bossBar; + private final BossBarConfig config; private boolean isShown; private final Competition competition; - private final HashMap privatePlaceholders; + private final Context privateContext; - /** - * Creates a new BossBarSender instance for a player. - * - * @param player The player to manage the boss bar for. - * @param config The configuration for the boss bar. - * @param competition The competition associated with this boss bar. - */ - public BossBarSender(Player player, BossBarConfigImpl config, Competition competition) { + public BossBarSender(Player player, BossBarConfig config, Competition competition) { this.player = player; - this.uuid = UUID.randomUUID(); + this.audience = BukkitCustomFishingPlugin.getInstance().getSenderFactory().getAudience(player); this.config = config; this.isShown = false; this.competition = competition; - this.privatePlaceholders = new HashMap<>(); - this.privatePlaceholders.put("{player}", player.getName()); + this.privateContext = Context.player(player); this.updatePrivatePlaceholders(); - String[] str = config.texts(); texts = new DynamicText[str.length]; for (int i = 0; i < str.length; i++) { texts[i] = new DynamicText(player, str[i]); - texts[i].update(privatePlaceholders); + texts[i].update(privateContext.placeholderMap()); } + bossBar = BossBar.bossBar( + AdventureHelper.miniMessage().deserialize(texts[0].getLatestValue()), + competition.getProgress(), + config.color(), + config.overlay(), + Set.of() + ); } - /** - * Updates private placeholders used in boss bar messages. - */ @SuppressWarnings("DuplicatedCode") private void updatePrivatePlaceholders() { - this.privatePlaceholders.put("{score}", String.format("%.2f", competition.getRanking().getPlayerScore(player.getName()))); + this.privateContext.arg(ContextKeys.SCORE, String.format("%.2f", competition.getRanking().getPlayerScore(player.getName()))); int rank = competition.getRanking().getPlayerRank(player.getName()); - this.privatePlaceholders.put("{rank}", rank != -1 ? String.valueOf(rank) : CFLocale.MSG_No_Rank); - this.privatePlaceholders.putAll(competition.getCachedPlaceholders()); + this.privateContext.arg(ContextKeys.RANK, rank != -1 ? String.valueOf(rank) : StandardLocales.COMPETITION_NO_RANK); + this.privateContext.combine(competition.getPublicContext()); } - /** - * Shows the boss bar to the player. - */ public void show() { this.isShown = true; - BukkitCustomFishingPluginImpl.getProtocolManager().sendServerPacket(player, getCreatePacket()); - senderTask = BukkitCustomFishingPlugin.get().getScheduler().runTaskAsyncTimer(() -> { + this.bossBar.addViewer(audience); + this.senderTask = BukkitCustomFishingPlugin.getInstance().getScheduler().asyncRepeating(() -> { switchTimer++; if (switchTimer > config.switchInterval()) { switchTimer = 0; @@ -109,88 +94,25 @@ public class BossBarSender { refreshTimer = 0; DynamicText text = texts[counter % (texts.length)]; updatePrivatePlaceholders(); - if (text.update(privatePlaceholders)) { - BukkitCustomFishingPluginImpl.getProtocolManager().sendServerPacket(player, getUpdatePacket(text)); + if (text.update(privateContext.placeholderMap())) { + bossBar.name(AdventureHelper.miniMessage().deserialize(text.getLatestValue())); } - BukkitCustomFishingPluginImpl.getProtocolManager().sendServerPacket(player, getProgressPacket()); + bossBar.progress(competition.getProgress()); } }, 50, 50, TimeUnit.MILLISECONDS); } - /** - * Checks if the boss bar is currently visible to the player. - * - * @return True if the boss bar is visible, false otherwise. - */ public boolean isVisible() { return this.isShown; } - /** - * Gets the boss bar configuration. - * - * @return The boss bar configuration. - */ - public BossBarConfigImpl getConfig() { + public BossBarConfig getConfig() { return config; } - /** - * Hides the boss bar from the player. - */ public void hide() { - BukkitCustomFishingPluginImpl.getProtocolManager().sendServerPacket(player, getRemovePacket()); - if (senderTask != null && !senderTask.isCancelled()) senderTask.cancel(); + this.bossBar.removeViewer(audience); + if (senderTask != null) senderTask.cancel(); this.isShown = false; } - - private PacketContainer getUpdatePacket(DynamicText text) { - PacketContainer packet = new PacketContainer(PacketType.Play.Server.BOSS); - packet.getModifier().write(0, uuid); - try { - Object chatComponent = ReflectionUtils.iChatComponentMethod.invoke(null, - GsonComponentSerializer.gson().serialize( - AdventureHelper.getInstance().getComponentFromMiniMessage( - text.getLatestValue() - ))); - Object updatePacket = ReflectionUtils.updateConstructor.newInstance(chatComponent); - packet.getModifier().write(1, updatePacket); - } catch (InvocationTargetException | IllegalAccessException | InstantiationException e) { - throw new RuntimeException(e); - } - return packet; - } - - private PacketContainer getProgressPacket() { - PacketContainer packet = new PacketContainer(PacketType.Play.Server.BOSS); - packet.getModifier().write(0, uuid); - try { - Object updatePacket = ReflectionUtils.progressConstructor.newInstance(competition.getProgress()); - packet.getModifier().write(1, updatePacket); - } catch (InvocationTargetException | IllegalAccessException | InstantiationException e) { - throw new RuntimeException(e); - } - return packet; - } - - private PacketContainer getCreatePacket() { - PacketContainer packet = new PacketContainer(PacketType.Play.Server.BOSS); - packet.getModifier().write(0, uuid); - InternalStructure internalStructure = packet.getStructures().read(1); - internalStructure.getChatComponents().write(0, WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize(texts[0].getLatestValue())))); - internalStructure.getFloat().write(0, competition.getProgress()); - internalStructure.getEnumModifier(BarColor.class, 2).write(0, config.getColor()); - internalStructure.getEnumModifier(BossBarConfigImpl.Overlay.class, 3).write(0, config.getOverlay()); - internalStructure.getModifier().write(4, false); - internalStructure.getModifier().write(5, false); - internalStructure.getModifier().write(6, false); - return packet; - } - - private PacketContainer getRemovePacket() { - PacketContainer packet = new PacketContainer(PacketType.Play.Server.BOSS); - packet.getModifier().write(0, uuid); - packet.getModifier().write(1, ReflectionUtils.removeBossBarPacket); - return packet; - } } diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/competition/ranking/LocalRankingProvider.java b/core/src/main/java/net/momirealms/customfishing/bukkit/competition/ranking/LocalRankingProvider.java index 8c60698e..8990a637 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/competition/ranking/LocalRankingProvider.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/competition/ranking/LocalRankingProvider.java @@ -19,6 +19,7 @@ package net.momirealms.customfishing.bukkit.competition.ranking; import net.momirealms.customfishing.api.mechanic.competition.CompetitionPlayer; import net.momirealms.customfishing.api.mechanic.competition.RankingProvider; +import net.momirealms.customfishing.common.util.Pair; import java.util.*; diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/competition/ranking/RedisRankingProvider.java b/core/src/main/java/net/momirealms/customfishing/bukkit/competition/ranking/RedisRankingProvider.java index 1625b00c..e267fdb1 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/competition/ranking/RedisRankingProvider.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/competition/ranking/RedisRankingProvider.java @@ -17,10 +17,11 @@ package net.momirealms.customfishing.bukkit.competition.ranking; -import net.momirealms.customfishing.api.common.Pair; import net.momirealms.customfishing.api.mechanic.competition.CompetitionPlayer; import net.momirealms.customfishing.api.mechanic.competition.RankingProvider; -import net.momirealms.customfishing.storage.method.database.nosql.RedisManager; +import net.momirealms.customfishing.api.mechanic.config.ConfigManager; +import net.momirealms.customfishing.bukkit.storage.method.database.nosql.RedisManager; +import net.momirealms.customfishing.common.util.Pair; import redis.clients.jedis.Jedis; import redis.clients.jedis.resps.Tuple; @@ -35,7 +36,7 @@ public class RedisRankingProvider implements RankingProvider { @Override public void clear() { try (Jedis jedis = RedisManager.getInstance().getJedis()) { - jedis.del("cf_competition_" + CFConfig.serverGroup); + jedis.del("cf_competition_" + ConfigManager.serverGroup()); } } @@ -48,7 +49,7 @@ public class RedisRankingProvider implements RankingProvider { @Override public CompetitionPlayer getCompetitionPlayer(String player) { try (Jedis jedis = RedisManager.getInstance().getJedis()) { - Double score = jedis.zscore("cf_competition_" + CFConfig.serverGroup, player); + Double score = jedis.zscore("cf_competition_" + ConfigManager.serverGroup(), player); if (score == null || score == 0) return null; return new CompetitionPlayer(player, Float.parseFloat(score.toString())); } @@ -57,8 +58,8 @@ public class RedisRankingProvider implements RankingProvider { @Override public CompetitionPlayer getCompetitionPlayer(int rank) { try (Jedis jedis = RedisManager.getInstance().getJedis()) { - List player = jedis.zrevrangeWithScores("cf_competition_" + CFConfig.serverGroup, rank - 1, rank -1); - if (player == null || player.size() == 0) return null; + List player = jedis.zrevrangeWithScores("cf_competition_" + ConfigManager.serverGroup(), rank - 1, rank -1); + if (player == null || player.isEmpty()) return null; return new CompetitionPlayer(player.get(0).getElement(), player.get(0).getScore()); } } @@ -66,14 +67,14 @@ public class RedisRankingProvider implements RankingProvider { @Override public void addPlayer(CompetitionPlayer competitionPlayer) { try (Jedis jedis = RedisManager.getInstance().getJedis()) { - jedis.zincrby("cf_competition_" + CFConfig.serverGroup, competitionPlayer.getScore(), competitionPlayer.getPlayer()); + jedis.zincrby("cf_competition_" + ConfigManager.serverGroup(), competitionPlayer.getScore(), competitionPlayer.getPlayer()); } } @Override public void removePlayer(String player) { try (Jedis jedis = RedisManager.getInstance().getJedis()) { - jedis.zrem("cf_competition_" + CFConfig.serverGroup, player); + jedis.zrem("cf_competition_" + ConfigManager.serverGroup(), player); } } @@ -85,7 +86,7 @@ public class RedisRankingProvider implements RankingProvider { @Override public Iterator> getIterator() { try (Jedis jedis = RedisManager.getInstance().getJedis()) { - List players = jedis.zrevrangeWithScores("cf_competition_" + CFConfig.serverGroup, 0, -1); + List players = jedis.zrevrangeWithScores("cf_competition_" + ConfigManager.serverGroup(), 0, -1); return players.stream().map(it -> Pair.of(it.getElement(), it.getScore())).toList().iterator(); } } @@ -98,7 +99,7 @@ public class RedisRankingProvider implements RankingProvider { @Override public int getSize() { try (Jedis jedis = RedisManager.getInstance().getJedis()) { - long size = jedis.zcard("cf_competition_" + CFConfig.serverGroup); + long size = jedis.zcard("cf_competition_" + ConfigManager.serverGroup()); return (int) size; } } @@ -112,7 +113,7 @@ public class RedisRankingProvider implements RankingProvider { @Override public int getPlayerRank(String player) { try (Jedis jedis = RedisManager.getInstance().getJedis()) { - Long rank = jedis.zrevrank("cf_competition_" + CFConfig.serverGroup, player); + Long rank = jedis.zrevrank("cf_competition_" + ConfigManager.serverGroup(), player); if (rank == null) return -1; return (int) (rank + 1); @@ -128,7 +129,7 @@ public class RedisRankingProvider implements RankingProvider { @Override public double getPlayerScore(String player) { try (Jedis jedis = RedisManager.getInstance().getJedis()) { - Double rank = jedis.zscore("cf_competition_" + CFConfig.serverGroup, player); + Double rank = jedis.zscore("cf_competition_" + ConfigManager.serverGroup(), player); if (rank == null) return 0; return rank.floatValue(); @@ -144,7 +145,7 @@ public class RedisRankingProvider implements RankingProvider { @Override public void refreshData(String player, double score) { try (Jedis jedis = RedisManager.getInstance().getJedis()) { - jedis.zincrby("cf_competition_" + CFConfig.serverGroup, score, player); + jedis.zincrby("cf_competition_" + ConfigManager.serverGroup(), score, player); } } @@ -157,7 +158,7 @@ public class RedisRankingProvider implements RankingProvider { @Override public void setData(String player, double score) { try (Jedis jedis = RedisManager.getInstance().getJedis()) { - jedis.zadd("cf_competition_" + CFConfig.serverGroup, score, player); + jedis.zadd("cf_competition_" + ConfigManager.serverGroup(), score, player); } } @@ -170,8 +171,8 @@ public class RedisRankingProvider implements RankingProvider { @Override public String getPlayerAt(int rank) { try (Jedis jedis = RedisManager.getInstance().getJedis()) { - List player = jedis.zrevrange("cf_competition_" + CFConfig.serverGroup, rank - 1, rank -1); - if (player == null || player.size() == 0) return null; + List player = jedis.zrevrange("cf_competition_" + ConfigManager.serverGroup(), rank - 1, rank -1); + if (player == null || player.isEmpty()) return null; return player.get(0); } } @@ -185,8 +186,8 @@ public class RedisRankingProvider implements RankingProvider { @Override public double getScoreAt(int rank) { try (Jedis jedis = RedisManager.getInstance().getJedis()) { - List players = jedis.zrevrangeWithScores("cf_competition_" + CFConfig.serverGroup, rank - 1, rank -1); - if (players == null || players.size() == 0) return 0; + List players = jedis.zrevrangeWithScores("cf_competition_" + ConfigManager.serverGroup(), rank - 1, rank -1); + if (players == null || players.isEmpty()) return 0; return players.get(0).getScore(); } } diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/effect/EffectManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/bukkit/effect/BukkitEffectManager.java similarity index 98% rename from core/src/main/java/net/momirealms/customfishing/mechanic/effect/EffectManagerImpl.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/effect/BukkitEffectManager.java index cc6bfd63..be2667fd 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/effect/EffectManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/effect/BukkitEffectManager.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.mechanic.effect; +package net.momirealms.customfishing.bukkit.effect; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.common.Key; @@ -24,7 +24,7 @@ import net.momirealms.customfishing.api.mechanic.effect.LootBaseEffectImpl; import net.momirealms.customfishing.api.mechanic.misc.value.MathValue; import net.momirealms.customfishing.api.mechanic.requirement.Requirement; import net.momirealms.customfishing.mechanic.misc.value.PlainMathValue; -import net.momirealms.customfishing.util.ConfigUtils; +import net.momirealms.customfishing.bukkit.util.ConfigUtils; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import org.jetbrains.annotations.NotNull; @@ -33,13 +33,13 @@ import org.jetbrains.annotations.Nullable; import java.io.File; import java.util.*; -public class EffectManagerImpl implements EffectManager { +public class BukkitEffectManager implements EffectManager { private final BukkitCustomFishingPlugin plugin; private final HashMap effectMap; - public EffectManagerImpl(BukkitCustomFishingPlugin plugin) { + public BukkitEffectManager(BukkitCustomFishingPlugin plugin) { this.plugin = plugin; this.effectMap = new HashMap<>(); } diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/entity/EntityManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/bukkit/entity/BukkitEntityManager.java similarity index 97% rename from core/src/main/java/net/momirealms/customfishing/mechanic/entity/EntityManagerImpl.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/entity/BukkitEntityManager.java index 99232e26..00e744fd 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/entity/EntityManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/entity/BukkitEntityManager.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.mechanic.entity; +package net.momirealms.customfishing.bukkit.entity; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.integration.EntityProvider; @@ -32,13 +32,13 @@ import org.bukkit.util.Vector; import java.io.File; import java.util.*; -public class EntityManagerImpl implements EntityManager { +public class BukkitEntityManager implements EntityManager { private final BukkitCustomFishingPlugin plugin; private final HashMap entityLibraryMap; private final HashMap entityConfigMap; - public EntityManagerImpl(BukkitCustomFishingPlugin plugin) { + public BukkitEntityManager(BukkitCustomFishingPlugin plugin) { this.plugin = plugin; this.entityLibraryMap = new HashMap<>(); this.entityConfigMap = new HashMap<>(); diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/BaitAnimationTask.java b/core/src/main/java/net/momirealms/customfishing/bukkit/fishing/BaitAnimationTask.java similarity index 94% rename from core/src/main/java/net/momirealms/customfishing/mechanic/fishing/BaitAnimationTask.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/fishing/BaitAnimationTask.java index 339861ba..736c1da6 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/BaitAnimationTask.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/fishing/BaitAnimationTask.java @@ -15,12 +15,12 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.mechanic.fishing; +package net.momirealms.customfishing.bukkit.fishing; -import net.momirealms.customfishing.BukkitCustomFishingPluginImpl; +import net.momirealms.customfishing.bukkit.BukkitCustomFishingPluginImpl; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.scheduler.CancellableTask; -import net.momirealms.customfishing.util.FakeItemUtils; +import net.momirealms.customfishing.bukkit.util.FakeItemUtils; import org.bukkit.entity.FishHook; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/FishingManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/bukkit/fishing/BukkitFishingManager.java similarity index 98% rename from core/src/main/java/net/momirealms/customfishing/mechanic/fishing/FishingManagerImpl.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/fishing/BukkitFishingManager.java index 75c4f423..2016da5d 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/FishingManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/fishing/BukkitFishingManager.java @@ -15,14 +15,14 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.mechanic.fishing; +package net.momirealms.customfishing.bukkit.fishing; import com.destroystokyo.paper.event.player.PlayerJumpEvent; import de.tr7zw.changeme.nbtapi.NBTCompound; import de.tr7zw.changeme.nbtapi.NBTItem; import net.kyori.adventure.key.Key; import net.kyori.adventure.sound.Sound; -import net.momirealms.customfishing.BukkitCustomFishingPluginImpl; +import net.momirealms.customfishing.bukkit.BukkitCustomFishingPluginImpl; import net.momirealms.customfishing.api.common.Pair; import net.momirealms.customfishing.api.event.FishingResultEvent; import net.momirealms.customfishing.api.event.LavaFishingEvent; @@ -39,8 +39,7 @@ 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.WeightUtils; -import net.momirealms.customfishing.mechanic.requirement.RequirementManagerImpl; -import net.momirealms.customfishing.util.ItemUtils; +import net.momirealms.customfishing.bukkit.util.ItemUtils; import org.bukkit.*; import org.bukkit.entity.*; import org.bukkit.event.EventHandler; @@ -60,7 +59,7 @@ import java.util.Optional; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -public class FishingManagerImpl implements Listener, FishingManager { +public class BukkitFishingManager implements Listener, FishingManager { private final BukkitCustomFishingPluginImpl plugin; private final ConcurrentHashMap hookCacheMap; @@ -69,7 +68,7 @@ public class FishingManagerImpl implements Listener, FishingManager { private final ConcurrentHashMap gamingPlayerMap; private final ConcurrentHashMap> vanillaLootMap; - public FishingManagerImpl(BukkitCustomFishingPluginImpl plugin) { + public BukkitFishingManager(BukkitCustomFishingPluginImpl plugin) { this.plugin = plugin; this.hookCacheMap = new ConcurrentHashMap<>(); this.tempFishingStateMap = new ConcurrentHashMap<>(); @@ -803,8 +802,8 @@ public class FishingManagerImpl implements Listener, FishingManager { */ @Override public boolean startFishingGame(Player player, GameSettings settings, GameInstance gameInstance) { - plugin.debug("Difficulty:" + settings.getDifficulty()); - plugin.debug("Time:" + settings.getTime()); + plugin.debug("Difficulty:" + settings.difficulty()); + plugin.debug("Time:" + settings.time()); FishHook hook = getHook(player.getUniqueId()); if (hook != null) { this.gamingPlayerMap.put(player.getUniqueId(), gameInstance.start(player, hook, settings)); diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/FishingPreparationImpl.java b/core/src/main/java/net/momirealms/customfishing/bukkit/fishing/FishingPreparationImpl.java similarity index 99% rename from core/src/main/java/net/momirealms/customfishing/mechanic/fishing/FishingPreparationImpl.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/fishing/FishingPreparationImpl.java index 906c892c..c8f079c8 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/FishingPreparationImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/fishing/FishingPreparationImpl.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.mechanic.fishing; +package net.momirealms.customfishing.bukkit.fishing; import de.tr7zw.changeme.nbtapi.NBTCompound; import de.tr7zw.changeme.nbtapi.NBTItem; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/HookCheckTimerTask.java b/core/src/main/java/net/momirealms/customfishing/bukkit/fishing/HookCheckTimerTask.java similarity index 98% rename from core/src/main/java/net/momirealms/customfishing/mechanic/fishing/HookCheckTimerTask.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/fishing/HookCheckTimerTask.java index 4c73310a..1169e5b7 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/HookCheckTimerTask.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/fishing/HookCheckTimerTask.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.mechanic.fishing; +package net.momirealms.customfishing.bukkit.fishing; import net.kyori.adventure.key.Key; import net.kyori.adventure.sound.Sound; @@ -46,7 +46,7 @@ import java.util.concurrent.TimeUnit; */ public class HookCheckTimerTask implements Runnable { - private final FishingManagerImpl manager; + private final BukkitFishingManager manager; private final CancellableTask hookMovementTask; private LavaEffectTask lavaFishingTask; private final FishHook fishHook; @@ -71,7 +71,7 @@ public class HookCheckTimerTask implements Runnable { * @param initialEffect The initial fishing effect. */ public HookCheckTimerTask( - FishingManagerImpl manager, + BukkitFishingManager manager, FishHook fishHook, FishingPreparation fishingPreparation, FishingEffect initialEffect diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/LavaEffectTask.java b/core/src/main/java/net/momirealms/customfishing/bukkit/fishing/LavaEffectTask.java similarity index 98% rename from core/src/main/java/net/momirealms/customfishing/mechanic/fishing/LavaEffectTask.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/fishing/LavaEffectTask.java index c80de8a3..cc73ccbb 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/LavaEffectTask.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/fishing/LavaEffectTask.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.mechanic.fishing; +package net.momirealms.customfishing.bukkit.fishing; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.scheduler.CancellableTask; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/game/GameManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/bukkit/game/BukkitGameManager.java similarity index 97% rename from core/src/main/java/net/momirealms/customfishing/mechanic/game/GameManagerImpl.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/game/BukkitGameManager.java index 225e7a0b..913df568 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/game/GameManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/game/BukkitGameManager.java @@ -15,15 +15,14 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.mechanic.game; +package net.momirealms.customfishing.bukkit.game; import net.kyori.adventure.key.Key; import net.kyori.adventure.sound.Sound; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.mechanic.game.*; import net.momirealms.customfishing.common.util.Pair; -import net.momirealms.customfishing.mechanic.requirement.RequirementManagerImpl; -import net.momirealms.customfishing.util.ConfigUtils; +import net.momirealms.customfishing.bukkit.util.ConfigUtils; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import org.jetbrains.annotations.Nullable; @@ -36,14 +35,14 @@ import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; @SuppressWarnings("DuplicatedCode") -public class GameManagerImpl implements GameManager { +public class BukkitGameManager implements GameManager { private final BukkitCustomFishingPlugin plugin; private final HashMap gameCreatorMap; private final HashMap> gameInstanceMap; private final String EXPANSION_FOLDER = "expansions/minigame"; - public GameManagerImpl(BukkitCustomFishingPlugin plugin) { + public BukkitGameManager(BukkitCustomFishingPlugin plugin) { this.plugin = plugin; this.gameCreatorMap = new HashMap<>(); this.gameInstanceMap = new HashMap<>(); @@ -223,7 +222,7 @@ public class GameManagerImpl implements GameManager { @Override public void arrangeTask() { - var period = ((double) 10*(200-settings.getDifficulty()))/((double) (1+4*settings.getDifficulty())); + var period = ((double) 10*(200-settings.difficulty()))/((double) (1+4*settings.difficulty())); this.task = BukkitCustomFishingPlugin.get().getScheduler().runTaskAsyncTimer( this, 50, @@ -310,11 +309,11 @@ public class GameManagerImpl implements GameManager { public void onTick() { if (player.isSneaking()) addV(); else reduceV(); - if (timer < 40 - (settings.getDifficulty() / 10)) { + if (timer < 40 - (settings.difficulty() / 10)) { timer++; } else { timer = 0; - if (Math.random() > ((double) 25 / (settings.getDifficulty() + 100))) { + if (Math.random() > ((double) 25 / (settings.difficulty() + 100))) { burst(); } } @@ -338,9 +337,9 @@ public class GameManagerImpl implements GameManager { private void burst() { if (Math.random() < (judgement_position / barEffectiveWidth)) { - judgement_velocity = -1 - 0.8 * Math.random() * ((double) settings.getDifficulty() / 15); + judgement_velocity = -1 - 0.8 * Math.random() * ((double) settings.difficulty() / 15); } else { - judgement_velocity = 1 + 0.8 * Math.random() * ((double) settings.getDifficulty() / 15); + judgement_velocity = 1 + 0.8 * Math.random() * ((double) settings.difficulty() / 15); } } @@ -439,8 +438,8 @@ public class GameManagerImpl implements GameManager { @Override public void onTick() { if (struggling_time <= 0) { - if (Math.random() < ((double) settings.getDifficulty() / 4000)) { - struggling_time = (int) (10 + Math.random() * (settings.getDifficulty() / 4)); + if (Math.random() < ((double) settings.difficulty() / 4000)) { + struggling_time = (int) (10 + Math.random() * (settings.difficulty() / 4)); } } else { struggling_time--; @@ -463,7 +462,7 @@ public class GameManagerImpl implements GameManager { public void pull() { played = true; if (struggling_time > 0) { - strain += (strugglingIncrease + ((double) settings.getDifficulty() / 50)); + strain += (strugglingIncrease + ((double) settings.difficulty() / 50)); fish_position -= 1; } else { strain += normalIncrease; @@ -535,7 +534,7 @@ public class GameManagerImpl implements GameManager { @Override public void arrangeTask() { - requiredTimes = settings.getDifficulty() / 4; + requiredTimes = settings.difficulty() / 4; order = new int[requiredTimes]; for (int i = 0; i < requiredTimes; i++) { order[i] = ThreadLocalRandom.current().nextInt(0, easy ? 2 : 4); @@ -788,7 +787,7 @@ public class GameManagerImpl implements GameManager { return (player, fishHook, settings) -> new AbstractGamingPlayer(player, fishHook, settings) { private int clickedTimes; - private final int requiredTimes = settings.getDifficulty(); + private final int requiredTimes = settings.difficulty(); private boolean preventFirst = true; @Override @@ -878,7 +877,7 @@ public class GameManagerImpl implements GameManager { @Override public void onTick() { timer++; - if (timer % (21 - settings.getDifficulty() / 5) == 0) { + if (timer % (21 - settings.difficulty() / 5) == 0) { movePointer(); } showUI(); @@ -955,7 +954,7 @@ public class GameManagerImpl implements GameManager { @Override public void arrangeTask() { - var period = ((double) 10*(200-settings.getDifficulty()))/((double) (1+4*settings.getDifficulty())); + var period = ((double) 10*(200-settings.difficulty()))/((double) (1+4*settings.difficulty())); this.task = BukkitCustomFishingPlugin.get().getScheduler().runTaskAsyncTimer( this, 50, @@ -1053,11 +1052,11 @@ public class GameManagerImpl implements GameManager { @Override public void onTick() { - if (timer < 40 - (settings.getDifficulty() / 10)) { + if (timer < 40 - (settings.difficulty() / 10)) { timer++; } else { timer = 0; - if (Math.random() > ((double) 25 / (settings.getDifficulty() + 100))) { + if (Math.random() > ((double) 25 / (settings.difficulty() + 100))) { burst(); } } @@ -1081,9 +1080,9 @@ public class GameManagerImpl implements GameManager { private void burst() { if (Math.random() < (judgement_position / barEffectiveWidth)) { - judgement_velocity = -1 - 0.8 * Math.random() * ((double) settings.getDifficulty() / 15); + judgement_velocity = -1 - 0.8 * Math.random() * ((double) settings.difficulty() / 15); } else { - judgement_velocity = 1 + 0.8 * Math.random() * ((double) settings.getDifficulty() / 15); + judgement_velocity = 1 + 0.8 * Math.random() * ((double) settings.difficulty() / 15); } } diff --git a/core/src/main/java/net/momirealms/customfishing/gui/Icon.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/Icon.java similarity index 93% rename from core/src/main/java/net/momirealms/customfishing/gui/Icon.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/Icon.java index 7124f185..a9626e38 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/Icon.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/Icon.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui; +package net.momirealms.customfishing.bukkit.gui; public interface Icon { } diff --git a/core/src/main/java/net/momirealms/customfishing/gui/ParentPage.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/ParentPage.java similarity index 88% rename from core/src/main/java/net/momirealms/customfishing/gui/ParentPage.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/ParentPage.java index 55ac592d..4464473d 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/ParentPage.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/ParentPage.java @@ -15,9 +15,9 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui; +package net.momirealms.customfishing.bukkit.gui; -import net.momirealms.customfishing.gui.icon.BackToPageItem; +import net.momirealms.customfishing.bukkit.gui.icon.BackToPageItem; import xyz.xenondevs.invui.item.Item; public interface ParentPage { diff --git a/core/src/main/java/net/momirealms/customfishing/gui/SectionPage.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/SectionPage.java similarity index 94% rename from core/src/main/java/net/momirealms/customfishing/gui/SectionPage.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/SectionPage.java index 9ea86ecf..f2c6f71c 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/SectionPage.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/SectionPage.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui; +package net.momirealms.customfishing.bukkit.gui; import org.bukkit.configuration.ConfigurationSection; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/YamlPage.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/YamlPage.java similarity index 93% rename from core/src/main/java/net/momirealms/customfishing/gui/YamlPage.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/YamlPage.java index 53e7deba..76d3490d 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/YamlPage.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/YamlPage.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui; +package net.momirealms.customfishing.bukkit.gui; public interface YamlPage extends ParentPage { diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/BackGroundItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/BackGroundItem.java similarity index 92% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/BackGroundItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/BackGroundItem.java index 057c68a5..1c9fe237 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/BackGroundItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/BackGroundItem.java @@ -15,9 +15,9 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon; +package net.momirealms.customfishing.bukkit.gui.icon; -import net.momirealms.customfishing.gui.Icon; +import net.momirealms.customfishing.bukkit.gui.Icon; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/BackToFolderItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/BackToFolderItem.java similarity index 93% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/BackToFolderItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/BackToFolderItem.java index 6d15c914..5b702f00 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/BackToFolderItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/BackToFolderItem.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon; +package net.momirealms.customfishing.bukkit.gui.icon; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.Icon; -import net.momirealms.customfishing.gui.page.file.FileSelector; +import net.momirealms.customfishing.bukkit.gui.Icon; +import net.momirealms.customfishing.bukkit.gui.page.file.FileSelector; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/BackToPageItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/BackToPageItem.java similarity index 94% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/BackToPageItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/BackToPageItem.java index 484cfeee..519c7a52 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/BackToPageItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/BackToPageItem.java @@ -15,10 +15,10 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon; +package net.momirealms.customfishing.bukkit.gui.icon; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.ParentPage; +import net.momirealms.customfishing.bukkit.gui.ParentPage; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/NextPageItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/NextPageItem.java similarity index 94% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/NextPageItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/NextPageItem.java index 7c3b3eb8..51d1cbc3 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/NextPageItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/NextPageItem.java @@ -15,10 +15,10 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon; +package net.momirealms.customfishing.bukkit.gui.icon; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.Icon; +import net.momirealms.customfishing.bukkit.gui.Icon; import org.bukkit.Material; import xyz.xenondevs.invui.gui.PagedGui; import xyz.xenondevs.invui.item.ItemProvider; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/PreviousPageItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/PreviousPageItem.java similarity index 94% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/PreviousPageItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/PreviousPageItem.java index ca81b9b1..a26925db 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/PreviousPageItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/PreviousPageItem.java @@ -15,10 +15,10 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon; +package net.momirealms.customfishing.bukkit.gui.icon; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.Icon; +import net.momirealms.customfishing.bukkit.gui.Icon; import org.bukkit.Material; import xyz.xenondevs.invui.gui.PagedGui; import xyz.xenondevs.invui.item.ItemProvider; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/ScrollDownItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/ScrollDownItem.java similarity index 94% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/ScrollDownItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/ScrollDownItem.java index 5688795c..3561f12f 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/ScrollDownItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/ScrollDownItem.java @@ -15,10 +15,10 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon; +package net.momirealms.customfishing.bukkit.gui.icon; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.Icon; +import net.momirealms.customfishing.bukkit.gui.Icon; import org.bukkit.Material; import xyz.xenondevs.invui.gui.ScrollGui; import xyz.xenondevs.invui.item.ItemProvider; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/ScrollUpItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/ScrollUpItem.java similarity index 94% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/ScrollUpItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/ScrollUpItem.java index 31eaf903..c65fc046 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/ScrollUpItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/ScrollUpItem.java @@ -15,10 +15,10 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon; +package net.momirealms.customfishing.bukkit.gui.icon; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.Icon; +import net.momirealms.customfishing.bukkit.gui.Icon; import org.bukkit.Material; import xyz.xenondevs.invui.gui.ScrollGui; import xyz.xenondevs.invui.item.ItemProvider; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/AmountItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/AmountItem.java similarity index 93% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/AmountItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/AmountItem.java index b2ab90e6..83e09882 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/AmountItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/AmountItem.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon.property.item; +package net.momirealms.customfishing.bukkit.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.page.property.AmountEditor; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.page.property.AmountEditor; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/CMDItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/CMDItem.java similarity index 93% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/CMDItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/CMDItem.java index 99f5a5d6..d8018fff 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/CMDItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/CMDItem.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon.property.item; +package net.momirealms.customfishing.bukkit.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.page.property.CustomModelDataEditor; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.page.property.CustomModelDataEditor; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/DisplayNameItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/DisplayNameItem.java similarity index 93% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/DisplayNameItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/DisplayNameItem.java index a0426d10..e15b73b4 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/DisplayNameItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/DisplayNameItem.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon.property.item; +package net.momirealms.customfishing.bukkit.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.page.property.DisplayNameEditor; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.page.property.DisplayNameEditor; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/DurabilityItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/DurabilityItem.java similarity index 93% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/DurabilityItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/DurabilityItem.java index 344b4d50..d81ebe05 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/DurabilityItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/DurabilityItem.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon.property.item; +package net.momirealms.customfishing.bukkit.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.page.property.DurabilityEditor; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.page.property.DurabilityEditor; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/EnchantmentItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/EnchantmentItem.java similarity index 94% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/EnchantmentItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/EnchantmentItem.java index 8ff0a1e5..9d00893d 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/EnchantmentItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/EnchantmentItem.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon.property.item; +package net.momirealms.customfishing.bukkit.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.page.property.EnchantmentEditor; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.page.property.EnchantmentEditor; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/Head64Item.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/Head64Item.java similarity index 95% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/Head64Item.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/Head64Item.java index a386281b..cdcb9468 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/Head64Item.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/Head64Item.java @@ -15,12 +15,12 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon.property.item; +package net.momirealms.customfishing.bukkit.gui.icon.property.item; -import net.momirealms.customfishing.BukkitCustomFishingPluginImpl; +import net.momirealms.customfishing.bukkit.BukkitCustomFishingPluginImpl; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.SectionPage; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/ItemFlagItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/ItemFlagItem.java similarity index 94% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/ItemFlagItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/ItemFlagItem.java index 712730af..e1803358 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/ItemFlagItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/ItemFlagItem.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon.property.item; +package net.momirealms.customfishing.bukkit.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.page.property.ItemFlagEditor; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.page.property.ItemFlagEditor; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/LoreItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/LoreItem.java similarity index 94% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/LoreItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/LoreItem.java index 7d4b6838..97df64aa 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/LoreItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/LoreItem.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon.property.item; +package net.momirealms.customfishing.bukkit.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.page.property.LoreEditor; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.page.property.LoreEditor; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/MaterialItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/MaterialItem.java similarity index 93% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/MaterialItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/MaterialItem.java index 3f45729c..8ed023f1 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/MaterialItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/MaterialItem.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon.property.item; +package net.momirealms.customfishing.bukkit.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.page.property.MaterialEditor; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.page.property.MaterialEditor; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/NBTItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/NBTItem.java similarity index 92% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/NBTItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/NBTItem.java index c1a9d86d..d128f30f 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/NBTItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/NBTItem.java @@ -15,12 +15,12 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon.property.item; +package net.momirealms.customfishing.bukkit.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.page.property.NBTEditor; -import net.momirealms.customfishing.util.ConfigUtils; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.page.property.NBTEditor; +import net.momirealms.customfishing.bukkit.util.ConfigUtils; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/PreventGrabItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/PreventGrabItem.java similarity index 95% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/PreventGrabItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/PreventGrabItem.java index e89ffec8..2f40b610 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/PreventGrabItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/PreventGrabItem.java @@ -15,10 +15,10 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon.property.item; +package net.momirealms.customfishing.bukkit.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.SectionPage; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/PriceItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/PriceItem.java similarity index 94% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/PriceItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/PriceItem.java index 8a22266c..5144ec95 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/PriceItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/PriceItem.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon.property.item; +package net.momirealms.customfishing.bukkit.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.page.property.PriceEditor; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.page.property.PriceEditor; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/RandomDurabilityItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/RandomDurabilityItem.java similarity index 95% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/RandomDurabilityItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/RandomDurabilityItem.java index 4ba2dcc9..688dad5c 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/RandomDurabilityItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/RandomDurabilityItem.java @@ -15,10 +15,10 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon.property.item; +package net.momirealms.customfishing.bukkit.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.SectionPage; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/SizeItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/SizeItem.java similarity index 93% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/SizeItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/SizeItem.java index cd2490fc..4abd29a0 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/SizeItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/SizeItem.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon.property.item; +package net.momirealms.customfishing.bukkit.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.page.property.SizeEditor; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.page.property.SizeEditor; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/StackableItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/StackableItem.java similarity index 95% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/StackableItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/StackableItem.java index 7f752e22..0170cde2 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/StackableItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/StackableItem.java @@ -15,10 +15,10 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon.property.item; +package net.momirealms.customfishing.bukkit.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.SectionPage; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/StoredEnchantmentItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/StoredEnchantmentItem.java similarity index 94% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/StoredEnchantmentItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/StoredEnchantmentItem.java index bcf77c38..b1a47e5e 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/StoredEnchantmentItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/StoredEnchantmentItem.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon.property.item; +package net.momirealms.customfishing.bukkit.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.page.property.EnchantmentEditor; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.page.property.EnchantmentEditor; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/TagItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/TagItem.java similarity index 94% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/TagItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/TagItem.java index 33494e6b..8dddc53a 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/TagItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/TagItem.java @@ -15,10 +15,10 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon.property.item; +package net.momirealms.customfishing.bukkit.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.SectionPage; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/UnbreakableItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/UnbreakableItem.java similarity index 95% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/UnbreakableItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/UnbreakableItem.java index fa9b664a..5705f84f 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/item/UnbreakableItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/item/UnbreakableItem.java @@ -15,10 +15,10 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon.property.item; +package net.momirealms.customfishing.bukkit.gui.icon.property.item; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.SectionPage; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/DisableGameItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/DisableGameItem.java similarity index 95% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/DisableGameItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/DisableGameItem.java index 50e50582..d95d0e6a 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/DisableGameItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/DisableGameItem.java @@ -15,10 +15,10 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon.property.loot; +package net.momirealms.customfishing.bukkit.gui.icon.property.loot; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.SectionPage; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/DisableStatsItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/DisableStatsItem.java similarity index 95% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/DisableStatsItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/DisableStatsItem.java index 1afd900c..e2725c2b 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/DisableStatsItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/DisableStatsItem.java @@ -15,10 +15,10 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon.property.loot; +package net.momirealms.customfishing.bukkit.gui.icon.property.loot; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.SectionPage; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/InstantGameItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/InstantGameItem.java similarity index 95% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/InstantGameItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/InstantGameItem.java index d20702e9..8ed1c68a 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/InstantGameItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/InstantGameItem.java @@ -15,10 +15,10 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon.property.loot; +package net.momirealms.customfishing.bukkit.gui.icon.property.loot; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.SectionPage; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/NickItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/NickItem.java similarity index 93% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/NickItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/NickItem.java index 0bfd0f5b..61bf1850 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/NickItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/NickItem.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon.property.loot; +package net.momirealms.customfishing.bukkit.gui.icon.property.loot; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.page.property.NickEditor; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.page.property.NickEditor; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/ScoreItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/ScoreItem.java similarity index 93% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/ScoreItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/ScoreItem.java index 2b054a5c..124af4b1 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/ScoreItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/ScoreItem.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon.property.loot; +package net.momirealms.customfishing.bukkit.gui.icon.property.loot; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.page.property.ScoreEditor; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.page.property.ScoreEditor; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/ShowInFinderItem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/ShowInFinderItem.java similarity index 95% rename from core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/ShowInFinderItem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/ShowInFinderItem.java index f224bb4f..bf31efb7 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/icon/property/loot/ShowInFinderItem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/icon/property/loot/ShowInFinderItem.java @@ -15,10 +15,10 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.icon.property.loot; +package net.momirealms.customfishing.bukkit.gui.icon.property.loot; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.SectionPage; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/file/FileSelector.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/file/FileSelector.java similarity index 92% rename from core/src/main/java/net/momirealms/customfishing/gui/page/file/FileSelector.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/file/FileSelector.java index 11d77ce2..4f32ae5d 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/file/FileSelector.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/file/FileSelector.java @@ -15,14 +15,14 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.page.file; +package net.momirealms.customfishing.bukkit.gui.page.file; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.icon.BackGroundItem; -import net.momirealms.customfishing.gui.icon.BackToFolderItem; -import net.momirealms.customfishing.gui.icon.ScrollDownItem; -import net.momirealms.customfishing.gui.icon.ScrollUpItem; -import net.momirealms.customfishing.gui.page.item.ItemSelector; +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 org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/item/AbstractSectionEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/AbstractSectionEditor.java similarity index 91% rename from core/src/main/java/net/momirealms/customfishing/gui/page/item/AbstractSectionEditor.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/AbstractSectionEditor.java index 11df942e..61a8eeae 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/item/AbstractSectionEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/AbstractSectionEditor.java @@ -15,15 +15,15 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.page.item; +package net.momirealms.customfishing.bukkit.gui.page.item; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.icon.BackGroundItem; -import net.momirealms.customfishing.gui.icon.BackToPageItem; -import net.momirealms.customfishing.gui.icon.NextPageItem; -import net.momirealms.customfishing.gui.icon.PreviousPageItem; +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 org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/item/BaitEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/BaitEditor.java similarity index 93% rename from core/src/main/java/net/momirealms/customfishing/gui/page/item/BaitEditor.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/BaitEditor.java index 57295a35..4586ef56 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/item/BaitEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/BaitEditor.java @@ -15,9 +15,9 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.page.item; +package net.momirealms.customfishing.bukkit.gui.page.item; -import net.momirealms.customfishing.gui.icon.property.item.*; +import net.momirealms.customfishing.bukkit.gui.icon.property.item.*; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import xyz.xenondevs.invui.item.Item; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/item/HookEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/HookEditor.java similarity index 93% rename from core/src/main/java/net/momirealms/customfishing/gui/page/item/HookEditor.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/HookEditor.java index 1ac8e4a6..fdb8de02 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/item/HookEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/HookEditor.java @@ -15,9 +15,9 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.page.item; +package net.momirealms.customfishing.bukkit.gui.page.item; -import net.momirealms.customfishing.gui.icon.property.item.*; +import net.momirealms.customfishing.bukkit.gui.icon.property.item.*; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import xyz.xenondevs.invui.item.Item; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/item/ItemSelector.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/ItemSelector.java similarity index 96% rename from core/src/main/java/net/momirealms/customfishing/gui/page/item/ItemSelector.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/ItemSelector.java index 84860d56..d125ce7c 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/item/ItemSelector.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/ItemSelector.java @@ -15,16 +15,16 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.page.item; +package net.momirealms.customfishing.bukkit.gui.page.item; import com.saicone.rtag.RtagItem; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.YamlPage; -import net.momirealms.customfishing.gui.icon.BackGroundItem; -import net.momirealms.customfishing.gui.icon.BackToFolderItem; -import net.momirealms.customfishing.gui.icon.NextPageItem; -import net.momirealms.customfishing.gui.icon.PreviousPageItem; +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 org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/item/RodEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/RodEditor.java similarity index 93% rename from core/src/main/java/net/momirealms/customfishing/gui/page/item/RodEditor.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/RodEditor.java index b6d35262..4864e89d 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/item/RodEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/RodEditor.java @@ -15,9 +15,9 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.page.item; +package net.momirealms.customfishing.bukkit.gui.page.item; -import net.momirealms.customfishing.gui.icon.property.item.*; +import net.momirealms.customfishing.bukkit.gui.icon.property.item.*; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import xyz.xenondevs.invui.item.Item; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/item/SectionEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/SectionEditor.java similarity index 92% rename from core/src/main/java/net/momirealms/customfishing/gui/page/item/SectionEditor.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/SectionEditor.java index 1b314394..9a0d3753 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/item/SectionEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/item/SectionEditor.java @@ -15,10 +15,10 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.page.item; +package net.momirealms.customfishing.bukkit.gui.page.item; -import net.momirealms.customfishing.gui.icon.property.item.*; -import net.momirealms.customfishing.gui.icon.property.loot.*; +import net.momirealms.customfishing.bukkit.gui.icon.property.item.*; +import net.momirealms.customfishing.bukkit.gui.icon.property.loot.*; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import xyz.xenondevs.invui.item.Item; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/property/AmountEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/AmountEditor.java similarity index 96% rename from core/src/main/java/net/momirealms/customfishing/gui/page/property/AmountEditor.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/AmountEditor.java index c305f515..2a649f74 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/property/AmountEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/AmountEditor.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.page.property; +package net.momirealms.customfishing.bukkit.gui.page.property; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.icon.BackGroundItem; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/property/CustomModelDataEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/CustomModelDataEditor.java similarity index 97% rename from core/src/main/java/net/momirealms/customfishing/gui/page/property/CustomModelDataEditor.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/CustomModelDataEditor.java index 3e98966a..c687a84d 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/property/CustomModelDataEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/CustomModelDataEditor.java @@ -15,12 +15,12 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.page.property; +package net.momirealms.customfishing.bukkit.gui.page.property; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.icon.BackGroundItem; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/property/DisplayNameEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/DisplayNameEditor.java similarity index 95% rename from core/src/main/java/net/momirealms/customfishing/gui/page/property/DisplayNameEditor.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/DisplayNameEditor.java index 1633da0d..52b3975f 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/property/DisplayNameEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/DisplayNameEditor.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.page.property; +package net.momirealms.customfishing.bukkit.gui.page.property; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.icon.BackGroundItem; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/property/DurabilityEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/DurabilityEditor.java similarity index 96% rename from core/src/main/java/net/momirealms/customfishing/gui/page/property/DurabilityEditor.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/DurabilityEditor.java index 96df812a..722604a1 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/property/DurabilityEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/DurabilityEditor.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.page.property; +package net.momirealms.customfishing.bukkit.gui.page.property; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.icon.BackGroundItem; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/property/EnchantmentEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/EnchantmentEditor.java similarity index 98% rename from core/src/main/java/net/momirealms/customfishing/gui/page/property/EnchantmentEditor.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/EnchantmentEditor.java index de46f2b1..6b5e2192 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/property/EnchantmentEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/EnchantmentEditor.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.page.property; +package net.momirealms.customfishing.bukkit.gui.page.property; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.icon.BackGroundItem; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/property/ItemFlagEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/ItemFlagEditor.java similarity index 96% rename from core/src/main/java/net/momirealms/customfishing/gui/page/property/ItemFlagEditor.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/ItemFlagEditor.java index bdda389c..ff080345 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/property/ItemFlagEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/ItemFlagEditor.java @@ -15,12 +15,12 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.page.property; +package net.momirealms.customfishing.bukkit.gui.page.property; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.icon.BackGroundItem; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/property/LoreEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/LoreEditor.java similarity index 97% rename from core/src/main/java/net/momirealms/customfishing/gui/page/property/LoreEditor.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/LoreEditor.java index f45e4640..b2d49846 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/property/LoreEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/LoreEditor.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.page.property; +package net.momirealms.customfishing.bukkit.gui.page.property; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.icon.BackGroundItem; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/property/MaterialEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/MaterialEditor.java similarity index 96% rename from core/src/main/java/net/momirealms/customfishing/gui/page/property/MaterialEditor.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/MaterialEditor.java index 2f1d08a9..d1a077db 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/property/MaterialEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/MaterialEditor.java @@ -15,13 +15,13 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.page.property; +package net.momirealms.customfishing.bukkit.gui.page.property; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.icon.BackGroundItem; -import net.momirealms.customfishing.mechanic.item.ItemManagerImpl; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; +import net.momirealms.customfishing.bukkit.item.ItemManagerImpl; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/property/NBTEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/NBTEditor.java similarity index 99% rename from core/src/main/java/net/momirealms/customfishing/gui/page/property/NBTEditor.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/NBTEditor.java index e1bf1986..9bb6aa40 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/property/NBTEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/NBTEditor.java @@ -15,12 +15,12 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.page.property; +package net.momirealms.customfishing.bukkit.gui.page.property; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.icon.BackGroundItem; -import net.momirealms.customfishing.util.ConfigUtils; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; +import net.momirealms.customfishing.bukkit.util.ConfigUtils; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/property/NickEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/NickEditor.java similarity index 95% rename from core/src/main/java/net/momirealms/customfishing/gui/page/property/NickEditor.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/NickEditor.java index 4cce6da3..13ec693f 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/property/NickEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/NickEditor.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.page.property; +package net.momirealms.customfishing.bukkit.gui.page.property; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.icon.BackGroundItem; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/property/PriceEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/PriceEditor.java similarity index 97% rename from core/src/main/java/net/momirealms/customfishing/gui/page/property/PriceEditor.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/PriceEditor.java index 09ecbbe6..99b3b76d 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/property/PriceEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/PriceEditor.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.page.property; +package net.momirealms.customfishing.bukkit.gui.page.property; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.icon.BackGroundItem; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/property/ScoreEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/ScoreEditor.java similarity index 96% rename from core/src/main/java/net/momirealms/customfishing/gui/page/property/ScoreEditor.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/ScoreEditor.java index a0b72d0a..076ef57c 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/property/ScoreEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/ScoreEditor.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.page.property; +package net.momirealms.customfishing.bukkit.gui.page.property; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.icon.BackGroundItem; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/gui/page/property/SizeEditor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/SizeEditor.java similarity index 97% rename from core/src/main/java/net/momirealms/customfishing/gui/page/property/SizeEditor.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/SizeEditor.java index 5d6b4199..1979cbd0 100644 --- a/core/src/main/java/net/momirealms/customfishing/gui/page/property/SizeEditor.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/gui/page/property/SizeEditor.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.gui.page.property; +package net.momirealms.customfishing.bukkit.gui.page.property; import net.momirealms.customfishing.bukkit.adventure.ShadedAdventureComponentWrapper; -import net.momirealms.customfishing.gui.SectionPage; -import net.momirealms.customfishing.gui.icon.BackGroundItem; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.icon.BackGroundItem; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/hook/HookManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/bukkit/hook/BukkitHookManager.java similarity index 97% rename from core/src/main/java/net/momirealms/customfishing/mechanic/hook/HookManagerImpl.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/hook/BukkitHookManager.java index dd86e5e5..ca91e814 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/hook/HookManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/hook/BukkitHookManager.java @@ -15,14 +15,14 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.mechanic.hook; +package net.momirealms.customfishing.bukkit.hook; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.mechanic.hook.HookManager; import net.momirealms.customfishing.api.mechanic.hook.HookSetting; import net.momirealms.customfishing.api.mechanic.requirement.RequirementManager; -import net.momirealms.customfishing.mechanic.item.ItemManagerImpl; -import net.momirealms.customfishing.util.ItemUtils; +import net.momirealms.customfishing.bukkit.item.ItemManagerImpl; +import net.momirealms.customfishing.bukkit.util.ItemUtils; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Material; @@ -40,12 +40,12 @@ import org.jetbrains.annotations.Nullable; import java.io.File; import java.util.*; -public class HookManagerImpl implements Listener, HookManager { +public class BukkitHookManager implements Listener, HookManager { private final BukkitCustomFishingPlugin plugin; private final HashMap hookSettingMap; - public HookManagerImpl(BukkitCustomFishingPlugin plugin) { + public BukkitHookManager(BukkitCustomFishingPlugin plugin) { this.plugin = plugin; this.hookSettingMap = new HashMap<>(); } 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 5e999847..d2e150da 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 @@ -36,12 +36,12 @@ public class BukkitItemManager implements ItemManager { this.itemProviders.put("vanilla", new ItemProvider() { @NotNull @Override - public ItemStack buildItem(Player player, String id) { + public ItemStack buildItem(@NotNull Player player, @NotNull String id) { return new ItemStack(Material.valueOf(id.toUpperCase(Locale.ENGLISH))); } @NotNull @Override - public String itemID(ItemStack itemStack) { + public String itemID(@NotNull ItemStack itemStack) { return itemStack.getType().name(); } @Override diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/item/ItemManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/bukkit/item/ItemManagerImpl.java similarity index 99% rename from core/src/main/java/net/momirealms/customfishing/mechanic/item/ItemManagerImpl.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/item/ItemManagerImpl.java index fd228958..3b42987b 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/item/ItemManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/item/ItemManagerImpl.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.mechanic.item; +package net.momirealms.customfishing.bukkit.item; import com.saicone.rtag.RtagItem; import com.saicone.rtag.tag.TagCompound; @@ -38,9 +38,9 @@ import net.momirealms.customfishing.api.mechanic.misc.placeholder.BukkitPlacehol import net.momirealms.customfishing.api.mechanic.misc.value.MathValue; import net.momirealms.customfishing.api.mechanic.requirement.RequirementManager; import net.momirealms.customfishing.bukkit.compatibility.item.CustomFishingItemProvider; -import net.momirealms.customfishing.util.ConfigUtils; -import net.momirealms.customfishing.util.ItemUtils; -import net.momirealms.customfishing.util.LocationUtils; +import net.momirealms.customfishing.bukkit.util.ConfigUtils; +import net.momirealms.customfishing.bukkit.util.ItemUtils; +import net.momirealms.customfishing.bukkit.util.LocationUtils; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/loot/BukkitLootManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/loot/BukkitLootManager.java similarity index 97% rename from core/src/main/java/net/momirealms/customfishing/mechanic/loot/BukkitLootManager.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/loot/BukkitLootManager.java index 303a486d..d097c7b4 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/loot/BukkitLootManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/loot/BukkitLootManager.java @@ -1,4 +1,4 @@ -package net.momirealms.customfishing.mechanic.loot; +package net.momirealms.customfishing.bukkit.loot; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.mechanic.context.Context; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/loot/LootManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/bukkit/loot/LootManagerImpl.java similarity index 98% rename from core/src/main/java/net/momirealms/customfishing/mechanic/loot/LootManagerImpl.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/loot/LootManagerImpl.java index 05331ee9..81014940 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/loot/LootManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/loot/LootManagerImpl.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.mechanic.loot; +package net.momirealms.customfishing.bukkit.loot; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.common.Pair; @@ -25,8 +25,7 @@ import net.momirealms.customfishing.api.mechanic.loot.LootManager; import net.momirealms.customfishing.api.mechanic.loot.LootType; import net.momirealms.customfishing.api.mechanic.statistic.StatisticsKeys; import net.momirealms.customfishing.api.util.WeightUtils; -import net.momirealms.customfishing.mechanic.requirement.RequirementManagerImpl; -import net.momirealms.customfishing.util.ConfigUtils; +import net.momirealms.customfishing.bukkit.util.ConfigUtils; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/market/MarketManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/bukkit/market/BukkitMarketManager.java similarity index 98% rename from core/src/main/java/net/momirealms/customfishing/mechanic/market/MarketManagerImpl.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/market/BukkitMarketManager.java index 7e170035..c228ba61 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/market/MarketManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/market/BukkitMarketManager.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.mechanic.market; +package net.momirealms.customfishing.bukkit.market; import de.tr7zw.changeme.nbtapi.NBTItem; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; @@ -25,8 +25,8 @@ import net.momirealms.customfishing.api.mechanic.market.MarketManager; import net.momirealms.customfishing.api.mechanic.misc.placeholder.BukkitPlaceholderManager; import net.momirealms.customfishing.api.scheduler.CancellableTask; import net.momirealms.customfishing.api.storage.data.EarningData; -import net.momirealms.customfishing.util.ConfigUtils; -import net.momirealms.customfishing.util.NumberUtils; +import net.momirealms.customfishing.bukkit.util.ConfigUtils; +import net.momirealms.customfishing.bukkit.util.NumberUtils; import net.objecthunter.exp4j.ExpressionBuilder; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -48,7 +48,7 @@ import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; -public class MarketManagerImpl implements MarketManager, Listener { +public class BukkitMarketManager implements MarketManager, Listener { private final BukkitCustomFishingPlugin plugin; private final HashMap priceMap; @@ -79,7 +79,7 @@ public class MarketManagerImpl implements MarketManager, Listener { private CancellableTask resetEarningsTask; private int date; - public MarketManagerImpl(BukkitCustomFishingPlugin plugin) { + public BukkitMarketManager(BukkitCustomFishingPlugin plugin) { this.plugin = plugin; this.priceMap = new HashMap<>(); this.decorativeIcons = new HashMap<>(); diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/market/MarketDynamicGUIElement.java b/core/src/main/java/net/momirealms/customfishing/bukkit/market/MarketDynamicGUIElement.java similarity index 94% rename from core/src/main/java/net/momirealms/customfishing/mechanic/market/MarketDynamicGUIElement.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/market/MarketDynamicGUIElement.java index f64e7556..0b3e4236 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/market/MarketDynamicGUIElement.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/market/MarketDynamicGUIElement.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.mechanic.market; +package net.momirealms.customfishing.bukkit.market; import org.bukkit.inventory.ItemStack; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/market/MarketGUI.java b/core/src/main/java/net/momirealms/customfishing/bukkit/market/MarketGUI.java similarity index 97% rename from core/src/main/java/net/momirealms/customfishing/mechanic/market/MarketGUI.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/market/MarketGUI.java index a9ed6ee9..3ca6d549 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/market/MarketGUI.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/market/MarketGUI.java @@ -15,14 +15,14 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.mechanic.market; +package net.momirealms.customfishing.bukkit.market; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.mechanic.market.MarketGUIHolder; import net.momirealms.customfishing.api.storage.data.EarningData; import net.momirealms.customfishing.api.util.InventoryUtils; -import net.momirealms.customfishing.util.ItemUtils; -import net.momirealms.customfishing.util.NumberUtils; +import net.momirealms.customfishing.bukkit.util.ItemUtils; +import net.momirealms.customfishing.bukkit.util.NumberUtils; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; @@ -39,7 +39,7 @@ public class MarketGUI { // A map that associates slot indices with MarketGUI elements. private final HashMap itemsSlotMap; private final Inventory inventory; - private final MarketManagerImpl manager; + private final BukkitMarketManager manager; private final Player owner; private final EarningData earningData; @@ -50,7 +50,7 @@ public class MarketGUI { * @param player The player who owns this MarketGUI. * @param earningData Data related to earnings for this MarketGUI. */ - public MarketGUI(MarketManagerImpl manager, Player player, EarningData earningData) { + public MarketGUI(BukkitMarketManager manager, Player player, EarningData earningData) { this.manager = manager; this.owner = player; this.earningData = earningData; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/market/MarketGUIElement.java b/core/src/main/java/net/momirealms/customfishing/bukkit/market/MarketGUIElement.java similarity index 96% rename from core/src/main/java/net/momirealms/customfishing/mechanic/market/MarketGUIElement.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/market/MarketGUIElement.java index 774b12cb..6242d211 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/market/MarketGUIElement.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/market/MarketGUIElement.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.mechanic.market; +package net.momirealms.customfishing.bukkit.market; import org.bukkit.inventory.ItemStack; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/misc/ChatCatcherManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/misc/ChatCatcherManager.java similarity index 87% rename from core/src/main/java/net/momirealms/customfishing/mechanic/misc/ChatCatcherManager.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/misc/ChatCatcherManager.java index e1c08073..3a12cfc7 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/misc/ChatCatcherManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/misc/ChatCatcherManager.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.mechanic.misc; +package net.momirealms.customfishing.bukkit.misc; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.common.Pair; -import net.momirealms.customfishing.gui.SectionPage; +import net.momirealms.customfishing.bukkit.gui.SectionPage; +import net.momirealms.customfishing.common.util.Pair; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -65,13 +65,14 @@ public class ChatCatcherManager implements Listener { @EventHandler public void onChat(AsyncPlayerChatEvent event) { - var uuid = event.getPlayer().getUniqueId(); + final Player player = event.getPlayer(); + var uuid = player.getUniqueId(); var pair = pageMap.remove(uuid); if (pair == null) return; event.setCancelled(true); - plugin.getScheduler().runTaskSync(() -> { + plugin.getScheduler().sync().run(() -> { pair.right().getSection().set(pair.left(), event.getMessage()); pair.right().reOpen(); - }, event.getPlayer().getLocation()); + }, player.getLocation()); } } 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 465f1974..585be069 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 @@ -2,16 +2,32 @@ package net.momirealms.customfishing.bukkit.requirement; import dev.dejvokep.boostedyaml.block.implementation.Section; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; +import net.momirealms.customfishing.api.integration.LevelerProvider; +import net.momirealms.customfishing.api.integration.SeasonProvider; import net.momirealms.customfishing.api.mechanic.action.Action; import net.momirealms.customfishing.api.mechanic.action.ActionManager; +import net.momirealms.customfishing.api.mechanic.competition.FishingCompetition; import net.momirealms.customfishing.api.mechanic.context.ContextKeys; import net.momirealms.customfishing.api.mechanic.effect.EffectProperties; +import net.momirealms.customfishing.api.mechanic.loot.Loot; +import net.momirealms.customfishing.api.mechanic.misc.season.Season; +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.*; +import net.momirealms.customfishing.api.util.MoonPhase; +import net.momirealms.customfishing.bukkit.compatibility.VaultHook; import net.momirealms.customfishing.common.util.ClassUtils; import net.momirealms.customfishing.common.util.ListUtils; import net.momirealms.customfishing.common.util.Pair; +import net.momirealms.sparrow.heart.SparrowHeart; import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -112,6 +128,100 @@ public class BukkitRequirementManager implements RequirementManager { this.registerInLavaRequirement(); this.registerAndRequirement(); this.registerOrRequirement(); + this.registerGroupRequirement(); + this.registerRodRequirement(); + this.registerPAPIRequirement(); + this.registerSeasonRequirement(); + this.registerPermissionRequirement(); + this.registerMoonPhaseRequirement(); + this.registerCoolDownRequirement(); + this.registerDateRequirement(); + this.registerWeatherRequirement(); + this.registerBiomeRequirement(); + this.registerWorldRequirement(); + this.registerMoneyRequirement(); + this.registerLevelRequirement(); + this.registerRandomRequirement(); + this.registerIceFishingRequirement(); + this.registerOpenWaterRequirement(); + this.registerBaitRequirement(); + this.registerLootRequirement(); + this.registerSizeRequirement(); + this.registerLootTypeRequirement(); + this.registerHasStatsRequirement(); + this.registerHookRequirement(); + this.registerEnvironmentRequirement(); + this.registerListRequirement(); + this.registerInBagRequirement(); + this.registerCompetitionRequirement(); + this.registerPluginLevelRequirement(); + } + + private void registerCompetitionRequirement() { + registerRequirement("competition", (args, actions, advanced) -> { + if (args instanceof ConfigurationSection section) { + boolean onCompetition = section.getBoolean("ongoing", true); + List ids = ListUtils.toList(section.get("id")); + return context -> { + if (ids.isEmpty()) { + if (plugin.getCompetitionManager().getOnGoingCompetition() != null == onCompetition) { + return true; + } + } else { + FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition(); + if (onCompetition) { + if (competition != null) + if (ids.contains(competition.getConfig().key())) + return true; + } else { + if (competition == null) + return true; + } + } + if (advanced) ActionManager.trigger(context, actions); + return false; + }; + } else { + plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at competition requirement which should be Section"); + return EmptyRequirement.INSTANCE; + } + }); + } + + private void registerInBagRequirement() { + registerRequirement("in-fishingbag", (args, actions, advanced) -> { + 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); + return false; + }; + }); + } + + private void registerPluginLevelRequirement() { + registerRequirement("plugin-level", (args, actions, advanced) -> { + if (args instanceof Section section) { + String pluginName = section.getString("plugin"); + int level = section.getInt("level"); + String target = section.getString("target"); + return context -> { + LevelerProvider levelerProvider = plugin.getIntegrationManager().getLevelerProvider(pluginName); + if (levelerProvider == null) { + plugin.getPluginLogger().warn("Plugin (" + pluginName + "'s) level is not compatible. Please double check if it's a problem caused by pronunciation."); + return true; + } + if (levelerProvider.getLevel(context.getHolder(), target) >= level) + return true; + if (advanced) ActionManager.trigger(context, actions); + return false; + }; + } else { + plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at plugin-level requirement which should be Section"); + return EmptyRequirement.INSTANCE; + } + }); } private void registerTimeRequirement() { @@ -239,6 +349,752 @@ public class BukkitRequirementManager implements RequirementManager { }); } + private void registerRodRequirement() { + registerRequirement("rod", (args, actions, advanced) -> { + 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); + return false; + }; + }); + registerRequirement("!rod", (args, actions, advanced) -> { + 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); + return false; + }; + }); + } + + private void registerGroupRequirement() { + registerRequirement("group", (args, actions, advanced) -> { + HashSet groups = new HashSet<>(ListUtils.toList(args)); + return context -> { + String lootID = context.arg(ContextKeys.ID); + Optional loot = plugin.getLootManager().getLoot(lootID); + if (loot.isEmpty()) return false; + String[] group = loot.get().lootGroup(); + if (group != null) + for (String x : group) + if (groups.contains(x)) + return true; + if (advanced) ActionManager.trigger(context, actions); + return false; + }; + }); + registerRequirement("!group", (args, actions, advanced) -> { + HashSet groups = new HashSet<>(ListUtils.toList(args)); + return context -> { + String lootID = context.arg(ContextKeys.ID); + Optional loot = plugin.getLootManager().getLoot(lootID); + if (loot.isEmpty()) return false; + String[] group = loot.get().lootGroup(); + if (group == null) + return true; + outer: { + for (String x : group) + if (groups.contains(x)) + break outer; + return true; + } + if (advanced) ActionManager.trigger(context, actions); + return false; + }; + }); + } + + private void registerLootRequirement() { + registerRequirement("loot", (args, actions, advanced) -> { + 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); + return false; + }; + }); + registerRequirement("!loot", (args, actions, advanced) -> { + 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); + return false; + }; + }); + } + + private void registerHookRequirement() { + registerRequirement("hook", (args, actions, advanced) -> { + 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); + return false; + }; + }); + registerRequirement("!hook", (args, actions, advanced) -> { + 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); + return false; + }; + }); + registerRequirement("has-hook", (args, actions, advanced) -> { + 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); + return false; + }; + }); + } + + private void registerBaitRequirement() { + registerRequirement("bait", (args, actions, advanced) -> { + 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); + return false; + }; + }); + registerRequirement("!bait", (args, actions, advanced) -> { + 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); + return false; + }; + }); + registerRequirement("has-bait", (args, actions, advanced) -> { + 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); + return false; + }; + }); + } + + private void registerSizeRequirement() { + registerRequirement("has-size", (args, actions, advanced) -> { + 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); + return false; + }; + }); + } + + private void registerOpenWaterRequirement() { + registerRequirement("open-water", (args, actions, advanced) -> { + 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); + return false; + }; + }); + } + + private void registerHasStatsRequirement() { + registerRequirement("has-stats", (args, actions, advanced) -> { + boolean has = (boolean) args; + return context -> { + String loot = context.arg(ContextKeys.ID); + Optional lootInstance = plugin.getLootManager().getLoot(loot); + if (lootInstance.isPresent()) { + if (!lootInstance.get().disableStats() && has) return true; + if (lootInstance.get().disableStats() && !has) return true; + } + if (advanced) ActionManager.trigger(context, actions); + return false; + }; + }); + } + + private void registerLootTypeRequirement() { + registerRequirement("loot-type", (args, actions, advanced) -> { + List types = ListUtils.toList(args); + return context -> { + String loot = context.arg(ContextKeys.ID); + Optional lootInstance = plugin.getLootManager().getLoot(loot); + if (lootInstance.isPresent()) { + if (types.contains(lootInstance.get().getType().name().toLowerCase(Locale.ENGLISH))) + return true; + } + if (advanced) ActionManager.trigger(context, actions); + return false; + }; + }); + registerRequirement("!loot-type", (args, actions, advanced) -> { + List types = ListUtils.toList(args); + return context -> { + String loot = context.arg(ContextKeys.ID); + Optional lootInstance = plugin.getLootManager().getLoot(loot); + if (lootInstance.isPresent()) { + if (!types.contains(lootInstance.get().getType().name().toLowerCase(Locale.ENGLISH))) + return true; + } + if (advanced) ActionManager.trigger(context, actions); + return false; + }; + }); + } + + private void registerListRequirement() { + registerRequirement("list", (args, actions, advanced) -> { + 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)) { + plugin.getPluginLogger().warn(" - " + e); + } + return EmptyRequirement.INSTANCE; + }); + } + + private void registerEnvironmentRequirement() { + registerRequirement("environment", (args, actions, advanced) -> { + 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); + return false; + }; + }); + registerRequirement("!environment", (args, actions, advanced) -> { + 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); + return false; + }; + }); + } + + private void registerIceFishingRequirement() { + registerRequirement("ice-fishing", (args, actions, advanced) -> { + boolean iceFishing = (boolean) args; + return context -> { + Location location = requireNonNull(context.arg(ContextKeys.LOCATION)); + int water = 0, ice = 0; + for (int i = -2; i <= 2; i++) + for (int j = -1; j <= 2; j++) + for (int k = -2; k <= 2; k++) { + Block block = location.clone().add(i, j, k).getBlock(); + Material material = block.getType(); + switch (material) { + case ICE -> ice++; + case WATER -> water++; + } + } + if ((ice >= 16 && water >= 25) == iceFishing) + return true; + if (advanced) ActionManager.trigger(context, actions); + return false; + }; + }); + } + + private void registerLevelRequirement() { + registerRequirement("level", (args, actions, advanced) -> { + 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); + return false; + }; + }); + } + + private void registerMoneyRequirement() { + registerRequirement("money", (args, actions, advanced) -> { + 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); + return false; + }; + }); + } + + private void registerRandomRequirement() { + registerRequirement("random", (args, actions, advanced) -> { + MathValue value = MathValue.auto(args); + return context -> { + if (Math.random() < value.evaluate(context)) + return true; + if (advanced) ActionManager.trigger(context, actions); + return false; + }; + }); + } + + private void registerBiomeRequirement() { + registerRequirement("biome", (args, actions, advanced) -> { + HashSet biomes = new HashSet<>(ListUtils.toList(args)); + return context -> { + Location location = requireNonNull(context.arg(ContextKeys.LOCATION)); + String currentBiome = SparrowHeart.getInstance().getBiomeResourceLocation(location); + if (biomes.contains(currentBiome)) + return true; + if (advanced) ActionManager.trigger(context, actions); + return false; + }; + }); + registerRequirement("!biome", (args, actions, advanced) -> { + HashSet biomes = new HashSet<>(ListUtils.toList(args)); + return context -> { + Location location = requireNonNull(context.arg(ContextKeys.LOCATION)); + String currentBiome = SparrowHeart.getInstance().getBiomeResourceLocation(location); + if (!biomes.contains(currentBiome)) + return true; + if (advanced) ActionManager.trigger(context, actions); + return false; + }; + }); + } + + private void registerMoonPhaseRequirement() { + registerRequirement("moon-phase", (args, actions, advanced) -> { + 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); + return false; + }; + }); + registerRequirement("!moon-phase", (args, actions, advanced) -> { + 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); + return false; + }; + }); + } + + private void registerWorldRequirement() { + registerRequirement("world", (args, actions, advanced) -> { + 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); + return false; + }; + }); + registerRequirement("!world", (args, actions, advanced) -> { + 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); + return false; + }; + }); + } + + private void registerWeatherRequirement() { + registerRequirement("weather", (args, actions, advanced) -> { + HashSet weathers = new HashSet<>(ListUtils.toList(args)); + return context -> { + String currentWeather; + Location location = requireNonNull(context.arg(ContextKeys.LOCATION)); + World world = location.getWorld(); + if (world.isClearWeather()) currentWeather = "clear"; + else if (world.isThundering()) currentWeather = "thunder"; + else currentWeather = "rain"; + if (weathers.contains(currentWeather)) return true; + if (advanced) ActionManager.trigger(context, actions); + return false; + }; + }); + } + + private void registerCoolDownRequirement() { + registerRequirement("cooldown", (args, actions, advanced) -> { + return null; + }); + } + + private void registerDateRequirement() { + registerRequirement("date", (args, actions, advanced) -> { + 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); + return false; + }; + }); + } + + private void registerPermissionRequirement() { + registerRequirement("permission", (args, actions, advanced) -> { + List perms = ListUtils.toList(args); + return context -> { + for (String perm : perms) + if (context.getHolder().hasPermission(perm)) + return true; + if (advanced) ActionManager.trigger(context, actions); + return false; + }; + }); + registerRequirement("!permission", (args, actions, advanced) -> { + List perms = ListUtils.toList(args); + return context -> { + for (String perm : perms) + if (context.getHolder().hasPermission(perm)) { + if (advanced) ActionManager.trigger(context, actions); + return false; + } + return true; + }; + }); + } + + private void registerSeasonRequirement() { + registerRequirement("season", (args, actions, advanced) -> { + List seasons = ListUtils.toList(args); + return context -> { + SeasonProvider seasonProvider = plugin.getIntegrationManager().getSeasonProvider(); + if (seasonProvider == null) return true; + Location location = requireNonNull(context.arg(ContextKeys.LOCATION)); + 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); + return false; + }; + }); + } + + private void registerPAPIRequirement() { + registerRequirement("<", (args, actions, advanced) -> { + if (args instanceof ConfigurationSection 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); + return false; + }; + } else { + plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at < requirement which should be Section"); + return EmptyRequirement.INSTANCE; + } + }); + registerRequirement("<=", (args, actions, advanced) -> { + if (args instanceof ConfigurationSection 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); + return false; + }; + } else { + plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at <= requirement which should be Section"); + return EmptyRequirement.INSTANCE; + } + }); + registerRequirement("!=", (args, actions, advanced) -> { + if (args instanceof ConfigurationSection 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); + return false; + }; + } else { + plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at != requirement which should be Section"); + return EmptyRequirement.INSTANCE; + } + }); + registerRequirement("==", (args, actions, advanced) -> { + if (args instanceof ConfigurationSection 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); + return false; + }; + } else { + plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at == requirement which should be Section"); + return EmptyRequirement.INSTANCE; + } + }); + registerRequirement(">=", (args, actions, advanced) -> { + if (args instanceof ConfigurationSection 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); + return false; + }; + } else { + plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at >= requirement which should be Section"); + return EmptyRequirement.INSTANCE; + } + }); + registerRequirement(">", (args, actions, advanced) -> { + if (args instanceof ConfigurationSection 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); + return false; + }; + } else { + plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at > requirement which should be Section"); + return EmptyRequirement.INSTANCE; + } + }); + registerRequirement("regex", (args, actions, advanced) -> { + if (args instanceof ConfigurationSection 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); + return false; + }; + } else { + plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at regex requirement which should be Section"); + return EmptyRequirement.INSTANCE; + } + }); + registerRequirement("startsWith", (args, actions, advanced) -> { + if (args instanceof ConfigurationSection 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); + return false; + }; + } else { + plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at startsWith requirement which should be Section"); + return EmptyRequirement.INSTANCE; + } + }); + registerRequirement("!startsWith", (args, actions, advanced) -> { + if (args instanceof ConfigurationSection 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); + return false; + }; + } else { + plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at !startsWith requirement which should be Section"); + return EmptyRequirement.INSTANCE; + } + }); + registerRequirement("endsWith", (args, actions, advanced) -> { + if (args instanceof ConfigurationSection 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); + return false; + }; + } else { + plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at endsWith requirement which should be Section"); + return EmptyRequirement.INSTANCE; + } + }); + registerRequirement("!endsWith", (args, actions, advanced) -> { + if (args instanceof ConfigurationSection 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); + return false; + }; + } else { + plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at !endsWith requirement which should be Section"); + return EmptyRequirement.INSTANCE; + } + }); + registerRequirement("contains", (args, actions, advanced) -> { + if (args instanceof ConfigurationSection 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); + return false; + }; + } else { + plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at contains requirement which should be Section"); + return EmptyRequirement.INSTANCE; + } + }); + registerRequirement("!contains", (args, actions, advanced) -> { + if (args instanceof ConfigurationSection 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); + return false; + }; + } else { + plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at !contains requirement which should be Section"); + return EmptyRequirement.INSTANCE; + } + }); + registerRequirement("in-list", (args, actions, advanced) -> { + if (args instanceof ConfigurationSection 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); + return false; + }; + } else { + plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at in-list requirement which should be Section"); + return EmptyRequirement.INSTANCE; + } + }); + registerRequirement("!in-list", (args, actions, advanced) -> { + if (args instanceof ConfigurationSection 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); + return false; + }; + } else { + plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at !in-list requirement which should be Section"); + return EmptyRequirement.INSTANCE; + } + }); + registerRequirement("equals", (args, actions, advanced) -> { + if (args instanceof ConfigurationSection 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); + return false; + }; + } else { + plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at equals requirement which should be Section"); + return EmptyRequirement.INSTANCE; + } + }); + registerRequirement("!equals", (args, actions, advanced) -> { + if (args instanceof ConfigurationSection 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); + return false; + }; + } else { + plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at !equals requirement which should be Section"); + return EmptyRequirement.INSTANCE; + } + }); + } + + private void registerPotionEffectRequirement() { + registerRequirement("potion-effect", (args, actions, advanced) -> { + String potions = (String) args; + String[] split = potions.split("(<=|>=|<|>|==)", 2); + PotionEffectType type = PotionEffectType.getByName(split[0]); + if (type == null) { + plugin.getPluginLogger().warn("Potion effect doesn't exist: " + split[0]); + return EmptyRequirement.INSTANCE; + } + int required = Integer.parseInt(split[1]); + String operator = potions.substring(split[0].length(), potions.length() - split[1].length()); + return context -> { + int level = -1; + PotionEffect potionEffect = context.getHolder().getPotionEffect(type); + if (potionEffect != null) { + level = potionEffect.getAmplifier(); + } + boolean result = false; + switch (operator) { + case ">=" -> { + if (level >= required) result = true; + } + case ">" -> { + if (level > required) result = true; + } + case "==" -> { + if (level == required) result = true; + } + case "!=" -> { + if (level != required) result = true; + } + case "<=" -> { + if (level <= required) result = true; + } + case "<" -> { + if (level < required) result = true; + } + } + if (result) { + return true; + } + if (advanced) ActionManager.trigger(context, actions); + return false; + }; + }); + } + /** * Loads requirement expansions from external JAR files located in the expansion folder. * Each expansion JAR should contain classes that extends the RequirementExpansion class. diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/requirement/ConditionalElement.java b/core/src/main/java/net/momirealms/customfishing/bukkit/requirement/ConditionalElement.java similarity index 97% rename from core/src/main/java/net/momirealms/customfishing/mechanic/requirement/ConditionalElement.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/requirement/ConditionalElement.java index e7bb9d08..89f4691d 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/requirement/ConditionalElement.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/requirement/ConditionalElement.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.mechanic.requirement; +package net.momirealms.customfishing.bukkit.requirement; import net.momirealms.customfishing.api.common.Pair; import net.momirealms.customfishing.api.mechanic.requirement.Requirement; diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/BukkitSchedulerAdapter.java b/core/src/main/java/net/momirealms/customfishing/bukkit/scheduler/BukkitSchedulerAdapter.java similarity index 97% rename from core/src/main/java/net/momirealms/customfishing/bukkit/BukkitSchedulerAdapter.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/scheduler/BukkitSchedulerAdapter.java index bc5f139b..73032d73 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/BukkitSchedulerAdapter.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/scheduler/BukkitSchedulerAdapter.java @@ -23,7 +23,7 @@ * SOFTWARE. */ -package net.momirealms.customfishing.bukkit; +package net.momirealms.customfishing.bukkit.scheduler; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.common.plugin.scheduler.AbstractJavaScheduler; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/statistic/StatisticsManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/bukkit/statistic/BukkitStatisticsManager.java similarity index 94% rename from core/src/main/java/net/momirealms/customfishing/mechanic/statistic/StatisticsManagerImpl.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/statistic/BukkitStatisticsManager.java index 4cd1ae72..2a252bf0 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/statistic/StatisticsManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/statistic/BukkitStatisticsManager.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.mechanic.statistic; +package net.momirealms.customfishing.bukkit.statistic; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.mechanic.statistic.StatisticsManager; @@ -25,12 +25,12 @@ import org.jetbrains.annotations.Nullable; import java.io.File; import java.util.*; -public class StatisticsManagerImpl implements StatisticsManager { +public class BukkitStatisticsManager implements StatisticsManager { private final BukkitCustomFishingPlugin plugin; private final HashMap> categoryMap; - public StatisticsManagerImpl(BukkitCustomFishingPlugin plugin) { + public BukkitStatisticsManager(BukkitCustomFishingPlugin plugin) { this.plugin = plugin; this.categoryMap = new HashMap<>(); } diff --git a/core/src/main/java/net/momirealms/customfishing/storage/StorageManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/bukkit/storage/BukkitStorageManager.java similarity index 94% rename from core/src/main/java/net/momirealms/customfishing/storage/StorageManagerImpl.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/storage/BukkitStorageManager.java index 4d252c87..b2805f9a 100644 --- a/core/src/main/java/net/momirealms/customfishing/storage/StorageManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/storage/BukkitStorageManager.java @@ -15,12 +15,12 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.storage; +package net.momirealms.customfishing.bukkit.storage; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonSyntaxException; -import net.momirealms.customfishing.BukkitCustomFishingPluginImpl; +import net.momirealms.customfishing.bukkit.BukkitCustomFishingPluginImpl; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.scheduler.CancellableTask; import net.momirealms.customfishing.api.storage.DataStorageProvider; @@ -28,15 +28,15 @@ import net.momirealms.customfishing.api.storage.StorageManager; import net.momirealms.customfishing.api.storage.StorageType; import net.momirealms.customfishing.api.storage.data.PlayerData; import net.momirealms.customfishing.api.storage.user.UserData; -import net.momirealms.customfishing.storage.method.database.nosql.MongoDBImpl; -import net.momirealms.customfishing.storage.method.database.nosql.RedisManager; -import net.momirealms.customfishing.storage.method.database.sql.H2Impl; -import net.momirealms.customfishing.storage.method.database.sql.MariaDBImpl; -import net.momirealms.customfishing.storage.method.database.sql.MySQLImpl; -import net.momirealms.customfishing.storage.method.database.sql.SQLiteImpl; -import net.momirealms.customfishing.storage.method.file.JsonImpl; -import net.momirealms.customfishing.storage.method.file.YAMLImpl; -import net.momirealms.customfishing.storage.user.OfflineUser; +import net.momirealms.customfishing.bukkit.storage.method.database.nosql.MongoDBImpl; +import net.momirealms.customfishing.bukkit.storage.method.database.nosql.RedisManager; +import net.momirealms.customfishing.bukkit.storage.method.database.sql.H2Impl; +import net.momirealms.customfishing.bukkit.storage.method.database.sql.MariaDBImpl; +import net.momirealms.customfishing.bukkit.storage.method.database.sql.MySQLImpl; +import net.momirealms.customfishing.bukkit.storage.method.database.sql.SQLiteImpl; +import net.momirealms.customfishing.bukkit.storage.method.file.JsonImpl; +import net.momirealms.customfishing.bukkit.storage.method.file.YAMLImpl; +import net.momirealms.customfishing.bukkit.storage.user.OfflineUser; import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; @@ -61,7 +61,7 @@ import java.util.concurrent.TimeUnit; * This class implements the StorageManager interface and is responsible for managing player data storage. * It includes methods to handle player data retrieval, storage, and serialization. */ -public class StorageManagerImpl implements StorageManager, Listener { +public class BukkitStorageManager implements StorageManager, Listener { private final BukkitCustomFishingPlugin plugin; private DataStorageProvider dataSource; @@ -74,7 +74,7 @@ public class StorageManagerImpl implements StorageManager, Listener { private CancellableTask timerSaveTask; private final Gson gson; - public StorageManagerImpl(BukkitCustomFishingPluginImpl plugin) { + public BukkitStorageManager(BukkitCustomFishingPluginImpl plugin) { this.plugin = plugin; this.locked = new HashSet<>(); this.onlineUserMap = new ConcurrentHashMap<>(); diff --git a/core/src/main/java/net/momirealms/customfishing/storage/method/AbstractStorage.java b/core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/AbstractStorage.java similarity index 95% rename from core/src/main/java/net/momirealms/customfishing/storage/method/AbstractStorage.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/AbstractStorage.java index 248be24b..38682b76 100644 --- a/core/src/main/java/net/momirealms/customfishing/storage/method/AbstractStorage.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/AbstractStorage.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.storage.method; +package net.momirealms.customfishing.bukkit.storage.method; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.storage.DataStorageProvider; @@ -80,4 +80,8 @@ public abstract class AbstractStorage implements DataStorageProvider { // By default, delegate to the updatePlayerData method to update or insert player data. return updatePlayerData(uuid, playerData, unlock); } + + public BukkitCustomFishingPlugin getPlugin() { + return plugin; + } } diff --git a/core/src/main/java/net/momirealms/customfishing/storage/method/database/nosql/MongoDBImpl.java b/core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/database/nosql/MongoDBImpl.java similarity index 98% rename from core/src/main/java/net/momirealms/customfishing/storage/method/database/nosql/MongoDBImpl.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/database/nosql/MongoDBImpl.java index f6fa9c10..edc58d1c 100644 --- a/core/src/main/java/net/momirealms/customfishing/storage/method/database/nosql/MongoDBImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/database/nosql/MongoDBImpl.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.storage.method.database.nosql; +package net.momirealms.customfishing.bukkit.storage.method.database.nosql; import com.mongodb.*; import com.mongodb.client.*; @@ -25,7 +25,7 @@ import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.storage.StorageType; import net.momirealms.customfishing.api.storage.data.PlayerData; import net.momirealms.customfishing.api.storage.user.UserData; -import net.momirealms.customfishing.storage.method.AbstractStorage; +import net.momirealms.customfishing.bukkit.storage.method.AbstractStorage; import org.bson.Document; import org.bson.UuidRepresentation; import org.bson.conversions.Bson; diff --git a/core/src/main/java/net/momirealms/customfishing/storage/method/database/nosql/RedisManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/database/nosql/RedisManager.java similarity index 76% rename from core/src/main/java/net/momirealms/customfishing/storage/method/database/nosql/RedisManager.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/database/nosql/RedisManager.java index a20ea1bf..6b775f2a 100644 --- a/core/src/main/java/net/momirealms/customfishing/storage/method/database/nosql/RedisManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/database/nosql/RedisManager.java @@ -15,14 +15,17 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.storage.method.database.nosql; +package net.momirealms.customfishing.bukkit.storage.method.database.nosql; +import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteStreams; +import dev.dejvokep.boostedyaml.YamlDocument; +import dev.dejvokep.boostedyaml.block.implementation.Section; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; +import net.momirealms.customfishing.api.mechanic.config.ConfigManager; import net.momirealms.customfishing.api.storage.StorageType; import net.momirealms.customfishing.api.storage.data.PlayerData; -import net.momirealms.customfishing.storage.method.AbstractStorage; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.YamlConfiguration; +import net.momirealms.customfishing.bukkit.storage.method.AbstractStorage; import org.jetbrains.annotations.NotNull; import redis.clients.jedis.*; import redis.clients.jedis.exceptions.JedisException; @@ -77,10 +80,10 @@ public class RedisManager extends AbstractStorage { */ @Override public void initialize() { - YamlConfiguration config = plugin.getConfig("database.yml"); - ConfigurationSection section = config.getConfigurationSection("Redis"); + YamlDocument config = plugin.getConfigManager().loadConfig("database.yml"); + Section section = config.getSection("Redis"); if (section == null) { - LogUtils.warn("Failed to load database config. It seems that your config is broken. Please regenerate a new one."); + plugin.getPluginLogger().warn("Failed to load database config. It seems that your config is broken. Please regenerate a new one."); return; } @@ -88,7 +91,7 @@ public class RedisManager extends AbstractStorage { jedisPoolConfig.setTestWhileIdle(true); jedisPoolConfig.setTimeBetweenEvictionRuns(Duration.ofMillis(30000)); jedisPoolConfig.setNumTestsPerEvictionRun(-1); - jedisPoolConfig.setMinEvictableIdleTime(Duration.ofMillis(section.getInt("MinEvictableIdleTimeMillis",1800000))); + jedisPoolConfig.setMinEvictableIdleDuration(Duration.ofMillis(section.getInt("MinEvictableIdleTimeMillis", 1800000))); jedisPoolConfig.setMaxTotal(section.getInt("MaxTotal",8)); jedisPoolConfig.setMaxIdle(section.getInt("MaxIdle",8)); jedisPoolConfig.setMinIdle(section.getInt("MinIdle",1)); @@ -107,9 +110,9 @@ public class RedisManager extends AbstractStorage { String info; try (Jedis jedis = jedisPool.getResource()) { info = jedis.info(); - LogUtils.info("Redis server connected."); + plugin.getPluginLogger().info("Redis server connected."); } catch (JedisException e) { - LogUtils.warn("Failed to connect redis.", e); + plugin.getPluginLogger().warn("Failed to connect redis.", e); return; } @@ -139,12 +142,9 @@ public class RedisManager extends AbstractStorage { /** * Send a message to Redis on a specified channel. * - * @param server The Redis channel to send the message to. * @param message The message to send. */ - public void publishRedisMessage(@NotNull String server, @NotNull String message) { - message = server + ";" + message; - plugin.debug("Sent Redis message: " + message); + public void publishRedisMessage(@NotNull String message) { if (isNewerThan5) { try (Jedis jedis = jedisPool.getResource()) { HashMap messages = new HashMap<>(); @@ -187,30 +187,28 @@ public class RedisManager extends AbstractStorage { thread.start(); } - private static void handleMessage(String message) { - BukkitCustomFishingPlugin.get().debug("Received Redis message: " + message); - String[] split = message.split(";"); - String server = split[0]; - if (!CFConfig.serverGroup.contains(server)) { + private void handleMessage(String message) { + ByteArrayDataInput input = ByteStreams.newDataInput(message.getBytes(StandardCharsets.UTF_8)); + String server = input.readUTF(); + if (!ConfigManager.serverGroup().equals(server)) return; - } - String action = split[1]; - BukkitCustomFishingPlugin.get().getScheduler().runTaskAsync(() -> { + String type = input.readUTF(); + if (type.equals("competition")) { + String action = input.readUTF(); switch (action) { case "start" -> { - // start competition for all the servers that connected to redis - BukkitCustomFishingPlugin.get().getCompetitionManager().startCompetition(split[2], true, null); + plugin.getCompetitionManager().startCompetition(input.readUTF(), true, null); } case "end" -> { - if (BukkitCustomFishingPlugin.get().getCompetitionManager().getOnGoingCompetition() != null) - BukkitCustomFishingPlugin.get().getCompetitionManager().getOnGoingCompetition().end(true); + if (plugin.getCompetitionManager().getOnGoingCompetition() != null) + plugin.getCompetitionManager().getOnGoingCompetition().end(true); } case "stop" -> { - if (BukkitCustomFishingPlugin.get().getCompetitionManager().getOnGoingCompetition() != null) - BukkitCustomFishingPlugin.get().getCompetitionManager().getOnGoingCompetition().stop(true); + if (plugin.getCompetitionManager().getOnGoingCompetition() != null) + plugin.getCompetitionManager().getOnGoingCompetition().stop(true); } } - }); + } } @Override @@ -226,7 +224,7 @@ public class RedisManager extends AbstractStorage { */ public CompletableFuture setChangeServer(UUID uuid) { var future = new CompletableFuture(); - plugin.getScheduler().runTaskAsync(() -> { + plugin.getScheduler().async().execute(() -> { try (Jedis jedis = jedisPool.getResource()) { jedis.setex( getRedisKey("cf_server", uuid), @@ -235,7 +233,6 @@ public class RedisManager extends AbstractStorage { ); } future.complete(null); - plugin.debug("Server data set for " + uuid); }); return future; } @@ -248,16 +245,14 @@ public class RedisManager extends AbstractStorage { */ public CompletableFuture getChangeServer(UUID uuid) { var future = new CompletableFuture(); - plugin.getScheduler().runTaskAsync(() -> { + plugin.getScheduler().async().execute(() -> { try (Jedis jedis = jedisPool.getResource()) { byte[] key = getRedisKey("cf_server", uuid); if (jedis.get(key) != null) { jedis.del(key); future.complete(true); - plugin.debug("Server data retrieved for " + uuid + "; value: true"); } else { future.complete(false); - plugin.debug("Server data retrieved for " + uuid + "; value: false"); } } }); @@ -274,21 +269,18 @@ public class RedisManager extends AbstractStorage { @Override public CompletableFuture> getPlayerData(UUID uuid, boolean lock) { var future = new CompletableFuture>(); - plugin.getScheduler().runTaskAsync(() -> { + plugin.getScheduler().async().execute(() -> { try (Jedis jedis = jedisPool.getResource()) { byte[] key = getRedisKey("cf_data", uuid); byte[] data = jedis.get(key); jedis.del(key); if (data != null) { future.complete(Optional.of(plugin.getStorageManager().fromBytes(data))); - plugin.debug("Redis data retrieved for " + uuid + "; normal data"); } else { future.complete(Optional.empty()); - plugin.debug("Redis data retrieved for " + uuid + "; empty data"); } } catch (Exception e) { future.complete(Optional.empty()); - LogUtils.warn("Failed to get redis data for " + uuid, e); } }); return future; @@ -305,7 +297,7 @@ public class RedisManager extends AbstractStorage { @Override public CompletableFuture updatePlayerData(UUID uuid, PlayerData playerData, boolean ignore) { var future = new CompletableFuture(); - plugin.getScheduler().runTaskAsync(() -> { + plugin.getScheduler().async().execute(() -> { try (Jedis jedis = jedisPool.getResource()) { jedis.setex( getRedisKey("cf_data", uuid), @@ -313,24 +305,15 @@ public class RedisManager extends AbstractStorage { plugin.getStorageManager().toBytes(playerData) ); future.complete(true); - plugin.debug("Redis data set for " + uuid); } catch (Exception e) { future.complete(false); - LogUtils.warn("Failed to set redis data for player " + uuid, e); } }); return future; } - /** - * Get a set of unique player UUIDs from Redis (Returns an empty set). - * This method is designed for importing and exporting so it would not actually be called. - * - * @param legacy Flag indicating whether to retrieve legacy data (not used). - * @return An empty set of UUIDs. - */ @Override - public Set getUniqueUsers(boolean legacy) { + public Set getUniqueUsers() { return new HashSet<>(); } @@ -349,17 +332,17 @@ public class RedisManager extends AbstractStorage { return STREAM; } - private static boolean isRedisNewerThan5(String version) { + private boolean isRedisNewerThan5(String version) { String[] split = version.split("\\."); int major = Integer.parseInt(split[0]); if (major < 7) { - LogUtils.warn(String.format("Detected that you are running an outdated Redis server. v%s. ", version)); - LogUtils.warn("It's recommended to update to avoid security vulnerabilities!"); + plugin.getPluginLogger().warn(String.format("Detected that you are running an outdated Redis server. v%s. ", version)); + plugin.getPluginLogger().warn("It's recommended to update to avoid security vulnerabilities!"); } return major >= 5; } - private static String parseRedisVersion(String info) { + private String parseRedisVersion(String info) { for (String line : info.split("\n")) { if (line.startsWith("redis_version:")) { return line.split(":")[1]; @@ -386,7 +369,7 @@ public class RedisManager extends AbstractStorage { if (connection != null) { var messages = connection.xread(XReadParams.xReadParams().count(1).block(2000), map); connection.close(); - if (messages != null && messages.size() != 0) { + if (messages != null && !messages.isEmpty()) { for (Map.Entry> message : messages) { if (message.getKey().equals(getStream())) { var value = message.getValue().get(0).getFields().get("value"); @@ -398,7 +381,7 @@ public class RedisManager extends AbstractStorage { Thread.sleep(2000); } } catch (Exception e) { - LogUtils.warn("Failed to connect redis. Try reconnecting 10s later",e); + plugin.getPluginLogger().warn("Failed to connect redis. Try reconnecting 10s later",e); try { Thread.sleep(10000); } catch (InterruptedException ex) { diff --git a/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/AbstractHikariDatabase.java b/core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/database/sql/AbstractHikariDatabase.java similarity index 99% rename from core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/AbstractHikariDatabase.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/database/sql/AbstractHikariDatabase.java index 477da913..7d04464e 100644 --- a/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/AbstractHikariDatabase.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/database/sql/AbstractHikariDatabase.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.storage.method.database.sql; +package net.momirealms.customfishing.bukkit.storage.method.database.sql; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; diff --git a/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/AbstractSQLDatabase.java b/core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/database/sql/AbstractSQLDatabase.java similarity index 98% rename from core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/AbstractSQLDatabase.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/database/sql/AbstractSQLDatabase.java index cb2417b1..7a26fe3e 100644 --- a/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/AbstractSQLDatabase.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/database/sql/AbstractSQLDatabase.java @@ -15,12 +15,12 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.storage.method.database.sql; +package net.momirealms.customfishing.bukkit.storage.method.database.sql; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.storage.data.PlayerData; import net.momirealms.customfishing.api.storage.user.UserData; -import net.momirealms.customfishing.storage.method.AbstractStorage; +import net.momirealms.customfishing.bukkit.storage.method.AbstractStorage; import org.bukkit.Bukkit; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/H2Impl.java b/core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/database/sql/H2Impl.java similarity index 95% rename from core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/H2Impl.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/database/sql/H2Impl.java index d8b6e7f0..6dcaed9b 100644 --- a/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/H2Impl.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/database/sql/H2Impl.java @@ -15,9 +15,9 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.storage.method.database.sql; +package net.momirealms.customfishing.bukkit.storage.method.database.sql; -import net.momirealms.customfishing.BukkitCustomFishingPluginImpl; +import net.momirealms.customfishing.bukkit.BukkitCustomFishingPluginImpl; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.storage.StorageType; import net.momirealms.customfishing.libraries.dependencies.Dependency; diff --git a/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/MariaDBImpl.java b/core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/database/sql/MariaDBImpl.java similarity index 93% rename from core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/MariaDBImpl.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/database/sql/MariaDBImpl.java index be3d7cc8..e09270a6 100644 --- a/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/MariaDBImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/database/sql/MariaDBImpl.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.storage.method.database.sql; +package net.momirealms.customfishing.bukkit.storage.method.database.sql; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.storage.StorageType; diff --git a/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/MySQLImpl.java b/core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/database/sql/MySQLImpl.java similarity index 93% rename from core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/MySQLImpl.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/database/sql/MySQLImpl.java index 43c1fd3e..4b5ae1e6 100644 --- a/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/MySQLImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/database/sql/MySQLImpl.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.storage.method.database.sql; +package net.momirealms.customfishing.bukkit.storage.method.database.sql; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.storage.StorageType; diff --git a/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/SQLiteImpl.java b/core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/database/sql/SQLiteImpl.java similarity index 98% rename from core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/SQLiteImpl.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/database/sql/SQLiteImpl.java index feae00a0..9951fb78 100644 --- a/core/src/main/java/net/momirealms/customfishing/storage/method/database/sql/SQLiteImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/database/sql/SQLiteImpl.java @@ -15,9 +15,9 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.storage.method.database.sql; +package net.momirealms.customfishing.bukkit.storage.method.database.sql; -import net.momirealms.customfishing.BukkitCustomFishingPluginImpl; +import net.momirealms.customfishing.bukkit.BukkitCustomFishingPluginImpl; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.storage.StorageType; import net.momirealms.customfishing.api.storage.data.PlayerData; diff --git a/core/src/main/java/net/momirealms/customfishing/storage/method/file/JsonImpl.java b/core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/file/JsonImpl.java similarity index 97% rename from core/src/main/java/net/momirealms/customfishing/storage/method/file/JsonImpl.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/file/JsonImpl.java index 892f8c4f..5ced0d62 100644 --- a/core/src/main/java/net/momirealms/customfishing/storage/method/file/JsonImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/file/JsonImpl.java @@ -15,13 +15,13 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.storage.method.file; +package net.momirealms.customfishing.bukkit.storage.method.file; import com.google.gson.Gson; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.storage.StorageType; import net.momirealms.customfishing.api.storage.data.PlayerData; -import net.momirealms.customfishing.storage.method.AbstractStorage; +import net.momirealms.customfishing.bukkit.storage.method.AbstractStorage; import org.bukkit.Bukkit; import java.io.File; diff --git a/core/src/main/java/net/momirealms/customfishing/storage/method/file/YAMLImpl.java b/core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/file/YAMLImpl.java similarity index 97% rename from core/src/main/java/net/momirealms/customfishing/storage/method/file/YAMLImpl.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/file/YAMLImpl.java index 34ddedcc..60b3f595 100644 --- a/core/src/main/java/net/momirealms/customfishing/storage/method/file/YAMLImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/storage/method/file/YAMLImpl.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.storage.method.file; +package net.momirealms.customfishing.bukkit.storage.method.file; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.storage.StorageType; @@ -23,8 +23,8 @@ import net.momirealms.customfishing.api.storage.data.EarningData; import net.momirealms.customfishing.api.storage.data.InventoryData; import net.momirealms.customfishing.api.storage.data.PlayerData; import net.momirealms.customfishing.api.storage.data.StatisticData; -import net.momirealms.customfishing.storage.method.AbstractStorage; -import net.momirealms.customfishing.util.ConfigUtils; +import net.momirealms.customfishing.bukkit.storage.method.AbstractStorage; +import net.momirealms.customfishing.bukkit.util.ConfigUtils; import org.bukkit.Bukkit; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; diff --git a/core/src/main/java/net/momirealms/customfishing/storage/user/OfflineUser.java b/core/src/main/java/net/momirealms/customfishing/bukkit/storage/user/OfflineUser.java similarity index 98% rename from core/src/main/java/net/momirealms/customfishing/storage/user/OfflineUser.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/storage/user/OfflineUser.java index 5b023362..0ade99fc 100644 --- a/core/src/main/java/net/momirealms/customfishing/storage/user/OfflineUser.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/storage/user/OfflineUser.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.storage.user; +package net.momirealms.customfishing.bukkit.storage.user; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.mechanic.misc.placeholder.BukkitPlaceholderManager; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/totem/ActivatedTotem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/totem/ActivatedTotem.java similarity index 98% rename from core/src/main/java/net/momirealms/customfishing/mechanic/totem/ActivatedTotem.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/totem/ActivatedTotem.java index b6282db1..8e10c550 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/totem/ActivatedTotem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/totem/ActivatedTotem.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.mechanic.totem; +package net.momirealms.customfishing.bukkit.totem; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.mechanic.action.Action; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/totem/TotemManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/bukkit/totem/BukkitTotemManager.java similarity index 97% rename from core/src/main/java/net/momirealms/customfishing/mechanic/totem/TotemManagerImpl.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/totem/BukkitTotemManager.java index ca714aac..54f9e503 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/totem/TotemManagerImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/totem/BukkitTotemManager.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.mechanic.totem; +package net.momirealms.customfishing.bukkit.totem; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.common.Pair; @@ -33,9 +33,9 @@ import net.momirealms.customfishing.api.mechanic.totem.block.property.HalfImpl; import net.momirealms.customfishing.api.mechanic.totem.block.property.TotemBlockProperty; import net.momirealms.customfishing.api.mechanic.totem.block.type.TypeCondition; import net.momirealms.customfishing.api.scheduler.CancellableTask; -import net.momirealms.customfishing.mechanic.totem.particle.DustParticleSetting; -import net.momirealms.customfishing.mechanic.totem.particle.ParticleSetting; -import net.momirealms.customfishing.util.LocationUtils; +import net.momirealms.customfishing.bukkit.totem.particle.DustParticleSetting; +import net.momirealms.customfishing.bukkit.totem.particle.ParticleSetting; +import net.momirealms.customfishing.bukkit.util.LocationUtils; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -56,7 +56,7 @@ import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; -public class TotemManagerImpl implements TotemManager, Listener { +public class BukkitTotemManager implements TotemManager, Listener { private final BukkitCustomFishingPlugin plugin; private final HashMap> totemConfigMap; @@ -64,7 +64,7 @@ public class TotemManagerImpl implements TotemManager, Listener { private final ConcurrentHashMap activatedTotems; private CancellableTask timerCheckTask; - public TotemManagerImpl(BukkitCustomFishingPlugin plugin) { + public BukkitTotemManager(BukkitCustomFishingPlugin plugin) { this.plugin = plugin; this.totemConfigMap = new HashMap<>(); this.allMaterials = Arrays.stream(Material.values()).map(Enum::name).toList(); diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/totem/particle/DustParticleSetting.java b/core/src/main/java/net/momirealms/customfishing/bukkit/totem/particle/DustParticleSetting.java similarity index 97% rename from core/src/main/java/net/momirealms/customfishing/mechanic/totem/particle/DustParticleSetting.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/totem/particle/DustParticleSetting.java index e7ef06fb..d2e751f1 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/totem/particle/DustParticleSetting.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/totem/particle/DustParticleSetting.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.mechanic.totem.particle; +package net.momirealms.customfishing.bukkit.totem.particle; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.common.Pair; diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/totem/particle/ParticleSetting.java b/core/src/main/java/net/momirealms/customfishing/bukkit/totem/particle/ParticleSetting.java similarity index 98% rename from core/src/main/java/net/momirealms/customfishing/mechanic/totem/particle/ParticleSetting.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/totem/particle/ParticleSetting.java index 9d324c24..1b1e21b3 100644 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/totem/particle/ParticleSetting.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/totem/particle/ParticleSetting.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.mechanic.totem.particle; +package net.momirealms.customfishing.bukkit.totem.particle; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import net.momirealms.customfishing.api.common.Pair; diff --git a/core/src/main/java/net/momirealms/customfishing/util/ArmorStandUtils.java b/core/src/main/java/net/momirealms/customfishing/bukkit/util/ArmorStandUtils.java similarity index 98% rename from core/src/main/java/net/momirealms/customfishing/util/ArmorStandUtils.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/util/ArmorStandUtils.java index 38b84623..0e2cea39 100644 --- a/core/src/main/java/net/momirealms/customfishing/util/ArmorStandUtils.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/util/ArmorStandUtils.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.util; +package net.momirealms.customfishing.bukkit.util; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.events.PacketContainer; @@ -23,7 +23,7 @@ import com.comphenix.protocol.wrappers.*; import com.google.common.collect.Lists; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.momirealms.customfishing.BukkitCustomFishingPluginImpl; +import net.momirealms.customfishing.bukkit.BukkitCustomFishingPluginImpl; import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; import org.bukkit.Location; import org.bukkit.entity.EntityType; diff --git a/core/src/main/java/net/momirealms/customfishing/util/ConfigUtils.java b/core/src/main/java/net/momirealms/customfishing/bukkit/util/ConfigUtils.java similarity index 99% rename from core/src/main/java/net/momirealms/customfishing/util/ConfigUtils.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/util/ConfigUtils.java index 4bdb6351..5c236536 100644 --- a/core/src/main/java/net/momirealms/customfishing/util/ConfigUtils.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/util/ConfigUtils.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.util; +package net.momirealms.customfishing.bukkit.util; import net.momirealms.customfishing.api.mechanic.misc.placeholder.BukkitPlaceholderManager; import net.momirealms.customfishing.api.mechanic.misc.value.MathValue; diff --git a/core/src/main/java/net/momirealms/customfishing/util/FakeItemUtils.java b/core/src/main/java/net/momirealms/customfishing/bukkit/util/FakeItemUtils.java similarity index 99% rename from core/src/main/java/net/momirealms/customfishing/util/FakeItemUtils.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/util/FakeItemUtils.java index d8f47255..c6520867 100644 --- a/core/src/main/java/net/momirealms/customfishing/util/FakeItemUtils.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/util/FakeItemUtils.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.util; +package net.momirealms.customfishing.bukkit.util; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.events.PacketContainer; diff --git a/core/src/main/java/net/momirealms/customfishing/util/ItemUtils.java b/core/src/main/java/net/momirealms/customfishing/bukkit/util/ItemUtils.java similarity index 99% rename from core/src/main/java/net/momirealms/customfishing/util/ItemUtils.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/util/ItemUtils.java index f98d1fd8..626946b6 100644 --- a/core/src/main/java/net/momirealms/customfishing/util/ItemUtils.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/util/ItemUtils.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.util; +package net.momirealms.customfishing.bukkit.util; import de.tr7zw.changeme.nbtapi.NBTCompound; import de.tr7zw.changeme.nbtapi.NBTItem; diff --git a/core/src/main/java/net/momirealms/customfishing/util/LocationUtils.java b/core/src/main/java/net/momirealms/customfishing/bukkit/util/LocationUtils.java similarity index 97% rename from core/src/main/java/net/momirealms/customfishing/util/LocationUtils.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/util/LocationUtils.java index d4616720..10c9b0cf 100644 --- a/core/src/main/java/net/momirealms/customfishing/util/LocationUtils.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/util/LocationUtils.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.util; +package net.momirealms.customfishing.bukkit.util; import org.bukkit.Bukkit; import org.bukkit.Location; diff --git a/core/src/main/java/net/momirealms/customfishing/util/NumberUtils.java b/core/src/main/java/net/momirealms/customfishing/bukkit/util/NumberUtils.java similarity index 94% rename from core/src/main/java/net/momirealms/customfishing/util/NumberUtils.java rename to core/src/main/java/net/momirealms/customfishing/bukkit/util/NumberUtils.java index d2f053ec..5dee0bd6 100644 --- a/core/src/main/java/net/momirealms/customfishing/util/NumberUtils.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/util/NumberUtils.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.util; +package net.momirealms.customfishing.bukkit.util; public class NumberUtils { diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/action/ActionManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/mechanic/action/ActionManagerImpl.java deleted file mode 100644 index 31f0a936..00000000 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/action/ActionManagerImpl.java +++ /dev/null @@ -1,1046 +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.mechanic.action; - -import net.kyori.adventure.key.Key; -import net.kyori.adventure.sound.Sound; -import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; -import net.momirealms.customfishing.api.common.Pair; -import net.momirealms.customfishing.api.mechanic.action.*; -import net.momirealms.customfishing.api.mechanic.loot.Loot; -import net.momirealms.customfishing.api.mechanic.loot.LootManager; -import net.momirealms.customfishing.api.mechanic.misc.placeholder.BukkitPlaceholderManager; -import net.momirealms.customfishing.api.mechanic.requirement.Requirement; -import net.momirealms.customfishing.api.scheduler.CancellableTask; -import net.momirealms.customfishing.bukkit.compatibility.VaultHook; -import net.momirealms.customfishing.common.util.ClassUtils; -import net.momirealms.customfishing.util.ArmorStandUtils; -import net.momirealms.customfishing.util.ConfigUtils; -import net.momirealms.customfishing.util.ItemUtils; -import net.momirealms.customfishing.util.LocationUtils; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Entity; -import org.bukkit.entity.ExperienceOrb; -import org.bukkit.entity.Player; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.util.*; -import java.util.concurrent.ThreadLocalRandom; -import java.util.concurrent.TimeUnit; - -public class ActionManagerImpl implements ActionManager { - - private final BukkitCustomFishingPlugin plugin; - private final HashMap actionFactoryMap; - private final String EXPANSION_FOLDER = "expansions/action"; - - public ActionManagerImpl(BukkitCustomFishingPlugin plugin) { - this.plugin = plugin; - this.actionFactoryMap = new HashMap<>(); - this.registerInbuiltActions(); - } - - // Method to register various built-in actions during initialization. - private void registerInbuiltActions() { - this.registerMessageAction(); - this.registerCommandAction(); - this.registerMendingAction(); - this.registerExpAction(); - this.registerChainAction(); - this.registerPotionAction(); - this.registerSoundAction(); - this.registerPluginExpAction(); - this.registerTitleAction(); - this.registerActionBarAction(); - this.registerCloseInvAction(); - this.registerDelayedAction(); - this.registerConditionalAction(); - this.registerPriorityAction(); - this.registerLevelAction(); - this.registerHologramAction(); - this.registerFakeItemAction(); - this.registerFishFindAction(); - this.registerFoodAction(); - this.registerItemAmountAction(); - this.registerItemDurabilityAction(); - this.registerGiveItemAction(); - this.registerMoneyAction(); - this.registerTimerAction(); - } - - // Method to load expansions and global event actions. - public void load() { - this.loadExpansions(); - this.loadGlobalEventActions(); - } - - public void unload() { - GlobalSettings.unload(); - } - - public void disable() { - unload(); - this.actionFactoryMap.clear(); - } - - // Method to load global event actions from the plugin's configuration file. - private void loadGlobalEventActions() { - YamlConfiguration config = plugin.getConfig("config.yml"); - GlobalSettings.loadEvents(config.getConfigurationSection("mechanics.global-events")); - } - - /** - * Registers an ActionFactory for a specific action type. - * This method allows you to associate an ActionFactory with a custom action type. - * - * @param type The custom action type to register. - * @param actionFactory The ActionFactory responsible for creating actions of the specified type. - * @return True if the registration was successful (the action type was not already registered), false otherwise. - */ - @Override - public boolean registerAction(String type, ActionFactory actionFactory) { - if (this.actionFactoryMap.containsKey(type)) return false; - this.actionFactoryMap.put(type, actionFactory); - return true; - } - - /** - * Unregisters an ActionFactory for a specific action type. - * This method allows you to remove the association between an action type and its ActionFactory. - * - * @param type The custom action type to unregister. - * @return True if the action type was successfully unregistered, false if it was not found. - */ - @Override - public boolean unregisterAction(String type) { - return this.actionFactoryMap.remove(type) != null; - } - - /** - * Retrieves an Action object based on the configuration provided in a ConfigurationSection. - * This method reads the type of action from the section, obtains the corresponding ActionFactory, - * and builds an Action object using the specified values and chance. - * - * @param section The ConfigurationSection containing the action configuration. - * @return An Action object created based on the configuration, or an EmptyAction instance if the action type is invalid. - */ - @Override - public Action getAction(ConfigurationSection section) { - ActionFactory factory = getActionFactory(section.getString("type")); - if (factory == null) { - LogUtils.warn("Action type: " + section.getString("type") + " doesn't exist."); - // to prevent NPE - return EmptyAction.INSTANCE; - } - return factory.process( - section.get("value"), - section.getDouble("chance", 1d) - ); - } - - /** - * Retrieves a mapping of ActionTriggers to arrays of Actions from a ConfigurationSection. - * This method iterates through the provided ConfigurationSection to extract action triggers - * and their associated arrays of Actions. - * - * @param section The ConfigurationSection containing action mappings. - * @return A HashMap where keys are ActionTriggers and values are arrays of Action objects. - */ - @Override - @NotNull - public HashMap getActionMap(ConfigurationSection section) { - // Create an empty HashMap to store the action mappings - HashMap actionMap = new HashMap<>(); - - // If the provided ConfigurationSection is null, return the empty actionMap - if (section == null) return actionMap; - - // Iterate through all key-value pairs in the ConfigurationSection - for (Map.Entry entry : section.getValues(false).entrySet()) { - if (entry.getValue() instanceof ConfigurationSection innerSection) { - // Convert the key to an ActionTrigger enum (assuming it's in uppercase English) - // and map it to an array of Actions obtained from the inner section - try { - actionMap.put( - ActionTrigger.valueOf(entry.getKey().toUpperCase(Locale.ENGLISH)), - getActions(innerSection) - ); - } catch (IllegalArgumentException e) { - LogUtils.warn("Event: " + entry.getKey() + " doesn't exist!"); - } - } - } - return actionMap; - } - - /** - * Retrieves an array of Action objects from a ConfigurationSection. - * This method iterates through the provided ConfigurationSection to extract Action configurations - * and build an array of Action objects. - * - * @param section The ConfigurationSection containing action configurations. - * @return An array of Action objects created based on the configurations in the section. - */ - @NotNull - @Override - public Action[] getActions(ConfigurationSection section) { - // Create an ArrayList to store the Actions - ArrayList actionList = new ArrayList<>(); - if (section == null) return actionList.toArray(new Action[0]); - - // Iterate through all key-value pairs in the ConfigurationSection - for (Map.Entry entry : section.getValues(false).entrySet()) { - if (entry.getValue() instanceof ConfigurationSection innerSection) { - Action action = getAction(innerSection); - if (action != null) - actionList.add(action); - } - } - return actionList.toArray(new Action[0]); - } - - /** - * Retrieves an ActionFactory associated with a specific action type. - * - * @param type The action type for which to retrieve the ActionFactory. - * @return The ActionFactory associated with the specified action type, or null if not found. - */ - @Nullable - @Override - public ActionFactory getActionFactory(@NotNull String type) { - return actionFactoryMap.get(type); - } - - /** - * Loads custom ActionExpansions from JAR files located in the expansion directory. - * This method scans the expansion folder for JAR files, loads classes that extend ActionExpansion, - * and registers them with the appropriate action type and ActionFactory. - */ - @SuppressWarnings("ResultOfMethodCallIgnored") - private void loadExpansions() { - File expansionFolder = new File(plugin.getDataFolder(), EXPANSION_FOLDER); - if (!expansionFolder.exists()) - expansionFolder.mkdirs(); - - List> classes = new ArrayList<>(); - File[] expansionJars = expansionFolder.listFiles(); - if (expansionJars == null) return; - for (File expansionJar : expansionJars) { - if (expansionJar.getName().endsWith(".jar")) { - try { - Class> expansionClass = (Class>) ClassUtils.findClass(expansionJar, ActionExpansion.class); - classes.add(expansionClass); - } catch (IOException | ClassNotFoundException e) { - LogUtils.warn("Failed to load expansion: " + expansionJar.getName(), e); - } - } - } - try { - for (Class expansionClass : classes) { - ActionExpansion expansion = expansionClass.getDeclaredConstructor().newInstance(); - unregisterAction(expansion.getActionType()); - registerAction(expansion.getActionType(), expansion.getActionFactory()); - LogUtils.info("Loaded action expansion: " + expansion.getActionType() + "[" + expansion.getVersion() + "]" + " by " + expansion.getAuthor() ); - } - } catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) { - LogUtils.warn("Error occurred when creating expansion instance.", e); - } - } - - /** - * Retrieves a mapping of success times to corresponding arrays of actions from a ConfigurationSection. - * - * @param section The ConfigurationSection containing success times actions. - * @return A HashMap where success times associated with actions. - */ - @Override - public HashMap getTimesActionMap(ConfigurationSection section) { - HashMap actionMap = new HashMap<>(); - if (section == null) return actionMap; - for (Map.Entry entry : section.getValues(false).entrySet()) { - if (entry.getValue() instanceof ConfigurationSection innerSection) { - actionMap.put(Integer.parseInt(entry.getKey()), plugin.getActionManager().getActions(innerSection)); - } - } - return actionMap; - } - - private void registerMessageAction() { - registerAction("message", (args, chance) -> { - ArrayList msg = ConfigUtils.stringListArgs(args); - return condition -> { - if (Math.random() > chance) return; - List replaced = BukkitPlaceholderManager.getInstance().parse( - condition.getPlayer(), - msg, - condition.getArgs() - ); - for (String text : replaced) { - AdventureHelper.getInstance().sendPlayerMessage(condition.getPlayer(), text); - } - }; - }); - registerAction("broadcast", (args, chance) -> { - ArrayList msg = ConfigUtils.stringListArgs(args); - return condition -> { - if (Math.random() > chance) return; - List replaced = BukkitPlaceholderManager.getInstance().parse( - condition.getPlayer(), - msg, - condition.getArgs() - ); - for (Player player : Bukkit.getOnlinePlayers()) { - for (String text : replaced) { - AdventureHelper.getInstance().sendPlayerMessage(player, text); - } - } - }; - }); - registerAction("message-nearby", (args, chance) -> { - if (args instanceof ConfigurationSection section) { - List msg = section.getStringList("message"); - int range = section.getInt("range"); - return condition -> { - if (Math.random() > chance) return; - Player owner = condition.getPlayer(); - plugin.getScheduler().runTaskSync(() -> { - for (Entity player : condition.getLocation().getWorld().getNearbyEntities(condition.getLocation(), range, range, range, entity -> entity instanceof Player)) { - double distance = LocationUtils.getDistance(player.getLocation(), condition.getLocation()); - if (distance <= range) { - condition.insertArg("{near}", player.getName()); - List replaced = BukkitPlaceholderManager.getInstance().parse( - owner, - msg, - condition.getArgs() - ); - for (String text : replaced) { - AdventureHelper.getInstance().sendPlayerMessage((Player) player, text); - } - condition.delArg("{near}"); - } - } - }, condition.getLocation()); - }; - } else { - LogUtils.warn("Illegal value format found at action: message-nearby"); - return EmptyAction.INSTANCE; - } - }); - registerAction("random-message", (args, chance) -> { - ArrayList msg = ConfigUtils.stringListArgs(args); - return condition -> { - if (Math.random() > chance) return; - String random = msg.get(ThreadLocalRandom.current().nextInt(msg.size())); - random = BukkitPlaceholderManager.getInstance().parse(condition.getPlayer(), random, condition.getArgs()); - AdventureHelper.getInstance().sendPlayerMessage(condition.getPlayer(), random); - }; - }); - } - - private void registerCommandAction() { - registerAction("command", (args, chance) -> { - ArrayList cmd = ConfigUtils.stringListArgs(args); - return condition -> { - if (Math.random() > chance) return; - List replaced = BukkitPlaceholderManager.getInstance().parse( - condition.getPlayer(), - cmd, - condition.getArgs() - ); - plugin.getScheduler().runTaskSync(() -> { - for (String text : replaced) { - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), text); - } - }, condition.getLocation()); - }; - }); - registerAction("random-command", (args, chance) -> { - ArrayList cmd = ConfigUtils.stringListArgs(args); - return condition -> { - if (Math.random() > chance) return; - String random = cmd.get(ThreadLocalRandom.current().nextInt(cmd.size())); - random = BukkitPlaceholderManager.getInstance().parse(condition.getPlayer(), random, condition.getArgs()); - String finalRandom = random; - plugin.getScheduler().runTaskSync(() -> { - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), finalRandom); - }, condition.getLocation()); - }; - }); - registerAction("command-nearby", (args, chance) -> { - if (args instanceof ConfigurationSection section) { - List cmd = section.getStringList("command"); - int range = section.getInt("range"); - return condition -> { - if (Math.random() > chance) return; - Player owner = condition.getPlayer(); - plugin.getScheduler().runTaskSync(() -> { - for (Entity player : condition.getLocation().getWorld().getNearbyEntities(condition.getLocation(), range, range, range, entity -> entity instanceof Player)) { - double distance = LocationUtils.getDistance(player.getLocation(), condition.getLocation()); - if (distance <= range) { - condition.insertArg("{near}", player.getName()); - List replaced = BukkitPlaceholderManager.getInstance().parse( - owner, - cmd, - condition.getArgs() - ); - for (String text : replaced) { - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), text); - } - condition.delArg("{near}"); - } - } - }, condition.getLocation()); - }; - } else { - LogUtils.warn("Illegal value format found at action: command-nearby"); - return EmptyAction.INSTANCE; - } - }); - } - - private void registerCloseInvAction() { - registerAction("close-inv", (args, chance) -> condition -> { - if (Math.random() > chance) return; - condition.getPlayer().closeInventory(); - }); - } - - private void registerActionBarAction() { - registerAction("actionbar", (args, chance) -> { - return context -> { - }; - }); - registerAction("random-actionbar", (args, chance) -> { - ArrayList texts = ConfigUtils.stringListArgs(args); - return condition -> { - if (Math.random() > chance) return; - String random = texts.get(ThreadLocalRandom.current().nextInt(texts.size())); - random = BukkitPlaceholderManager.getInstance().parse(condition.getPlayer(), random, condition.getArgs()); - AdventureHelper.getInstance().sendActionbar(condition.getPlayer(), random); - }; - }); - registerAction("actionbar-nearby", (args, chance) -> { - if (args instanceof ConfigurationSection section) { - String actionbar = section.getString("actionbar"); - int range = section.getInt("range"); - return condition -> { - if (Math.random() > chance) return; - Player owner = condition.getPlayer(); - plugin.getScheduler().runTaskSync(() -> { - for (Entity player : condition.getLocation().getWorld().getNearbyEntities(condition.getLocation(), range, range, range, entity -> entity instanceof Player)) { - double distance = LocationUtils.getDistance(player.getLocation(), condition.getLocation()); - if (distance <= range) { - condition.insertArg("{near}", player.getName()); - String replaced = BukkitPlaceholderManager.getInstance().parse( - owner, - actionbar, - condition.getArgs() - ); - AdventureHelper.getInstance().sendActionbar((Player) player, replaced); - condition.delArg("{near}"); - } - } - }, condition.getLocation() - ); - }; - } else { - LogUtils.warn("Illegal value format found at action: command-nearby"); - return EmptyAction.INSTANCE; - } - }); - } - - private void registerMendingAction() { - registerAction("mending", (args, chance) -> { - var value = ConfigUtils.getValue(args); - return condition -> { - if (Math.random() > chance) return; - if (BukkitCustomFishingPlugin.get().getVersionManager().isSpigot()) { - condition.getPlayer().getLocation().getWorld().spawn(condition.getPlayer().getLocation(), ExperienceOrb.class, e -> e.setExperience((int) value.get(condition.getPlayer(), condition.getArgs()))); - } else { - condition.getPlayer().giveExp((int) value.get(condition.getPlayer(), condition.getArgs()), true); - AdventureHelper.getInstance().sendSound(condition.getPlayer(), Sound.Source.PLAYER, Key.key("minecraft:entity.experience_orb.pickup"), 1, 1); - } - }; - }); - } - - private void registerFoodAction() { - registerAction("food", (args, chance) -> { - var value = ConfigUtils.getValue(args); - return condition -> { - if (Math.random() > chance) return; - Player player = condition.getPlayer(); - player.setFoodLevel((int) (player.getFoodLevel() + value.get(player, condition.getArgs()))); - }; - }); - registerAction("saturation", (args, chance) -> { - var value = ConfigUtils.getValue(args); - return condition -> { - if (Math.random() > chance) return; - Player player = condition.getPlayer(); - player.setSaturation((float) (player.getSaturation() + value.get(player, condition.getArgs()))); - }; - }); - } - - private void registerExpAction() { - registerAction("exp", (args, chance) -> { - var value = ConfigUtils.getValue(args); - return condition -> { - if (Math.random() > chance) return; - condition.getPlayer().giveExp((int) value.get(condition.getPlayer(), condition.getArgs())); - AdventureHelper.getInstance().sendSound(condition.getPlayer(), Sound.Source.PLAYER, Key.key("minecraft:entity.experience_orb.pickup"), 1, 1); - }; - }); - } - - private void registerHologramAction() { - registerAction("hologram", (args, chance) -> { - if (args instanceof ConfigurationSection section) { - String text = section.getString("text", ""); - int duration = section.getInt("duration", 20); - boolean position = section.getString("position", "other").equals("other"); - double x = section.getDouble("x"); - double y = section.getDouble("y"); - double z = section.getDouble("z"); - int range = section.getInt("range", 16); - return condition -> { - if (Math.random() > chance) return; - Player owner = condition.getPlayer(); - Location location = position ? condition.getLocation() : owner.getLocation(); - if (range > 0) { - plugin.getScheduler().runTaskSync(() -> { - for (Entity player : location.getWorld().getNearbyEntities(location, range, range, range, entity -> entity instanceof Player)) { - double distance = LocationUtils.getDistance(player.getLocation(), location); - if (distance <= range) { - ArmorStandUtils.sendHologram( - (Player) player, - location.clone().add(x, y, z), - AdventureHelper.getInstance().getComponentFromMiniMessage( - BukkitPlaceholderManager.getInstance().parse(owner, text, condition.getArgs()) - ), - duration - ); - } - } - }, location - ); - } else { - ArmorStandUtils.sendHologram( - owner, - location.clone().add(x, y, z), - AdventureHelper.getInstance().getComponentFromMiniMessage( - BukkitPlaceholderManager.getInstance().parse(owner, text, condition.getArgs()) - ), - duration - ); - } - }; - } else { - LogUtils.warn("Illegal value format found at action: hologram"); - return EmptyAction.INSTANCE; - } - }); - } - - private void registerItemAmountAction() { - registerAction("item-amount", (args, chance) -> { - if (args instanceof ConfigurationSection section) { - boolean mainOrOff = section.getString("hand", "main").equalsIgnoreCase("main"); - int amount = section.getInt("amount", 1); - return condition -> { - if (Math.random() > chance) return; - Player player = condition.getPlayer(); - ItemStack itemStack = mainOrOff ? player.getInventory().getItemInMainHand() : player.getInventory().getItemInOffHand(); - itemStack.setAmount(Math.max(0, itemStack.getAmount() + amount)); - }; - } else { - LogUtils.warn("Illegal value format found at action: item-amount"); - return EmptyAction.INSTANCE; - } - }); - } - - private void registerItemDurabilityAction() { - registerAction("durability", (args, chance) -> { - if (args instanceof ConfigurationSection section) { - EquipmentSlot slot = EquipmentSlot.valueOf(section.getString("slot", "hand").toUpperCase(Locale.ENGLISH)); - int amount = section.getInt("amount", 1); - return condition -> { - if (Math.random() > chance) return; - Player player = condition.getPlayer(); - ItemStack itemStack = player.getInventory().getItem(slot); - if (amount > 0) { - ItemUtils.increaseDurability(itemStack, amount, true); - } else { - ItemUtils.decreaseDurability(condition.getPlayer(), itemStack, -amount, true); - } - }; - } else { - LogUtils.warn("Illegal value format found at action: durability"); - return EmptyAction.INSTANCE; - } - }); - } - - private void registerGiveItemAction() { - registerAction("give-item", (args, chance) -> { - if (args instanceof ConfigurationSection section) { - String id = section.getString("item"); - int amount = section.getInt("amount", 1); - return condition -> { - if (Math.random() > chance) return; - Player player = condition.getPlayer(); - ItemUtils.giveItem(player, Objects.requireNonNull(BukkitCustomFishingPlugin.get().getItemManager().buildAnyPluginItemByID(player, id)), amount); - }; - } else { - LogUtils.warn("Illegal value format found at action: give-item"); - return EmptyAction.INSTANCE; - } - }); - } - - private void registerFakeItemAction() { - registerAction("fake-item", (args, chance) -> { - if (args instanceof ConfigurationSection section) { - String[] itemSplit = section.getString("item", "").split(":", 2); - int duration = section.getInt("duration", 20); - boolean position = !section.getString("position", "player").equals("player"); - String x = ConfigUtils.getString(section.get("x", "0")); - String y = ConfigUtils.getString(section.get("y", "0")); - String z = ConfigUtils.getString(section.get("z", "0")); - String yaw = ConfigUtils.getString(section.get("yaw", "0")); - int range = section.getInt("range", 0); - boolean opposite = section.getBoolean("opposite-yaw", false); - return condition -> { - if (Math.random() > chance) return; - Player owner = condition.getPlayer(); - Location location = position ? condition.getLocation() : owner.getLocation(); - location = location.clone().add( - plugin.getPlaceholderManager().getExpressionValue(owner, x, condition.getArgs()), - plugin.getPlaceholderManager().getExpressionValue(owner, y, condition.getArgs()), - plugin.getPlaceholderManager().getExpressionValue(owner, z, condition.getArgs()) - ); - Location finalLocation = location; - ItemStack itemStack = plugin.getItemManager().buildInternal( - owner, itemSplit[0], - plugin.getPlaceholderManager().parse(owner, itemSplit[1], condition.getArgs()), - condition.getArgs() - ); - if (range > 0) { - plugin.getScheduler().runTaskSync(() -> { - for (Entity player : finalLocation.getWorld().getNearbyEntities(finalLocation, range, range, range, entity -> entity instanceof Player)) { - double distance = LocationUtils.getDistance(player.getLocation(), finalLocation); - if (distance <= range) { - Location locationTemp = finalLocation.clone(); - if (opposite) locationTemp.setYaw(-player.getLocation().getYaw()); - else locationTemp.setYaw((float) plugin.getPlaceholderManager().getExpressionValue((Player) player, yaw, condition.getArgs())); - ArmorStandUtils.sendFakeItem( - condition.getPlayer(), - locationTemp, - itemStack, - duration - ); - } - } - }, condition.getLocation() - ); - } else { - if (opposite) finalLocation.setYaw(-owner.getLocation().getYaw()); - else finalLocation.setYaw((float) plugin.getPlaceholderManager().getExpressionValue(owner, yaw, condition.getArgs())); - ArmorStandUtils.sendFakeItem( - condition.getPlayer(), - finalLocation, - itemStack, - duration - ); - } - }; - } else { - LogUtils.warn("Illegal value format found at action: fake-item"); - return EmptyAction.INSTANCE; - } - }); - } - - private void registerChainAction() { - registerAction("chain", (args, chance) -> { - List actions = new ArrayList<>(); - if (args instanceof ConfigurationSection section) { - for (Map.Entry entry : section.getValues(false).entrySet()) { - if (entry.getValue() instanceof ConfigurationSection innerSection) { - actions.add(getAction(innerSection)); - } - } - } - return condition -> { - if (Math.random() > chance) return; - for (Action action : actions) { - action.trigger(condition); - } - }; - }); - } - - private void registerMoneyAction() { - registerAction("give-money", (args, chance) -> { - var value = ConfigUtils.getValue(args); - return condition -> { - if (Math.random() > chance) return; - VaultHook.getEconomy().depositPlayer(condition.getPlayer(), value.get(condition.getPlayer(), condition.getArgs())); - }; - }); - registerAction("take-money", (args, chance) -> { - var value = ConfigUtils.getValue(args); - return condition -> { - if (Math.random() > chance) return; - VaultHook.getEconomy().withdrawPlayer(condition.getPlayer(), value.get(condition.getPlayer(), condition.getArgs())); - }; - }); - } - - private void registerDelayedAction() { - registerAction("delay", (args, chance) -> { - List actions = new ArrayList<>(); - int delay; - boolean async; - if (args instanceof ConfigurationSection section) { - delay = section.getInt("delay", 1); - async = section.getBoolean("async", false); - ConfigurationSection actionSection = section.getConfigurationSection("actions"); - if (actionSection != null) { - for (Map.Entry entry : actionSection.getValues(false).entrySet()) { - if (entry.getValue() instanceof ConfigurationSection innerSection) { - actions.add(getAction(innerSection)); - } - } - } - } else { - delay = 1; - async = false; - } - return condition -> { - if (Math.random() > chance) return; - if (async) { - plugin.getScheduler().runTaskSyncLater(() -> { - for (Action action : actions) { - action.trigger(condition); - } - }, condition.getLocation(), delay * 50L, TimeUnit.MILLISECONDS); - } else { - plugin.getScheduler().runTaskSyncLater(() -> { - for (Action action : actions) { - action.trigger(condition); - } - }, condition.getLocation(), delay * 50L, TimeUnit.MILLISECONDS); - } - }; - }); - } - - private void registerTimerAction() { - registerAction("timer", (args, chance) -> { - List actions = new ArrayList<>(); - int delay; - int duration; - int period; - boolean async; - if (args instanceof ConfigurationSection section) { - delay = section.getInt("delay", 2); - duration = section.getInt("duration", 20); - period = section.getInt("period", 2); - async = section.getBoolean("async", false); - ConfigurationSection actionSection = section.getConfigurationSection("actions"); - if (actionSection != null) { - for (Map.Entry entry : actionSection.getValues(false).entrySet()) { - if (entry.getValue() instanceof ConfigurationSection innerSection) { - actions.add(getAction(innerSection)); - } - } - } - } else { - delay = 1; - async = false; - duration = 20; - period = 1; - } - return condition -> { - if (Math.random() > chance) return; - CancellableTask cancellableTask; - if (async) { - cancellableTask = plugin.getScheduler().runTaskAsyncTimer(() -> { - for (Action action : actions) { - action.trigger(condition); - } - }, delay * 50L, period * 50L, TimeUnit.MILLISECONDS); - } else { - cancellableTask = plugin.getScheduler().runTaskSyncTimer(() -> { - for (Action action : actions) { - action.trigger(condition); - } - }, condition.getLocation(), delay, period); - } - plugin.getScheduler().runTaskSyncLater(cancellableTask::cancel, condition.getLocation(), duration); - }; - }); - } - - private void registerTitleAction() { - registerAction("title", (args, chance) -> { - if (args instanceof ConfigurationSection section) { - String title = section.getString("title"); - String subtitle = section.getString("subtitle"); - int fadeIn = section.getInt("fade-in", 20); - int stay = section.getInt("stay", 30); - int fadeOut = section.getInt("fade-out", 10); - return condition -> { - if (Math.random() > chance) return; - AdventureHelper.getInstance().sendTitle( - condition.getPlayer(), - BukkitPlaceholderManager.getInstance().parse(condition.getPlayer(), title, condition.getArgs()), - BukkitPlaceholderManager.getInstance().parse(condition.getPlayer(), subtitle, condition.getArgs()), - fadeIn, - stay, - fadeOut - ); - }; - } else { - LogUtils.warn("Illegal value format found at action: title"); - return EmptyAction.INSTANCE; - } - }); - registerAction("title-nearby", (args, chance) -> { - if (args instanceof ConfigurationSection section) { - String title = section.getString("title"); - String subtitle = section.getString("subtitle"); - int fadeIn = section.getInt("fade-in", 20); - int stay = section.getInt("stay", 30); - int fadeOut = section.getInt("fade-out", 10); - int range = section.getInt("range", 0); - return condition -> { - if (Math.random() > chance) return; - plugin.getScheduler().runTaskSync(() -> { - for (Entity player : condition.getLocation().getWorld().getNearbyEntities(condition.getLocation(), range, range, range, entity -> entity instanceof Player)) { - double distance = LocationUtils.getDistance(player.getLocation(), condition.getLocation()); - if (distance <= range) { - condition.insertArg("{near}", player.getName()); - AdventureHelper.getInstance().sendTitle( - condition.getPlayer(), - BukkitPlaceholderManager.getInstance().parse(condition.getPlayer(), title, condition.getArgs()), - BukkitPlaceholderManager.getInstance().parse(condition.getPlayer(), subtitle, condition.getArgs()), - fadeIn, - stay, - fadeOut - ); - condition.delArg("{near}"); - } - } - }, condition.getLocation() - ); - }; - } else { - LogUtils.warn("Illegal value format found at action: title-nearby"); - return EmptyAction.INSTANCE; - } - }); - registerAction("random-title", (args, chance) -> { - if (args instanceof ConfigurationSection section) { - List titles = section.getStringList("titles"); - if (titles.size() == 0) titles.add(""); - List subtitles = section.getStringList("subtitles"); - if (subtitles.size() == 0) subtitles.add(""); - int fadeIn = section.getInt("fade-in", 20); - int stay = section.getInt("stay", 30); - int fadeOut = section.getInt("fade-out", 10); - return condition -> { - if (Math.random() > chance) return; - AdventureHelper.getInstance().sendTitle( - condition.getPlayer(), - BukkitPlaceholderManager.getInstance().parse(condition.getPlayer(), titles.get(ThreadLocalRandom.current().nextInt(titles.size())), condition.getArgs()), - BukkitPlaceholderManager.getInstance().parse(condition.getPlayer(), subtitles.get(ThreadLocalRandom.current().nextInt(subtitles.size())), condition.getArgs()), - fadeIn, - stay, - fadeOut - ); - }; - } else { - LogUtils.warn("Illegal value format found at action: random-title"); - return EmptyAction.INSTANCE; - } - }); - } - - private void registerPotionAction() { - registerAction("potion-effect", (args, chance) -> { - if (args instanceof ConfigurationSection section) { - PotionEffect potionEffect = new PotionEffect( - Objects.requireNonNull(PotionEffectType.getByName(section.getString("type", "BLINDNESS").toUpperCase(Locale.ENGLISH))), - section.getInt("duration", 20), - section.getInt("amplifier", 0) - ); - return condition -> { - if (Math.random() > chance) return; - condition.getPlayer().addPotionEffect(potionEffect); - }; - } else { - LogUtils.warn("Illegal value format found at action: potion-effect"); - return EmptyAction.INSTANCE; - } - }); - } - - private void registerLevelAction() { - registerAction("level", (args, chance) -> { - var value = ConfigUtils.getValue(args); - return condition -> { - if (Math.random() > chance) return; - Player player = condition.getPlayer(); - player.setLevel((int) Math.max(0, player.getLevel() + value.get(condition.getPlayer(), condition.getArgs()))); - }; - }); - } - - @SuppressWarnings("all") - private void registerSoundAction() { - registerAction("sound", (args, chance) -> { - if (args instanceof ConfigurationSection section) { - Sound sound = Sound.sound( - Key.key(section.getString("key")), - Sound.Source.valueOf(section.getString("source", "PLAYER").toUpperCase(Locale.ENGLISH)), - (float) section.getDouble("volume", 1), - (float) section.getDouble("pitch", 1) - ); - return condition -> { - if (Math.random() > chance) return; - AdventureHelper.getInstance().sendSound(condition.getPlayer(), sound); - }; - } else { - LogUtils.warn("Illegal value format found at action: sound"); - return EmptyAction.INSTANCE; - } - }); - } - - private void registerConditionalAction() { - registerAction("conditional", (args, chance) -> { - if (args instanceof ConfigurationSection section) { - Action[] actions = getActions(section.getConfigurationSection("actions")); - Requirement[] requirements = plugin.getRequirementManager().parseRequirements(section.getConfigurationSection("conditions"), true); - return condition -> { - if (Math.random() > chance) return; - if (requirements != null) - for (Requirement requirement : requirements) { - if (!requirement.check(condition)) { - return; - } - } - for (Action action : actions) { - action.trigger(condition); - } - }; - } else { - LogUtils.warn("Illegal value format found at action: conditional"); - return EmptyAction.INSTANCE; - } - }); - } - - private void registerPriorityAction() { - registerAction("priority", (args, chance) -> { - if (args instanceof ConfigurationSection section) { - List> conditionActionPairList = new ArrayList<>(); - for (Map.Entry entry : section.getValues(false).entrySet()) { - if (entry.getValue() instanceof ConfigurationSection inner) { - Action[] actions = getActions(inner.getConfigurationSection("actions")); - Requirement[] requirements = plugin.getRequirementManager().parseRequirements(inner.getConfigurationSection("conditions"), false); - conditionActionPairList.add(Pair.of(requirements, actions)); - } - } - return condition -> { - if (Math.random() > chance) return; - outer: - for (Pair pair : conditionActionPairList) { - if (pair.left() != null) - for (Requirement requirement : pair.left()) { - if (!requirement.check(condition)) { - continue outer; - } - } - if (pair.right() != null) - for (Action action : pair.right()) { - action.trigger(condition); - } - return; - } - }; - } else { - LogUtils.warn("Illegal value format found at action: priority"); - return EmptyAction.INSTANCE; - } - }); - } - - private void registerPluginExpAction() { - registerAction("plugin-exp", (args, chance) -> { - if (args instanceof ConfigurationSection section) { - String pluginName = section.getString("plugin"); - var value = ConfigUtils.getValue(section.get("exp")); - String target = section.getString("target"); - return condition -> { - if (Math.random() > chance) return; - Optional.ofNullable(plugin.getIntegrationManager().getLevelPlugin(pluginName)).ifPresentOrElse(it -> { - it.addXp(condition.getPlayer(), target, value.get(condition.getPlayer(), condition.getArgs())); - }, () -> LogUtils.warn("Plugin (" + pluginName + "'s) level is not compatible. Please double check if it's a problem caused by pronunciation.")); - }; - } else { - LogUtils.warn("Illegal value format found at action: plugin-exp"); - return EmptyAction.INSTANCE; - } - }); - } - - private void registerFishFindAction() { - registerAction("fish-finder", (args, chance) -> { - boolean arg = (boolean) args; - return condition -> { - if (Math.random() > chance) return; - condition.insertArg("{lava}", String.valueOf(arg)); - LootManager lootManager = plugin.getLootManager(); - List loots = plugin.getLootManager().getPossibleLootKeys(condition).stream().map(lootManager::getLoot).filter(Objects::nonNull).filter(Loot::showInFinder).map(Loot::getNick).toList(); - StringJoiner stringJoiner = new StringJoiner(CFLocale.MSG_Split_Char); - for (String loot : loots) { - stringJoiner.add(loot); - } - condition.delArg("{lava}"); - AdventureHelper.getInstance().sendMessageWithPrefix(condition.getPlayer(), CFLocale.MSG_Possible_Loots + stringJoiner); - }; - }); - } -} diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/BukkitFishingManager.java b/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/BukkitFishingManager.java deleted file mode 100644 index d9ac85d7..00000000 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/fishing/BukkitFishingManager.java +++ /dev/null @@ -1,4 +0,0 @@ -package net.momirealms.customfishing.mechanic.fishing; - -public class BukkitFishingManager { -} diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/requirement/BukkitRequirementManager.java b/core/src/main/java/net/momirealms/customfishing/mechanic/requirement/BukkitRequirementManager.java deleted file mode 100644 index 44c928fd..00000000 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/requirement/BukkitRequirementManager.java +++ /dev/null @@ -1,4 +0,0 @@ -package net.momirealms.customfishing.mechanic.requirement; - -public class BukkitRequirementManager { -} diff --git a/core/src/main/java/net/momirealms/customfishing/mechanic/requirement/RequirementManagerImpl.java b/core/src/main/java/net/momirealms/customfishing/mechanic/requirement/RequirementManagerImpl.java deleted file mode 100644 index 5fcf9dc3..00000000 --- a/core/src/main/java/net/momirealms/customfishing/mechanic/requirement/RequirementManagerImpl.java +++ /dev/null @@ -1,1389 +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.mechanic.requirement; - -import net.momirealms.customfishing.BukkitCustomFishingPluginImpl; -import net.momirealms.customfishing.api.common.Pair; -import net.momirealms.customfishing.api.integration.LevelerProvider; -import net.momirealms.customfishing.api.integration.SeasonProvider; -import net.momirealms.customfishing.api.mechanic.action.Action; -import net.momirealms.customfishing.api.mechanic.competition.FishingCompetition; -import net.momirealms.customfishing.api.mechanic.loot.Loot; -import net.momirealms.customfishing.api.mechanic.requirement.*; -import net.momirealms.customfishing.bukkit.compatibility.VaultHook; -import net.momirealms.customfishing.bukkit.misc.placeholder.papi.ParseUtils; -import net.momirealms.customfishing.common.util.ClassUtils; -import net.momirealms.customfishing.util.ConfigUtils; -import net.momirealms.customfishing.util.MoonPhase; -import net.momirealms.sparrow.heart.SparrowHeart; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.MemorySection; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.util.*; - -public class RequirementManagerImpl implements RequirementManager { - - public static Requirement[] mechanicRequirements; - private final BukkitCustomFishingPluginImpl plugin; - private final HashMap requirementFactoryMap; - private final LinkedHashMap conditionalLootsMap; - private final LinkedHashMap conditionalGamesMap; - private final String EXPANSION_FOLDER = "expansions/requirement"; - - public RequirementManagerImpl(BukkitCustomFishingPluginImpl plugin) { - this.plugin = plugin; - this.requirementFactoryMap = new HashMap<>(); - this.conditionalLootsMap = new LinkedHashMap<>(); - this.conditionalGamesMap = new LinkedHashMap<>(); - this.registerInbuiltRequirements(); - } - - public void load() { - this.loadExpansions(); - this.loadRequirementGroupFileConfig(); - } - - public void unload() { - this.conditionalLootsMap.clear(); - } - - public void disable() { - this.requirementFactoryMap.clear(); - this.conditionalLootsMap.clear(); - } - - @Override - public boolean putLegacyLootToMap(String key, Requirement[] requirements, double weight) { - if (conditionalLootsMap.containsKey("LEGACY_" + key)) { - return false; - } else { - conditionalLootsMap.put("LEGACY_" + key, new ConditionalElement(requirements, List.of(Pair.of(key, (player, origin) -> weight + origin)), new HashMap<>())); - return true; - } - } - - /** - * Loads requirement group configuration data from various configuration files. - */ - public void loadRequirementGroupFileConfig() { - // Load mechanic requirements from the main configuration file - YamlConfiguration main = plugin.getConfig("config.yml"); - mechanicRequirements = getRequirements(main.getConfigurationSection("mechanics.mechanic-requirements"), true); - - // Load conditional loot data from the loot conditions configuration file - YamlConfiguration config1 = plugin.getConfig("loot-conditions.yml"); - for (Map.Entry entry : config1.getValues(false).entrySet()) { - if (entry.getValue() instanceof ConfigurationSection section) { - conditionalLootsMap.put(entry.getKey(), getConditionalElements(section)); - } - } - - // Load conditional game data from the game conditions configuration file - YamlConfiguration config2 = plugin.getConfig("game-conditions.yml"); - for (Map.Entry entry : config2.getValues(false).entrySet()) { - if (entry.getValue() instanceof ConfigurationSection section) { - conditionalGamesMap.put(entry.getKey(), getConditionalElements(section)); - } - } - } - - /** - * Registers a custom requirement type with its corresponding factory. - * - * @param type The type identifier of the requirement. - * @param requirementFactory The factory responsible for creating instances of the requirement. - * @return True if registration was successful, false if the type is already registered. - */ - @Override - public boolean registerRequirement(@NotNull String type, @NotNull RequirementFactory requirementFactory) { - if (this.requirementFactoryMap.containsKey(type)) return false; - this.requirementFactoryMap.put(type, requirementFactory); - return true; - } - - /** - * Unregisters a custom requirement type. - * - * @param type The type identifier of the requirement to unregister. - * @return True if unregistration was successful, false if the type is not registered. - */ - @Override - public boolean unregisterRequirement(@NotNull String type) { - return this.requirementFactoryMap.remove(type) != null; - } - - /** - * Retrieves a ConditionalElement from a given ConfigurationSection. - * - * @param section The ConfigurationSection containing the conditional element data. - * @return A ConditionalElement instance representing the data in the section. - */ - private ConditionalElement getConditionalElements(ConfigurationSection section) { - var sub = section.getConfigurationSection("sub-groups"); - if (sub == null) { - return new ConditionalElement( - getRequirements(section.getConfigurationSection("conditions"), false), - ConfigUtils.getModifiers(section.getStringList("list")), - null - ); - } else { - HashMap subElements = new HashMap<>(); - for (Map.Entry entry : sub.getValues(false).entrySet()) { - if (entry.getValue() instanceof ConfigurationSection innerSection) { - subElements.put(entry.getKey(), getConditionalElements(innerSection)); - } - } - return new ConditionalElement( - getRequirements(section.getConfigurationSection("conditions"), false), - ConfigUtils.getModifiers(section.getStringList("list")), - subElements - ); - } - } - - private void registerInbuiltRequirements() { - this.registerTimeRequirement(); - this.registerYRequirement(); - this.registerContainRequirement(); - this.registerStartWithRequirement(); - this.registerEndWithRequirement(); - this.registerEqualsRequirement(); - this.registerBiomeRequirement(); - this.registerMoonPhaseRequirement(); - this.registerDateRequirement(); - this.registerPluginLevelRequirement(); - this.registerPermissionRequirement(); - this.registerWorldRequirement(); - this.registerWeatherRequirement(); - this.registerSeasonRequirement(); - this.registerLavaFishingRequirement(); - this.registerRodRequirement(); - this.registerBaitRequirement(); - this.registerGreaterThanRequirement(); - this.registerAndRequirement(); - this.registerOrRequirement(); - this.registerLevelRequirement(); - this.registerRandomRequirement(); - this.registerIceFishingRequirement(); - this.registerOpenWaterRequirement(); - this.registerCoolDownRequirement(); - this.registerGroupRequirement(); - this.registerLootRequirement(); - this.registerLessThanRequirement(); - this.registerNumberEqualRequirement(); - this.registerRegexRequirement(); - this.registerItemInHandRequirement(); - this.registerMoneyRequirement(); - this.registerInBagRequirement(); - this.registerHookRequirement(); - this.registerCompetitionRequirement(); - this.registerListRequirement(); - this.registerEnvironmentRequirement(); - this.registerPotionEffectRequirement(); - this.registerSizeRequirement(); - this.registerHasStatsRequirement(); - this.registerLootTypeRequirement(); - this.registerInListRequirement(); - } - - public HashMap getLootWithWeight(PlayerContext playerContext) { - return getString2DoubleMap(playerContext, conditionalLootsMap); - } - - public HashMap getGameWithWeight(PlayerContext playerContext) { - return getString2DoubleMap(playerContext, conditionalGamesMap); - } - - /** - * Retrieves a mapping of strings to doubles based on conditional elements and a player's condition. - * - * @param playerContext The player's condition. - * @param conditionalGamesMap The map of conditional elements representing loots/games. - * @return A HashMap with strings as keys and doubles as values representing loot/game weights. - */ - @NotNull - private HashMap getString2DoubleMap(PlayerContext playerContext, LinkedHashMap conditionalGamesMap) { - HashMap lootWeightMap = new HashMap<>(); - Queue> lootQueue = new LinkedList<>(); - lootQueue.add(conditionalGamesMap); - Player player = playerContext.getPlayer(); - while (!lootQueue.isEmpty()) { - HashMap currentLootMap = lootQueue.poll(); - for (ConditionalElement loots : currentLootMap.values()) { - if (RequirementManager.isRequirementMet(playerContext, loots.getRequirements())) { - loots.combine(player, lootWeightMap); - if (loots.getSubElements() != null) { - lootQueue.add(loots.getSubElements()); - } - } - } - } - return lootWeightMap; - } - - /** - * Retrieves an array of requirements based on a configuration section. - * - * @param section The configuration section containing requirement definitions. - * @param advanced A flag indicating whether to use advanced requirements. - * @return An array of Requirement objects based on the configuration section - */ - @NotNull - @Override - public Requirement[] getRequirements(ConfigurationSection section, boolean advanced) { - List requirements = new ArrayList<>(); - if (section == null) { - return requirements.toArray(new Requirement[0]); - } - for (Map.Entry entry : section.getValues(false).entrySet()) { - String typeOrName = entry.getKey(); - if (hasRequirement(typeOrName)) { - requirements.add(parseRequirement(typeOrName, entry.getValue())); - } else { - requirements.add(getRequirement(section.getConfigurationSection(typeOrName), advanced)); - } - } - return requirements.toArray(new Requirement[0]); - } - - @Override - public boolean hasRequirement(@NotNull String type) { - return requirementFactoryMap.containsKey(type); - } - - /** - * Retrieves a Requirement object based on a configuration section and advanced flag. - * - * @param section The configuration section containing requirement definitions. - * @param advanced A flag indicating whether to use advanced requirements. - * @return A Requirement object based on the configuration section, or an EmptyRequirement if the section is null or invalid. - */ - @NotNull - @Override - public Requirement getRequirement(ConfigurationSection section, boolean advanced) { - if (section == null) return EmptyRequirement.INSTANCE; - List actionList = null; - if (advanced) { - actionList = new ArrayList<>(); - if (section.contains("not-met-actions")) { - for (Map.Entry entry : Objects.requireNonNull(section.getConfigurationSection("not-met-actions")).getValues(false).entrySet()) { - if (entry.getValue() instanceof MemorySection inner) { - actionList.add(plugin.getActionManager().getAction(inner)); - } - } - } - if (actionList.size() == 0) - actionList = null; - } - String type = section.getString("type"); - if (type == null) { - LogUtils.warn("No requirement type found at " + section.getCurrentPath()); - return EmptyRequirement.INSTANCE; - } - var builder = getRequirementFactory(type); - if (builder == null) { - return EmptyRequirement.INSTANCE; - } - return builder.build(section.get("value"), actionList, advanced); - } - - /** - * Gets a requirement based on the provided key and value. - * If a valid RequirementFactory is found for the key, it is used to create the requirement. - * If no factory is found, a warning is logged, and an empty requirement instance is returned. - * - * @param type The key representing the requirement type. - * @param value The value associated with the requirement. - * @return A Requirement instance based on the key and value, or an empty requirement if not found. - */ - @Override - @NotNull - public Requirement parseRequirement(@NotNull String type, @NotNull Object value) { - RequirementFactory factory = getRequirementFactory(type); - if (factory == null) { - LogUtils.warn("Requirement type: " + type + " doesn't exist."); - return EmptyRequirement.INSTANCE; - } - return factory.build(value); - } - - /** - * Retrieves a RequirementFactory based on the specified requirement type. - * - * @param type The requirement type for which to retrieve a factory. - * @return A RequirementFactory for the specified type, or null if no factory is found. - */ - @Override - @Nullable - public RequirementFactory getRequirementFactory(@NotNull String type) { - return requirementFactoryMap.get(type); - } - - private void registerTimeRequirement() { - registerRequirement("time", (args, actions, advanced) -> { - List> timePairs = ConfigUtils.stringListArgs(args).stream().map(it -> ConfigUtils.splitStringIntegerArgs(it, "~")).toList(); - return condition -> { - long time = condition.getLocation().getWorld().getTime(); - for (Pair pair : timePairs) - if (time >= pair.left() && time <= pair.right()) - return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - } - - private void registerGroupRequirement() { - registerRequirement("group", (args, actions, advanced) -> { - HashSet arg = new HashSet<>(ConfigUtils.stringListArgs(args)); - return condition -> { - String lootID = condition.getArg("{loot}"); - Loot loot = plugin.getLootManager().getLoot(lootID); - String[] groups = loot.lootGroup(); - if (groups != null) { - for (String g : groups) { - if (arg.contains(g)) { - return true; - } - } - } - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - registerRequirement("!group", (args, actions, advanced) -> { - HashSet arg = new HashSet<>(ConfigUtils.stringListArgs(args)); - return condition -> { - String lootID = condition.getArg("{loot}"); - Loot loot = plugin.getLootManager().getLoot(lootID); - String[] groups = loot.lootGroup(); - if (groups == null) { - return true; - } - outer: { - for (String g : groups) { - if (arg.contains(g)) { - break outer; - } - } - return true; - } - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - } - - private void registerLootRequirement() { - registerRequirement("loot", (args, actions, advanced) -> { - HashSet arg = new HashSet<>(ConfigUtils.stringListArgs(args)); - return condition -> { - String lootID = condition.getArg("{loot}"); - if (arg.contains(lootID)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - registerRequirement("!loot", (args, actions, advanced) -> { - HashSet arg = new HashSet<>(ConfigUtils.stringListArgs(args)); - return condition -> { - String lootID = condition.getArg("{loot}"); - if (!arg.contains(lootID)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - } - - private void registerYRequirement() { - registerRequirement("ypos", (args, actions, advanced) -> { - List> timePairs = ConfigUtils.stringListArgs(args).stream().map(it -> ConfigUtils.splitStringIntegerArgs(it, "~")).toList(); - return condition -> { - int y = condition.getLocation().getBlockY(); - for (Pair pair : timePairs) - if (y >= pair.left() && y <= pair.right()) - return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - } - - private void registerOrRequirement() { - registerRequirement("||", (args, actions, advanced) -> { - if (args instanceof ConfigurationSection section) { - Requirement[] requirements = getRequirements(section, advanced); - return condition -> { - for (Requirement requirement : requirements) { - if (requirement.check(condition)) { - return true; - } - } - if (advanced) triggerActions(actions, condition); - return false; - }; - } else { - LogUtils.warn("Wrong value format found at || requirement."); - return EmptyRequirement.INSTANCE; - } - }); - } - - private void registerAndRequirement() { - registerRequirement("&&", (args, actions, advanced) -> { - if (args instanceof ConfigurationSection section) { - Requirement[] requirements = getRequirements(section, advanced); - return condition -> { - outer: { - for (Requirement requirement : requirements) { - if (!requirement.check(condition)) { - break outer; - } - } - return true; - } - if (advanced) triggerActions(actions, condition); - return false; - }; - } else { - LogUtils.warn("Wrong value format found at && requirement."); - return EmptyRequirement.INSTANCE; - } - }); - } - - private void registerLavaFishingRequirement() { - registerRequirement("lava-fishing", (args, actions, advanced) -> { - boolean inLava = (boolean) args; - return condition -> { - String current = condition.getArgs().getOrDefault("{lava}","false"); - if (current.equals(String.valueOf(inLava))) - return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - } - - private void registerOpenWaterRequirement() { - registerRequirement("open-water", (args, actions, advanced) -> { - boolean inLava = (boolean) args; - return condition -> { - String current = condition.getArgs().getOrDefault("{open-water}", "false"); - if (current.equals(String.valueOf(inLava))) - return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - } - - private void registerIceFishingRequirement() { - registerRequirement("ice-fishing", (args, actions, advanced) -> { - boolean iceFishing = (boolean) args; - return condition -> { - Location location = condition.getLocation(); - int water = 0; - int ice = 0; - for (int i = -2; i <= 2; i++) { - for (int j = -1; j <= 2; j++) { - for (int k = -2; k <= 2; k++) { - Block block = location.clone().add(i, j, k).getBlock(); - Material material = block.getType(); - switch (material) { - case ICE -> ice++; - case WATER -> water++; - } - } - } - } - if ((ice >= 16 && water >= 25) == iceFishing) - return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - } - - private void registerLevelRequirement() { - registerRequirement("level", (args, actions, advanced) -> { - int level = (int) args; - return condition -> { - int current = condition.getPlayer().getLevel(); - if (current >= level) - return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - } - - private void registerMoneyRequirement() { - registerRequirement("money", (args, actions, advanced) -> { - double money = ConfigUtils.getDoubleValue(args); - return condition -> { - double current = VaultHook.getBalance(condition.getPlayer()); - if (current >= money) - return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - } - - private void registerRandomRequirement() { - registerRequirement("random", (args, actions, advanced) -> { - double random = ConfigUtils.getDoubleValue(args); - return condition -> { - if (Math.random() < random) - return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - } - - private void registerBiomeRequirement() { - registerRequirement("biome", (args, actions, advanced) -> { - HashSet biomes = new HashSet<>(ConfigUtils.stringListArgs(args)); - return condition -> { - String currentBiome = SparrowHeart.getInstance().getBiomeResourceLocation(condition.getLocation()); - if (biomes.contains(currentBiome)) - return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - registerRequirement("!biome", (args, actions, advanced) -> { - HashSet biomes = new HashSet<>(ConfigUtils.stringListArgs(args)); - return condition -> { - String currentBiome = SparrowHeart.getInstance().getBiomeResourceLocation(condition.getLocation()); - if (!biomes.contains(currentBiome)) - return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - } - - private void registerMoonPhaseRequirement() { - registerRequirement("moon-phase", (args, actions, advanced) -> { - HashSet moonPhases = new HashSet<>(ConfigUtils.stringListArgs(args)); - return condition -> { - long days = condition.getLocation().getWorld().getFullTime() / 24_000; - if (moonPhases.contains(MoonPhase.getPhase(days).name().toLowerCase(Locale.ENGLISH))) - return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - registerRequirement("!moon-phase", (args, actions, advanced) -> { - HashSet moonPhases = new HashSet<>(ConfigUtils.stringListArgs(args)); - return condition -> { - long days = condition.getLocation().getWorld().getFullTime() / 24_000; - if (!moonPhases.contains(MoonPhase.getPhase(days).name().toLowerCase(Locale.ENGLISH))) - return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - } - - private void registerWorldRequirement() { - registerRequirement("world", (args, actions, advanced) -> { - HashSet worlds = new HashSet<>(ConfigUtils.stringListArgs(args)); - return condition -> { - if (worlds.contains(condition.getLocation().getWorld().getName())) - return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - registerRequirement("!world", (args, actions, advanced) -> { - HashSet worlds = new HashSet<>(ConfigUtils.stringListArgs(args)); - return condition -> { - if (!worlds.contains(condition.getLocation().getWorld().getName())) - return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - } - - private void registerWeatherRequirement() { - registerRequirement("weather", (args, actions, advanced) -> { - List weathers = ConfigUtils.stringListArgs(args); - return condition -> { - String currentWeather; - World world = condition.getLocation().getWorld(); - if (world.isClearWeather()) currentWeather = "clear"; - else if (world.isThundering()) currentWeather = "thunder"; - else currentWeather = "rain"; - for (String weather : weathers) - if (weather.equalsIgnoreCase(currentWeather)) - return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - } - - private void registerCoolDownRequirement() { - registerRequirement("cooldown", (args, actions, advanced) -> { - if (args instanceof ConfigurationSection section) { - String key = section.getString("key"); - int time = section.getInt("time"); - return condition -> { - if (!plugin.getCoolDownManager().isCoolDown(condition.getPlayer().getUniqueId(), key, time)) { - return true; - } - if (advanced) triggerActions(actions, condition); - return false; - }; - } else { - LogUtils.warn("Wrong value format found at cooldown requirement."); - return EmptyRequirement.INSTANCE; - } - }); - } - - private void registerDateRequirement() { - registerRequirement("date", (args, actions, advanced) -> { - HashSet dates = new HashSet<>(ConfigUtils.stringListArgs(args)); - return condition -> { - Calendar calendar = Calendar.getInstance(); - String current = (calendar.get(Calendar.MONTH) + 1) + "/" + calendar.get(Calendar.DATE); - if (dates.contains(current)) - return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - } - - private void registerPermissionRequirement() { - registerRequirement("permission", (args, actions, advanced) -> { - List perms = ConfigUtils.stringListArgs(args); - return condition -> { - for (String perm : perms) - if (condition.getPlayer().hasPermission(perm)) - return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - registerRequirement("!permission", (args, actions, advanced) -> { - List perms = ConfigUtils.stringListArgs(args); - return condition -> { - for (String perm : perms) - if (condition.getPlayer().hasPermission(perm)) { - if (advanced) triggerActions(actions, condition); - return false; - } - return true; - }; - }); - } - - private void registerSeasonRequirement() { - registerRequirement("season", (args, actions, advanced) -> { - List seasons = ConfigUtils.stringListArgs(args); - return condition -> { - SeasonProvider seasonProvider = plugin.getIntegrationManager().getSeasonInterface(); - if (seasonProvider == null) return true; - String season = seasonProvider.getSeason(condition.getLocation().getWorld()); - if (seasons.contains(season)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - } - - @SuppressWarnings("DuplicatedCode") - private void registerGreaterThanRequirement() { - registerRequirement(">=", (args, actions, advanced) -> { - if (args instanceof ConfigurationSection section) { - String v1 = section.getString("value1", ""); - String v2 = section.getString("value2", ""); - return condition -> { - String p1 = v1.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v1) : v1; - String p2 = v2.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v2) : v2; - if (Double.parseDouble(p1) >= Double.parseDouble(p2)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - } else { - LogUtils.warn("Wrong value format found at >= requirement."); - return EmptyRequirement.INSTANCE; - } - }); - registerRequirement(">", (args, actions, advanced) -> { - if (args instanceof ConfigurationSection section) { - String v1 = section.getString("value1", ""); - String v2 = section.getString("value2", ""); - return condition -> { - String p1 = v1.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v1) : v1; - String p2 = v2.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v2) : v2; - if (Double.parseDouble(p1) > Double.parseDouble(p2)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - } else { - LogUtils.warn("Wrong value format found at > requirement."); - return EmptyRequirement.INSTANCE; - } - }); - } - - private void registerRegexRequirement() { - registerRequirement("regex", (args, actions, advanced) -> { - if (args instanceof ConfigurationSection section) { - String v1 = section.getString("papi", ""); - String v2 = section.getString("regex", ""); - return condition -> { - if (ParseUtils.setPlaceholders(condition.getPlayer(), v1).matches(v2)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - } else { - LogUtils.warn("Wrong value format found at regex requirement."); - return EmptyRequirement.INSTANCE; - } - }); - } - - private void registerNumberEqualRequirement() { - registerRequirement("==", (args, actions, advanced) -> { - if (args instanceof ConfigurationSection section) { - String v1 = section.getString("value1", ""); - String v2 = section.getString("value2", ""); - return condition -> { - String p1 = v1.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v1) : v1; - String p2 = v2.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v2) : v2; - if (Double.parseDouble(p1) == Double.parseDouble(p2)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - } else { - LogUtils.warn("Wrong value format found at !startsWith requirement."); - return EmptyRequirement.INSTANCE; - } - }); - registerRequirement("!=", (args, actions, advanced) -> { - if (args instanceof ConfigurationSection section) { - String v1 = section.getString("value1", ""); - String v2 = section.getString("value2", ""); - return condition -> { - String p1 = v1.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v1) : v1; - String p2 = v2.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v2) : v2; - if (Double.parseDouble(p1) != Double.parseDouble(p2)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - } else { - LogUtils.warn("Wrong value format found at !startsWith requirement."); - return EmptyRequirement.INSTANCE; - } - }); - } - - @SuppressWarnings("DuplicatedCode") - private void registerLessThanRequirement() { - registerRequirement("<", (args, actions, advanced) -> { - if (args instanceof ConfigurationSection section) { - String v1 = section.getString("value1", ""); - String v2 = section.getString("value2", ""); - return condition -> { - String p1 = v1.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v1) : v1; - String p2 = v2.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v2) : v2; - if (Double.parseDouble(p1) < Double.parseDouble(p2)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - } else { - LogUtils.warn("Wrong value format found at < requirement."); - return EmptyRequirement.INSTANCE; - } - }); - registerRequirement("<=", (args, actions, advanced) -> { - if (args instanceof ConfigurationSection section) { - String v1 = section.getString("value1", ""); - String v2 = section.getString("value2", ""); - return condition -> { - String p1 = v1.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v1) : v1; - String p2 = v2.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v2) : v2; - if (Double.parseDouble(p1) <= Double.parseDouble(p2)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - } else { - LogUtils.warn("Wrong value format found at <= requirement."); - return EmptyRequirement.INSTANCE; - } - }); - } - - private void registerStartWithRequirement() { - registerRequirement("startsWith", (args, actions, advanced) -> { - if (args instanceof ConfigurationSection section) { - String v1 = section.getString("value1", ""); - String v2 = section.getString("value2", ""); - return condition -> { - String p1 = v1.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v1) : v1; - String p2 = v2.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v2) : v2; - if (p1.startsWith(p2)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - } else { - LogUtils.warn("Wrong value format found at startsWith requirement."); - return EmptyRequirement.INSTANCE; - } - }); - registerRequirement("!startsWith", (args, actions, advanced) -> { - if (args instanceof ConfigurationSection section) { - String v1 = section.getString("value1", ""); - String v2 = section.getString("value2", ""); - return condition -> { - String p1 = v1.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v1) : v1; - String p2 = v2.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v2) : v2; - if (!p1.startsWith(p2)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - } else { - LogUtils.warn("Wrong value format found at !startsWith requirement."); - return EmptyRequirement.INSTANCE; - } - }); - } - - private void registerEndWithRequirement() { - registerRequirement("endsWith", (args, actions, advanced) -> { - if (args instanceof ConfigurationSection section) { - String v1 = section.getString("value1", ""); - String v2 = section.getString("value2", ""); - return condition -> { - String p1 = v1.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v1) : v1; - String p2 = v2.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v2) : v2; - if (p1.endsWith(p2)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - } else { - LogUtils.warn("Wrong value format found at endsWith requirement."); - return EmptyRequirement.INSTANCE; - } - }); - registerRequirement("!endsWith", (args, actions, advanced) -> { - if (args instanceof ConfigurationSection section) { - String v1 = section.getString("value1", ""); - String v2 = section.getString("value2", ""); - return condition -> { - String p1 = v1.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v1) : v1; - String p2 = v2.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v2) : v2; - if (!p1.endsWith(p2)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - } else { - LogUtils.warn("Wrong value format found at !endsWith requirement."); - return EmptyRequirement.INSTANCE; - } - }); - } - - private void registerContainRequirement() { - registerRequirement("contains", (args, actions, advanced) -> { - if (args instanceof ConfigurationSection section) { - String v1 = section.getString("value1", ""); - String v2 = section.getString("value2", ""); - return condition -> { - String p1 = v1.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v1) : v1; - String p2 = v2.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v2) : v2; - if (p1.contains(p2)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - } else { - LogUtils.warn("Wrong value format found at contains requirement."); - return EmptyRequirement.INSTANCE; - } - }); - registerRequirement("!contains", (args, actions, advanced) -> { - if (args instanceof ConfigurationSection section) { - String v1 = section.getString("value1", ""); - String v2 = section.getString("value2", ""); - return condition -> { - String p1 = v1.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v1) : v1; - String p2 = v2.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v2) : v2; - if (!p1.contains(p2)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - } else { - LogUtils.warn("Wrong value format found at !contains requirement."); - return EmptyRequirement.INSTANCE; - } - }); - } - - private void registerInListRequirement() { - registerRequirement("in-list", (args, actions, advanced) -> { - if (args instanceof ConfigurationSection section) { - String papi = section.getString("papi", ""); - List values = ConfigUtils.stringListArgs(section.get("values")); - return condition -> { - String p1 = papi.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), papi) : papi; - if (values.contains(p1)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - } else { - LogUtils.warn("Wrong value format found at in-list requirement."); - return EmptyRequirement.INSTANCE; - } - }); - registerRequirement("!in-list", (args, actions, advanced) -> { - if (args instanceof ConfigurationSection section) { - String papi = section.getString("papi", ""); - List values = ConfigUtils.stringListArgs(section.get("values")); - return condition -> { - String p1 = papi.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), papi) : papi; - if (!values.contains(p1)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - } else { - LogUtils.warn("Wrong value format found at in-list requirement."); - return EmptyRequirement.INSTANCE; - } - }); - } - - private void registerEqualsRequirement() { - registerRequirement("equals", (args, actions, advanced) -> { - if (args instanceof ConfigurationSection section) { - String v1 = section.getString("value1", ""); - String v2 = section.getString("value2", ""); - return condition -> { - String p1 = v1.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v1) : v1; - String p2 = v2.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v2) : v2; - if (p1.equals(p2)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - } else { - LogUtils.warn("Wrong value format found at equals requirement."); - return EmptyRequirement.INSTANCE; - } - }); - registerRequirement("!equals", (args, actions, advanced) -> { - if (args instanceof ConfigurationSection section) { - String v1 = section.getString("value1", ""); - String v2 = section.getString("value2", ""); - return condition -> { - String p1 = v1.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v1) : v1; - String p2 = v2.startsWith("%") ? ParseUtils.setPlaceholders(condition.getPlayer(), v2) : v2; - if (!p1.equals(p2)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - } else { - LogUtils.warn("Wrong value format found at !equals requirement."); - return EmptyRequirement.INSTANCE; - } - }); - } - - private void registerRodRequirement() { - registerRequirement("rod", (args, actions, advanced) -> { - List rods = ConfigUtils.stringListArgs(args); - return condition -> { - String id = condition.getArg("{rod}"); - if (rods.contains(id)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - registerRequirement("!rod", (args, actions, advanced) -> { - List rods = ConfigUtils.stringListArgs(args); - return condition -> { - String id = condition.getArg("{rod}"); - if (!rods.contains(id)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - } - - private void registerItemInHandRequirement() { - registerRequirement("item-in-hand", (args, actions, advanced) -> { - if (args instanceof ConfigurationSection section) { - boolean mainOrOff = section.getString("hand","main").equalsIgnoreCase("main"); - int amount = section.getInt("amount", 1); - List items = ConfigUtils.stringListArgs(section.get("item")); - return condition -> { - ItemStack itemStack = mainOrOff ? - condition.getPlayer().getInventory().getItemInMainHand() - : condition.getPlayer().getInventory().getItemInOffHand(); - String id = plugin.getItemManager().getAnyPluginItemID(itemStack); - if (items.contains(id) && itemStack.getAmount() >= amount) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - } else { - LogUtils.warn("Wrong value format found at item-in-hand requirement."); - return EmptyRequirement.INSTANCE; - } - }); - } - - private void registerBaitRequirement() { - registerRequirement("bait", (args, actions, advanced) -> { - List baits = ConfigUtils.stringListArgs(args); - return condition -> { - String id = condition.getArg("{bait}"); - if (baits.contains(id)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - registerRequirement("!bait", (args, actions, advanced) -> { - List baits = ConfigUtils.stringListArgs(args); - return condition -> { - String id = condition.getArg("{bait}"); - if (!baits.contains(id)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - registerRequirement("has-bait", (args, actions, advanced) -> { - boolean has = (boolean) args; - return condition -> { - String id = condition.getArg("{bait}"); - if (id != null && has) return true; - if (id == null && !has) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - } - - private void registerSizeRequirement() { - registerRequirement("has-size", (args, actions, advanced) -> { - boolean has = (boolean) args; - return condition -> { - String size = condition.getArg("{SIZE}"); - if (size != null && has) return true; - if (size == null && !has) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - } - - private void registerHasStatsRequirement() { - registerRequirement("has-stats", (args, actions, advanced) -> { - boolean has = (boolean) args; - return condition -> { - String loot = condition.getArg("{loot}"); - Loot lootInstance = plugin.getLootManager().getLoot(loot); - if (lootInstance != null) { - if (!lootInstance.disableStats() && has) return true; - if (lootInstance.disableStats() && !has) return true; - } - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - } - - private void registerLootTypeRequirement() { - registerRequirement("loot-type", (args, actions, advanced) -> { - List types = ConfigUtils.stringListArgs(args); - return condition -> { - String loot = condition.getArg("{loot}"); - Loot lootInstance = plugin.getLootManager().getLoot(loot); - if (lootInstance != null) { - if (types.contains(lootInstance.getType().name().toLowerCase(Locale.ENGLISH))) return true; - } - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - registerRequirement("!loot-type", (args, actions, advanced) -> { - List types = ConfigUtils.stringListArgs(args); - return condition -> { - String loot = condition.getArg("{loot}"); - Loot lootInstance = plugin.getLootManager().getLoot(loot); - if (lootInstance != null) { - if (!types.contains(lootInstance.getType().name().toLowerCase(Locale.ENGLISH))) return true; - } - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - } - - private void registerEnvironmentRequirement() { - registerRequirement("environment", (args, actions, advanced) -> { - List environments = ConfigUtils.stringListArgs(args); - return condition -> { - var name = condition.getLocation().getWorld().getEnvironment().name().toLowerCase(Locale.ENGLISH); - if (environments.contains(name)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - registerRequirement("!environment", (args, actions, advanced) -> { - List environments = ConfigUtils.stringListArgs(args); - return condition -> { - var name = condition.getLocation().getWorld().getEnvironment().name().toLowerCase(Locale.ENGLISH); - if (!environments.contains(name)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - } - - private void registerHookRequirement() { - registerRequirement("hook", (args, actions, advanced) -> { - List hooks = ConfigUtils.stringListArgs(args); - return condition -> { - String id = condition.getArg("{hook}"); - if (hooks.contains(id)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - registerRequirement("!hook", (args, actions, advanced) -> { - List hooks = ConfigUtils.stringListArgs(args); - return condition -> { - String id = condition.getArg("{hook}"); - if (!hooks.contains(id)) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - registerRequirement("has-hook", (args, actions, advanced) -> { - boolean has = (boolean) args; - return condition -> { - String id = condition.getArg("{hook}"); - if (id != null && has) return true; - if (id == null && !has) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - } - - private void registerInBagRequirement() { - registerRequirement("in-fishingbag", (args, actions, advanced) -> { - boolean arg = (boolean) args; - return condition -> { - String inBag = condition.getArg("{in-bag}"); - if (inBag == null && !arg) return true; - if (inBag != null && inBag.equals(String.valueOf(arg))) return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - } - - private void registerListRequirement() { - registerRequirement("list", (args, actions, advanced) -> { - LogUtils.severe("It seems that you made a mistake where you put \"list\" into \"conditions\" section."); - ArrayList list = ConfigUtils.stringListArgs(args); - LogUtils.warn("list:"); - for (String e : list) { - LogUtils.warn(" - " + e); - } - return EmptyRequirement.INSTANCE; - }); - } - - private void registerCompetitionRequirement() { - registerRequirement("competition", (args, actions, advanced) -> { - if (args instanceof ConfigurationSection section) { - boolean onCompetition = section.getBoolean("ongoing", true); - List ids = ConfigUtils.stringListArgs(section.get("id")); - return condition -> { - if (ids.size() == 0) { - if (plugin.getCompetitionManager().getOnGoingCompetition() != null == onCompetition) { - return true; - } - } else { - FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition(); - if (onCompetition) { - if (competition != null) { - if (ids.contains(competition.getConfig().getKey())) { - return true; - } - } - } else { - if (competition == null) { - return true; - } - } - } - if (advanced) triggerActions(actions, condition); - return false; - }; - } else { - LogUtils.warn("Wrong value format found at competition requirement."); - return EmptyRequirement.INSTANCE; - } - }); - } - - private void registerPluginLevelRequirement() { - registerRequirement("plugin-level", (args, actions, advanced) -> { - if (args instanceof ConfigurationSection section) { - String pluginName = section.getString("plugin"); - int level = section.getInt("level"); - String target = section.getString("target"); - return condition -> { - LevelerProvider levelerProvider = plugin.getIntegrationManager().getLevelPlugin(pluginName); - if (levelerProvider == null) { - LogUtils.warn("Plugin (" + pluginName + "'s) level is not compatible. Please double check if it's a problem caused by pronunciation."); - return true; - } - if (levelerProvider.getLevel(condition.getPlayer(), target) >= level) - return true; - if (advanced) triggerActions(actions, condition); - return false; - }; - } else { - LogUtils.warn("Wrong value format found at plugin-level requirement."); - return EmptyRequirement.INSTANCE; - } - }); - } - - - private void registerPotionEffectRequirement() { - registerRequirement("potion-effect", (args, actions, advanced) -> { - String potions = (String) args; - String[] split = potions.split("(<=|>=|<|>|==)", 2); - PotionEffectType type = PotionEffectType.getByName(split[0]); - if (type == null) { - LogUtils.warn("Potion effect doesn't exist: " + split[0]); - return EmptyRequirement.INSTANCE; - } - int required = Integer.parseInt(split[1]); - String operator = potions.substring(split[0].length(), potions.length() - split[1].length()); - return condition -> { - int level = -1; - PotionEffect potionEffect = condition.getPlayer().getPotionEffect(type); - if (potionEffect != null) { - level = potionEffect.getAmplifier(); - } - boolean result = false; - switch (operator) { - case ">=" -> { - if (level >= required) result = true; - } - case ">" -> { - if (level > required) result = true; - } - case "==" -> { - if (level == required) result = true; - } - case "!=" -> { - if (level != required) result = true; - } - case "<=" -> { - if (level <= required) result = true; - } - case "<" -> { - if (level < required) result = true; - } - } - if (result) { - return true; - } - if (advanced) triggerActions(actions, condition); - return false; - }; - }); - } - - /** - * Triggers a list of actions with the given condition. - * If the list of actions is not null, each action in the list is triggered. - * - * @param actions The list of actions to trigger. - * @param playerContext The condition associated with the actions. - */ - private void triggerActions(List actions, PlayerContext playerContext) { - if (actions != null) - for (Action action : actions) - action.trigger(playerContext); - } - - /** - * Loads requirement expansions from external JAR files located in the expansion folder. - * Each expansion JAR should contain classes that extends the RequirementExpansion class. - * Expansions are registered and used to create custom requirements. - */ - @SuppressWarnings("ResultOfMethodCallIgnored") - private void loadExpansions() { - File expansionFolder = new File(plugin.getDataFolder(), EXPANSION_FOLDER); - if (!expansionFolder.exists()) - expansionFolder.mkdirs(); - - List> classes = new ArrayList<>(); - File[] expansionJars = expansionFolder.listFiles(); - if (expansionJars == null) return; - for (File expansionJar : expansionJars) { - if (expansionJar.getName().endsWith(".jar")) { - try { - Class expansionClass = ClassUtils.findClass(expansionJar, RequirementExpansion.class); - classes.add(expansionClass); - } catch (IOException | ClassNotFoundException e) { - LogUtils.warn("Failed to load expansion: " + expansionJar.getName(), e); - } - } - } - try { - for (Class expansionClass : classes) { - RequirementExpansion expansion = expansionClass.getDeclaredConstructor().newInstance(); - unregisterRequirement(expansion.getRequirementType()); - registerRequirement(expansion.getRequirementType(), expansion.getRequirementFactory()); - LogUtils.info("Loaded requirement expansion: " + expansion.getRequirementType() + "[" + expansion.getVersion() + "]" + " by " + expansion.getAuthor()); - } - } catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) { - LogUtils.warn("Error occurred when creating expansion instance.", e); - } - } -} diff --git a/gradle.properties b/gradle.properties index 261df69d..52f63977 100644 --- a/gradle.properties +++ b/gradle.properties @@ -41,6 +41,7 @@ exp4j_version=0.4.8 placeholder_api_version=2.11.5 invui_version=1.30 vault_version=1.7 +guava_version=33.2.0-jre # Proxy settings systemProp.socks.proxyHost=127.0.0.1