From 193876c05c496ef2a0eb7a3259e76693e2c1b6b6 Mon Sep 17 00:00:00 2001 From: Xiao-MoMi <70987828+Xiao-MoMi@users.noreply.github.com> Date: Sun, 28 Aug 2022 15:42:04 +0800 Subject: [PATCH] 1.1.0 --- build.gradle | 8 +- .../customfishing/ConfigReader.java | 1179 +++++++++-------- .../customfishing/CustomFishing.java | 67 +- .../customfishing/command/Execute.java | 134 +- .../customfishing/command/TabComplete.java | 19 +- .../competition/Competition.java | 28 +- .../competition/CompetitionConfig.java | 8 +- .../competition/CompetitionSchedule.java | 4 +- .../competition/bossbar/BossBarManager.java | 4 +- .../competition/reward/MessageImpl.java | 40 - .../competition/reward/Reward.java | 24 - .../customfishing/helper/LibraryLoader.java | 2 - .../momirealms/customfishing/helper/Log.java | 13 +- .../customfishing/helper/MavenLibraries.java | 6 +- .../customfishing/helper/MavenLibrary.java | 12 +- .../helper/NonnullByDefault.java | 46 - .../customfishing/helper/Repository.java | 7 +- .../helper/URLClassLoaderAccess.java | 10 +- .../customfishing/hook/CustomCropsSeason.java | 11 - .../customfishing/hook/ItemsAdderItem.java | 11 + .../customfishing/hook/MMOItemsHook.java | 14 + .../customfishing/hook/MythicItems.java | 11 + ...thicMobsUtils.java => MythicMobsUtil.java} | 21 +- .../customfishing/hook/OraxenItem.java | 11 + .../hook/season/CustomCropsSeason.java | 10 + .../hook/{ => season}/RealisticSeason.java | 6 +- .../hook/season/SeasonInterface.java | 7 + .../customfishing/hook/skill/Aurelium.java | 5 + .../customfishing/hook/skill/EcoSkill.java | 5 + .../customfishing/hook/skill/MMOCore.java | 5 + .../customfishing/hook/skill/SkillXP.java | 1 + .../customfishing/hook/skill/mcMMO.java | 6 + .../momirealms/customfishing/item/Bait.java | 84 -- .../momirealms/customfishing/item/Item.java | 35 - .../customfishing/item/ItemGive.java | 52 - .../momirealms/customfishing/item/Loot.java | 124 -- .../momirealms/customfishing/item/Rod.java | 80 -- .../momirealms/customfishing/item/Util.java | 65 - .../customfishing/listener/FishListener.java | 856 ++++++++++++ .../listener/MMOItemsConverter.java | 10 +- .../{PapiReload.java => PapiUnregister.java} | 2 +- .../listener/PickUpListener.java | 27 + .../listener/PlayerListener.java | 493 ------- .../customfishing/object/Bonus.java | 61 + .../{titlebar => object}/Difficulty.java | 12 +- .../{titlebar => object}/FishingPlayer.java | 14 +- .../momirealms/customfishing/object/Item.java | 82 ++ .../{titlebar => object}/Layout.java | 6 +- .../LeveledEnchantment.java} | 37 +- .../MobVector.java} | 14 +- .../{utils => object}/Modifier.java | 21 +- .../customfishing/object/VanillaLoot.java | 22 + .../customfishing/object/action/ActionB.java | 7 + .../customfishing/object/action/CommandA.java | 23 + .../customfishing/object/action/CommandB.java | 23 + .../object/action/FishingXPB.java | 14 + .../customfishing/object/action/MessageA.java | 16 + .../customfishing/object/action/MessageB.java | 16 + .../customfishing/object/action/XPA.java | 13 + .../customfishing/object/action/XPB.java | 13 + .../object/loot/DroppedItem.java | 49 + .../customfishing/object/loot/Loot.java | 132 ++ .../customfishing/object/loot/Mob.java | 35 + .../requirements/CustomPapi.java | 110 ++ .../requirements/FishingCondition.java | 39 +- .../customfishing/requirements/Season.java | 13 +- .../requirements/SkillLevel.java | 10 + .../customfishing/requirements/Weather.java | 3 +- .../customfishing/requirements/World.java | 3 +- .../requirements/papi/ExpressionAnd.java | 15 + .../requirements/papi/ExpressionOr.java | 15 + .../requirements/papi/PapiEquals.java | 13 + .../requirements/papi/PapiGreater.java | 12 + .../requirements/papi/PapiNoLarger.java | 12 + .../requirements/papi/PapiNoLess.java | 12 + .../requirements/papi/PapiRequirement.java | 7 + .../requirements/papi/PapiSmaller.java | 12 + .../customfishing/titlebar/Timer.java | 1 + .../customfishing/titlebar/TimerTask.java | 13 +- ...ventureManager.java => AdventureUtil.java} | 10 +- .../{UpdateConfig.java => ConfigUtil.java} | 2 +- ...StackGenerator.java => ItemStackUtil.java} | 68 +- .../utils/{SaveItem.java => ItemUtil.java} | 94 +- .../customfishing/utils/JedisUtil.java | 3 +- .../customfishing/utils/NBTUtil.java | 29 +- .../customfishing/utils/VectorUtil.java | 23 - src/main/resources/baits.yml | 50 - src/main/resources/baits/default.yml | 49 + src/main/resources/bars.yml | 2 +- src/main/resources/competition.yml | 7 +- src/main/resources/config.yml | 41 +- src/main/resources/custom-enchant-bonus.yml | 25 + src/main/resources/loots.yml | 594 --------- src/main/resources/loots/default.yml | 462 +++++++ src/main/resources/loots/example.yml | 184 +++ src/main/resources/messages/messages_cn.yml | 2 + src/main/resources/messages/messages_en.yml | 32 +- src/main/resources/messages/messages_es.yml | 2 + src/main/resources/mobs/example.yml | 41 + src/main/resources/plugin.yml | 6 +- src/main/resources/redis.yml | 2 + src/main/resources/rods.yml | 43 - src/main/resources/rods/default.yml | 42 + src/main/resources/titles.yml | 9 +- src/main/resources/utils.yml | 9 - src/main/resources/utils/fishfinder.yml | 7 + 106 files changed, 3597 insertions(+), 2704 deletions(-) delete mode 100644 src/main/java/net/momirealms/customfishing/competition/reward/MessageImpl.java delete mode 100644 src/main/java/net/momirealms/customfishing/competition/reward/Reward.java delete mode 100644 src/main/java/net/momirealms/customfishing/helper/NonnullByDefault.java delete mode 100644 src/main/java/net/momirealms/customfishing/hook/CustomCropsSeason.java create mode 100644 src/main/java/net/momirealms/customfishing/hook/ItemsAdderItem.java create mode 100644 src/main/java/net/momirealms/customfishing/hook/MMOItemsHook.java create mode 100644 src/main/java/net/momirealms/customfishing/hook/MythicItems.java rename src/main/java/net/momirealms/customfishing/hook/{MythicMobsUtils.java => MythicMobsUtil.java} (80%) create mode 100644 src/main/java/net/momirealms/customfishing/hook/OraxenItem.java create mode 100644 src/main/java/net/momirealms/customfishing/hook/season/CustomCropsSeason.java rename src/main/java/net/momirealms/customfishing/hook/{ => season}/RealisticSeason.java (77%) create mode 100644 src/main/java/net/momirealms/customfishing/hook/season/SeasonInterface.java delete mode 100644 src/main/java/net/momirealms/customfishing/item/Bait.java delete mode 100644 src/main/java/net/momirealms/customfishing/item/Item.java delete mode 100644 src/main/java/net/momirealms/customfishing/item/ItemGive.java delete mode 100644 src/main/java/net/momirealms/customfishing/item/Loot.java delete mode 100644 src/main/java/net/momirealms/customfishing/item/Rod.java delete mode 100644 src/main/java/net/momirealms/customfishing/item/Util.java create mode 100644 src/main/java/net/momirealms/customfishing/listener/FishListener.java rename src/main/java/net/momirealms/customfishing/listener/{PapiReload.java => PapiUnregister.java} (90%) create mode 100644 src/main/java/net/momirealms/customfishing/listener/PickUpListener.java delete mode 100644 src/main/java/net/momirealms/customfishing/listener/PlayerListener.java create mode 100644 src/main/java/net/momirealms/customfishing/object/Bonus.java rename src/main/java/net/momirealms/customfishing/{titlebar => object}/Difficulty.java (81%) rename src/main/java/net/momirealms/customfishing/{titlebar => object}/FishingPlayer.java (75%) create mode 100644 src/main/java/net/momirealms/customfishing/object/Item.java rename src/main/java/net/momirealms/customfishing/{titlebar => object}/Layout.java (92%) rename src/main/java/net/momirealms/customfishing/{competition/reward/CommandImpl.java => object/LeveledEnchantment.java} (55%) rename src/main/java/net/momirealms/customfishing/{utils/Enchantment.java => object/MobVector.java} (73%) rename src/main/java/net/momirealms/customfishing/{utils => object}/Modifier.java (72%) create mode 100644 src/main/java/net/momirealms/customfishing/object/VanillaLoot.java create mode 100644 src/main/java/net/momirealms/customfishing/object/action/ActionB.java create mode 100644 src/main/java/net/momirealms/customfishing/object/action/CommandA.java create mode 100644 src/main/java/net/momirealms/customfishing/object/action/CommandB.java create mode 100644 src/main/java/net/momirealms/customfishing/object/action/FishingXPB.java create mode 100644 src/main/java/net/momirealms/customfishing/object/action/MessageA.java create mode 100644 src/main/java/net/momirealms/customfishing/object/action/MessageB.java create mode 100644 src/main/java/net/momirealms/customfishing/object/action/XPA.java create mode 100644 src/main/java/net/momirealms/customfishing/object/action/XPB.java create mode 100644 src/main/java/net/momirealms/customfishing/object/loot/DroppedItem.java create mode 100644 src/main/java/net/momirealms/customfishing/object/loot/Loot.java create mode 100644 src/main/java/net/momirealms/customfishing/object/loot/Mob.java create mode 100644 src/main/java/net/momirealms/customfishing/requirements/CustomPapi.java create mode 100644 src/main/java/net/momirealms/customfishing/requirements/SkillLevel.java create mode 100644 src/main/java/net/momirealms/customfishing/requirements/papi/ExpressionAnd.java create mode 100644 src/main/java/net/momirealms/customfishing/requirements/papi/ExpressionOr.java create mode 100644 src/main/java/net/momirealms/customfishing/requirements/papi/PapiEquals.java create mode 100644 src/main/java/net/momirealms/customfishing/requirements/papi/PapiGreater.java create mode 100644 src/main/java/net/momirealms/customfishing/requirements/papi/PapiNoLarger.java create mode 100644 src/main/java/net/momirealms/customfishing/requirements/papi/PapiNoLess.java create mode 100644 src/main/java/net/momirealms/customfishing/requirements/papi/PapiRequirement.java create mode 100644 src/main/java/net/momirealms/customfishing/requirements/papi/PapiSmaller.java rename src/main/java/net/momirealms/customfishing/utils/{AdventureManager.java => AdventureUtil.java} (85%) rename src/main/java/net/momirealms/customfishing/utils/{UpdateConfig.java => ConfigUtil.java} (97%) rename src/main/java/net/momirealms/customfishing/utils/{ItemStackGenerator.java => ItemStackUtil.java} (55%) rename src/main/java/net/momirealms/customfishing/utils/{SaveItem.java => ItemUtil.java} (67%) delete mode 100644 src/main/java/net/momirealms/customfishing/utils/VectorUtil.java delete mode 100644 src/main/resources/baits.yml create mode 100644 src/main/resources/baits/default.yml create mode 100644 src/main/resources/custom-enchant-bonus.yml delete mode 100644 src/main/resources/loots.yml create mode 100644 src/main/resources/loots/default.yml create mode 100644 src/main/resources/loots/example.yml create mode 100644 src/main/resources/mobs/example.yml delete mode 100644 src/main/resources/rods.yml create mode 100644 src/main/resources/rods/default.yml delete mode 100644 src/main/resources/utils.yml create mode 100644 src/main/resources/utils/fishfinder.yml diff --git a/build.gradle b/build.gradle index bf8ac625..8b8e1139 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'net.momirealms' -version = '1.0.6' +version = '1.1.0' repositories { mavenCentral() @@ -44,15 +44,16 @@ repositories { dependencies { compileOnly fileTree(dir:'libs',includes:['*.jar']) + compileOnly 'io.papermc.paper:paper-api:1.17.1-R0.1-SNAPSHOT' compileOnly('com.github.Archy-X:AureliumSkills:Beta1.3.6') compileOnly('redis.clients:jedis:4.2.3') - compileOnly('com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT') compileOnly('me.clip:placeholderapi:2.11.1') compileOnly('com.sk89q.worldguard:worldguard-bukkit:7.0.7') compileOnly('io.lumine:Mythic-Dist:5.0.3-SNAPSHOT') compileOnly('dev.dejvokep:boosted-yaml:1.3') + compileOnly('com.github.LoneDev6:api-itemsadder:3.2.3c') implementation('net.kyori:adventure-api:4.11.0') - implementation('net.kyori:adventure-platform-bukkit:4.1.1') + implementation('net.kyori:adventure-platform-bukkit:4.1.2') implementation('net.kyori:adventure-text-minimessage:4.11.0') implementation('net.kyori:adventure-text-serializer-legacy:4.11.0') implementation('de.tr7zw:item-nbt-api:2.10.0') @@ -89,5 +90,4 @@ tasks.withType(JavaCompile) { shadowJar { relocate 'de.tr7zw', 'net.momirealms.customfishing.libs' - relocate 'net.kyori', 'net.momirealms.customfishing.libs' } \ No newline at end of file diff --git a/src/main/java/net/momirealms/customfishing/ConfigReader.java b/src/main/java/net/momirealms/customfishing/ConfigReader.java index 869bdd9a..a34db8ad 100644 --- a/src/main/java/net/momirealms/customfishing/ConfigReader.java +++ b/src/main/java/net/momirealms/customfishing/ConfigReader.java @@ -22,23 +22,22 @@ import net.momirealms.customcrops.helper.Log; import net.momirealms.customfishing.competition.CompetitionConfig; import net.momirealms.customfishing.competition.Goal; import net.momirealms.customfishing.competition.bossbar.BossBarConfig; -import net.momirealms.customfishing.competition.reward.CommandImpl; -import net.momirealms.customfishing.competition.reward.MessageImpl; -import net.momirealms.customfishing.competition.reward.Reward; -import net.momirealms.customfishing.hook.Placeholders; +import net.momirealms.customfishing.hook.season.CustomCropsSeason; +import net.momirealms.customfishing.hook.season.RealisticSeason; +import net.momirealms.customfishing.hook.season.SeasonInterface; import net.momirealms.customfishing.hook.skill.*; -import net.momirealms.customfishing.titlebar.Difficulty; -import net.momirealms.customfishing.titlebar.Layout; -import net.momirealms.customfishing.item.Bait; -import net.momirealms.customfishing.item.Loot; -import net.momirealms.customfishing.item.Rod; -import net.momirealms.customfishing.item.Util; +import net.momirealms.customfishing.object.*; +import net.momirealms.customfishing.object.action.*; +import net.momirealms.customfishing.object.loot.DroppedItem; +import net.momirealms.customfishing.object.loot.Loot; +import net.momirealms.customfishing.object.loot.Mob; import net.momirealms.customfishing.requirements.*; import net.momirealms.customfishing.utils.*; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.NamespacedKey; +import org.bukkit.configuration.MemorySection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.inventory.ItemFlag; @@ -50,17 +49,16 @@ import java.util.*; public class ConfigReader{ public static HashMap LOOT = new HashMap<>(); - public static HashMap LOOTITEM = new HashMap<>(); - public static HashMap UTIL = new HashMap<>(); - public static HashMap UTILITEM = new HashMap<>(); - public static HashMap ROD = new HashMap<>(); - public static HashMap RODITEM = new HashMap<>(); - public static HashMap BAIT = new HashMap<>(); - public static HashMap BAITITEM = new HashMap<>(); + public static HashMap LootItem = new HashMap<>(); + public static HashMap UtilItem = new HashMap<>(); + public static HashMap ROD = new HashMap<>(); + public static HashMap RodItem = new HashMap<>(); + public static HashMap BAIT = new HashMap<>(); + public static HashMap BaitItem = new HashMap<>(); public static HashMap LAYOUT = new HashMap<>(); - public static HashMap Competitions = new HashMap<>(); - public static HashMap CompetitionsCommand = new HashMap<>(); - + public static HashMap CompetitionsT = new HashMap<>(); + public static HashMap CompetitionsC = new HashMap<>(); + public static boolean useRedis; public static YamlConfiguration getConfig(String configName) { File file = new File(CustomFishing.instance.getDataFolder(), configName); @@ -87,21 +85,22 @@ public class ConfigReader{ public static boolean wg; public static boolean mm; public static boolean papi; - public static boolean season; - public static boolean vanillaDrop; public static boolean needOpenWater; public static boolean needSpecialRod; public static boolean competition; public static boolean convertMMOItems; public static boolean loseDurability; - public static boolean rsSeason; - public static boolean ccSeason; - public static String season_papi; - public static String lang; + public static boolean preventPick; + public static boolean doubleRealIn; + public static boolean vanillaLoot; + public static boolean showBar; public static int fishFinderCoolDown; public static double timeMultiply; + public static double vanillaRatio; public static SkillXP skillXP; public static String version; + public static String lang; + public static SeasonInterface season; public static void loadConfig() { @@ -109,110 +108,92 @@ public class ConfigReader{ CustomFishing.instance.reloadConfig(); FileConfiguration config = CustomFishing.instance.getConfig(); - wg = config.getBoolean("config.integrations.WorldGuard"); - if (wg){ - if (Bukkit.getPluginManager().getPlugin("WorldGuard") == null){ - AdventureManager.consoleMessage("[CustomFishing] Failed to initialize WorldGuard!"); - wg = false; - }else { - AdventureManager.consoleMessage("[CustomFishing] WorldGuard Hooked!"); + wg = (mm = (papi = false)); + if (config.getBoolean("config.integrations.WorldGuard")){ + if (Bukkit.getPluginManager().getPlugin("WorldGuard") == null) AdventureUtil.consoleMessage("[CustomFishing] Failed to initialize WorldGuard!"); + else { + AdventureUtil.consoleMessage("[CustomFishing] WorldGuard Hooked!"); + wg = true; } } - mm = config.getBoolean("config.integrations.MythicMobs"); - if (mm){ - if (Bukkit.getPluginManager().getPlugin("MythicMobs") == null){ - AdventureManager.consoleMessage("[CustomFishing] Failed to initialize MythicMobs!"); - mm = false; - }else { - AdventureManager.consoleMessage("[CustomFishing] MythicMobs Hooked!"); + if (config.getBoolean("config.integrations.MythicMobs")){ + if (Bukkit.getPluginManager().getPlugin("MythicMobs") == null) AdventureUtil.consoleMessage("[CustomFishing] Failed to initialize MythicMobs!"); + else { + AdventureUtil.consoleMessage("[CustomFishing] MythicMobs Hooked!"); + mm = true; } } - papi = config.getBoolean("config.integrations.PlaceholderAPI"); - if (papi){ - if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") == null){ - AdventureManager.consoleMessage("[CustomFishing] Failed to initialize PlaceholderAPI!"); - papi = false; - } + if (config.getBoolean("config.integrations.PlaceholderAPI")){ + if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") == null) AdventureUtil.consoleMessage("[CustomFishing] Failed to initialize PlaceholderAPI!"); + else papi = true; } skillXP = null; - if(config.getBoolean("config.integrations.mcMMO",false)){ - if(Bukkit.getPluginManager().getPlugin("mcMMO") == null){ - CustomFishing.instance.getLogger().warning("Failed to initialize mcMMO!"); - }else { + if (Bukkit.getPluginManager().getPlugin("mcMMO") == null) CustomFishing.instance.getLogger().warning("Failed to initialize mcMMO!"); + else { skillXP = new mcMMO(); - AdventureManager.consoleMessage("[CustomFishing] mcMMO Hooked!"); + AdventureUtil.consoleMessage("[CustomFishing] mcMMO Hooked!"); } } if(config.getBoolean("config.integrations.AureliumSkills",false)){ - if(Bukkit.getPluginManager().getPlugin("AureliumSkills") == null){ - CustomFishing.instance.getLogger().warning("Failed to initialize AureliumSkills!"); - }else { + if (Bukkit.getPluginManager().getPlugin("AureliumSkills") == null) CustomFishing.instance.getLogger().warning("Failed to initialize AureliumSkills!"); + else { skillXP = new Aurelium(); - AdventureManager.consoleMessage("[CustomFishing] AureliumSkills Hooked!"); + AdventureUtil.consoleMessage("[CustomFishing] AureliumSkills Hooked!"); } } if(config.getBoolean("config.integrations.MMOCore",false)){ - if(Bukkit.getPluginManager().getPlugin("MMOCore") == null){ - CustomFishing.instance.getLogger().warning("Failed to initialize MMOCore!"); - }else { + if (Bukkit.getPluginManager().getPlugin("MMOCore") == null) CustomFishing.instance.getLogger().warning("Failed to initialize MMOCore!"); + else { skillXP = new MMOCore(); - AdventureManager.consoleMessage("[CustomFishing] MMOCore Hooked!"); + AdventureUtil.consoleMessage("[CustomFishing] MMOCore Hooked!"); } } if(config.getBoolean("config.integrations.EcoSkills",false)){ - if(Bukkit.getPluginManager().getPlugin("EcoSkills") == null){ - CustomFishing.instance.getLogger().warning("Failed to initialize EcoSkills!"); - }else { + if (Bukkit.getPluginManager().getPlugin("EcoSkills") == null) CustomFishing.instance.getLogger().warning("Failed to initialize EcoSkills!"); + else { skillXP = new EcoSkill(); - AdventureManager.consoleMessage("[CustomFishing] EcoSkills Hooked!"); + AdventureUtil.consoleMessage("[CustomFishing] EcoSkills Hooked!"); } } - season = config.getBoolean("config.season.enable"); - if (!papi && season) { - season = false; - }else { - season_papi = config.getString("config.season.papi"); - } - - rsSeason = false; + season = null; if (config.getBoolean("config.integrations.RealisticSeasons",false)){ if (Bukkit.getPluginManager().getPlugin("RealisticSeasons") == null) Log.warn("Failed to initialize RealisticSeasons!"); else { - rsSeason = true; - AdventureManager.consoleMessage("[CustomFishing] RealisticSeasons Hooked!"); + season = new RealisticSeason(); + AdventureUtil.consoleMessage("[CustomFishing] RealisticSeasons Hooked!"); } } - ccSeason = false; if (config.getBoolean("config.integrations.CustomCrops",false)){ if (Bukkit.getPluginManager().getPlugin("CustomCrops") == null) Log.warn("Failed to initialize CustomCrops!"); else { - ccSeason = true; - AdventureManager.consoleMessage("[CustomFishing] CustomCrops Hooked!"); + season = new CustomCropsSeason(); + AdventureUtil.consoleMessage("[CustomFishing] CustomCrops Hooked!"); } } - if (rsSeason || ccSeason){ - season = true; - } - - vanillaDrop = config.getBoolean("config.vanilla-loot-when-no-custom-fish", true); + doubleRealIn = config.getBoolean("config.double-reel-in", true); + vanillaLoot = config.getBoolean("config.vanilla-loot.enable", true); + showBar = config.getBoolean("config.vanilla-loot.bar", true); convertMMOItems = config.getBoolean("config.convert-MMOITEMS", false); needOpenWater = config.getBoolean("config.need-open-water", false); needSpecialRod = config.getBoolean("config.need-special-rod", false); loseDurability = config.getBoolean("config.rod-lose-durability", true); + preventPick = config.getBoolean("config.prevent-other-players-pick-up-loot", false); version = config.getString("config-version"); fishFinderCoolDown = config.getInt("config.fishfinder-cooldown"); timeMultiply = config.getDouble("config.time-multiply"); + vanillaRatio = config.getDouble("config.vanilla-loot.ratio"); lang = config.getString("config.lang","cn"); competition = config.getBoolean("config.fishing-competition",true); } } public static class Message { + public static String prefix; public static String reload; public static String escape; @@ -238,8 +219,13 @@ public class ConfigReader{ public static String forceCancel; public static String noPlayer; public static String noScore; + public static String noRod; + public static String hookOther; + public static void loadMessage() { + YamlConfiguration config = getConfig("messages/messages_" + Config.lang +".yml"); + prefix = config.getString("messages.prefix"); reload = config.getString("messages.reload"); escape = config.getString("messages.escape"); @@ -263,24 +249,30 @@ public class ConfigReader{ forceFailure = config.getString("messages.force-competition-failure"); forceEnd = config.getString("messages.force-competition-end"); forceCancel = config.getString("messages.force-competition-cancel"); - noPlayer = config.getString("messages.no-player"); - noScore = config.getString("messages.no-score"); + noPlayer = config.getString("messages.no-player", "messages.no-player is missing"); + noScore = config.getString("messages.no-score", "messages.no-score is missing"); + noRod = config.getString("messages.no-rod", "messages.no-rod is missing"); + hookOther = config.getString("messages.hook-other-entity","messages.hook-other-entity is missing"); } } public static class Title { + public static List success_title; public static List success_subtitle; + public static List failure_title; + public static List failure_subtitle; public static int success_in; public static int success_out; public static int success_stay; - public static List failure_title; - public static List failure_subtitle; public static int failure_in; public static int failure_out; public static int failure_stay; + public static void loadTitle() { + YamlConfiguration config = getConfig("titles.yml"); + success_title = config.getStringList("titles.success.title"); success_subtitle = config.getStringList("titles.success.subtitle"); success_in = config.getInt("titles.success.fade.in")*50; @@ -294,565 +286,611 @@ public class ConfigReader{ } } - /* - 载入Loot战利品 - */ public static void loadLoot() { LOOT.clear(); - LOOTITEM.clear(); + LootItem.clear(); + CustomPapi.allPapi.clear(); - YamlConfiguration config = getConfig("loots.yml"); - Set keys = Objects.requireNonNull(config.getConfigurationSection("items")).getKeys(false); - keys.forEach(key -> { + File loot_file = new File(CustomFishing.instance.getDataFolder() + File.separator + "loots"); - Difficulty difficulty; - if (config.contains("items." + key + ".difficulty")) { - String[] split = StringUtils.split(config.getString("items." + key + ".difficulty"), "-"); - assert split != null; - if (Integer.parseInt(split[1]) <= 0 || Integer.parseInt(split[0]) <= 0){ - AdventureManager.consoleMessage("[CustomFishing] Error! " + key + " has wrong difficulty format!"); - return; - }else { - difficulty = new Difficulty(Integer.parseInt(split[0]), Integer.parseInt(split[1])); - } - } else { - difficulty = new Difficulty(1, 1); - } - int weight; - if (config.contains("items." + key + ".weight")) { - weight = config.getInt("items." + key + ".weight"); - } else { - AdventureManager.consoleMessage("[CustomFishing] Error! No weight set for " + key + " !"); + if (!loot_file.exists()) { + if (!loot_file.mkdir()) { + AdventureUtil.consoleMessage("[CustomFishing] Error! Failed to create loots folder..."); return; } - int time; - if (config.contains("items." + key + ".time")) { - time = config.getInt("items." + key + ".time"); - if (time <= 0){ - AdventureManager.consoleMessage("[CustomFishing] Error! " + key + " time must be positive!"); - return; - } - } else { - time = 10000; - } - - Loot loot = new Loot(key, difficulty, weight, time); - - if (config.contains("items." + key + ".material")) { - loot.setMaterial(config.getString("items." + key + ".material")); - } else { - AdventureManager.consoleMessage("[CustomFishing] Error! No material set for " + key + " !"); - return; - } - /* - 可选的设置内容 - */ - if (config.contains("items." + key + ".display.lore")) - loot.setLore(config.getStringList("items." + key + ".display.lore")); - if (config.contains("items." + key + ".display.name")) - loot.setName(config.getString("items." + key + ".display.name")); - if (config.contains("items." + key + ".enchantments")) { - ArrayList arrayList = new ArrayList<>(); - config.getStringList("items." + key + ".enchantments").forEach(enchant -> { - String[] split = StringUtils.split(enchant, "/"); - NamespacedKey namespacedKey = NamespacedKey.fromString(split[0]); - arrayList.add(new Enchantment(namespacedKey, Integer.parseInt(split[1]))); - }); - loot.setEnchantment(arrayList); - } - if (config.contains("items." + key + ".item_flags")) { - ArrayList arrayList = new ArrayList<>(); - config.getStringList("items." + key + ".item_flags").forEach(flag -> { - arrayList.add(ItemFlag.valueOf(flag)); - }); - loot.setItemFlags(arrayList); - } - if (config.contains("items." + key + ".nbt")) - loot.setNbt((Map) config.getMapList("items." + key + ".nbt").get(0)); - if (config.contains("items." + key + ".custom-model-data")) - loot.setCustommodeldata(config.getInt("items." + key + ".custom-model-data")); - if (config.contains("items."+ key +".nick")){ - loot.setNick(config.getString("items."+key+".nick")); - }else { - loot.setNick(loot.getName()); - } - loot.setUnbreakable(config.getBoolean("items." + key + ".unbreakable",false)); - loot.setScore((float) config.getDouble("items." + key + ".score",0)); - - if (config.contains("items." + key + ".action.message")) - loot.setMsg(config.getStringList("items." + key + ".action.message")); - if (config.contains("items." + key + ".action.command")) - loot.setCommands(config.getStringList("items." + key + ".action.command")); - if (config.contains("items." + key + ".action-hook.message")) - loot.setHookMsg(config.getStringList("items." + key + ".action-hook.message")); - if (config.contains("items." + key + ".action-hook.command")) - loot.setHookCommands(config.getStringList("items." + key + ".action-hook.command")); - if (config.contains("items." + key + ".action.exp")) - loot.setExp(config.getInt("items." + key + ".action.exp")); - if (config.contains("items." + key + ".layout")) - loot.setLayout(config.getString("items." + key + ".layout")); - if (config.contains("items." + key + ".skill-xp")) - loot.setSkillXP(config.getDouble("items." + key + ".skill-xp")); - if (config.contains("items." + key + ".group")) - loot.setGroup(config.getString("items." + key + ".group")); - if (config.contains("items." + key + ".show-in-fishfinder")){ - loot.setShowInFinder(config.getBoolean("items." + key + ".show-in-fishfinder")); - }else { - loot.setShowInFinder(true); - } - /* - 设置捕获条件 - */ - if (config.contains("items." + key + ".requirements")){ - List requirements = new ArrayList<>(); - Objects.requireNonNull(config.getConfigurationSection("items." + key + ".requirements")).getKeys(false).forEach(requirement -> { - switch (requirement){ - case "weather" -> requirements.add(new Weather(config.getStringList("items." + key + ".requirements.weather"))); - case "ypos" -> requirements.add(new YPos(config.getStringList("items." + key + ".requirements.ypos"))); - case "season" -> { - if (Config.season){ - requirements.add(new Season(config.getStringList("items." + key + ".requirements.season"))); - }else { - AdventureManager.consoleMessage("[CustomFishing] Plz enable season in config.yml!"); - } - } - case "world" -> requirements.add(new World(config.getStringList("items." + key + ".requirements.world"))); - case "biome" -> requirements.add(new Biome(config.getStringList("items." + key + ".requirements.biome"))); - case "permission" -> requirements.add(new Permission(config.getString("items." + key + ".requirements.permission"))); - case "region" -> { - if (Config.wg){ - requirements.add(new Region(config.getStringList("items." + key + ".requirements.regions"))); - }else { - AdventureManager.consoleMessage("[CustomFishing] Plz enable WorldGuard Integration!"); - } - } - case "time" -> requirements.add(new Time(config.getStringList("items." + key + ".requirements.time"))); - } - }); - loot.setRequirements(requirements); - } - LOOT.put(key, loot); - if (loot.getMaterial().equalsIgnoreCase("AIR")){ - LOOTITEM.put(key, new ItemStack(Material.AIR)); - }else { - LOOTITEM.put(key, ItemStackGenerator.fromItem(loot)); - } - }); - - if (config.contains("mobs") && Config.mm){ - Set mobs = Objects.requireNonNull(config.getConfigurationSection("mobs")).getKeys(false); - mobs.forEach(key -> { - - /* - 必设置的内容,为构造所需 - */ - String name; - if (config.contains("mobs." + key + ".name")) { - name = config.getString("mobs." + key + ".name"); - } else { - AdventureManager.consoleMessage("[CustomFishing] Error! No name set for mob " + key + " !"); - return; - } - Difficulty difficulty; - if (config.contains("mobs." + key + ".difficulty")) { - String[] split = StringUtils.split(config.getString("mobs." + key + ".difficulty"), "-"); - assert split != null; - if (Integer.parseInt(split[1]) <= 0 || Integer.parseInt(split[0]) <= 0){ - AdventureManager.consoleMessage("[CustomFishing] Error! " + key + " has wrong difficulty format!"); - return; - }else { - difficulty = new Difficulty(Integer.parseInt(split[0]), Integer.parseInt(split[1])); - } - } else { - difficulty = new Difficulty(1, 1); - } - int weight; - if (config.contains("mobs." + key + ".weight")) { - weight = config.getInt("mobs." + key + ".weight"); - } else { - AdventureManager.consoleMessage("[CustomFishing] Error! No weight set for " + key + " !"); - return; - } - int time; - if (config.contains("mobs." + key + ".time")) { - time = config.getInt("mobs." + key + ".time"); - if (time <= 0){ - AdventureManager.consoleMessage("[CustomFishing] Error! " + key + " time must be positive!"); - return; - } - } else { - time = 10000; - } - //新建单例 - Loot loot = new Loot(key, difficulty, weight, time); - //设置昵称 - loot.setNick(name); - //设置MM怪ID - if (config.contains("mobs." + key + ".mythicmobsID")) { - loot.setMm(config.getString("mobs." + key + ".mythicmobsID")); - } else { - AdventureManager.consoleMessage("[CustomFishing] Error! No MythicMobs id set for " + key + " !"); - return; - } - //设置MM怪位移 - if (config.contains("mobs." + key + ".vector.horizontal") && config.contains("mobs." + key + ".vector.vertical")) { - loot.setVectorUtil(new VectorUtil(config.getDouble("mobs." + key + ".vector.horizontal"), config.getDouble("mobs." + key + ".vector.vertical"))); - } else { - loot.setVectorUtil(new VectorUtil(1.1, 1.3)); - } - - if (config.contains("mobs." + key + ".level")) - loot.setMmLevel(config.getInt("mobs." + key + ".level", 0)); - if (config.contains("mobs." + key + ".action.message")) - loot.setMsg(config.getStringList("mobs." + key + ".action.message")); - if (config.contains("mobs." + key + ".action.command")) - loot.setCommands(config.getStringList("mobs." + key + ".action.command")); - if (config.contains("mobs." + key + ".action-hook.message")) - loot.setHookMsg(config.getStringList("mobs." + key + ".action-hook.message")); - if (config.contains("mobs." + key + ".action-hook.command")) - loot.setHookCommands(config.getStringList("mobs." + key + ".action-hook.command")); - if (config.contains("mobs." + key + ".action.exp")) - loot.setExp(config.getInt("mobs." + key + ".action.exp")); - if (config.contains("mobs." + key + ".skill-xp")) - loot.setSkillXP(config.getDouble("mobs." + key + ".skill-xp")); - if (config.contains("mobs." + key + ".layout")) - loot.setLayout(config.getString("mobs." + key + "layout")); - if (config.contains("mobs." + key + ".group")) - loot.setGroup(config.getString("mobs." + key + ".group")); - if (config.contains("mobs." + key + ".show-in-fishfinder")){ - loot.setShowInFinder(config.getBoolean("mobs." + key + ".show-in-fishfinder")); - }else { - loot.setShowInFinder(true); - } - loot.setScore((float) config.getDouble("mobs." + key + ".score",0)); - /* - 设置捕获条件 - */ - if (config.contains("mobs." + key + ".requirements")){ - List requirements = new ArrayList<>(); - Objects.requireNonNull(config.getConfigurationSection("mobs." + key + ".requirements")).getKeys(false).forEach(requirement -> { - switch (requirement){ - case "weather" -> requirements.add(new Weather(config.getStringList("mobs." + key + ".requirements.weather"))); - case "ypos" -> requirements.add(new YPos(config.getStringList("mobs." + key + ".requirements.ypos"))); - case "season" -> { - if (Config.season){ - requirements.add(new Season(config.getStringList("mobs." + key + ".requirements.season"))); - }else { - AdventureManager.consoleMessage("[CustomFishing] Plz enable season in config.yml!"); - } - } - case "world" -> requirements.add(new World(config.getStringList("mobs." + key + ".requirements.world"))); - case "biome" -> requirements.add(new Biome(config.getStringList("mobs." + key + ".requirements.biome"))); - case "permission" -> requirements.add(new Permission(config.getString("mobs." + key + ".requirements.permission"))); - case "region" -> { - if (Config.wg){ - requirements.add(new Region(config.getStringList("mobs." + key + ".requirements.regions"))); - }else { - AdventureManager.consoleMessage("[CustomFishing] Plz enable WorldGuard Integration!"); - } - } - case "time" -> requirements.add(new Time(config.getStringList("mobs." + key + ".requirements.time"))); - } - }); - loot.setRequirements(requirements); - } - //丢入缓存 - LOOT.put(key, loot); - }); - if (keys.size() != LOOTITEM.size() || mobs.size() != LOOT.size()- LOOTITEM.size()) { - AdventureManager.consoleMessage("[CustomFishing] loots.yml exists error!"); - } else { - AdventureManager.consoleMessage("[CustomFishing] " + keys.size() + " loots loaded!"); - AdventureManager.consoleMessage("[CustomFishing] " + mobs.size() + " mobs loaded!"); - } - return; + CustomFishing.instance.saveResource("loots" + File.separator + "default.yml", false); + CustomFishing.instance.saveResource("loots" + File.separator + "example.yml", false); } - if (keys.size() != LOOTITEM.size()){ - AdventureManager.consoleMessage("[CustomFishing] loots.yml exists error!"); - } else { - AdventureManager.consoleMessage("[CustomFishing] " + keys.size() + " loots loaded!"); + + File[] files = loot_file.listFiles(); + + if (files != null) { + + for (File file : files) { + + YamlConfiguration config = YamlConfiguration.loadConfiguration(file); + Set keys = config.getKeys(false); + + keys.forEach(key -> { + + if (!config.getBoolean(key + ".enable", true)) return; + + DroppedItem loot = new DroppedItem(key); + + String[] diff = StringUtils.split(config.getString(key + ".difficulty", "1-1"),"-"); + Difficulty difficulty = new Difficulty(Integer.parseInt(diff[0]), Integer.parseInt(diff[1])); + + int weight = config.getInt(key + ".weight",10); + int time = config.getInt(key + ".time",10000); + + loot.setDifficulty(difficulty); + loot.setTime(time); + loot.setWeight(weight); + loot.setNick(config.getString(key + ".nick", key)); + loot.setScore(config.getDouble(key + ".score",0)); + loot.setShowInFinder(config.getBoolean(key + ".show-in-fishfinder", true)); + loot.setRandomDurability(config.getBoolean(key + ".random-durability", false)); + + if (config.contains(key + ".group")) + loot.setGroup(config.getString(key + ".group")); + if (config.contains(key + ".layout")) + loot.setLayout(config.getStringList(key + ".layout")); + if (config.contains(key + ".random-enchantments")){ + List randomEnchants = new ArrayList<>(); + config.getConfigurationSection(key + ".random-enchantments").getValues(false).forEach((order, enchant) -> { + if (enchant instanceof MemorySection memorySection){ + LeveledEnchantment enchantment = new LeveledEnchantment(NamespacedKey.fromString(memorySection.getString("enchant")), memorySection.getInt("level")); + enchantment.setChance(memorySection.getDouble("chance")); + randomEnchants.add(enchantment); + } + }); + loot.setRandomEnchants(randomEnchants); + } + + List successActions = new ArrayList<>(); + if (config.contains(key + ".action.success.message")) + successActions.add(new MessageA(config.getStringList(key + ".action.success.message"), loot.getNick())); + if (config.contains(key + ".action.success.command")) + successActions.add(new CommandA(config.getStringList(key + ".action.success.command"), loot.getNick())); + if (config.contains(key + ".action.success.exp")) + successActions.add(new XPB(config.getInt(key + ".action.success.exp"))); + if (config.contains(key + ".action.success.mending")) + successActions.add(new XPA(config.getInt(key + ".action.success.mending"))); + if (config.contains(key + ".action.success.skill-xp")) + successActions.add(new FishingXPB(config.getInt(key + ".action.success.skill-xp"))); + loot.setSuccessActions(successActions); + + List failureActions = new ArrayList<>(); + if (config.contains(key + ".action.failure.message")) + failureActions.add(new MessageA(config.getStringList(key + ".action.failure.message"), loot.getNick())); + if (config.contains( key + ".action.failure.command")) + failureActions.add(new CommandA(config.getStringList(key + ".action.failure.command"), loot.getNick())); + if (config.contains( key + ".action.failure.exp")) + failureActions.add(new XPB(config.getInt( key + ".action.failure.exp"))); + if (config.contains(key + ".action.failure.mending")) + failureActions.add(new XPA(config.getInt(key + ".action.failure.mending"))); + if (config.contains( key + ".action.failure.skill-xp")) + failureActions.add(new FishingXPB(config.getInt( key + ".action.failure.skill-xp"))); + loot.setFailureActions(failureActions); + + List hookActions = new ArrayList<>(); + if (config.contains(key + ".action.hook.message")) + hookActions.add(new MessageA(config.getStringList(key + ".action.hook.message"), loot.getNick())); + if (config.contains(key + ".action.hook.command")) + hookActions.add(new CommandA(config.getStringList(key + ".action.hook.command"), loot.getNick())); + if (config.contains(key + ".action.hook.exp")) + successActions.add(new XPB(config.getInt(key + ".action.hook.exp"))); + if (config.contains(key + ".action.hook.mending")) + successActions.add(new XPA(config.getInt(key + ".action.hook.mending"))); + if (config.contains(key + ".action.hook.skill-xp")) + successActions.add(new FishingXPB(config.getInt(key + ".action.hook.skill-xp"))); + loot.setHookActions(hookActions); + + if (config.contains(key + ".requirements")){ + List requirements = new ArrayList<>(); + config.getConfigurationSection(key + ".requirements").getKeys(false).forEach(requirement -> { + switch (requirement){ + case "weather" -> requirements.add(new Weather(config.getStringList(key + ".requirements.weather"))); + case "ypos" -> requirements.add(new YPos(config.getStringList(key + ".requirements.ypos"))); + case "season" -> { + if (Config.season != null) requirements.add(new Season(config.getStringList(key + ".requirements.season"))); + else AdventureUtil.consoleMessage("[CustomFishing] You need to enable season hook in config.yml to use season condition!"); + } + case "world" -> requirements.add(new World(config.getStringList(key + ".requirements.world"))); + case "biome" -> requirements.add(new Biome(config.getStringList(key + ".requirements.biome"))); + case "permission" -> requirements.add(new Permission(config.getString(key + ".requirements.permission"))); + case "region" -> { + if (Config.wg) requirements.add(new Region(config.getStringList(key + ".requirements.regions"))); + else AdventureUtil.consoleMessage("[CustomFishing] You need to enable WorldGuard Integration to use region condition!"); + } + case "time" -> requirements.add(new Time(config.getStringList(key + ".requirements.time"))); + case "skill-level" -> requirements.add(new SkillLevel(config.getInt(key + ".requirements.skill-level"))); + case "papi-condition" -> { + if (Config.papi) requirements.add(new CustomPapi(config.getConfigurationSection(key + ".requirements.papi-condition").getValues(false))); + else AdventureUtil.consoleMessage("[CustomFishing] You need to enable PlaceholderAPI Integration to use papi condition!"); + } + } + }); + loot.setRequirements(requirements); + } + + String material = config.getString(key + ".material","COD"); + if (material.contains(":")) { + if (material.startsWith("ItemsAdder:")){ + loot.setType("ia"); + loot.setId(material.substring(11)); + } + else if (material.startsWith("Oraxen:")){ + loot.setType("oraxen"); + loot.setId(material.substring(7)); + } + else if (material.startsWith("MMOItems:")){ + loot.setType("mmoitems"); + loot.setId(material.substring(9)); + } + else if (material.startsWith("MythicMobs:")){ + loot.setType("mm"); + loot.setId(material.substring(11)); + } + else { + AdventureUtil.consoleMessage("Unknown Item: " + key); + return; + } + LOOT.put(key, loot); + } + else { + + Item item = new Item(material); + + item.setUnbreakable(config.getBoolean(key + ".unbreakable",false)); + + if (config.contains(key + ".display.lore")) + item.setLore(config.getStringList(key + ".display.lore")); + if (config.contains(key + ".display.name")) + item.setName(config.getString(key + ".display.name")); + if (config.contains(key + ".custom-model-data")) + item.setCustomModelData(config.getInt(key + ".custom-model-data")); + if (config.contains(key + ".enchantments")){ + List enchantmentList = new ArrayList<>(); + config.getConfigurationSection(key + ".enchantments").getKeys(false).forEach(enchant -> { + LeveledEnchantment leveledEnchantment = new LeveledEnchantment( + NamespacedKey.fromString(enchant), + config.getInt(key + ".enchantments." + enchant) + ); + enchantmentList.add(leveledEnchantment); + }); + item.setEnchantment(enchantmentList); + } + if (config.contains(key + ".item_flags")) { + ArrayList itemFlags = new ArrayList<>(); + config.getStringList(key + ".item_flags").forEach(flag -> itemFlags.add(ItemFlag.valueOf(flag))); + item.setItemFlags(itemFlags); + } + if (config.contains(key + ".nbt")){ + Map nbt = config.getConfigurationSection(key + ".nbt").getValues(false); + item.setNbt(nbt); + } + loot.setType("default"); + LOOT.put(key, loot); + if (item.getMaterial().equalsIgnoreCase("AIR")) LootItem.put(key, new ItemStack(Material.AIR)); + else LootItem.put(key, ItemStackUtil.getFromItem(item)); + } + }); + } + AdventureUtil.consoleMessage("[CustomFishing] Loaded " + LootItem.size() + " loots"); + } + + if (Config.mm){ + File mob_file = new File(CustomFishing.instance.getDataFolder() + File.separator + "mobs"); + if (!mob_file.exists()) { + if (!mob_file.mkdir()) { + AdventureUtil.consoleMessage("[CustomFishing] Error! Failed to create mobs folder..."); + return; + } + CustomFishing.instance.saveResource("loots" + File.separator + "ExampleMob.yml", false); + } + File[] mobFiles = mob_file.listFiles(); + if (mobFiles != null) { + for (File file : mobFiles) { + YamlConfiguration config = YamlConfiguration.loadConfiguration(file); + Set mobs = config.getKeys(false); + mobs.forEach(key -> { + + if (!config.getBoolean(key + ".enable", true)) return; + + Mob loot = new Mob(key, config.getString(key + ".mythicmobsID", key)); + + String[] diff = StringUtils.split(config.getString(key + ".difficulty", "1-1"),"-"); + Difficulty difficulty = new Difficulty(Integer.parseInt(diff[0]), Integer.parseInt(diff[1])); + + int weight = config.getInt(key + ".weight",10); + int time = config.getInt(key + ".time",10000); + + loot.setDifficulty(difficulty); + loot.setTime(time); + loot.setWeight(weight); + loot.setNick(config.getString(key + ".name", key)); + loot.setScore(config.getDouble(key + ".score",0)); + loot.setShowInFinder(config.getBoolean(key + ".show-in-fishfinder", true)); + loot.setMmLevel(config.getInt(key + ".level", 0)); + loot.setMobVector(new MobVector( + config.getDouble(key + ".vector.horizontal",1.1), + config.getDouble(key + ".vector.vertical",1.3) + )); + + if (config.contains(key + ".group")) + loot.setGroup(config.getString(key + ".group")); + if (config.contains(key + ".layout")) + loot.setLayout(config.getStringList(key + ".layout")); + + List successActions = new ArrayList<>(); + if (config.contains(key + ".action.success.message")) + successActions.add(new MessageA(config.getStringList(key + ".action.success.message"), loot.getNick())); + if (config.contains(key + ".action.success.command")) + successActions.add(new CommandA(config.getStringList(key + ".action.success.command"), loot.getNick())); + if (config.contains(key + ".action.success.exp")) + successActions.add(new XPB(config.getInt(key + ".action.success.exp"))); + if (config.contains(key + ".action.success.mending")) + successActions.add(new XPA(config.getInt(key + ".action.success.mending"))); + if (config.contains(key + ".action.success.skill-xp")) + successActions.add(new FishingXPB(config.getInt(key + ".action.success.skill-xp"))); + loot.setSuccessActions(successActions); + + List failureActions = new ArrayList<>(); + if (config.contains(key + ".action.failure.message")) + failureActions.add(new MessageA(config.getStringList(key + ".action.failure.message"), loot.getNick())); + if (config.contains(key + ".action.failure.command")) + failureActions.add(new CommandA(config.getStringList(key + ".action.failure.command"), loot.getNick())); + if (config.contains(key + ".action.failure.exp")) + failureActions.add(new XPB(config.getInt(key + ".action.failure.exp"))); + if (config.contains(key + ".action.failure.mending")) + failureActions.add(new XPA(config.getInt(key + ".action.failure.mending"))); + if (config.contains(key + ".action.failure.skill-xp")) + failureActions.add(new FishingXPB(config.getInt(key + ".action.failure.skill-xp"))); + loot.setFailureActions(failureActions); + + List hookActions = new ArrayList<>(); + if (config.contains(key + ".action.hook.message")) + hookActions.add(new MessageA(config.getStringList(key + ".action.hook.message"), loot.getNick())); + if (config.contains(key + ".action.hook.command")) + hookActions.add(new CommandA(config.getStringList(key + ".action.hook.command"), loot.getNick())); + if (config.contains(key + ".action.hook.exp")) + successActions.add(new XPB(config.getInt(key + ".action.hook.exp"))); + if (config.contains(key + ".action.hook.mending")) + successActions.add(new XPA(config.getInt(key + ".action.hook.mending"))); + if (config.contains(key + ".action.hook.skill-xp")) + successActions.add(new FishingXPB(config.getInt(key + ".action.hook.skill-xp"))); + loot.setHookActions(hookActions); + + if (config.contains(key + ".requirements")){ + List requirements = new ArrayList<>(); + config.getConfigurationSection(key + ".requirements").getKeys(false).forEach(requirement -> { + switch (requirement){ + case "weather" -> requirements.add(new Weather(config.getStringList(key + ".requirements.weather"))); + case "ypos" -> requirements.add(new YPos(config.getStringList(key + ".requirements.ypos"))); + case "season" -> { + if (Config.season != null) requirements.add(new Season(config.getStringList(key + ".requirements.season"))); + else AdventureUtil.consoleMessage("[CustomFishing] You need to enable season hook in config.yml to use season condition!"); + } + case "world" -> requirements.add(new World(config.getStringList(key + ".requirements.world"))); + case "biome" -> requirements.add(new Biome(config.getStringList(key + ".requirements.biome"))); + case "permission" -> requirements.add(new Permission(config.getString(key + ".requirements.permission"))); + case "region" -> { + if (Config.wg) requirements.add(new Region(config.getStringList(key + ".requirements.regions"))); + else AdventureUtil.consoleMessage("[CustomFishing] You need to enable WorldGuard Integration to use region condition!"); + } + case "time" -> requirements.add(new Time(config.getStringList(key + ".requirements.time"))); + case "skill-level" -> requirements.add(new SkillLevel(config.getInt(key + ".requirements.skill-level"))); + case "papi-condition" -> { + if (Config.papi) requirements.add(new CustomPapi(config.getConfigurationSection(key + ".requirements.papi-condition").getValues(false))); + else AdventureUtil.consoleMessage("[CustomFishing] You need to enable PlaceholderAPI Integration to use papi condition!"); + } + } + }); + loot.setRequirements(requirements); + } + LOOT.put(key, loot); + }); + } + AdventureUtil.consoleMessage("[CustomFishing] Loaded " + (LOOT.size() - LootItem.size()) + " mobs"); + } } } - /* - 载入util物品 - */ public static void loadUtil() { - UTIL.clear(); - UTILITEM.clear(); + UtilItem.clear(); - YamlConfiguration config = getConfig("utils.yml"); - Set keys = Objects.requireNonNull(config.getConfigurationSection("utils")).getKeys(false); - keys.forEach(key -> { - /* - 必设置的内容,为构造所需 - */ + File util_file = new File(CustomFishing.instance.getDataFolder() + File.separator + "utils"); - String material; - if (config.contains("utils." + key + ".material")) { - material = config.getString("utils." + key + ".material"); - } else { - AdventureManager.consoleMessage("[CustomFishing] Error! No material set for " + key + " !"); + if (!util_file.exists()) { + if (!util_file.mkdir()) { + AdventureUtil.consoleMessage("[CustomFishing] Error! Failed to create utils folder..."); return; } + CustomFishing.instance.saveResource("utils" + File.separator + "fishfinder.yml", false); + } - Util utilInstance = new Util(material); - if (config.contains("utils." + key + ".custom-model-data")) - utilInstance.setCustommodeldata(config.getInt("utils." + key + ".custom-model-data")); - if (config.contains("utils." + key + ".display.name")) - utilInstance.setName(config.getString("utils." + key + ".display.name")); - if (config.contains("utils." + key + ".display.lore")) - utilInstance.setLore(config.getStringList("utils." + key + ".display.lore")); - if (config.contains("utils." + key + ".nbt")) - utilInstance.setNbt((Map) config.getMapList("utils." + key + ".nbt").get(0)); - utilInstance.setUnbreakable(config.getBoolean("utils." + key + ".unbreakable",false)); - if (config.contains("utils." + key + ".enchantments")) { - ArrayList arrayList = new ArrayList<>(); - config.getStringList("utils." + key + ".enchantments").forEach(enchant -> { - String[] split = StringUtils.split(enchant, "/"); - NamespacedKey namespacedKey = NamespacedKey.fromString(split[0]); - arrayList.add(new Enchantment(namespacedKey, Integer.parseInt(split[1]))); - }); - utilInstance.setEnchantment(arrayList); - } - if (config.contains("utils." + key + ".item_flags")) { - ArrayList arrayList = new ArrayList<>(); - config.getStringList("utils." + key + ".item_flags").forEach(flag -> { - arrayList.add(ItemFlag.valueOf(flag)); - }); - utilInstance.setItemFlags(arrayList); - } + File[] files = util_file.listFiles(); - UTIL.put(key, utilInstance); - UTILITEM.put(key, NBTUtil.addIdentifier(ItemStackGenerator.fromItem(utilInstance), "util", key)); - }); - if (keys.size() != UTILITEM.size()){ - AdventureManager.consoleMessage("[CustomFishing] utils.yml exists error!"); - } else { - AdventureManager.consoleMessage("[CustomFishing] " + keys.size() + " utils loaded!"); + if (files != null) { + for (File file : files) { + YamlConfiguration config = YamlConfiguration.loadConfiguration(file); + Set keys = config.getKeys(false); + keys.forEach(key -> { + + if (!config.getBoolean(key + ".enable", true)) return; + + Item item = new Item(config.getString(key + ".material", "COMPASS")); + item.setUnbreakable(config.getBoolean(key + ".unbreakable", false)); + if (config.contains(key + ".display.lore")) + item.setLore(config.getStringList(key + ".display.lore")); + if (config.contains(key + ".display.name")) + item.setName(config.getString(key + ".display.name")); + if (config.contains(key + ".custom-model-data")) + item.setCustomModelData(config.getInt(key + ".custom-model-data")); + if (config.contains(key + ".enchantments")) { + List enchantmentList = new ArrayList<>(); + config.getConfigurationSection(key + ".enchantments").getKeys(false).forEach(enchant -> { + LeveledEnchantment leveledEnchantment = new LeveledEnchantment( + NamespacedKey.fromString(enchant), + config.getInt(key + ".enchantments." + enchant) + ); + enchantmentList.add(leveledEnchantment); + }); + item.setEnchantment(enchantmentList); + } + if (config.contains(key + ".item_flags")) { + ArrayList itemFlags = new ArrayList<>(); + config.getStringList(key + ".item_flags").forEach(flag -> itemFlags.add(ItemFlag.valueOf(flag))); + item.setItemFlags(itemFlags); + } + if (config.contains(key + ".nbt")) { + Map nbt = config.getConfigurationSection(key + ".nbt").getValues(false); + item.setNbt(nbt); + } + UtilItem.put(key, NBTUtil.addIdentifier(ItemStackUtil.getFromItem(item), "util", key)); + }); + } + AdventureUtil.consoleMessage("[CustomFishing] Loaded " + UtilItem.size() + " utils"); } } - /* - 载入rod物品 - */ public static void loadRod() { ROD.clear(); - RODITEM.clear(); + RodItem.clear(); - YamlConfiguration config = getConfig("rods.yml"); - Set keys = Objects.requireNonNull(config.getConfigurationSection("rods")).getKeys(false); + File rod_file = new File(CustomFishing.instance.getDataFolder() + File.separator + "rods"); - keys.forEach(key -> { - Rod rodInstance = new Rod(); - if (config.contains("rods." + key + ".display.name")) - rodInstance.setName(config.getString("rods." + key + ".display.name")); - if (config.contains("rods." + key + ".display.lore")) - rodInstance.setLore(config.getStringList("rods." + key + ".display.lore")); - if (config.contains("rods." + key + ".nbt")) - rodInstance.setNbt((Map)(config.getMapList("rods." + key + ".nbt").get(0))); - if (config.contains("rods." + key + ".custom-model-data")) - rodInstance.setCustommodeldata(config.getInt("rods." + key + ".custom-model-data")); - rodInstance.setUnbreakable(config.getBoolean("rods." + key + ".unbreakable",false)); - if (config.contains("rods." + key + ".enchantments")) { - ArrayList arrayList = new ArrayList<>(); - config.getStringList("rods." + key + ".enchantments").forEach(enchant -> { - String[] split = StringUtils.split(enchant, "/"); - NamespacedKey namespacedKey = NamespacedKey.fromString(split[0]); - arrayList.add(new Enchantment(namespacedKey, Integer.parseInt(split[1]))); - }); - rodInstance.setEnchantment(arrayList); + if (!rod_file.exists()) { + if (!rod_file.mkdir()) { + AdventureUtil.consoleMessage("[CustomFishing] Error! Failed to create rods folder..."); + return; } - if (config.contains("rods." + key + ".item_flags")) { - ArrayList arrayList = new ArrayList<>(); - config.getStringList("rods." + key + ".item_flags").forEach(flag -> { - arrayList.add(ItemFlag.valueOf(flag)); - }); - rodInstance.setItemFlags(arrayList); - } - if (config.contains("rods." + key + ".modifier")){ - config.getConfigurationSection("rods." + key + ".modifier").getKeys(false).forEach(modifier -> { - switch (modifier){ - case "weight-PM" -> { - HashMap pm = new HashMap<>(); - config.getConfigurationSection("rods." + key + ".modifier.weight-PM").getValues(false).forEach((group, value) -> { - pm.put(group, (Integer) value); - }); - rodInstance.setWeightPM(pm); - } - case "weight-MQ" -> { - HashMap mq = new HashMap<>(); - config.getConfigurationSection("rods." + key + ".modifier.weight-MQ").getValues(false).forEach((group, value) -> { - mq.put(group, (Double) value); - }); - rodInstance.setWeightMQ(mq); - } - case "time" -> rodInstance.setTime(config.getDouble("rods." + key + ".modifier.time")); - case "difficulty" -> rodInstance.setDifficulty(config.getInt("rods." + key + ".modifier.difficulty")); - case "double-loot" -> rodInstance.setDoubleLoot(config.getDouble("rods." + key + ".modifier.double-loot")); - case "score" -> rodInstance.setScoreModifier(config.getDouble("rods." + key + ".modifier.score")); + CustomFishing.instance.saveResource("rods" + File.separator + "default.yml", false); + } + + File[] files = rod_file.listFiles(); + + if (files != null) { + for (File file : files) { + + YamlConfiguration config = YamlConfiguration.loadConfiguration(file); + Set keys = config.getKeys(false); + + keys.forEach(key -> { + + Item item = new Item("FISHING_ROD"); + item.setUnbreakable(config.getBoolean(key + ".unbreakable", false)); + if (config.contains(key + ".display.lore")) + item.setLore(config.getStringList(key + ".display.lore")); + if (config.contains(key + ".display.name")) + item.setName(config.getString(key + ".display.name")); + if (config.contains(key + ".custom-model-data")) + item.setCustomModelData(config.getInt(key + ".custom-model-data")); + if (config.contains(key + ".enchantments")) { + List enchantmentList = new ArrayList<>(); + config.getConfigurationSection(key + ".enchantments").getKeys(false).forEach(enchant -> { + LeveledEnchantment leveledEnchantment = new LeveledEnchantment( + NamespacedKey.fromString(enchant), + config.getInt(key + ".enchantments." + enchant) + ); + enchantmentList.add(leveledEnchantment); + }); + item.setEnchantment(enchantmentList); + } + if (config.contains(key + ".item_flags")) { + ArrayList itemFlags = new ArrayList<>(); + config.getStringList(key + ".item_flags").forEach(flag -> itemFlags.add(ItemFlag.valueOf(flag))); + item.setItemFlags(itemFlags); + } + if (config.contains(key + ".nbt")) { + Map nbt = config.getConfigurationSection(key + ".nbt").getValues(false); + item.setNbt(nbt); + } + RodItem.put(key, NBTUtil.addIdentifier(ItemStackUtil.getFromItem(item), "rod", key)); + + if (config.contains(key + ".modifier")) { + Bonus bonus = new Bonus(); + config.getConfigurationSection(key + ".modifier").getKeys(false).forEach(modifier -> { + switch (modifier) { + case "weight-PM" -> { + HashMap pm = new HashMap<>(); + config.getConfigurationSection(key + ".modifier.weight-PM").getValues(false).forEach((group, value) -> { + pm.put(group, (Integer) value); + }); + bonus.setWeightPM(pm); + } + case "weight-MQ" -> { + HashMap mq = new HashMap<>(); + config.getConfigurationSection(key + ".modifier.weight-MQ").getValues(false).forEach((group, value) -> { + mq.put(group, Double.valueOf(String.valueOf(value))); + }); + bonus.setWeightMQ(mq); + } + case "time" -> bonus.setTime(config.getDouble(key + ".modifier.time")); + case "difficulty" -> bonus.setDifficulty(config.getInt(key + ".modifier.difficulty")); + case "double-loot" -> bonus.setDoubleLoot(config.getDouble(key + ".modifier.double-loot")); + case "score" -> bonus.setScore(config.getDouble(key + ".modifier.score")); + } + }); + ROD.put(key, bonus); } }); } - ROD.put(key, rodInstance); - RODITEM.put(key, NBTUtil.addIdentifier(ItemStackGenerator.fromItem(rodInstance), "rod", key)); - }); - - if (keys.size() != RODITEM.size()){ - AdventureManager.consoleMessage("[CustomFishing] rods.yml exists error!"); - } else { - AdventureManager.consoleMessage("[CustomFishing] " + keys.size() + " rods loaded!"); + AdventureUtil.consoleMessage("[CustomFishing] Loaded " + RodItem.size() + " rods"); } } public static void loadBait(){ - BAITITEM.clear(); BAIT.clear(); + BaitItem.clear(); - YamlConfiguration config = getConfig("baits.yml"); - Set keys = config.getConfigurationSection("baits").getKeys(false); + File bait_file = new File(CustomFishing.instance.getDataFolder() + File.separator + "baits"); - keys.forEach(key -> { - String material; - if (config.contains("baits." + key + ".material")) { - material = config.getString("baits." + key + ".material"); - } else { - AdventureManager.consoleMessage("[CustomFishing] Error! No material set for " + key + " !"); + if (!bait_file.exists()) { + if (!bait_file.mkdir()) { + AdventureUtil.consoleMessage("[CustomFishing] Error! Failed to create baits folder..."); return; } - Bait baitInstance = new Bait(material); - if (config.contains("baits." + key + ".display.lore")) - baitInstance.setLore(config.getStringList("baits." + key + ".display.lore")); - if (config.contains("baits." + key + ".display.name")) - baitInstance.setName(config.getString("baits." + key + ".display.name")); - if (config.contains("baits." + key + ".custom-model-data")) - baitInstance.setCustommodeldata(config.getInt("baits." + key + ".custom-model-data")); - if (config.contains("baits." + key + ".nbt")) { - baitInstance.setNbt((Map) config.getMapList("baits." + key + ".nbt").get(0)); - } - baitInstance.setUnbreakable(config.getBoolean("baits." + key + ".unbreakable",false)); - if (config.contains("baits." + key + ".enchantments")) { - ArrayList arrayList = new ArrayList<>(); - config.getStringList("baits." + key + ".enchantments").forEach(enchant -> { - String[] split = StringUtils.split(enchant, "/"); - NamespacedKey namespacedKey = NamespacedKey.fromString(split[0]); - arrayList.add(new Enchantment(namespacedKey, Integer.parseInt(split[1]))); - }); - baitInstance.setEnchantment(arrayList); - } - if (config.contains("baits." + key + ".item_flags")) { - ArrayList arrayList = new ArrayList<>(); - config.getStringList("baits." + key + ".item_flags").forEach(flag -> { - arrayList.add(ItemFlag.valueOf(flag)); - }); - baitInstance.setItemFlags(arrayList); - } - if (config.contains("baits." + key + ".modifier")){ - config.getConfigurationSection("baits." + key + ".modifier").getKeys(false).forEach(modifier -> { - switch (modifier){ - case "weight-PM" -> { - HashMap pm = new HashMap<>(); - config.getConfigurationSection("baits." + key + ".modifier.weight-PM").getValues(false).forEach((group, value) -> { - pm.put(group, (Integer) value); - }); - baitInstance.setWeightPM(pm); - } - case "weight-MQ" -> { - HashMap mq = new HashMap<>(); - config.getConfigurationSection("baits." + key + ".modifier.weight-MQ").getValues(false).forEach((group, value) -> { - mq.put(group, (Double) value); - }); - baitInstance.setWeightMQ(mq); - } - case "time" -> baitInstance.setTime(config.getDouble("baits." + key + ".modifier.time")); - case "difficulty" -> baitInstance.setDifficulty(config.getInt("baits." + key + ".modifier.difficulty")); - case "double-loot" -> baitInstance.setDoubleLoot(config.getDouble("baits." + key + ".modifier.double-loot")); - case "score" -> baitInstance.setScoreModifier(config.getDouble("baits." + key + ".modifier.score")); + CustomFishing.instance.saveResource("baits" + File.separator + "default.yml", false); + } + + File[] files = bait_file.listFiles(); + + if (files != null) { + for (File file : files) { + + YamlConfiguration config = YamlConfiguration.loadConfiguration(file); + Set keys = config.getKeys(false); + keys.forEach(key -> { + + Item item = new Item(config.getString(key + ".material", "PAPER")); + item.setUnbreakable(config.getBoolean(key + ".unbreakable", false)); + if (config.contains(key + ".display.lore")) + item.setLore(config.getStringList(key + ".display.lore")); + if (config.contains(key + ".display.name")) + item.setName(config.getString(key + ".display.name")); + if (config.contains(key + ".custom-model-data")) + item.setCustomModelData(config.getInt(key + ".custom-model-data")); + if (config.contains(key + ".enchantments")) { + List enchantmentList = new ArrayList<>(); + config.getConfigurationSection(key + ".enchantments").getKeys(false).forEach(enchant -> { + LeveledEnchantment leveledEnchantment = new LeveledEnchantment( + NamespacedKey.fromString(enchant), + config.getInt(key + ".enchantments." + enchant) + ); + enchantmentList.add(leveledEnchantment); + }); + item.setEnchantment(enchantmentList); + } + if (config.contains(key + ".item_flags")) { + ArrayList itemFlags = new ArrayList<>(); + config.getStringList(key + ".item_flags").forEach(flag -> itemFlags.add(ItemFlag.valueOf(flag))); + item.setItemFlags(itemFlags); + } + if (config.contains(key + ".nbt")) { + Map nbt = config.getConfigurationSection(key + ".nbt").getValues(false); + item.setNbt(nbt); + } + BaitItem.put(key, NBTUtil.addIdentifier(ItemStackUtil.getFromItem(item), "bait", key)); + + if (config.contains(key + ".modifier")) { + Bonus bonus = new Bonus(); + config.getConfigurationSection(key + ".modifier").getKeys(false).forEach(modifier -> { + switch (modifier) { + case "weight-PM" -> { + HashMap pm = new HashMap<>(); + config.getConfigurationSection(key + ".modifier.weight-PM").getValues(false).forEach((group, value) -> { + pm.put(group, (Integer) value); + }); + bonus.setWeightPM(pm); + } + case "weight-MQ" -> { + HashMap mq = new HashMap<>(); + config.getConfigurationSection(key + ".modifier.weight-MQ").getValues(false).forEach((group, value) -> { + mq.put(group, Double.valueOf(String.valueOf(value))); + }); + bonus.setWeightMQ(mq); + } + case "time" -> bonus.setTime(config.getDouble(key + ".modifier.time")); + case "difficulty" -> bonus.setDifficulty(config.getInt(key + ".modifier.difficulty")); + case "double-loot" -> bonus.setDoubleLoot(config.getDouble(key + ".modifier.double-loot")); + case "score" -> bonus.setScore(config.getDouble(key + ".modifier.score")); + } + }); + BAIT.put(key, bonus); } }); } - BAIT.put(key, baitInstance); - BAITITEM.put(key, NBTUtil.addIdentifier(ItemStackGenerator.fromItem(baitInstance), "bait", key)); - }); - - if (keys.size() != BAITITEM.size()){ - AdventureManager.consoleMessage("[CustomFishing] baits.yml exists error!"); - } else { - AdventureManager.consoleMessage("[CustomFishing] " + keys.size() + " baits loaded!"); + AdventureUtil.consoleMessage("[CustomFishing] Loaded " + BaitItem.size() + " baits"); } } public static void loadCompetitions(){ - Competitions.clear(); - CompetitionsCommand.clear(); + + CompetitionsT.clear(); + CompetitionsC.clear(); + YamlConfiguration config = getConfig("competition.yml"); - Set keys = config.getConfigurationSection("").getKeys(false); + + Set keys = config.getKeys(false); keys.forEach(key -> { CompetitionConfig competitionConfig; - if (config.getBoolean(key + ".bossbar.enable", true)){ + boolean enableBsb = config.getBoolean(key + ".bossbar.enable", false); + if (enableBsb){ competitionConfig = new CompetitionConfig(true); BossBarConfig bossBarConfig = new BossBarConfig( - config.getString(key + ".bossbar.text"), - BossBar.Overlay.valueOf(config.getString(key + ".bossbar.overlay")), - BossBar.Color.valueOf(config.getString(key + ".bossbar.color")), - config.getInt(key + ".bossbar.refresh-rate") + config.getString(key + ".bossbar.text", "You forget to set text for bossbar"), + BossBar.Overlay.valueOf(config.getString(key + ".bossbar.overlay","SOLID").toUpperCase()), + BossBar.Color.valueOf(config.getString(key + ".bossbar.color","WHITE").toUpperCase()), + config.getInt(key + ".bossbar.refresh-rate",5) ); competitionConfig.setBossBarConfig(bossBarConfig); - }else { - competitionConfig = new CompetitionConfig(false); - } + } else competitionConfig = new CompetitionConfig(false); + competitionConfig.setDuration(config.getInt(key + ".duration",600)); competitionConfig.setGoal(Goal.valueOf(config.getString(key + ".goal", "RANDOM"))); - if (config.contains(key + ".broadcast.start")){ + if (config.contains(key + ".broadcast.start")) competitionConfig.setStartMessage(config.getStringList(key + ".broadcast.start")); - } - if (config.contains(key + ".broadcast.end")){ + if (config.contains(key + ".broadcast.end")) competitionConfig.setEndMessage(config.getStringList(key + ".broadcast.end")); - } - if (config.contains(key + ".command.join")){ + if (config.contains(key + ".command.join")) competitionConfig.setJoinCommand(config.getStringList(key + ".command.join")); - } - if (config.contains(key + ".command.start")){ + if (config.contains(key + ".command.start")) competitionConfig.setStartCommand(config.getStringList(key + ".command.start")); - } - if (config.contains(key + ".command.end")){ + if (config.contains(key + ".command.end")) competitionConfig.setEndCommand(config.getStringList(key + ".command.end")); - } - if (config.contains(key + ".min-players")){ + if (config.contains(key + ".min-players")) competitionConfig.setMinPlayers(config.getInt(key + ".min-players")); - } if (config.contains(key + ".prize")){ - HashMap> rewardsMap = new HashMap<>(); + HashMap> rewardsMap = new HashMap<>(); config.getConfigurationSection(key + ".prize").getKeys(false).forEach(rank -> { - List rewards = new ArrayList<>(); - if (config.contains(key + ".prize." + rank + ".messages")){ - rewards.add(new MessageImpl(config.getStringList(key + ".prize." + rank + ".messages"))); - } - if (config.contains(key + ".prize." + rank + ".commands")){ - rewards.add(new CommandImpl(config.getStringList(key + ".prize." + rank + ".commands"))); - } + List rewards = new ArrayList<>(); + if (config.contains(key + ".prize." + rank + ".messages")) + rewards.add(new MessageB(config.getStringList(key + ".prize." + rank + ".messages"))); + if (config.contains(key + ".prize." + rank + ".commands")) + rewards.add(new CommandB(config.getStringList(key + ".prize." + rank + ".commands"))); rewardsMap.put(rank, rewards); }); competitionConfig.setRewards(rewardsMap); } - config.getStringList(key + ".start-time").forEach(time -> { - Competitions.put(time, competitionConfig); - }); - CompetitionsCommand.put(key, competitionConfig); + if (config.contains(key + ".start-time")){ + config.getStringList(key + ".start-time").forEach(time -> CompetitionsT.put(time, competitionConfig)); + } + CompetitionsC.put(key, competitionConfig); }); } public static void tryEnableJedis(){ YamlConfiguration configuration = ConfigReader.getConfig("redis.yml"); + useRedis = false; if (configuration.getBoolean("redis.enable")){ JedisUtil.initializeRedis(configuration); - JedisUtil.useRedis = true; - }else { - JedisUtil.useRedis = false; + useRedis = true; } } @@ -864,11 +902,10 @@ public class ConfigReader{ int range = config.getInt(key + ".range"); Set rates = Objects.requireNonNull(config.getConfigurationSection(key + ".layout")).getKeys(false); double[] successRate = new double[rates.size()]; - for(int i = 0; i < rates.size(); i++){ + for(int i = 0; i < rates.size(); i++) successRate[i] = config.getDouble(key + ".layout." +(i + 1)); - } int size = rates.size()*range -1; - Layout layout = new Layout(key, range, successRate, size); + Layout layout = new Layout(range, successRate, size); layout.setTitle(config.getString(key + ".title"," ")); layout.setBar(config.getString(key + ".subtitle.bar","뀃")); layout.setEnd(config.getString(key + ".subtitle.end","")); diff --git a/src/main/java/net/momirealms/customfishing/CustomFishing.java b/src/main/java/net/momirealms/customfishing/CustomFishing.java index 5b6e9494..be2c12ac 100644 --- a/src/main/java/net/momirealms/customfishing/CustomFishing.java +++ b/src/main/java/net/momirealms/customfishing/CustomFishing.java @@ -26,10 +26,11 @@ import net.momirealms.customfishing.competition.bossbar.BossBarManager; import net.momirealms.customfishing.helper.LibraryLoader; import net.momirealms.customfishing.hook.Placeholders; import net.momirealms.customfishing.listener.MMOItemsConverter; -import net.momirealms.customfishing.listener.PapiReload; -import net.momirealms.customfishing.listener.PlayerListener; -import net.momirealms.customfishing.utils.AdventureManager; -import net.momirealms.customfishing.utils.UpdateConfig; +import net.momirealms.customfishing.listener.PapiUnregister; +import net.momirealms.customfishing.listener.PickUpListener; +import net.momirealms.customfishing.listener.FishListener; +import net.momirealms.customfishing.utils.AdventureUtil; +import net.momirealms.customfishing.utils.ConfigUtil; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; @@ -57,34 +58,46 @@ public final class CustomFishing extends JavaPlugin { miniMessage = MiniMessage.miniMessage(); Objects.requireNonNull(Bukkit.getPluginCommand("customfishing")).setExecutor(new Execute()); Objects.requireNonNull(Bukkit.getPluginCommand("customfishing")).setTabCompleter(new TabComplete()); - Bukkit.getPluginManager().registerEvents(new PlayerListener(),this); - AdventureManager.consoleMessage("[CustomFishing] Running on " + Bukkit.getVersion()); + Bukkit.getPluginManager().registerEvents(new FishListener(),this); - ConfigReader.Reload(); - if (ConfigReader.Config.competition){ - competitionSchedule = new CompetitionSchedule(); - competitionSchedule.checkTime(); - Bukkit.getPluginManager().registerEvents(new BossBarManager(), this); - } - if (ConfigReader.Config.convertMMOItems){ - Bukkit.getPluginManager().registerEvents(new MMOItemsConverter(), this); - } - if (ConfigReader.Config.papi){ - placeholders = new Placeholders(); - placeholders.register(); - AdventureManager.consoleMessage("[CustomFishing] PlaceholderAPI Hooked!"); - Bukkit.getPluginManager().registerEvents(new PapiReload(), this); - } - ConfigReader.tryEnableJedis(); - if (!Objects.equals(ConfigReader.Config.version, "3")){ - UpdateConfig.update(); - } - AdventureManager.consoleMessage("[CustomFishing] Plugin Enabled!"); + AdventureUtil.consoleMessage("[CustomFishing] Running on " + Bukkit.getVersion()); + + Bukkit.getScheduler().runTaskAsynchronously(this, ()-> { + ConfigReader.Reload(); + if (ConfigReader.Config.competition){ + competitionSchedule = new CompetitionSchedule(); + competitionSchedule.checkTime(); + Bukkit.getScheduler().runTask(this, () -> { + Bukkit.getPluginManager().registerEvents(new BossBarManager(), this); + }); + } + if (ConfigReader.Config.convertMMOItems){ + Bukkit.getScheduler().runTask(this, () -> { + Bukkit.getPluginManager().registerEvents(new MMOItemsConverter(), this); + }); + } + if (ConfigReader.Config.papi){ + placeholders = new Placeholders(); + Bukkit.getScheduler().runTask(this, () -> { + placeholders.register(); + Bukkit.getPluginManager().registerEvents(new PapiUnregister(), this); + }); + } + ConfigReader.tryEnableJedis(); + if (!Objects.equals(ConfigReader.Config.version, "5")){ + ConfigUtil.update(); + } + if (ConfigReader.Config.preventPick){ + Bukkit.getScheduler().runTask(this, () -> { + Bukkit.getPluginManager().registerEvents(new PickUpListener(),this); + }); + } + AdventureUtil.consoleMessage("[CustomFishing] Plugin Enabled!"); + }); } @Override public void onDisable() { - if (competitionSchedule != null){ competitionSchedule.stopCheck(); competitionSchedule = null; diff --git a/src/main/java/net/momirealms/customfishing/command/Execute.java b/src/main/java/net/momirealms/customfishing/command/Execute.java index 9de8a533..e22bf789 100644 --- a/src/main/java/net/momirealms/customfishing/command/Execute.java +++ b/src/main/java/net/momirealms/customfishing/command/Execute.java @@ -1,25 +1,23 @@ package net.momirealms.customfishing.command; import net.momirealms.customfishing.competition.CompetitionSchedule; -import net.momirealms.customfishing.item.*; -import net.momirealms.customfishing.utils.AdventureManager; +import net.momirealms.customfishing.utils.AdventureUtil; import net.momirealms.customfishing.ConfigReader; -import net.momirealms.customfishing.utils.SaveItem; +import net.momirealms.customfishing.utils.ItemUtil; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; - -import javax.annotation.ParametersAreNonnullByDefault; +import org.jetbrains.annotations.NotNull; public class Execute implements CommandExecutor { + @Override - @ParametersAreNonnullByDefault - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean onCommand(CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { if (!(sender.hasPermission("customfishing.admin") || sender.isOp())) { - AdventureManager.playerMessage((Player) sender,ConfigReader.Message.prefix + ConfigReader.Message.noPerm); + AdventureUtil.playerMessage((Player) sender,ConfigReader.Message.prefix + ConfigReader.Message.noPerm); return true; } @@ -31,23 +29,23 @@ public class Execute implements CommandExecutor { if (args[0].equalsIgnoreCase("reload")) { ConfigReader.Reload(); if (sender instanceof Player){ - AdventureManager.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.reload); + AdventureUtil.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.reload); }else { - AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.reload); + AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.reload); } return true; } - if (args[0].equalsIgnoreCase("export")) { + if (args[0].equalsIgnoreCase("import")) { if (args.length < 2){ lackArgs(sender); return true; } if (sender instanceof Player player){ - SaveItem.saveToFile(player.getInventory().getItemInMainHand(), args[1]); - AdventureManager.playerMessage(player, ConfigReader.Message.prefix + "Done!"); + ItemUtil.saveToFile(player.getInventory().getItemInMainHand(), args[1]); + AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + "Done! File is saved to /CustomFishing/loots/" + args[1] + ".yml"); }else { - AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.noConsole); + AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.noConsole); } return true; } @@ -88,23 +86,23 @@ public class Execute implements CommandExecutor { //检验参数长度 [0]items [1]loot [2]get [3]xxx [4](amount) if (sender instanceof Player player){ //是否存在于缓存中 - if (!ConfigReader.LOOTITEM.containsKey(args[3])){ + if (!ConfigReader.LootItem.containsKey(args[3])){ noItem(sender); return true; } if (args.length == 4){ - ItemGive.givePlayerLoot(player, args[3], 1); - AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", "1").replace("{Item}",args[3])); + ItemUtil.givePlayerLoot(player, args[3], 1); + AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", "1").replace("{Item}",args[3])); }else { if (Integer.parseInt(args[4]) < 1){ wrongAmount(sender); return true; } - ItemGive.givePlayerLoot(player, args[3], Integer.parseInt(args[4])); - AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", args[4]).replace("{Item}",args[3])); + ItemUtil.givePlayerLoot(player, args[3], Integer.parseInt(args[4])); + AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", args[4]).replace("{Item}",args[3])); } }else { - AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.noConsole); + AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.noConsole); } return true; } @@ -121,19 +119,19 @@ public class Execute implements CommandExecutor { return true; } //是否存在于缓存中 - if (!ConfigReader.LOOTITEM.containsKey(args[4])){ + if (!ConfigReader.LootItem.containsKey(args[4])){ noItem(sender); return true; } if (args.length == 5){ - ItemGive.givePlayerLoot(player, args[4], 1); + ItemUtil.givePlayerLoot(player, args[4], 1); giveItem(sender, args[3], args[4], 1); }else { if (Integer.parseInt(args[5]) < 1){ wrongAmount(sender); return true; } - ItemGive.givePlayerLoot(player, args[4], Integer.parseInt(args[5])); + ItemUtil.givePlayerLoot(player, args[4], Integer.parseInt(args[5])); giveItem(sender, args[3], args[4], Integer.parseInt(args[5])); } return true; @@ -147,23 +145,23 @@ public class Execute implements CommandExecutor { //检验参数长度 [0]items [1]util [2]get [3]xxx [4](amount) if (sender instanceof Player player){ //是否存在于缓存中 - if (!ConfigReader.UTIL.containsKey(args[3])){ + if (!ConfigReader.UtilItem.containsKey(args[3])){ noItem(sender); return true; } if (args.length == 4){ - ItemGive.givePlayerUtil(player, args[3], 1); - AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", "1").replace("{Item}",args[3])); + ItemUtil.givePlayerUtil(player, args[3], 1); + AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", "1").replace("{Item}",args[3])); }else { if (Integer.parseInt(args[4]) < 1){ wrongAmount(sender); return true; } - ItemGive.givePlayerUtil(player, args[3], Integer.parseInt(args[4])); - AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", args[4]).replace("{Item}",args[3])); + ItemUtil.givePlayerUtil(player, args[3], Integer.parseInt(args[4])); + AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", args[4]).replace("{Item}",args[3])); } }else { - AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.noConsole); + AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.noConsole); } return true; } @@ -180,19 +178,19 @@ public class Execute implements CommandExecutor { return true; } //是否存在于缓存中 - if (!ConfigReader.UTIL.containsKey(args[4])){ + if (!ConfigReader.UtilItem.containsKey(args[4])){ noItem(sender); return true; } if (args.length == 5){ - ItemGive.givePlayerUtil(player, args[4], 1); + ItemUtil.givePlayerUtil(player, args[4], 1); giveItem(sender, args[3], args[4], 1); }else { if (Integer.parseInt(args[5]) < 1){ wrongAmount(sender); return true; } - ItemGive.givePlayerUtil(player, args[4], Integer.parseInt(args[5])); + ItemUtil.givePlayerUtil(player, args[4], Integer.parseInt(args[5])); giveItem(sender, args[3], args[4], Integer.parseInt(args[5])); } return true; @@ -203,23 +201,23 @@ public class Execute implements CommandExecutor { //检验参数长度 [0]items [1]rod [2]get [3]xxx [4](amount) if (sender instanceof Player player){ //是否存在于缓存中 - if (!ConfigReader.ROD.containsKey(args[3])){ + if (!ConfigReader.RodItem.containsKey(args[3])){ noItem(sender); return true; } if (args.length == 4){ - ItemGive.givePlayerRod(player, args[3], 1); - AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", "1").replace("{Item}",args[3])); + ItemUtil.givePlayerRod(player, args[3], 1); + AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", "1").replace("{Item}",args[3])); }else { if (Integer.parseInt(args[4]) < 1){ wrongAmount(sender); return true; } - ItemGive.givePlayerRod(player, args[3], Integer.parseInt(args[4])); - AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", args[4]).replace("{Item}",args[3])); + ItemUtil.givePlayerRod(player, args[3], Integer.parseInt(args[4])); + AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", args[4]).replace("{Item}",args[3])); } }else { - AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.noConsole); + AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.noConsole); } return true; } @@ -236,19 +234,19 @@ public class Execute implements CommandExecutor { return true; } //是否存在于缓存中 - if (!ConfigReader.ROD.containsKey(args[4])){ + if (!ConfigReader.RodItem.containsKey(args[4])){ noItem(sender); return true; } if (args.length == 5){ - ItemGive.givePlayerRod(player, args[4], 1); + ItemUtil.givePlayerRod(player, args[4], 1); giveItem(sender, args[3], args[4], 1); }else { if (Integer.parseInt(args[5]) < 1){ wrongAmount(sender); return true; } - ItemGive.givePlayerRod(player, args[4], Integer.parseInt(args[5])); + ItemUtil.givePlayerRod(player, args[4], Integer.parseInt(args[5])); giveItem(sender, args[3], args[4], Integer.parseInt(args[5])); } return true; @@ -259,23 +257,23 @@ public class Execute implements CommandExecutor { //检验参数长度 [0]items [1]bait [2]get [3]xxx [4](amount) if (sender instanceof Player player){ //是否存在于缓存中 - if (!ConfigReader.BAIT.containsKey(args[3])){ + if (!ConfigReader.BaitItem.containsKey(args[3])){ noItem(sender); return true; } if (args.length == 4){ - ItemGive.givePlayerBait(player, args[3], 1); - AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", "1").replace("{Item}",args[3])); + ItemUtil.givePlayerBait(player, args[3], 1); + AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", "1").replace("{Item}",args[3])); }else { if (Integer.parseInt(args[4]) < 1){ wrongAmount(sender); return true; } - ItemGive.givePlayerBait(player, args[3], Integer.parseInt(args[4])); - AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", args[4]).replace("{Item}",args[3])); + ItemUtil.givePlayerBait(player, args[3], Integer.parseInt(args[4])); + AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", args[4]).replace("{Item}",args[3])); } }else { - AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.noConsole); + AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.noConsole); } return true; } @@ -292,19 +290,19 @@ public class Execute implements CommandExecutor { return true; } //是否存在于缓存中 - if (!ConfigReader.BAIT.containsKey(args[4])){ + if (!ConfigReader.BaitItem.containsKey(args[4])){ noItem(sender); return true; } if (args.length == 5){ - ItemGive.givePlayerBait(player, args[4], 1); + ItemUtil.givePlayerBait(player, args[4], 1); giveItem(sender, args[3], args[4], 1); }else { if (Integer.parseInt(args[5]) < 1){ wrongAmount(sender); return true; } - ItemGive.givePlayerBait(player, args[4], Integer.parseInt(args[5])); + ItemUtil.givePlayerBait(player, args[4], Integer.parseInt(args[5])); giveItem(sender, args[3], args[4], Integer.parseInt(args[5])); } return true; @@ -316,74 +314,74 @@ public class Execute implements CommandExecutor { private void lackArgs(CommandSender sender){ if (sender instanceof Player){ - AdventureManager.playerMessage((Player) sender,ConfigReader.Message.prefix + ConfigReader.Message.lackArgs); + AdventureUtil.playerMessage((Player) sender,ConfigReader.Message.prefix + ConfigReader.Message.lackArgs); }else { - AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.lackArgs); + AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.lackArgs); } } private void notOnline(CommandSender sender){ if (sender instanceof Player){ - AdventureManager.playerMessage((Player) sender,ConfigReader.Message.prefix + ConfigReader.Message.notOnline); + AdventureUtil.playerMessage((Player) sender,ConfigReader.Message.prefix + ConfigReader.Message.notOnline); }else { - AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.notOnline); + AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.notOnline); } } private void noItem(CommandSender sender){ if (sender instanceof Player){ - AdventureManager.playerMessage((Player) sender,ConfigReader.Message.prefix + ConfigReader.Message.notExist); + AdventureUtil.playerMessage((Player) sender,ConfigReader.Message.prefix + ConfigReader.Message.notExist); }else { - AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.notExist); + AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.notExist); } } private void giveItem(CommandSender sender, String name, String item, int amount){ String string = ConfigReader.Message.prefix + ConfigReader.Message.giveItem.replace("{Amount}", String.valueOf(amount)).replace("{Player}",name).replace("{Item}",item); if (sender instanceof Player){ - AdventureManager.playerMessage((Player) sender, string); + AdventureUtil.playerMessage((Player) sender, string); }else { - AdventureManager.consoleMessage(string); + AdventureUtil.consoleMessage(string); } } private void wrongAmount(CommandSender sender){ if (sender instanceof Player){ - AdventureManager.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.wrongAmount); + AdventureUtil.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.wrongAmount); }else { - AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.wrongAmount); + AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.wrongAmount); } } private void forceSuccess(CommandSender sender){ if (sender instanceof Player){ - AdventureManager.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.forceSuccess); + AdventureUtil.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.forceSuccess); }else { - AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.forceSuccess); + AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.forceSuccess); } } private void forceFailure(CommandSender sender){ if (sender instanceof Player){ - AdventureManager.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.forceFailure); + AdventureUtil.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.forceFailure); }else { - AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.forceFailure); + AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.forceFailure); } } private void forceEnd(CommandSender sender){ if (sender instanceof Player){ - AdventureManager.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.forceEnd); + AdventureUtil.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.forceEnd); }else { - AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.forceEnd); + AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.forceEnd); } } private void forceCancel(CommandSender sender){ if (sender instanceof Player){ - AdventureManager.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.forceCancel); + AdventureUtil.playerMessage((Player) sender, ConfigReader.Message.prefix + ConfigReader.Message.forceCancel); }else { - AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.forceCancel); + AdventureUtil.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.forceCancel); } } } diff --git a/src/main/java/net/momirealms/customfishing/command/TabComplete.java b/src/main/java/net/momirealms/customfishing/command/TabComplete.java index 08680fe6..aa758723 100644 --- a/src/main/java/net/momirealms/customfishing/command/TabComplete.java +++ b/src/main/java/net/momirealms/customfishing/command/TabComplete.java @@ -5,23 +5,22 @@ import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; +import org.jetbrains.annotations.NotNull; -import javax.annotation.ParametersAreNonnullByDefault; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class TabComplete implements TabCompleter { @Override - @ParametersAreNonnullByDefault - public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + public List onTabComplete(CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) { if (!(sender.hasPermission("customfishing.admin") || sender.isOp())) { return null; } if (args.length == 1){ List arrayList = new ArrayList<>(); - for (String cmd : Arrays.asList("competition","reload","items","export")) { + for (String cmd : Arrays.asList("competition","reload", "items","import")) { if (cmd.startsWith(args[0])) arrayList.add(cmd); } @@ -36,7 +35,7 @@ public class TabComplete implements TabCompleter { } return arrayList; } - if (args[0].equalsIgnoreCase("export")){ + if (args[0].equalsIgnoreCase("import")){ return List.of("FileName"); } if (args[0].equalsIgnoreCase("competition")){ @@ -229,18 +228,18 @@ public class TabComplete implements TabCompleter { } private List loots(){ - return new ArrayList<>(ConfigReader.LOOTITEM.keySet()); + return new ArrayList<>(ConfigReader.LootItem.keySet()); } private List utils(){ - return new ArrayList<>(ConfigReader.UTIL.keySet()); + return new ArrayList<>(ConfigReader.UtilItem.keySet()); } private List rods() { - return new ArrayList<>(ConfigReader.ROD.keySet()); + return new ArrayList<>(ConfigReader.RodItem.keySet()); } private List baits() { - return new ArrayList<>(ConfigReader.BAIT.keySet()); + return new ArrayList<>(ConfigReader.BaitItem.keySet()); } private List competitions() { - return new ArrayList<>(ConfigReader.CompetitionsCommand.keySet()); + return new ArrayList<>(ConfigReader.CompetitionsC.keySet()); } } diff --git a/src/main/java/net/momirealms/customfishing/competition/Competition.java b/src/main/java/net/momirealms/customfishing/competition/Competition.java index ad9d4f38..bbf5bbf7 100644 --- a/src/main/java/net/momirealms/customfishing/competition/Competition.java +++ b/src/main/java/net/momirealms/customfishing/competition/Competition.java @@ -24,9 +24,8 @@ import net.momirealms.customfishing.competition.bossbar.BossBarManager; import net.momirealms.customfishing.competition.ranking.Ranking; import net.momirealms.customfishing.competition.ranking.RankingImpl; import net.momirealms.customfishing.competition.ranking.RedisRankingImpl; -import net.momirealms.customfishing.competition.reward.Reward; -import net.momirealms.customfishing.utils.AdventureManager; -import net.momirealms.customfishing.utils.JedisUtil; +import net.momirealms.customfishing.object.action.ActionB; +import net.momirealms.customfishing.utils.AdventureUtil; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; @@ -50,7 +49,7 @@ public class Competition { private final List endCommand; private final List startCommand; private final List joinCommand; - private final HashMap> rewardsMap; + private final HashMap> rewardsMap; public static long remainingTime; public static float progress; @@ -79,7 +78,7 @@ public class Competition { Collection playerCollections = Bukkit.getOnlinePlayers(); if (playerCollections.size() >= minPlayers || forceStart) { status = true; - if (JedisUtil.useRedis){ + if (ConfigReader.useRedis){ ranking = new RedisRankingImpl(); }else { ranking = new RankingImpl(); @@ -88,7 +87,7 @@ public class Competition { if (startMessage != null){ playerCollections.forEach(player -> { startMessage.forEach(message -> { - AdventureManager.playerMessage(player, message); + AdventureUtil.playerMessage(player, message); }); }); } @@ -100,7 +99,7 @@ public class Competition { } else { playerCollections.forEach(player -> { - AdventureManager.playerMessage(player, ConfigReader.Message.notEnoughPlayers); + AdventureUtil.playerMessage(player, ConfigReader.Message.notEnoughPlayers); }); } } @@ -155,7 +154,7 @@ public class Competition { }); Bukkit.getOnlinePlayers().forEach(player -> { newMessage.forEach(message -> { - AdventureManager.playerMessage(player, message); + AdventureUtil.playerMessage(player, message); }); }); } @@ -178,20 +177,20 @@ public class Competition { String playerName = iterator.next(); Player player = Bukkit.getPlayer(playerName); if (player != null){ - for (Reward reward : rewardsMap.get(String.valueOf(i))) { - reward.giveReward(player); + for (ActionB action : rewardsMap.get(String.valueOf(i))) { + action.doOn(player); } } i++; } else { - List rewards = rewardsMap.get("participation"); - if (rewards != null) { + List actions = rewardsMap.get("participation"); + if (actions != null) { iterator.forEachRemaining(playerName -> { Player player = Bukkit.getPlayer(playerName); if (player != null){ - for (Reward reward : rewards) { - reward.giveReward(player); + for (ActionB action : actions) { + action.doOn(player); } } }); @@ -213,7 +212,6 @@ public class Competition { public void refreshRanking(String player, float score) { if (this.goal != Goal.TOTAL_SCORE) score = 1.0f; - if (score == 0) return; ranking.refreshData(player, score); } diff --git a/src/main/java/net/momirealms/customfishing/competition/CompetitionConfig.java b/src/main/java/net/momirealms/customfishing/competition/CompetitionConfig.java index 920647f6..9b2b8f0f 100644 --- a/src/main/java/net/momirealms/customfishing/competition/CompetitionConfig.java +++ b/src/main/java/net/momirealms/customfishing/competition/CompetitionConfig.java @@ -18,7 +18,7 @@ package net.momirealms.customfishing.competition; import net.momirealms.customfishing.competition.bossbar.BossBarConfig; -import net.momirealms.customfishing.competition.reward.Reward; +import net.momirealms.customfishing.object.action.ActionB; import java.util.HashMap; import java.util.List; @@ -35,7 +35,7 @@ public class CompetitionConfig { private Goal goal; private BossBarConfig bossBarConfig; private final boolean enableBossBar; - private HashMap> rewards; + private HashMap> rewards; public CompetitionConfig(boolean enableBossBar){this.enableBossBar = enableBossBar;} @@ -48,7 +48,7 @@ public class CompetitionConfig { public void setEndCommand(List endCommand) {this.endCommand = endCommand;} public void setJoinCommand(List joinCommand) {this.joinCommand = joinCommand;} public void setMinPlayers(int minPlayers) {this.minPlayers = minPlayers;} - public HashMap> getRewards() {return rewards;} + public HashMap> getRewards() {return rewards;} public Goal getGoal() {return goal;} public int getMinPlayers() {return minPlayers;} @@ -57,7 +57,7 @@ public class CompetitionConfig { public boolean isEnableBossBar() {return enableBossBar;} public List getEndMessage() {return endMessage;} public List getStartMessage() {return startMessage;} - public void setRewards(HashMap> rewards) {this.rewards = rewards;} + public void setRewards(HashMap> rewards) {this.rewards = rewards;} public List getEndCommand() {return endCommand;} public List getJoinCommand() {return joinCommand;} public List getStartCommand() {return startCommand;} diff --git a/src/main/java/net/momirealms/customfishing/competition/CompetitionSchedule.java b/src/main/java/net/momirealms/customfishing/competition/CompetitionSchedule.java index 58ab73d4..a21869cb 100644 --- a/src/main/java/net/momirealms/customfishing/competition/CompetitionSchedule.java +++ b/src/main/java/net/momirealms/customfishing/competition/CompetitionSchedule.java @@ -37,7 +37,7 @@ public class CompetitionSchedule { } public static boolean startCompetition(String competitionName){ - CompetitionConfig competitionConfig = ConfigReader.CompetitionsCommand.get(competitionName); + CompetitionConfig competitionConfig = ConfigReader.CompetitionsC.get(competitionName); if (competitionConfig == null) return false; if (competition != null && competition.isGoingOn()){ competition.end(); @@ -73,7 +73,7 @@ public class CompetitionSchedule { BukkitTask checkTimeTask = new BukkitRunnable(){ public void run(){ if (isANewMinute()){ - CompetitionConfig competitionConfig = ConfigReader.Competitions.get(getCurrentTime()); + CompetitionConfig competitionConfig = ConfigReader.CompetitionsT.get(getCurrentTime()); if (competitionConfig != null){ startCompetition(competitionConfig); } diff --git a/src/main/java/net/momirealms/customfishing/competition/bossbar/BossBarManager.java b/src/main/java/net/momirealms/customfishing/competition/bossbar/BossBarManager.java index bd455966..0f0e971a 100644 --- a/src/main/java/net/momirealms/customfishing/competition/bossbar/BossBarManager.java +++ b/src/main/java/net/momirealms/customfishing/competition/bossbar/BossBarManager.java @@ -19,7 +19,7 @@ package net.momirealms.customfishing.competition.bossbar; import net.momirealms.customfishing.ConfigReader; import net.momirealms.customfishing.competition.CompetitionSchedule; -import net.momirealms.customfishing.utils.AdventureManager; +import net.momirealms.customfishing.utils.AdventureUtil; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -41,7 +41,7 @@ public class BossBarManager implements Listener { BossBarTimer timerTask = new BossBarTimer(player, CompetitionSchedule.competition.getBossBarConfig()); cache.put(player, timerTask); }else { - AdventureManager.playerMessage(player, ConfigReader.Message.competitionOn); + AdventureUtil.playerMessage(player, ConfigReader.Message.competitionOn); } } } diff --git a/src/main/java/net/momirealms/customfishing/competition/reward/MessageImpl.java b/src/main/java/net/momirealms/customfishing/competition/reward/MessageImpl.java deleted file mode 100644 index 2f250cc3..00000000 --- a/src/main/java/net/momirealms/customfishing/competition/reward/MessageImpl.java +++ /dev/null @@ -1,40 +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.competition.reward; - -import net.momirealms.customfishing.utils.AdventureManager; -import org.bukkit.entity.Player; - -import java.util.List; - -public class MessageImpl implements Reward{ - - private final List messages; - - public MessageImpl(List messages){ - this.messages = messages; - } - - @Override - public void giveReward(Player player) { - if (!player.isOnline()) return; - messages.forEach(message -> { - AdventureManager.playerMessage(player, message); - }); - } -} diff --git a/src/main/java/net/momirealms/customfishing/competition/reward/Reward.java b/src/main/java/net/momirealms/customfishing/competition/reward/Reward.java deleted file mode 100644 index 836b725b..00000000 --- a/src/main/java/net/momirealms/customfishing/competition/reward/Reward.java +++ /dev/null @@ -1,24 +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.competition.reward; - -import org.bukkit.entity.Player; - -public interface Reward { - void giveReward(Player player); -} diff --git a/src/main/java/net/momirealms/customfishing/helper/LibraryLoader.java b/src/main/java/net/momirealms/customfishing/helper/LibraryLoader.java index 7170fd57..d268313f 100644 --- a/src/main/java/net/momirealms/customfishing/helper/LibraryLoader.java +++ b/src/main/java/net/momirealms/customfishing/helper/LibraryLoader.java @@ -43,7 +43,6 @@ import java.util.Objects; * Resolves {@link MavenLibrary} annotations for a class, and loads the dependency * into the classloader. */ -@NonnullByDefault public final class LibraryLoader { @SuppressWarnings("Guava") @@ -119,7 +118,6 @@ public final class LibraryLoader { return jarDir; } - @NonnullByDefault public static final class Dependency { private final String groupId; private final String artifactId; diff --git a/src/main/java/net/momirealms/customfishing/helper/Log.java b/src/main/java/net/momirealms/customfishing/helper/Log.java index 175afaeb..1de2eb0f 100644 --- a/src/main/java/net/momirealms/customfishing/helper/Log.java +++ b/src/main/java/net/momirealms/customfishing/helper/Log.java @@ -27,33 +27,32 @@ package net.momirealms.customfishing.helper; import net.momirealms.customfishing.CustomFishing; import org.bukkit.Bukkit; +import org.jetbrains.annotations.NotNull; import java.util.logging.Level; -import javax.annotation.Nonnull; - /** * Utility for quickly accessing a logger instance without using {@link Bukkit#getLogger()} */ public final class Log { - public static void info(@Nonnull String s) { + public static void info(@NotNull String s) { CustomFishing.instance.getLogger().info(s); } - public static void warn(@Nonnull String s) { + public static void warn(@NotNull String s) { CustomFishing.instance.getLogger().warning(s); } - public static void severe(@Nonnull String s) { + public static void severe(@NotNull String s) { CustomFishing.instance.getLogger().severe(s); } - public static void warn(@Nonnull String s, Throwable t) { + public static void warn(@NotNull String s, Throwable t) { CustomFishing.instance.getLogger().log(Level.WARNING, s, t); } - public static void severe(@Nonnull String s, Throwable t) { + public static void severe(@NotNull String s, Throwable t) { CustomFishing.instance.getLogger().log(Level.SEVERE, s, t); } diff --git a/src/main/java/net/momirealms/customfishing/helper/MavenLibraries.java b/src/main/java/net/momirealms/customfishing/helper/MavenLibraries.java index 0a89bf49..63c08271 100644 --- a/src/main/java/net/momirealms/customfishing/helper/MavenLibraries.java +++ b/src/main/java/net/momirealms/customfishing/helper/MavenLibraries.java @@ -25,14 +25,14 @@ package net.momirealms.customfishing.helper; +import org.jetbrains.annotations.NotNull; + import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import javax.annotation.Nonnull; - /** * Annotation to indicate the required libraries for a class. */ @@ -41,7 +41,7 @@ import javax.annotation.Nonnull; @Retention(RetentionPolicy.RUNTIME) public @interface MavenLibraries { - @Nonnull + @NotNull MavenLibrary[] value() default {}; } diff --git a/src/main/java/net/momirealms/customfishing/helper/MavenLibrary.java b/src/main/java/net/momirealms/customfishing/helper/MavenLibrary.java index de197ae9..513a652e 100644 --- a/src/main/java/net/momirealms/customfishing/helper/MavenLibrary.java +++ b/src/main/java/net/momirealms/customfishing/helper/MavenLibrary.java @@ -25,6 +25,8 @@ package net.momirealms.customfishing.helper; +import org.jetbrains.annotations.NotNull; + import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Repeatable; @@ -32,8 +34,6 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import javax.annotation.Nonnull; - /** * Annotation to indicate a required library for a class. */ @@ -48,7 +48,7 @@ public @interface MavenLibrary { * * @return the group id of the library */ - @Nonnull + @NotNull String groupId(); /** @@ -56,7 +56,7 @@ public @interface MavenLibrary { * * @return the artifact id of the library */ - @Nonnull + @NotNull String artifactId(); /** @@ -64,7 +64,7 @@ public @interface MavenLibrary { * * @return the version of the library */ - @Nonnull + @NotNull String version(); /** @@ -72,7 +72,7 @@ public @interface MavenLibrary { * * @return the repo where the library can be obtained from */ - @Nonnull + @NotNull Repository repo() default @Repository(url = "https://repo1.maven.org/maven2"); } diff --git a/src/main/java/net/momirealms/customfishing/helper/NonnullByDefault.java b/src/main/java/net/momirealms/customfishing/helper/NonnullByDefault.java deleted file mode 100644 index 1c63b4b9..00000000 --- a/src/main/java/net/momirealms/customfishing/helper/NonnullByDefault.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This file is part of helper, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.momirealms.customfishing.helper; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -import javax.annotation.Nonnull; -import javax.annotation.meta.TypeQualifierDefault; - -@Nonnull -@Documented -@TypeQualifierDefault({ - ElementType.FIELD, - ElementType.METHOD, - ElementType.PARAMETER -}) -@Retention(RetentionPolicy.RUNTIME) -public @interface NonnullByDefault { - -} diff --git a/src/main/java/net/momirealms/customfishing/helper/Repository.java b/src/main/java/net/momirealms/customfishing/helper/Repository.java index 1764e119..2e1a92e8 100644 --- a/src/main/java/net/momirealms/customfishing/helper/Repository.java +++ b/src/main/java/net/momirealms/customfishing/helper/Repository.java @@ -25,14 +25,13 @@ package net.momirealms.customfishing.helper; +import org.jetbrains.annotations.NotNull; + import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; - -import javax.annotation.Nonnull; - /** * Represents a maven repository. */ @@ -46,7 +45,7 @@ public @interface Repository { * * @return the base url of the repository */ - @Nonnull + @NotNull String url(); } diff --git a/src/main/java/net/momirealms/customfishing/helper/URLClassLoaderAccess.java b/src/main/java/net/momirealms/customfishing/helper/URLClassLoaderAccess.java index 8ddf8f42..adb705ca 100644 --- a/src/main/java/net/momirealms/customfishing/helper/URLClassLoaderAccess.java +++ b/src/main/java/net/momirealms/customfishing/helper/URLClassLoaderAccess.java @@ -25,13 +25,13 @@ package net.momirealms.customfishing.helper; +import org.jetbrains.annotations.NotNull; + import java.lang.reflect.Field; import java.net.URL; import java.net.URLClassLoader; import java.util.Collection; -import javax.annotation.Nonnull; - /** * Provides access to {@link URLClassLoader}#addURL. */ @@ -63,7 +63,7 @@ public abstract class URLClassLoaderAccess { * * @param url the URL to add */ - public abstract void addURL(@Nonnull URL url); + public abstract void addURL(@NotNull URL url); /** * Accesses using sun.misc.Unsafe, supported on Java 9+. @@ -117,7 +117,7 @@ public abstract class URLClassLoaderAccess { } @Override - public void addURL(@Nonnull URL url) { + public void addURL(@NotNull URL url) { this.unopenedURLs.add(url); this.pathURLs.add(url); } @@ -131,7 +131,7 @@ public abstract class URLClassLoaderAccess { } @Override - public void addURL(@Nonnull URL url) { + public void addURL(@NotNull URL url) { throw new UnsupportedOperationException(); } } diff --git a/src/main/java/net/momirealms/customfishing/hook/CustomCropsSeason.java b/src/main/java/net/momirealms/customfishing/hook/CustomCropsSeason.java deleted file mode 100644 index a33e2dc2..00000000 --- a/src/main/java/net/momirealms/customfishing/hook/CustomCropsSeason.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.momirealms.customfishing.hook; - -import net.momirealms.customcrops.api.CustomCropsAPI; -import org.bukkit.World; - -public class CustomCropsSeason { - - public static String getSeason(World world){ - return CustomCropsAPI.getSeason(world.getName()); - } -} diff --git a/src/main/java/net/momirealms/customfishing/hook/ItemsAdderItem.java b/src/main/java/net/momirealms/customfishing/hook/ItemsAdderItem.java new file mode 100644 index 00000000..da094515 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/hook/ItemsAdderItem.java @@ -0,0 +1,11 @@ +package net.momirealms.customfishing.hook; + +import dev.lone.itemsadder.api.CustomStack; +import org.bukkit.inventory.ItemStack; + +public class ItemsAdderItem { + + public static ItemStack getItemStack(String namespacedID){ + return CustomStack.getInstance(namespacedID).getItemStack(); + } +} diff --git a/src/main/java/net/momirealms/customfishing/hook/MMOItemsHook.java b/src/main/java/net/momirealms/customfishing/hook/MMOItemsHook.java new file mode 100644 index 00000000..979f3b26 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/hook/MMOItemsHook.java @@ -0,0 +1,14 @@ +package net.momirealms.customfishing.hook; + +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.Type; +import org.apache.commons.lang.StringUtils; +import org.bukkit.inventory.ItemStack; + +public class MMOItemsHook { + + public static ItemStack getItemStack(String name){ + String[] split = StringUtils.split(name, ":"); + return MMOItems.plugin.getMMOItem(Type.get(split[0]), split[1]).newBuilder().getItemStack(); + } +} diff --git a/src/main/java/net/momirealms/customfishing/hook/MythicItems.java b/src/main/java/net/momirealms/customfishing/hook/MythicItems.java new file mode 100644 index 00000000..871750fa --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/hook/MythicItems.java @@ -0,0 +1,11 @@ +package net.momirealms.customfishing.hook; + +import io.lumine.mythic.bukkit.MythicBukkit; +import org.bukkit.inventory.ItemStack; + +public class MythicItems { + + public static ItemStack getItemStack(String name){ + return MythicBukkit.inst().getItemManager().getItemStack(name); + } +} diff --git a/src/main/java/net/momirealms/customfishing/hook/MythicMobsUtils.java b/src/main/java/net/momirealms/customfishing/hook/MythicMobsUtil.java similarity index 80% rename from src/main/java/net/momirealms/customfishing/hook/MythicMobsUtils.java rename to src/main/java/net/momirealms/customfishing/hook/MythicMobsUtil.java index d4165a3e..3a1b19d0 100644 --- a/src/main/java/net/momirealms/customfishing/hook/MythicMobsUtils.java +++ b/src/main/java/net/momirealms/customfishing/hook/MythicMobsUtil.java @@ -24,29 +24,26 @@ import io.lumine.mythic.api.mobs.MythicMob; import io.lumine.mythic.bukkit.MythicBukkit; import io.lumine.mythic.bukkit.utils.serialize.Position; import io.lumine.mythic.core.mobs.ActiveMob; -import net.momirealms.customfishing.item.Loot; -import net.momirealms.customfishing.utils.VectorUtil; +import net.momirealms.customfishing.object.MobVector; +import net.momirealms.customfishing.object.loot.Mob; import org.bukkit.Location; import org.bukkit.util.Vector; import java.util.Optional; -public class MythicMobsUtils { +public class MythicMobsUtil { - public static void summonMM(Location pLocation, Location bLocation, Loot loot){ + public static void summonMM(Location pLocation, Location bLocation, Mob mob){ MobManager mobManager = MythicBukkit.inst().getMobManager(); - Optional mythicMob = mobManager.getMythicMob(loot.getMm()); + Optional mythicMob = mobManager.getMythicMob(mob.getMmID()); if (mythicMob.isPresent()) { - //获取MM怪实例 MythicMob theMob = mythicMob.get(); - //生成MM怪 Position position = Position.of(bLocation); AbstractLocation abstractLocation = new AbstractLocation(position); - ActiveMob activeMob = theMob.spawn(abstractLocation, loot.getMmLevel()); - - VectorUtil vectorUtil = loot.getVectorUtil(); - Vector vector = pLocation.subtract(bLocation).toVector().multiply((vectorUtil.getHorizontal())-1); - vector = vector.setY((vector.getY()+0.2)*vectorUtil.getVertical()); + ActiveMob activeMob = theMob.spawn(abstractLocation, mob.getMmLevel()); + MobVector mobVector = mob.getMobVector(); + Vector vector = pLocation.subtract(bLocation).toVector().multiply((mobVector.getHorizontal())-1); + vector = vector.setY((vector.getY()+0.2)*mobVector.getVertical()); activeMob.getEntity().setVelocity(new AbstractVector(vector.getX(),vector.getY(),vector.getZ())); } } diff --git a/src/main/java/net/momirealms/customfishing/hook/OraxenItem.java b/src/main/java/net/momirealms/customfishing/hook/OraxenItem.java new file mode 100644 index 00000000..307dbcc9 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/hook/OraxenItem.java @@ -0,0 +1,11 @@ +package net.momirealms.customfishing.hook; + +import io.th0rgal.oraxen.items.OraxenItems; +import org.bukkit.inventory.ItemStack; + +public class OraxenItem { + + public static ItemStack getItemStack(String namespacedID){ + return OraxenItems.getItemById(namespacedID).build(); + } +} diff --git a/src/main/java/net/momirealms/customfishing/hook/season/CustomCropsSeason.java b/src/main/java/net/momirealms/customfishing/hook/season/CustomCropsSeason.java new file mode 100644 index 00000000..d6acaca9 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/hook/season/CustomCropsSeason.java @@ -0,0 +1,10 @@ +package net.momirealms.customfishing.hook.season; + +import net.momirealms.customcrops.api.CustomCropsAPI; +import org.bukkit.World; + +public class CustomCropsSeason implements SeasonInterface{ + public String getSeason(World world){ + return CustomCropsAPI.getSeason(world.getName()); + } +} diff --git a/src/main/java/net/momirealms/customfishing/hook/RealisticSeason.java b/src/main/java/net/momirealms/customfishing/hook/season/RealisticSeason.java similarity index 77% rename from src/main/java/net/momirealms/customfishing/hook/RealisticSeason.java rename to src/main/java/net/momirealms/customfishing/hook/season/RealisticSeason.java index 988e6b9d..f76aa645 100644 --- a/src/main/java/net/momirealms/customfishing/hook/RealisticSeason.java +++ b/src/main/java/net/momirealms/customfishing/hook/season/RealisticSeason.java @@ -1,10 +1,10 @@ -package net.momirealms.customfishing.hook; +package net.momirealms.customfishing.hook.season; import me.casperge.realisticseasons.api.SeasonsAPI; import org.bukkit.World; -public class RealisticSeason { - public static String getSeason(World world){ +public class RealisticSeason implements SeasonInterface{ + public String getSeason(World world){ SeasonsAPI seasonsapi = SeasonsAPI.getInstance(); switch (seasonsapi.getSeason(world)){ case SPRING -> { diff --git a/src/main/java/net/momirealms/customfishing/hook/season/SeasonInterface.java b/src/main/java/net/momirealms/customfishing/hook/season/SeasonInterface.java new file mode 100644 index 00000000..033bfbf3 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/hook/season/SeasonInterface.java @@ -0,0 +1,7 @@ +package net.momirealms.customfishing.hook.season; + +import org.bukkit.World; + +public interface SeasonInterface { + String getSeason(World world); +} \ No newline at end of file diff --git a/src/main/java/net/momirealms/customfishing/hook/skill/Aurelium.java b/src/main/java/net/momirealms/customfishing/hook/skill/Aurelium.java index f27ca8a9..3d59a64f 100644 --- a/src/main/java/net/momirealms/customfishing/hook/skill/Aurelium.java +++ b/src/main/java/net/momirealms/customfishing/hook/skill/Aurelium.java @@ -31,4 +31,9 @@ public class Aurelium implements SkillXP{ public void addXp(Player player, double amount) { leveler.addXp(player, skill, amount); } + + @Override + public int getLevel(Player player) { + return AureliumAPI.getSkillLevel(player, skill); + } } diff --git a/src/main/java/net/momirealms/customfishing/hook/skill/EcoSkill.java b/src/main/java/net/momirealms/customfishing/hook/skill/EcoSkill.java index bef624ed..e9a1c256 100644 --- a/src/main/java/net/momirealms/customfishing/hook/skill/EcoSkill.java +++ b/src/main/java/net/momirealms/customfishing/hook/skill/EcoSkill.java @@ -10,4 +10,9 @@ public class EcoSkill implements SkillXP{ public void addXp(Player player, double amount) { EcoSkillsAPI.getInstance().giveSkillExperience(player, Skills.FISHING, amount); } + + @Override + public int getLevel(Player player) { + return EcoSkillsAPI.getInstance().getSkillLevel(player, Skills.FISHING); + } } diff --git a/src/main/java/net/momirealms/customfishing/hook/skill/MMOCore.java b/src/main/java/net/momirealms/customfishing/hook/skill/MMOCore.java index ddefd1ac..bd3df5a5 100644 --- a/src/main/java/net/momirealms/customfishing/hook/skill/MMOCore.java +++ b/src/main/java/net/momirealms/customfishing/hook/skill/MMOCore.java @@ -28,4 +28,9 @@ public class MMOCore implements SkillXP{ Profession profession = net.Indyuce.mmocore.MMOCore.plugin.professionManager.get("fishing"); profession.giveExperience(net.Indyuce.mmocore.MMOCore.plugin.dataProvider.getDataManager().get(player), amount, null , EXPSource.OTHER); } + + @Override + public int getLevel(Player player) { + return net.Indyuce.mmocore.MMOCore.plugin.dataProvider.getDataManager().get(player).getLevel(); + } } diff --git a/src/main/java/net/momirealms/customfishing/hook/skill/SkillXP.java b/src/main/java/net/momirealms/customfishing/hook/skill/SkillXP.java index d950c150..d8254002 100644 --- a/src/main/java/net/momirealms/customfishing/hook/skill/SkillXP.java +++ b/src/main/java/net/momirealms/customfishing/hook/skill/SkillXP.java @@ -21,4 +21,5 @@ import org.bukkit.entity.Player; public interface SkillXP { void addXp(Player player, double amount); + int getLevel(Player player); } diff --git a/src/main/java/net/momirealms/customfishing/hook/skill/mcMMO.java b/src/main/java/net/momirealms/customfishing/hook/skill/mcMMO.java index b7eab9d9..f6a72063 100644 --- a/src/main/java/net/momirealms/customfishing/hook/skill/mcMMO.java +++ b/src/main/java/net/momirealms/customfishing/hook/skill/mcMMO.java @@ -18,6 +18,7 @@ package net.momirealms.customfishing.hook.skill; import com.gmail.nossr50.api.ExperienceAPI; +import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import org.bukkit.entity.Player; public class mcMMO implements SkillXP{ @@ -26,4 +27,9 @@ public class mcMMO implements SkillXP{ public void addXp(Player player, double amount) { ExperienceAPI.addRawXP(player, "FISHING", (float) amount, "UNKNOWN"); } + + @Override + public int getLevel(Player player) { + return ExperienceAPI.getLevel(player, PrimarySkillType.FISHING); + } } diff --git a/src/main/java/net/momirealms/customfishing/item/Bait.java b/src/main/java/net/momirealms/customfishing/item/Bait.java deleted file mode 100644 index b90b399f..00000000 --- a/src/main/java/net/momirealms/customfishing/item/Bait.java +++ /dev/null @@ -1,84 +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.item; - -import org.bukkit.inventory.ItemFlag; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class Bait implements Item{ - - private String name; - private List lore; - private Map nbt; - private HashMap weightMQ; - private HashMap weightPM; - private double time; - private double scoreModifier; - private double doubleLoot; - private int difficulty; - private final String material; - private List enchantment; - private List itemFlags; - private int custommodeldata; - private boolean unbreakable; - - public Bait(String material) { - this.material = material; - } - - public void setName(String name) {this.name = name;} - public void setItemFlags(List itemFlags) {this.itemFlags = itemFlags;} - public void setDifficulty(int difficulty) {this.difficulty = difficulty;} - public void setNbt(Map nbt) {this.nbt = nbt;} - public void setLore(List lore) {this.lore = lore;} - public void setTime(double time) {this.time = time;} - public void setWeightMQ(HashMap weightMQ) {this.weightMQ = weightMQ;} - public void setWeightPM(HashMap weightPM) {this.weightPM = weightPM;} - public void setDoubleLoot(double doubleLoot) {this.doubleLoot = doubleLoot;} - public void setEnchantment(List enchantment) {this.enchantment = enchantment;} - public void setCustommodeldata(int custommodeldata){this.custommodeldata = custommodeldata;} - public void setUnbreakable(boolean unbreakable){this.unbreakable = unbreakable;} - public void setScoreModifier(double scoreModifier) {this.scoreModifier = scoreModifier;} - - public double getDoubleLoot() {return this.doubleLoot;} - public int getDifficulty() {return difficulty;} - public double getTime() {return time;} - public HashMap getWeightMQ() {return weightMQ;} - public HashMap getWeightPM() {return weightPM;} - public double getScoreModifier() {return scoreModifier;} - - @Override - public boolean isUnbreakable() {return this.unbreakable;} - @Override - public int getCustomModelData() {return this.custommodeldata;} - @Override - public List getLore() {return lore;} - @Override - public Map getNbt() {return nbt;} - @Override - public String getMaterial() {return this.material;} - @Override - public List getEnchantments() {return this.enchantment;} - @Override - public List getItemFlags() {return this.itemFlags;} - @Override - public String getName() {return this.name;} -} diff --git a/src/main/java/net/momirealms/customfishing/item/Item.java b/src/main/java/net/momirealms/customfishing/item/Item.java deleted file mode 100644 index 1d03c5ba..00000000 --- a/src/main/java/net/momirealms/customfishing/item/Item.java +++ /dev/null @@ -1,35 +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.item; - -import net.momirealms.customfishing.utils.Enchantment; -import org.bukkit.inventory.ItemFlag; - -import java.util.List; -import java.util.Map; - -public interface Item { - String getMaterial(); - List getEnchantments(); - List getItemFlags(); - String getName(); - List getLore(); - Map getNbt(); - int getCustomModelData(); - boolean isUnbreakable(); -} diff --git a/src/main/java/net/momirealms/customfishing/item/ItemGive.java b/src/main/java/net/momirealms/customfishing/item/ItemGive.java deleted file mode 100644 index d9e57f8e..00000000 --- a/src/main/java/net/momirealms/customfishing/item/ItemGive.java +++ /dev/null @@ -1,52 +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.item; - -import net.momirealms.customfishing.ConfigReader; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -public class ItemGive { - - public static void givePlayerLoot(Player player, String lootKey, int amount){ - ItemStack itemStack = ConfigReader.LOOTITEM.get(lootKey); - if (itemStack == null) return; - itemStack.setAmount(amount); - player.getInventory().addItem(itemStack); - } - - public static void givePlayerRod(Player player, String rodKey, int amount){ - ItemStack itemStack = ConfigReader.RODITEM.get(rodKey); - itemStack.setAmount(amount); - player.getInventory().addItem(itemStack); - } - - public static void givePlayerBait(Player player, String baitKey, int amount){ - ItemStack itemStack = ConfigReader.BAITITEM.get(baitKey); - if (itemStack == null) return; - itemStack.setAmount(amount); - player.getInventory().addItem(itemStack); - } - - public static void givePlayerUtil(Player player, String utilKey, int amount){ - ItemStack itemStack = ConfigReader.UTILITEM.get(utilKey); - if (itemStack == null) return; - itemStack.setAmount(amount); - player.getInventory().addItem(itemStack); - } -} diff --git a/src/main/java/net/momirealms/customfishing/item/Loot.java b/src/main/java/net/momirealms/customfishing/item/Loot.java deleted file mode 100644 index 9bde48dc..00000000 --- a/src/main/java/net/momirealms/customfishing/item/Loot.java +++ /dev/null @@ -1,124 +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.item; - -import net.momirealms.customfishing.requirements.Requirement; -import net.momirealms.customfishing.titlebar.Difficulty; -import net.momirealms.customfishing.utils.VectorUtil; -import org.bukkit.inventory.ItemFlag; - -import java.util.*; - -public class Loot implements Item { - - private final String key; - private String name; - private String nick; - private List lore; - private Map nbt; - private String material; - private String mm; - private String layout; - private VectorUtil vectorUtil; - private final Difficulty difficulty; - private final int weight; - private List requirements; - private final int time; - private int mmLevel; - private int exp; - private List msg; - private List commands; - private List hookCommands; - private List hookMsg; - private String group; - private List enchantment; - private List itemFlags; - private boolean showInFinder; - private int custommodeldata; - private boolean unbreakable; - private double skillXP; - private float score; - - public Loot(String key, Difficulty difficulty, int weight, int time){ - this.key = key; - this.difficulty = difficulty; - this.weight = weight; - this.time = time; - } - - public String getKey(){return this.key;} - public String getNick(){return this.nick;} - public List getMsg(){return this.msg;} - public String getLayout(){return this.layout;} - public String getMm(){return this.mm;} - public boolean isShowInFinder() {return this.showInFinder;} - public List getCommands(){return this.commands;} - public Difficulty getDifficulty(){return this.difficulty;} - public int getWeight(){return this.weight;} - public List getRequirements() { return this.requirements; } - public int getTime(){ return this.time; } - public int getMmLevel(){ return this.mmLevel; } - public VectorUtil getVectorUtil(){ return this.vectorUtil; } - public String getGroup() {return group;} - public int getExp() {return exp;} - public double getSkillXP() {return skillXP;} - public float getScore() {return score;} - public List getHookCommands() {return hookCommands;} - public List getHookMsg() {return hookMsg;} - - @Override - public List getLore(){return this.lore;} - @Override - public String getName(){return this.name;} - @Override - public String getMaterial(){return this.material;} - @Override - public List getEnchantments() {return this.enchantment;} - @Override - public List getItemFlags() {return this.itemFlags;} - @Override - public Map getNbt(){return this.nbt;} - @Override - public int getCustomModelData() {return this.custommodeldata;} - @Override - public boolean isUnbreakable() {return this.unbreakable;} - - public void setName(String name) {this.name = name;} - public void setShowInFinder(boolean showInFinder) {this.showInFinder = showInFinder;} - public void setLore(List lore){this.lore = lore;} - public void setNbt(Map nbt){this.nbt = nbt;} - public void setRequirements(List requirements) {this.requirements = requirements;} - public void setMaterial(String material){this.material = material;} - public void setNick(String nick){this.nick = nick;} - public void setMsg(List msg){this.msg = msg;} - public void setMm(String mm){this.mm = mm;} - public void setLayout(String layout){this.layout = layout;} - public void setVectorUtil(VectorUtil vectorUtil){this.vectorUtil = vectorUtil;} - public void setCommands(List commands){this.commands = commands;} - public void setMmLevel(int mmLevel){this.mmLevel = mmLevel;} - public void setGroup(String group) {this.group = group;} - public void setExp(int exp) {this.exp = exp;} - public void setItemFlags(List itemFlags) {this.itemFlags = itemFlags;} - public void setEnchantment(List enchantment) {this.enchantment = enchantment;} - public void setCustommodeldata(int custommodeldata){this.custommodeldata = custommodeldata;} - public void setUnbreakable(boolean unbreakable){this.unbreakable = unbreakable;} - public void setSkillXP(double skillXP) {this.skillXP = skillXP;} - public void setScore(float score) {this.score = score;} - public void setHookMsg(List hookMsg) {this.hookMsg = hookMsg;} - public void setHookCommands(List hookCommands) {this.hookCommands = hookCommands;} -} diff --git a/src/main/java/net/momirealms/customfishing/item/Rod.java b/src/main/java/net/momirealms/customfishing/item/Rod.java deleted file mode 100644 index f34cdbeb..00000000 --- a/src/main/java/net/momirealms/customfishing/item/Rod.java +++ /dev/null @@ -1,80 +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.item; - -import net.momirealms.customfishing.utils.Enchantment; -import org.bukkit.inventory.ItemFlag; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class Rod implements Item{ - - private String name; - private List lore; - private Map nbt; - private HashMap weightMQ; - private HashMap weightPM; - private double time; - private double scoreModifier; - private int difficulty; - private double doubleLoot; - private List enchantment; - private List itemFlags; - private int custommodeldata; - private boolean unbreakable; - - public void setDifficulty(int difficulty) {this.difficulty = difficulty;} - public void setDoubleLoot(double doubleLoot) {this.doubleLoot = doubleLoot;} - public void setNbt(Map nbt) {this.nbt = nbt;} - public void setLore(List lore) {this.lore = lore;} - public void setEnchantment(List enchantment) {this.enchantment = enchantment;} - public void setItemFlags(List itemFlags) {this.itemFlags = itemFlags;} - public void setTime(double time) {this.time = time;} - public void setWeightMQ(HashMap weightMQ) {this.weightMQ = weightMQ;} - public void setWeightPM(HashMap weightPM) {this.weightPM = weightPM;} - public void setCustommodeldata(int custommodeldata){this.custommodeldata = custommodeldata;} - public void setUnbreakable(boolean unbreakable){this.unbreakable = unbreakable;} - public void setName(String name) {this.name = name;} - public void setScoreModifier(double scoreModifier) {this.scoreModifier = scoreModifier;} - - public double getTime() {return time;} - public HashMap getWeightMQ() {return weightMQ;} - public HashMap getWeightPM() {return weightPM;} - public int getDifficulty() {return difficulty;} - public double getDoubleLoot() {return this.doubleLoot;} - public double getScoreModifier() {return scoreModifier;} - - @Override - public boolean isUnbreakable() {return this.unbreakable;} - @Override - public Map getNbt() {return nbt;} - @Override - public int getCustomModelData() {return this.custommodeldata;} - @Override - public String getMaterial() {return "fishing_rod";} - @Override - public List getEnchantments() {return this.enchantment;} - @Override - public List getItemFlags() {return this.itemFlags;} - @Override - public String getName() {return this.name;} - @Override - public List getLore() {return this.lore;} -} diff --git a/src/main/java/net/momirealms/customfishing/item/Util.java b/src/main/java/net/momirealms/customfishing/item/Util.java deleted file mode 100644 index cbe0ebde..00000000 --- a/src/main/java/net/momirealms/customfishing/item/Util.java +++ /dev/null @@ -1,65 +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.item; - -import net.momirealms.customfishing.utils.Enchantment; -import org.bukkit.inventory.ItemFlag; - -import java.util.List; -import java.util.Map; - -public class Util implements Item{ - - private String name; - private List lore; - private Map nbt; - private final String material; - private List enchantment; - private List itemFlags; - private int custommodeldata; - private boolean unbreakable; - - public Util(String material){ - this.material = material; - } - - public void setLore(List lore){this.lore = lore;} - public void setNbt(Map nbt){this.nbt = nbt;} - public void setEnchantment(List enchantment) {this.enchantment = enchantment;} - public void setItemFlags(List itemFlags) {this.itemFlags = itemFlags;} - public void setCustommodeldata(int custommodeldata){this.custommodeldata = custommodeldata;} - public void setUnbreakable(boolean unbreakable){this.unbreakable = unbreakable;} - public void setName(String name) {this.name = name;} - - @Override - public boolean isUnbreakable() {return this.unbreakable;} - @Override - public List getLore(){return this.lore;} - @Override - public String getMaterial(){return this.material;} - @Override - public String getName(){return this.name;} - @Override - public List getEnchantments() {return this.enchantment;} - @Override - public List getItemFlags() {return this.itemFlags;} - @Override - public Map getNbt(){return this.nbt;} - @Override - public int getCustomModelData() {return this.custommodeldata;} -} diff --git a/src/main/java/net/momirealms/customfishing/listener/FishListener.java b/src/main/java/net/momirealms/customfishing/listener/FishListener.java new file mode 100644 index 00000000..75d6916d --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/listener/FishListener.java @@ -0,0 +1,856 @@ +/* + * 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.listener; + +import de.tr7zw.changeme.nbtapi.NBTCompound; +import de.tr7zw.changeme.nbtapi.NBTItem; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.momirealms.customfishing.competition.CompetitionSchedule; +import net.momirealms.customfishing.competition.bossbar.BossBarManager; +import net.momirealms.customfishing.hook.*; +import net.momirealms.customfishing.object.*; +import net.momirealms.customfishing.object.Difficulty; +import net.momirealms.customfishing.object.action.ActionB; +import net.momirealms.customfishing.object.loot.DroppedItem; +import net.momirealms.customfishing.object.loot.Loot; +import net.momirealms.customfishing.object.loot.Mob; +import net.momirealms.customfishing.utils.AdventureUtil; +import net.momirealms.customfishing.ConfigReader; +import net.momirealms.customfishing.CustomFishing; +import net.momirealms.customfishing.requirements.FishingCondition; +import net.momirealms.customfishing.requirements.Requirement; +import net.momirealms.customfishing.titlebar.Timer; +import net.momirealms.customfishing.utils.ItemStackUtil; +import org.apache.commons.lang.StringUtils; +import org.bukkit.*; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.*; +import org.bukkit.entity.Item; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerFishEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.inventory.meta.Damageable; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; + +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; + +public class FishListener implements Listener { + + private final HashMap coolDown = new HashMap<>(); + private final HashMap nextLoot = new HashMap<>(); + private final HashMap modifiers = new HashMap<>(); + private final HashMap hooks = new HashMap<>(); + private final HashMap vanilla = new HashMap<>(); + public static ConcurrentHashMap fishingPlayers = new ConcurrentHashMap<>(); + + @EventHandler + public void onFish(PlayerFishEvent event){ + + PlayerFishEvent.State state = event.getState(); + Player player = event.getPlayer(); + + if (state.equals(PlayerFishEvent.State.FISHING)){ + + long time = System.currentTimeMillis(); + if (time - (coolDown.getOrDefault(player, time - 2000)) < 2000) { + return; + } + coolDown.put(player, time); + + hooks.put(player, event.getHook()); + + Bukkit.getScheduler().runTaskAsynchronously(CustomFishing.instance, ()->{ + + PlayerInventory inventory = player.getInventory(); + + boolean noRod = true; + double timeModifier = 1; + double doubleLoot = 0; + double scoreModifier = 1; + int difficultyModifier = 0; + + HashMap pm1 = new HashMap<>(); + HashMap mq1 = new HashMap<>(); + + ItemStack mainHandItem = inventory.getItemInMainHand(); + if (mainHandItem.getType() != Material.AIR){ + NBTItem nbtItem = new NBTItem(inventory.getItemInMainHand()); + NBTCompound nbtCompound = nbtItem.getCompound("CustomFishing"); + if (nbtCompound != null){ + if (nbtCompound.getString("type").equals("rod")) { + String key = nbtCompound.getString("id"); + Bonus rod = ConfigReader.ROD.get(key); + if (rod != null){ + pm1 = rod.getWeightPM(); + mq1 = rod.getWeightMQ(); + if (rod.getTime() != 0) timeModifier *= rod.getTime(); + if (rod.getDoubleLoot() != 0) doubleLoot += rod.getDoubleLoot(); + if (rod.getDifficulty() != 0) difficultyModifier += rod.getDifficulty(); + if (rod.getScore() != 0) scoreModifier *= rod.getScore(); + noRod = false; + } + } + else if (nbtCompound.getString("type").equals("bait")){ + String key = nbtCompound.getString("id"); + Bonus bait = ConfigReader.BAIT.get(key); + if (bait != null){ + pm1 = bait.getWeightPM(); + mq1 = bait.getWeightMQ(); + if (bait.getTime() != 0) timeModifier *= bait.getTime(); + if (bait.getDoubleLoot() != 0) doubleLoot += bait.getDoubleLoot(); + if (bait.getDifficulty() != 0) difficultyModifier += bait.getDifficulty(); + if (bait.getScore() != 0) scoreModifier *= bait.getScore(); + mainHandItem.setAmount(mainHandItem.getAmount() - 1); + } + } + } + } + + HashMap pm2 = new HashMap<>(); + HashMap mq2 = new HashMap<>(); + + ItemStack offHandItem = inventory.getItemInOffHand(); + if (offHandItem.getType() != Material.AIR){ + NBTItem offHand = new NBTItem(inventory.getItemInOffHand()); + NBTCompound offHandCompound = offHand.getCompound("CustomFishing"); + if (offHandCompound != null){ + if (offHandCompound.getString("type").equals("bait")) { + String key = offHandCompound.getString("id"); + Bonus bait = ConfigReader.BAIT.get(key); + if (bait != null){ + pm2 = bait.getWeightPM(); + mq2 = bait.getWeightMQ(); + if (bait.getTime() != 0) timeModifier *= bait.getTime(); + if (bait.getDoubleLoot() != 0) doubleLoot += bait.getDoubleLoot(); + if (bait.getDifficulty() != 0) difficultyModifier += bait.getDifficulty(); + if (bait.getScore() != 0) scoreModifier *= bait.getScore(); + offHandItem.setAmount(offHandItem.getAmount() - 1); + } + }else if (noRod && offHandCompound.getString("type").equals("rod")){ + String key = offHandCompound.getString("id"); + Bonus rod = ConfigReader.ROD.get(key); + if (rod != null){ + pm2 = rod.getWeightPM(); + mq2 = rod.getWeightMQ(); + if (rod.getTime() != 0) timeModifier *= rod.getTime(); + if (rod.getDoubleLoot() != 0) doubleLoot += rod.getDoubleLoot(); + if (rod.getDifficulty() != 0) difficultyModifier += rod.getDifficulty(); + if (rod.getScore() != 0) scoreModifier *= rod.getScore(); + noRod = false; + } + } + } + } + + if (ConfigReader.Config.needSpecialRod && noRod){ + if (!ConfigReader.Config.vanillaLoot) + AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.noRod); + nextLoot.put(player, null); + return; + } + + FishHook hook = event.getHook(); + hook.setMaxWaitTime((int) (timeModifier * hook.getMaxWaitTime())); + hook.setMinWaitTime((int) (timeModifier * hook.getMinWaitTime())); + + List possibleLoots = getPossibleLootList(new FishingCondition(hook.getLocation(), player)); + List availableLoots = new ArrayList<>(); + + if (possibleLoots.size() == 0){ + nextLoot.put(player, null); + return; + } + + Modifier modifier = new Modifier(); + modifier.setDifficulty(difficultyModifier); + modifier.setScore(scoreModifier); + modifier.setWillDouble(doubleLoot > Math.random()); + modifiers.put(player, modifier); + + double[] weights = new double[possibleLoots.size()]; + int index = 0; + for (Loot loot : possibleLoots){ + double weight = loot.getWeight(); + String group = loot.getGroup(); + if (group != null){ + if (pm1 != null && pm1.get(group) != null){ + weight += pm1.get(group); + } + if (pm2!= null && pm2.get(group) != null){ + weight += pm2.get(group); + } + if (mq1 != null && mq1.get(group) != null){ + weight *= mq1.get(group); + } + if (mq2 != null && mq2.get(group) != null){ + weight *= mq2.get(group); + } + } + if (weight <= 0) continue; + availableLoots.add(loot); + weights[index++] = weight; + } + + double total = Arrays.stream(weights).sum(); + double[] weightRatios = new double[index]; + for (int i = 0; i < index; i++){ + weightRatios[i] = weights[i]/total; + } + + double[] weightRange = new double[index]; + double startPos = 0; + for (int i = 0; i < index; i++) { + weightRange[i] = startPos + weightRatios[i]; + startPos += weightRatios[i]; + } + + double random = Math.random(); + int pos = Arrays.binarySearch(weightRange, random); + + if (pos < 0) { + pos = -pos - 1; + } else { + nextLoot.put(player, availableLoots.get(pos)); + return; + } + if (pos < weightRange.length && random < weightRange[pos]) { + nextLoot.put(player, availableLoots.get(pos)); + return; + } + nextLoot.put(player, null); + }); + } + + else if (state.equals(PlayerFishEvent.State.BITE)){ + + if (ConfigReader.Config.doubleRealIn) return; + + if (fishingPlayers.get(player) != null) return; + + Loot loot = nextLoot.get(player); + + if (loot == null) return; + + String layout; + if (loot.getLayout() != null){ + layout = loot.getLayout().get((int) (loot.getLayout().size() * Math.random())); + }else { + Object[] values = ConfigReader.LAYOUT.keySet().toArray(); + layout = (String) values[new Random().nextInt(values.length)]; + } + + int difficulty = loot.getDifficulty().getSpeed(); + difficulty += Objects.requireNonNullElse(modifiers.get(player).getDifficulty(), 0);; + if (difficulty < 1){ + difficulty = 1; + } + + Difficulty difficult = new Difficulty(loot.getDifficulty().getTimer(), difficulty); + fishingPlayers.put(player, + new FishingPlayer(System.currentTimeMillis() + loot.getTime(), + new Timer(player, difficult, layout) + ) + ); + + for (ActionB action : loot.getHookActions()){ + action.doOn(player); + } + + player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, loot.getTime()/50,3)); + + } + + //收杆拉鱼 + else if (state.equals(PlayerFishEvent.State.CAUGHT_FISH)) { + + //是否需要两次拉杆 + if (ConfigReader.Config.doubleRealIn) { + + FishingPlayer fishingPlayer = fishingPlayers.remove(player); + if (fishingPlayer == null){ + Entity entity = event.getCaught(); + if (entity instanceof Item item){ + //是否有原版战利品 + if (ConfigReader.Config.vanillaLoot) { + //不是原版战利品 + if (ConfigReader.Config.vanillaRatio < Math.random()) { + event.setCancelled(true); + vanilla.remove(player); + showPlayerBar(player); + } + //是原版战利品 + else { + //需要走力度条流程 + if (ConfigReader.Config.showBar){ + event.setCancelled(true); + vanilla.put(player, new VanillaLoot(item.getItemStack(), event.getExpToDrop())); + showPlayerBar(player); + } + } + } + //如果不许有原版战利品则清除 + else { + if (nextLoot.get(player) == null){ + item.remove(); + event.setExpToDrop(0); + AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.noLoot); + } + else { + event.setCancelled(true); + showPlayerBar(player); + } + } + } + } + else { + Entity entity = event.getCaught(); + if (entity instanceof Item item){ + item.remove(); + event.setExpToDrop(0); + } + Loot loot = nextLoot.remove(player); + VanillaLoot vanillaLoot = vanilla.remove(player); + Timer timer = fishingPlayer.getTimer(); + Layout layout = ConfigReader.LAYOUT.get(timer.getLayout()); + int last = (timer.getTimerTask().getProgress())/layout.getRange(); + + player.removePotionEffect(PotionEffectType.SLOW); + if (ConfigReader.Config.needOpenWater && !event.getHook().isInOpenWater()){ + AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.notOpenWater); + return; + } + + if (Math.random() < layout.getSuccessRate()[last]){ + if (ConfigReader.Config.loseDurability) + loseDurability(player); + Location location = event.getHook().getLocation(); + if (loot instanceof Mob mob){ + MythicMobsUtil.summonMM(player.getLocation(), location, mob); + for (ActionB action : loot.getSuccessActions()) + action.doOn(player); + if (CompetitionSchedule.competition != null && CompetitionSchedule.competition.isGoingOn()) { + float score = (float) (loot.getScore() * modifiers.get(player).getScore()); + CompetitionSchedule.competition.refreshRanking(player.getName(), score); + BossBarManager.joinCompetition(player); + } + } + else if (loot instanceof DroppedItem droppedItem){ + ItemStack itemStack; + if (vanillaLoot != null) { + itemStack = vanillaLoot.getItemStack(); + player.giveExp(vanillaLoot.getXp(), true); + player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1,1); + Entity item = location.getWorld().dropItem(location, itemStack); + Vector vector = player.getLocation().subtract(location).toVector().multiply(0.1); + vector = vector.setY((vector.getY()+0.2)*1.2); + item.setVelocity(vector); + if (CompetitionSchedule.competition != null && CompetitionSchedule.competition.isGoingOn()) { + CompetitionSchedule.competition.refreshRanking(player.getName(), 0); + BossBarManager.joinCompetition(player); + } + if (modifiers.get(player).isWillDouble()) { + Entity item2 = location.getWorld().dropItem(location, itemStack); + item2.setVelocity(vector); + } + String title = ConfigReader.Title.success_title.get((int) (ConfigReader.Title.success_title.size()*Math.random())); + Component titleComponent = getTitleComponent(itemStack, title); + String subTitle = ConfigReader.Title.success_subtitle.get((int) (ConfigReader.Title.success_subtitle.size()*Math.random())); + Component subtitleComponent = getTitleComponent(itemStack, subTitle); + + AdventureUtil.playerTitle( + player, + titleComponent, + subtitleComponent, + ConfigReader.Title.success_in, + ConfigReader.Title.success_stay, + ConfigReader.Title.success_out + ); + } + else { + if (CompetitionSchedule.competition != null && CompetitionSchedule.competition.isGoingOn()) { + float score = (float) (loot.getScore() * modifiers.get(player).getScore()); + CompetitionSchedule.competition.refreshRanking(player.getName(), score); + BossBarManager.joinCompetition(player); + } + for (ActionB action : loot.getSuccessActions()) + action.doOn(player); + dropLoot(player, location, droppedItem); + AdventureUtil.playerTitle( + player, + ConfigReader.Title.success_title.get((int) (ConfigReader.Title.success_title.size()*Math.random())) + .replace("{loot}",loot.getNick()) + .replace("{player}", player.getName()), + ConfigReader.Title.success_subtitle.get((int) (ConfigReader.Title.success_subtitle.size()*Math.random())) + .replace("{loot}",loot.getNick()) + .replace("{player}", player.getName()), + ConfigReader.Title.success_in, + ConfigReader.Title.success_stay, + ConfigReader.Title.success_out + ); + } + } + } + else if (vanillaLoot == null) { + fail(player, loot); + } + } + } + //不需要两次拉杆 + //除非设置否则肯定不会有原版掉落物 + else { + + Entity entity = event.getCaught(); + if (entity instanceof Item item){ + + //如果玩家正在钓鱼 + //那么拉杆的时候可能也会遇到上钩点,进行正常收杆判断 + FishingPlayer fishingPlayer = fishingPlayers.remove(player); + if (fishingPlayer != null){ + + item.remove(); + event.setExpToDrop(0); + + Loot loot = nextLoot.get(player); + Timer timer = fishingPlayer.getTimer(); + Layout layout = ConfigReader.LAYOUT.get(timer.getLayout()); + int last = (timer.getTimerTask().getProgress())/layout.getRange(); + player.removePotionEffect(PotionEffectType.SLOW); + + if (ConfigReader.Config.needOpenWater && !event.getHook().isInOpenWater()){ + AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.notOpenWater); + return; + } + + //捕鱼成功 + if (Math.random() < layout.getSuccessRate()[last]) { + Location location = event.getHook().getLocation(); + if (loot instanceof Mob mob){ + MythicMobsUtil.summonMM(player.getLocation(), location, mob); + } + else if (loot instanceof DroppedItem droppedItem){ + dropLoot(player, location, droppedItem); + } + for (ActionB action : loot.getSuccessActions()) + action.doOn(player); + if (ConfigReader.Config.loseDurability) + loseDurability(player); + if (CompetitionSchedule.competition != null && CompetitionSchedule.competition.isGoingOn()){ + float score = (float) (loot.getScore() * modifiers.get(player).getScore()); + CompetitionSchedule.competition.refreshRanking(player.getName(), score); + BossBarManager.joinCompetition(player); + } + AdventureUtil.playerTitle( + player, + ConfigReader.Title.success_title.get((int) (ConfigReader.Title.success_title.size()*Math.random())) + .replace("{loot}",loot.getNick()) + .replace("{player}", player.getName()), + ConfigReader.Title.success_subtitle.get((int) (ConfigReader.Title.success_subtitle.size()*Math.random())) + .replace("{loot}",loot.getNick()) + .replace("{player}", player.getName()), + ConfigReader.Title.success_in, + ConfigReader.Title.success_stay, + ConfigReader.Title.success_out + ); + } + //捕鱼失败 + else { + fail(player, loot); + } + } + else { + if (!ConfigReader.Config.vanillaLoot) { + item.remove(); + event.setExpToDrop(0); + } + } + } + } + } + + //普通收杆 + //对于在Vanilla HashMap中有值的,说明是有原版战利品,否则全部是插件战利品 + else if (state.equals(PlayerFishEvent.State.REEL_IN)){ + + FishingPlayer fishingPlayer = fishingPlayers.remove(player); + //首先得是钓鱼中的玩家 + if (fishingPlayer != null){ + + Loot loot = nextLoot.remove(player); + VanillaLoot vanillaLoot = vanilla.remove(player); + Timer timer = fishingPlayer.getTimer(); + Layout layout = ConfigReader.LAYOUT.get(timer.getLayout()); + int last = (timer.getTimerTask().getProgress())/layout.getRange(); + + player.removePotionEffect(PotionEffectType.SLOW); + if (ConfigReader.Config.needOpenWater && !event.getHook().isInOpenWater()){ + AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.notOpenWater); + return; + } + + if (Math.random() < layout.getSuccessRate()[last]){ + if (ConfigReader.Config.loseDurability) + loseDurability(player); + Location location = event.getHook().getLocation(); + if (loot instanceof Mob mob){ + MythicMobsUtil.summonMM(player.getLocation(), location, mob); + for (ActionB action : loot.getSuccessActions()) + action.doOn(player); + if (CompetitionSchedule.competition != null && CompetitionSchedule.competition.isGoingOn()) { + float score = (float) (loot.getScore() * modifiers.get(player).getScore()); + CompetitionSchedule.competition.refreshRanking(player.getName(), score); + BossBarManager.joinCompetition(player); + } + } + else if (loot instanceof DroppedItem droppedItem){ + ItemStack itemStack; + + if (vanillaLoot != null) { + itemStack = vanillaLoot.getItemStack(); + player.giveExp(vanillaLoot.getXp(), true); + player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1,1); + Entity item = location.getWorld().dropItem(location, itemStack); + Vector vector = player.getLocation().subtract(location).toVector().multiply(0.1); + vector = vector.setY((vector.getY()+0.2)*1.2); + item.setVelocity(vector); + if (CompetitionSchedule.competition != null && CompetitionSchedule.competition.isGoingOn()) { + CompetitionSchedule.competition.refreshRanking(player.getName(), 0); + BossBarManager.joinCompetition(player); + } + if (modifiers.get(player).isWillDouble()) { + Entity item2 = location.getWorld().dropItem(location, itemStack); + item2.setVelocity(vector); + } + String[] titleSplit = StringUtils.split(ConfigReader.Title.success_title.get((int) (ConfigReader.Title.success_title.size()*Math.random())) + .replace("{player}", player.getName()), "{loot}"); + String[] subtitleSplit = StringUtils.split(ConfigReader.Title.success_title.get((int) (ConfigReader.Title.success_title.size()*Math.random())) + .replace("{player}", player.getName()), "{loot}"); + Component titleComponent; + Component subComponent; + if (titleSplit.length == 1){ + titleComponent = MiniMessage.miniMessage().deserialize(titleSplit[0]); + } + else { + titleComponent = MiniMessage.miniMessage().deserialize(titleSplit[0]).append(itemStack.displayName()).append(MiniMessage.miniMessage().deserialize(titleSplit[1])); + } + if (subtitleSplit.length == 1){ + subComponent = MiniMessage.miniMessage().deserialize(subtitleSplit[0]); + } + else { + subComponent = MiniMessage.miniMessage().deserialize(subtitleSplit[0]).append(itemStack.displayName()).append(MiniMessage.miniMessage().deserialize(subtitleSplit[1])); + } + AdventureUtil.playerTitle( + player, + titleComponent, + subComponent, + ConfigReader.Title.success_in, + ConfigReader.Title.success_stay, + ConfigReader.Title.success_out + ); + } + else { + if (CompetitionSchedule.competition != null && CompetitionSchedule.competition.isGoingOn()) { + float score = (float) (loot.getScore() * modifiers.get(player).getScore()); + CompetitionSchedule.competition.refreshRanking(player.getName(), score); + BossBarManager.joinCompetition(player); + } + for (ActionB action : loot.getSuccessActions()) + action.doOn(player); + dropLoot(player, location, droppedItem); + AdventureUtil.playerTitle( + player, + ConfigReader.Title.success_title.get((int) (ConfigReader.Title.success_title.size()*Math.random())) + .replace("{loot}",loot.getNick()) + .replace("{player}", player.getName()), + ConfigReader.Title.success_subtitle.get((int) (ConfigReader.Title.success_subtitle.size()*Math.random())) + .replace("{loot}",loot.getNick()) + .replace("{player}", player.getName()), + ConfigReader.Title.success_in, + ConfigReader.Title.success_stay, + ConfigReader.Title.success_out + ); + } + } + } + else if (vanillaLoot == null) { + fail(player, loot); + } + } + else { + //钓上来的是物品 + if (event.getCaught() instanceof Item item) { + //是否允许原版掉落物 + if (ConfigReader.Config.vanillaLoot) { + if (ConfigReader.Config.showBar){ + item.remove(); + event.setExpToDrop(0); + //event.setCancelled(true); + vanilla.put(player, new VanillaLoot(item.getItemStack(), event.getExpToDrop())); + showPlayerBar(player); + } + else { + //啥也不干 + } + } + //不允许原版掉落物 + else { + item.remove(); + event.setExpToDrop(0); + //event.setCancelled(true); + } + } + } + } + else if (state.equals(PlayerFishEvent.State.CAUGHT_ENTITY)){ + //理论是不存在实体的 + //说明在钓鱼的时候可能鱼钩勾上了鱿鱼之类的生物 + //直接按照失败处理 + if (fishingPlayers.remove(player) != null && event.getCaught() != null){ + AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.hookOther); + } + } + } + + @NotNull + private Component getTitleComponent(ItemStack itemStack, String text) { + Component subtitleComponent; + if (text.contains("{loot}")){ + text = text.replace("{loot}","|"); + if (text.startsWith("|")){ + subtitleComponent = itemStack.displayName().append(MiniMessage.miniMessage().deserialize(text.substring(1))); + } + else if (text.endsWith("|")){ + subtitleComponent = MiniMessage.miniMessage().deserialize(text.substring(0,text.length()-1)).append(itemStack.displayName()); + } + else { + String[] titleSplit = StringUtils.split(text, "|"); + subtitleComponent = MiniMessage.miniMessage().deserialize(titleSplit[0]).append(itemStack.displayName()).append(MiniMessage.miniMessage().deserialize(titleSplit[1])); + } + } + else { + subtitleComponent = MiniMessage.miniMessage().deserialize(text); + } + return subtitleComponent; + } + + private void dropLoot(Player player, Location location, DroppedItem droppedItem) { + ItemStack itemStack; + switch (droppedItem.getType()){ + case "ia" -> itemStack = ItemsAdderItem.getItemStack(droppedItem.getId()); + case "oraxen" -> itemStack = OraxenItem.getItemStack(droppedItem.getId()); + case "mm" -> itemStack = MythicItems.getItemStack(droppedItem.getId()); + case "mmoitems" -> itemStack = MMOItemsHook.getItemStack(droppedItem.getId()); + default -> itemStack = ConfigReader.LootItem.get(droppedItem.getKey()).clone(); + } + + if (itemStack.getType() != Material.AIR) { + if (droppedItem.getRandomEnchants() != null) + ItemStackUtil.addRandomEnchants(itemStack, droppedItem.getRandomEnchants()); + if (droppedItem.isRandomDurability()) + ItemStackUtil.addRandomDamage(itemStack); + if (ConfigReader.Config.preventPick) + ItemStackUtil.addOwner(itemStack, player.getName()); + Entity item = location.getWorld().dropItem(location, itemStack); + Vector vector = player.getLocation().subtract(location).toVector().multiply(0.1); + vector = vector.setY((vector.getY()+0.2)*1.2); + item.setVelocity(vector); + if (modifiers.get(player).isWillDouble()){ + Entity item2 = location.getWorld().dropItem(location, itemStack); + item2.setVelocity(vector); + } + } + } + + private void loseDurability(Player player) { + if (player.getGameMode() == GameMode.CREATIVE) return; + PlayerInventory inventory = player.getInventory(); + ItemStack mainHand = inventory.getItemInMainHand(); + if (mainHand.getType() == Material.FISHING_ROD){ + Damageable damageable = (Damageable) mainHand.getItemMeta(); + if (damageable.isUnbreakable()) return; + Enchantment enchantment = Enchantment.DURABILITY; + if (Math.random() < (1/(double) (damageable.getEnchantLevel(enchantment) + 1))){ + damageable.setDamage(damageable.getDamage() + 1); + Bukkit.getScheduler().runTaskLater(CustomFishing.instance, ()->{ + mainHand.setItemMeta(damageable); + },1); + } + } + else { + ItemStack offHand = inventory.getItemInOffHand(); + if (offHand.getType() == Material.FISHING_ROD){ + Damageable damageable = (Damageable) offHand.getItemMeta(); + if (damageable.isUnbreakable()) return; + Enchantment enchantment = Enchantment.DURABILITY; + if (Math.random() < (1/(double) (damageable.getEnchantLevel(enchantment) + 1))){ + damageable.setDamage(damageable.getDamage() + 1); + Bukkit.getScheduler().runTaskLater(CustomFishing.instance, ()->{ + offHand.setItemMeta(damageable); + },1); + } + } + } + } + + private void fail(Player player, Loot loot) { + fishingPlayers.remove(player); + for (ActionB action : loot.getFailureActions()) + action.doOn(player); + AdventureUtil.playerTitle(player, ConfigReader.Title.failure_title.get((int) (ConfigReader.Title.failure_title.size()*Math.random())), ConfigReader.Title.failure_subtitle.get((int) (ConfigReader.Title.failure_subtitle.size()*Math.random())), ConfigReader.Title.failure_in, ConfigReader.Title.failure_stay, ConfigReader.Title.failure_out); + } + + @EventHandler + public void onQUit(PlayerQuitEvent event){ + Player player = event.getPlayer(); + player.removePotionEffect(PotionEffectType.SLOW); + if (hooks.get(player) != null){ + hooks.get(player).remove(); + } + hooks.remove(player); + coolDown.remove(player); + nextLoot.remove(player); + modifiers.remove(player); + fishingPlayers.remove(player); + vanilla.remove(player); + } + + @EventHandler + public void onInteract(PlayerInteractEvent event){ + if (!(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)) return; + ItemStack itemStack = event.getItem(); + if (itemStack == null || itemStack.getType() == Material.AIR) return; + NBTItem nbtItem = new NBTItem(itemStack); + if (nbtItem.getCompound("CustomFishing") == null) return; + if (nbtItem.getCompound("CustomFishing").getString("type").equals("util") && nbtItem.getCompound("CustomFishing").getString("id").equals("fishfinder")){ + Player player = event.getPlayer(); + //设置冷却时间 + long time = System.currentTimeMillis(); + if (time - (coolDown.getOrDefault(player, time - ConfigReader.Config.fishFinderCoolDown)) < ConfigReader.Config.fishFinderCoolDown) { + AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.coolDown); + return; + } + coolDown.put(player, time); + //获取玩家位置处可能的Loot实例列表 + List possibleLoots = getFinder(new FishingCondition(player.getLocation(), player)); + if (possibleLoots.size() == 0){ + AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.noLoot); + return; + } + StringBuilder stringBuilder = new StringBuilder(ConfigReader.Message.prefix + ConfigReader.Message.possibleLoots); + possibleLoots.forEach(loot -> stringBuilder.append(loot.getNick()).append(ConfigReader.Message.splitChar)); + AdventureUtil.playerMessage(player, stringBuilder.substring(0, stringBuilder.length()-ConfigReader.Message.splitChar.length())); + } + } + + /* + 获取可能的Loot列表 + */ + private List getPossibleLootList(FishingCondition fishingCondition) { + List available = new ArrayList<>(); + ConfigReader.LOOT.keySet().forEach(key -> { + Loot loot = ConfigReader.LOOT.get(key); + List requirements = loot.getRequirements(); + if (requirements == null){ + available.add(loot); + }else { + boolean isMet = true; + for (Requirement requirement : requirements){ + if (!requirement.isConditionMet(fishingCondition)){ + isMet = false; + } + } + if (isMet){ + available.add(loot); + } + } + }); + return available; + } + + private List getFinder(FishingCondition fishingCondition) { + List available = new ArrayList<>(); + ConfigReader.LOOT.keySet().forEach(key -> { + Loot loot = ConfigReader.LOOT.get(key); + if (!loot.isShowInFinder()) return; + List requirements = loot.getRequirements(); + if (requirements == null){ + available.add(loot); + }else { + boolean isMet = true; + for (Requirement requirement : requirements){ + if (!requirement.isConditionMet(fishingCondition)){ + isMet = false; + } + } + if (isMet){ + available.add(loot); + } + } + }); + return available; + } + + private void showPlayerBar(Player player){ + Loot loot = nextLoot.get(player); + + String layout; + if (loot.getLayout() != null){ + try { + layout = loot.getLayout().get((int) (loot.getLayout().size() * Math.random())); + } + catch (IndexOutOfBoundsException e){ + AdventureUtil.consoleMessage("[CustomFishing] Layouts should be in a list"); + return; + } + } + else { + Object[] values = ConfigReader.LAYOUT.keySet().toArray(); + layout = (String) values[new Random().nextInt(values.length)]; + } + + int difficulty = loot.getDifficulty().getSpeed(); + difficulty += Objects.requireNonNullElse(modifiers.get(player).getDifficulty(), 0);; + if (difficulty < 1){ + difficulty = 1; + } + + Difficulty difficult = new Difficulty(loot.getDifficulty().getTimer(), difficulty); + fishingPlayers.put(player, + new FishingPlayer(System.currentTimeMillis() + loot.getTime(), + new Timer(player, difficult, layout) + ) + ); + + if (vanilla.get(player) == null){ + for (ActionB action : loot.getHookActions()){ + action.doOn(player); + } + } + + player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, loot.getTime()/50,3)); + } +} \ No newline at end of file diff --git a/src/main/java/net/momirealms/customfishing/listener/MMOItemsConverter.java b/src/main/java/net/momirealms/customfishing/listener/MMOItemsConverter.java index 0d1ba098..ee55f3cd 100644 --- a/src/main/java/net/momirealms/customfishing/listener/MMOItemsConverter.java +++ b/src/main/java/net/momirealms/customfishing/listener/MMOItemsConverter.java @@ -24,6 +24,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerFishEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; @@ -52,7 +53,7 @@ public class MMOItemsConverter implements Listener { if(mainHand.getType() == Material.FISHING_ROD){ NBTItem nbtItem = new NBTItem(mainHand); if (nbtItem.getCompound("CustomFishing") == null) { - if (nbtItem.getString("MMOITEMS_ITEM_ID") != null){ + if (!nbtItem.getString("MMOITEMS_ITEM_ID").equals("")){ NBTCompound nbtCompound = nbtItem.addCompound("CustomFishing"); nbtCompound.setString("type","rod"); nbtCompound.setString("id",nbtItem.getString("MMOITEMS_ITEM_ID")); @@ -65,7 +66,7 @@ public class MMOItemsConverter implements Listener { if(offHand.getType() == Material.FISHING_ROD){ NBTItem nbtItem = new NBTItem(offHand); if (nbtItem.getCompound("CustomFishing") == null) { - if (nbtItem.getString("MMOITEMS_ITEM_ID") != null){ + if (!nbtItem.getString("MMOITEMS_ITEM_ID").equals("")){ NBTCompound nbtCompound = nbtItem.addCompound("CustomFishing"); nbtCompound.setString("type", "rod"); nbtCompound.setString("id", nbtItem.getString("MMOITEMS_ITEM_ID")); @@ -75,4 +76,9 @@ public class MMOItemsConverter implements Listener { } } } + + @EventHandler + public void onQuit(PlayerQuitEvent event){ + coolDown.remove(event.getPlayer()); + } } diff --git a/src/main/java/net/momirealms/customfishing/listener/PapiReload.java b/src/main/java/net/momirealms/customfishing/listener/PapiUnregister.java similarity index 90% rename from src/main/java/net/momirealms/customfishing/listener/PapiReload.java rename to src/main/java/net/momirealms/customfishing/listener/PapiUnregister.java index c815ab2f..7e3e83dc 100644 --- a/src/main/java/net/momirealms/customfishing/listener/PapiReload.java +++ b/src/main/java/net/momirealms/customfishing/listener/PapiUnregister.java @@ -4,7 +4,7 @@ import net.momirealms.customfishing.CustomFishing; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -public class PapiReload implements Listener { +public class PapiUnregister implements Listener { @EventHandler public void onReload(me.clip.placeholderapi.events.ExpansionUnregisterEvent event){ diff --git a/src/main/java/net/momirealms/customfishing/listener/PickUpListener.java b/src/main/java/net/momirealms/customfishing/listener/PickUpListener.java new file mode 100644 index 00000000..0303ea4c --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/listener/PickUpListener.java @@ -0,0 +1,27 @@ +package net.momirealms.customfishing.listener; + +import de.tr7zw.changeme.nbtapi.NBTItem; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerAttemptPickupItemEvent; +import org.bukkit.inventory.ItemStack; + +import java.util.Objects; + +public class PickUpListener implements Listener { + + @EventHandler + public void onPickUp(PlayerAttemptPickupItemEvent event){ + ItemStack itemStack = event.getItem().getItemStack(); + NBTItem nbtItem = new NBTItem(itemStack); + if (nbtItem.hasKey("M_Owner")){ + if (!Objects.equals(nbtItem.getString("M_Owner"), event.getPlayer().getName())){ + event.setCancelled(true); + } + else { + nbtItem.removeKey("M_Owner"); + itemStack.setItemMeta(nbtItem.getItem().getItemMeta()); + } + } + } +} diff --git a/src/main/java/net/momirealms/customfishing/listener/PlayerListener.java b/src/main/java/net/momirealms/customfishing/listener/PlayerListener.java deleted file mode 100644 index 7dd0db64..00000000 --- a/src/main/java/net/momirealms/customfishing/listener/PlayerListener.java +++ /dev/null @@ -1,493 +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.listener; - -import de.tr7zw.changeme.nbtapi.NBTCompound; -import de.tr7zw.changeme.nbtapi.NBTItem; -import net.momirealms.customfishing.competition.CompetitionSchedule; -import net.momirealms.customfishing.competition.bossbar.BossBarManager; -import net.momirealms.customfishing.hook.MythicMobsUtils; -import net.momirealms.customfishing.utils.AdventureManager; -import net.momirealms.customfishing.ConfigReader; -import net.momirealms.customfishing.CustomFishing; -import net.momirealms.customfishing.titlebar.Difficulty; -import net.momirealms.customfishing.titlebar.FishingPlayer; -import net.momirealms.customfishing.titlebar.Layout; -import net.momirealms.customfishing.item.Bait; -import net.momirealms.customfishing.item.Loot; -import net.momirealms.customfishing.item.Rod; -import net.momirealms.customfishing.requirements.FishingCondition; -import net.momirealms.customfishing.requirements.Requirement; -import net.momirealms.customfishing.titlebar.Timer; -import net.momirealms.customfishing.utils.Modifier; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.entity.Entity; -import org.bukkit.entity.FishHook; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.player.PlayerFishEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.PlayerInventory; -import org.bukkit.inventory.meta.Damageable; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.util.Vector; - -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; - -public class PlayerListener implements Listener { - - private final HashMap coolDown = new HashMap<>(); - private final HashMap nextLoot = new HashMap<>(); - private final HashMap modifiers = new HashMap<>(); - private final HashMap hooks = new HashMap<>(); - public static ConcurrentHashMap fishingPlayers = new ConcurrentHashMap<>(); - - @EventHandler - public void onFish(PlayerFishEvent event){ - - PlayerFishEvent.State state = event.getState(); - Player player = event.getPlayer(); - - //抛竿 - if (state.equals(PlayerFishEvent.State.FISHING)){ - - //设置冷却时间 - long time = System.currentTimeMillis(); - if (time - (coolDown.getOrDefault(player, time - 2000)) < 2000) { - return; - } - coolDown.put(player, time); - - hooks.put(player, event.getHook()); - - Bukkit.getScheduler().runTaskAsynchronously(CustomFishing.instance, ()->{ - - PlayerInventory inventory = player.getInventory(); - - boolean noRod = true; - double timeModifier = 1; - double doubleLoot = 0; - double scoreModifier = 1; - int difficultyModifier = 0; - - HashMap pm1 = new HashMap<>(); - HashMap mq1 = new HashMap<>(); - - ItemStack mainHandItem = inventory.getItemInMainHand(); - if (mainHandItem.getType() != Material.AIR){ - NBTItem nbtItem = new NBTItem(inventory.getItemInMainHand()); - NBTCompound nbtCompound = nbtItem.getCompound("CustomFishing"); - if (nbtCompound != null){ - if (nbtCompound.getString("type").equals("rod")) { - String key = nbtCompound.getString("id"); - Rod rod = ConfigReader.ROD.get(key); - if (rod != null){ - pm1 = rod.getWeightPM(); - mq1 = rod.getWeightMQ(); - if (rod.getTime() != 0) timeModifier *= rod.getTime(); - if (rod.getDoubleLoot() != 0) doubleLoot += rod.getDoubleLoot(); - if (rod.getDifficulty() != 0) difficultyModifier += rod.getDifficulty(); - if (rod.getScoreModifier() != 0) scoreModifier *= rod.getScoreModifier(); - noRod = false; - } - } - else if (nbtCompound.getString("type").equals("bait")){ - String key = nbtCompound.getString("id"); - Bait bait = ConfigReader.BAIT.get(key); - if (bait != null){ - pm1 = bait.getWeightPM(); - mq1 = bait.getWeightMQ(); - if (bait.getTime() != 0) timeModifier *= bait.getTime(); - if (bait.getDoubleLoot() != 0) doubleLoot += bait.getDoubleLoot(); - if (bait.getDifficulty() != 0) difficultyModifier += bait.getDifficulty(); - if (bait.getScoreModifier() != 0) scoreModifier *= bait.getScoreModifier(); - mainHandItem.setAmount(mainHandItem.getAmount() - 1); - } - } - } - } - - HashMap pm2 = new HashMap<>(); - HashMap mq2 = new HashMap<>(); - - ItemStack offHandItem = inventory.getItemInOffHand(); - if (offHandItem.getType() != Material.AIR){ - NBTItem offHand = new NBTItem(inventory.getItemInOffHand()); - NBTCompound offHandCompound = offHand.getCompound("CustomFishing"); - if (offHandCompound != null){ - if (offHandCompound.getString("type").equals("bait")) { - String key = offHandCompound.getString("id"); - Bait bait = ConfigReader.BAIT.get(key); - if (bait != null){ - pm2 = bait.getWeightPM(); - mq2 = bait.getWeightMQ(); - if (bait.getTime() != 0) timeModifier *= bait.getTime(); - if (bait.getDoubleLoot() != 0) doubleLoot += bait.getDoubleLoot(); - if (bait.getDifficulty() != 0) difficultyModifier += bait.getDifficulty(); - if (bait.getScoreModifier() != 0) scoreModifier *= bait.getScoreModifier(); - offHandItem.setAmount(offHandItem.getAmount() - 1); - } - }else if (noRod && offHandCompound.getString("type").equals("rod")){ - String key = offHandCompound.getString("id"); - Rod rod = ConfigReader.ROD.get(key); - if (rod != null){ - pm2 = rod.getWeightPM(); - mq2 = rod.getWeightMQ(); - if (rod.getTime() != 0) timeModifier *= rod.getTime(); - if (rod.getDoubleLoot() != 0) doubleLoot += rod.getDoubleLoot(); - if (rod.getDifficulty() != 0) difficultyModifier += rod.getDifficulty(); - if (rod.getScoreModifier() != 0) scoreModifier *= rod.getScoreModifier(); - noRod = false; - } - } - } - } - - //是否需要特殊鱼竿 - if (ConfigReader.Config.needSpecialRod && noRod){ - nextLoot.put(player, null); - return; - } - - //时间修改 - FishHook hook = event.getHook(); - hook.setMaxWaitTime((int) (timeModifier * hook.getMaxWaitTime())); - hook.setMinWaitTime((int) (timeModifier * hook.getMinWaitTime())); - - //获取抛竿位置处可能的Loot实例列表 - List possibleLoots = getPossibleLootList(new FishingCondition(player, hook.getLocation())); - List availableLoots = new ArrayList<>(); - - if (possibleLoots.size() == 0){ - nextLoot.put(player, null); - return; - } - - Modifier modifier = new Modifier(); - modifier.setDifficultyModifier(difficultyModifier); - modifier.setScoreModifier(scoreModifier); - modifier.setWillDouble(doubleLoot > Math.random()); - //修改 - modifiers.put(player, modifier); - - double[] weights = new double[possibleLoots.size()]; - int index = 0; - for (Loot loot : possibleLoots){ - double weight = loot.getWeight(); - String group = loot.getGroup(); - if (group != null){ - if (pm1 != null && pm1.get(group) != null){ - weight += pm1.get(group); - } - if (pm2!= null && pm2.get(group) != null){ - weight += pm2.get(group); - } - if (mq1 != null && mq1.get(group) != null){ - weight *= mq1.get(group); - } - if (mq2 != null && mq2.get(group) != null){ - weight *= mq2.get(group); - } - } - if (weight <= 0) continue; - availableLoots.add(loot); - weights[index++] = weight; - } - - double total = Arrays.stream(weights).sum(); - double[] weightRatios = new double[index]; - for (int i = 0; i < index; i++){ - weightRatios[i] = weights[i]/total; - } - - double[] weightRange = new double[index]; - double startPos = 0; - for (int i = 0; i < index; i++) { - weightRange[i] = startPos + weightRatios[i]; - startPos += weightRatios[i]; - } - - double random = Math.random(); - int pos = Arrays.binarySearch(weightRange, random); - - if (pos < 0) { - pos = -pos - 1; - } else { - nextLoot.put(player, availableLoots.get(pos)); - return; - } - if (pos < weightRange.length && random < weightRange[pos]) { - nextLoot.put(player, availableLoots.get(pos)); - return; - } - nextLoot.put(player, null); - }); - } - - //咬钩 - else if (state.equals(PlayerFishEvent.State.BITE)){ - //如果没有特殊鱼就返回 - if (nextLoot.get(player) == null) return; - //如果正在钓一个鱼了,那么也返回 - if (fishingPlayers.get(player) != null) return; - - Bukkit.getScheduler().runTaskAsynchronously(CustomFishing.instance, ()-> { - - Loot lootInstance = nextLoot.get(player); - - String layout = Optional.ofNullable(lootInstance.getLayout()).orElseGet(() ->{ - Object[] values = ConfigReader.LAYOUT.keySet().toArray(); - return (String) values[new Random().nextInt(values.length)]; - }); - - int difficulty = lootInstance.getDifficulty().getSpeed(); - difficulty += Objects.requireNonNullElse(modifiers.get(player).getDifficultyModifier(), 0);; - if (difficulty < 1){ - difficulty = 1; - } - Difficulty difficult = new Difficulty(lootInstance.getDifficulty().getTimer(), difficulty); - fishingPlayers.put(player, - new FishingPlayer(System.currentTimeMillis() + lootInstance.getTime(), - new Timer(player, difficult, layout) - ) - ); - if (lootInstance.getHookMsg() != null){ - lootInstance.getHookMsg().forEach(msg -> { - AdventureManager.playerMessage(player, msg.replace("{loot}",lootInstance.getNick()).replace("{player}", player.getName())); - }); - } - Bukkit.getScheduler().runTask(CustomFishing.instance, ()->{ - if (lootInstance.getHookCommands() != null){ - lootInstance.getHookCommands().forEach(command ->{ - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.replace("{player}", player.getName())); - }); - } - player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, lootInstance.getTime()/50,3)); - }); - }); - } - - //正常钓到鱼 & 正常收杆 - else if (state.equals(PlayerFishEvent.State.CAUGHT_FISH) || state.equals(PlayerFishEvent.State.REEL_IN)){ - //发现有特殊鱼,那么必须掉落特殊鱼 - if (fishingPlayers.get(player) != null){ - //清除原版战利品 - if (event.getCaught() != null){ - event.getCaught().remove(); - event.setExpToDrop(0); - } - Loot lootInstance = nextLoot.get(player); - Layout layout = ConfigReader.LAYOUT.get(fishingPlayers.get(player).getTimer().getLayout()); - int last = (fishingPlayers.get(player).getTimer().getTimerTask().getProgress())/layout.getRange(); - fishingPlayers.remove(player); - player.removePotionEffect(PotionEffectType.SLOW); - if (ConfigReader.Config.needOpenWater && !event.getHook().isInOpenWater()){ - AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.notOpenWater); - return; - } - if (Math.random() < layout.getSuccessRate()[last]){ - //捕鱼成功 - Location location = event.getHook().getLocation(); - //钓上来的是MM怪吗 - if (lootInstance.getMm() != null){ - MythicMobsUtils.summonMM(player.getLocation(), location, lootInstance); - }else { - ItemStack itemStack = ConfigReader.LOOTITEM.get(lootInstance.getKey()); - if (itemStack.getType() != Material.AIR) { - Entity item = location.getWorld().dropItem(location, itemStack); - Vector vector = player.getLocation().subtract(location).toVector().multiply(0.1); - vector = vector.setY((vector.getY()+0.2)*1.2); - item.setVelocity(vector); - if (modifiers.get(player).willDouble()){ - Entity item2 = location.getWorld().dropItem(location, itemStack); - item2.setVelocity(vector); - } - } - } - if (lootInstance.getMsg() != null){ - lootInstance.getMsg().forEach(msg -> { - AdventureManager.playerMessage(player, msg.replace("{loot}",lootInstance.getNick()).replace("{player}", player.getName())); - }); - } - if (lootInstance.getCommands() != null){ - lootInstance.getCommands().forEach(command ->{ - String finalCommand = command. - replaceAll("\\{x}", String.valueOf(Math.round(location.getX()))). - replaceAll("\\{y}", String.valueOf(Math.round(location.getY()))). - replaceAll("\\{z}", String.valueOf(Math.round(location.getZ()))). - replaceAll("\\{player}", player.getName()). - replaceAll("\\{world}", player.getWorld().getName()). - replaceAll("\\{loot}", lootInstance.getNick()); - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), finalCommand); - }); - } - if (lootInstance.getExp() != 0){ - player.giveExp(lootInstance.getExp(),true); - player.getWorld().playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1,1); - } - if (lootInstance.getSkillXP() != 0){ - ConfigReader.Config.skillXP.addXp(player, lootInstance.getSkillXP()); - } - if (ConfigReader.Config.loseDurability){ - PlayerInventory inventory = player.getInventory(); - ItemStack mainHand = inventory.getItemInMainHand(); - if (mainHand.getType() == Material.FISHING_ROD){ - Damageable damageable = (Damageable) mainHand.getItemMeta(); - if (damageable.hasDamage()) System.out.println(1); - damageable.setDamage(damageable.getDamage() + 1); - Bukkit.getScheduler().runTaskLater(CustomFishing.instance, ()->{ - mainHand.setItemMeta((ItemMeta) damageable); - },1); - }else { - ItemStack offHand = inventory.getItemInOffHand(); - if (offHand.getType() == Material.FISHING_ROD){ - Damageable damageable = (Damageable) offHand.getItemMeta(); - damageable.setDamage(damageable.getDamage() + 1); - Bukkit.getScheduler().runTaskLater(CustomFishing.instance, ()->{ - offHand.setItemMeta((ItemMeta) damageable); - },1); - } - } - } - if (CompetitionSchedule.competition != null && CompetitionSchedule.competition.isGoingOn()){ - float score = (float) (lootInstance.getScore() * modifiers.get(player).getScoreModifier()); - CompetitionSchedule.competition.refreshRanking(player.getName(), score); - BossBarManager.joinCompetition(player); - } - //发送Title - AdventureManager.playerTitle(player, ConfigReader.Title.success_title.get((int) (ConfigReader.Title.success_title.size()*Math.random())).replace("{loot}",lootInstance.getNick()), ConfigReader.Title.success_subtitle.get((int) (ConfigReader.Title.success_subtitle.size()*Math.random())).replace("{loot}",lootInstance.getNick()), ConfigReader.Title.success_in, ConfigReader.Title.success_stay, ConfigReader.Title.success_out); - }else { - //移除正在钓鱼的状态 - fishingPlayers.remove(player); - //捕鱼失败Title - AdventureManager.playerTitle(player, ConfigReader.Title.failure_title.get((int) (ConfigReader.Title.failure_title.size()*Math.random())), ConfigReader.Title.failure_subtitle.get((int) (ConfigReader.Title.failure_subtitle.size()*Math.random())), ConfigReader.Title.failure_in, ConfigReader.Title.failure_stay, ConfigReader.Title.failure_out); - } - } - //筛选后发现这个地方没有特殊鱼 - else { - //是否能钓到原版掉落物 - if (!ConfigReader.Config.vanillaDrop){ - if (event.getCaught() != null){ - event.getCaught().remove(); - } - event.setExpToDrop(0); - } - } - } - } - - @EventHandler - public void onQUit(PlayerQuitEvent event){ - Player player = event.getPlayer(); - player.removePotionEffect(PotionEffectType.SLOW); - if (hooks.get(player) != null){ - hooks.get(player).remove(); - } - hooks.remove(player); - coolDown.remove(player); - nextLoot.remove(player); - modifiers.remove(player); - fishingPlayers.remove(player); - } - - @EventHandler - public void onInteract(PlayerInteractEvent event){ - if (!(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)) return; - ItemStack itemStack = event.getItem(); - if (itemStack == null || itemStack.getType() == Material.AIR) return; - NBTItem nbtItem = new NBTItem(itemStack); - if (nbtItem.getCompound("CustomFishing") == null) return; - if (nbtItem.getCompound("CustomFishing").getString("type").equals("util") && nbtItem.getCompound("CustomFishing").getString("id").equals("fishfinder")){ - Player player = event.getPlayer(); - //设置冷却时间 - long time = System.currentTimeMillis(); - if (time - (coolDown.getOrDefault(player, time - ConfigReader.Config.fishFinderCoolDown)) < ConfigReader.Config.fishFinderCoolDown) { - AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.coolDown); - return; - } - coolDown.put(player, time); - //获取玩家位置处可能的Loot实例列表 - List possibleLoots = getFinder(new FishingCondition(player, player.getLocation())); - if (possibleLoots.size() == 0){ - AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.noLoot); - return; - } - StringBuilder stringBuilder = new StringBuilder(ConfigReader.Message.prefix + ConfigReader.Message.possibleLoots); - possibleLoots.forEach(loot -> stringBuilder.append(loot.getNick()).append(ConfigReader.Message.splitChar)); - AdventureManager.playerMessage(player, stringBuilder.substring(0, stringBuilder.length()-ConfigReader.Message.splitChar.length())); - } - } - - /* - 获取可能的Loot列表 - */ - private List getPossibleLootList(FishingCondition fishingCondition) { - List available = new ArrayList<>(); - ConfigReader.LOOT.keySet().forEach(key -> { - Loot loot = ConfigReader.LOOT.get(key); - List requirements = loot.getRequirements(); - if (requirements == null){ - available.add(loot); - }else { - boolean isMet = true; - for (Requirement requirement : requirements){ - if (!requirement.isConditionMet(fishingCondition)){ - isMet = false; - } - } - if (isMet){ - available.add(loot); - } - } - }); - return available; - } - - private List getFinder(FishingCondition fishingCondition) { - List available = new ArrayList<>(); - ConfigReader.LOOT.keySet().forEach(key -> { - Loot loot = ConfigReader.LOOT.get(key); - if (!loot.isShowInFinder()) return; - List requirements = loot.getRequirements(); - if (requirements == null){ - available.add(loot); - }else { - boolean isMet = true; - for (Requirement requirement : requirements){ - if (!requirement.isConditionMet(fishingCondition)){ - isMet = false; - } - } - if (isMet){ - available.add(loot); - } - } - }); - return available; - } -} \ No newline at end of file diff --git a/src/main/java/net/momirealms/customfishing/object/Bonus.java b/src/main/java/net/momirealms/customfishing/object/Bonus.java new file mode 100644 index 00000000..445ff36b --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/object/Bonus.java @@ -0,0 +1,61 @@ +package net.momirealms.customfishing.object; + +import java.util.HashMap; + +public class Bonus { + + private HashMap weightMQ; + private HashMap weightPM; + private double time; + private double score; + private int difficulty; + private double doubleLoot; + + public HashMap getWeightMQ() { + return weightMQ; + } + + public void setWeightMQ(HashMap weightMQ) { + this.weightMQ = weightMQ; + } + + public HashMap getWeightPM() { + return weightPM; + } + + public void setWeightPM(HashMap weightPM) { + this.weightPM = weightPM; + } + + public double getTime() { + return time; + } + + public void setTime(double time) { + this.time = time; + } + + public double getScore() { + return score; + } + + public void setScore(double score) { + this.score = score; + } + + public int getDifficulty() { + return difficulty; + } + + public void setDifficulty(int difficulty) { + this.difficulty = difficulty; + } + + public double getDoubleLoot() { + return doubleLoot; + } + + public void setDoubleLoot(double doubleLoot) { + this.doubleLoot = doubleLoot; + } +} diff --git a/src/main/java/net/momirealms/customfishing/titlebar/Difficulty.java b/src/main/java/net/momirealms/customfishing/object/Difficulty.java similarity index 81% rename from src/main/java/net/momirealms/customfishing/titlebar/Difficulty.java rename to src/main/java/net/momirealms/customfishing/object/Difficulty.java index 67d1b9e1..103b77c6 100644 --- a/src/main/java/net/momirealms/customfishing/titlebar/Difficulty.java +++ b/src/main/java/net/momirealms/customfishing/object/Difficulty.java @@ -15,9 +15,15 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.titlebar; +package net.momirealms.customfishing.object; public record Difficulty(int timer, int speed) { - public int getTimer() {return this.timer;} - public int getSpeed() {return this.speed;} + + public int getTimer() { + return this.timer; + } + + public int getSpeed() { + return this.speed; + } } diff --git a/src/main/java/net/momirealms/customfishing/titlebar/FishingPlayer.java b/src/main/java/net/momirealms/customfishing/object/FishingPlayer.java similarity index 75% rename from src/main/java/net/momirealms/customfishing/titlebar/FishingPlayer.java rename to src/main/java/net/momirealms/customfishing/object/FishingPlayer.java index 1e7bc93a..2c94c15a 100644 --- a/src/main/java/net/momirealms/customfishing/titlebar/FishingPlayer.java +++ b/src/main/java/net/momirealms/customfishing/object/FishingPlayer.java @@ -15,9 +15,17 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.titlebar; +package net.momirealms.customfishing.object; + +import net.momirealms.customfishing.titlebar.Timer; public record FishingPlayer(Long fishingTime, Timer timer) { - public Long getFishingTime() {return this.fishingTime;} - public Timer getTimer() {return this.timer;} + + public Long getFishingTime() { + return this.fishingTime; + } + + public Timer getTimer() { + return this.timer; + } } \ No newline at end of file diff --git a/src/main/java/net/momirealms/customfishing/object/Item.java b/src/main/java/net/momirealms/customfishing/object/Item.java new file mode 100644 index 00000000..04cabe1d --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/object/Item.java @@ -0,0 +1,82 @@ +package net.momirealms.customfishing.object; + +import org.bukkit.inventory.ItemFlag; + +import java.util.List; +import java.util.Map; + +public class Item { + + private final String material; + private String name; + private List lore; + private List itemFlags; + private int customModelData; + private boolean unbreakable; + private List enchantment; + private Map nbt; + + public Item(String material) { + this.material = material; + } + + public Map getNbt() { + return nbt; + } + + public void setNbt(Map nbt) { + this.nbt = nbt; + } + + public String getMaterial() { + return material; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getLore() { + return lore; + } + + public void setLore(List lore) { + this.lore = lore; + } + + public List getItemFlags() { + return itemFlags; + } + + public void setItemFlags(List itemFlags) { + this.itemFlags = itemFlags; + } + + public int getCustomModelData() { + return customModelData; + } + + public void setCustomModelData(int customModelData) { + this.customModelData = customModelData; + } + + public boolean isUnbreakable() { + return unbreakable; + } + + public void setUnbreakable(boolean unbreakable) { + this.unbreakable = unbreakable; + } + + public List getEnchantment() { + return enchantment; + } + + public void setEnchantment(List enchantment) { + this.enchantment = enchantment; + } +} diff --git a/src/main/java/net/momirealms/customfishing/titlebar/Layout.java b/src/main/java/net/momirealms/customfishing/object/Layout.java similarity index 92% rename from src/main/java/net/momirealms/customfishing/titlebar/Layout.java rename to src/main/java/net/momirealms/customfishing/object/Layout.java index 0fb2eece..654e6a20 100644 --- a/src/main/java/net/momirealms/customfishing/titlebar/Layout.java +++ b/src/main/java/net/momirealms/customfishing/object/Layout.java @@ -15,11 +15,10 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.titlebar; +package net.momirealms.customfishing.object; public class Layout { - private final String key; private final int range; private final double[] successRate; private final int size; @@ -32,8 +31,7 @@ public class Layout { private String pointerOffset; private String title; - public Layout(String key, int range, double[] successRate, int size){ - this.key = key; + public Layout(int range, double[] successRate, int size){ this.range = range; this.successRate = successRate; this.size = size; diff --git a/src/main/java/net/momirealms/customfishing/competition/reward/CommandImpl.java b/src/main/java/net/momirealms/customfishing/object/LeveledEnchantment.java similarity index 55% rename from src/main/java/net/momirealms/customfishing/competition/reward/CommandImpl.java rename to src/main/java/net/momirealms/customfishing/object/LeveledEnchantment.java index 186fd596..abd9340f 100644 --- a/src/main/java/net/momirealms/customfishing/competition/reward/CommandImpl.java +++ b/src/main/java/net/momirealms/customfishing/object/LeveledEnchantment.java @@ -15,25 +15,34 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.competition.reward; +package net.momirealms.customfishing.object; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; +import org.bukkit.NamespacedKey; -import java.util.List; +public class LeveledEnchantment { -public class CommandImpl implements Reward{ + private final NamespacedKey key; + private final int level; + private double chance; - private final List commands; - - public CommandImpl(List commands){ - this.commands = commands; + public LeveledEnchantment(NamespacedKey key, int level){ + this.key = key; + this.level = level; } - @Override - public void giveReward(Player player) { - commands.forEach(command -> { - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command.replace("{player}", player.getName())); - }); + public void setChance(double chance) { + this.chance = chance; + } + + public int getLevel() { + return level; + } + + public NamespacedKey getKey() { + return key; + } + + public double getChance() { + return chance; } } diff --git a/src/main/java/net/momirealms/customfishing/utils/Enchantment.java b/src/main/java/net/momirealms/customfishing/object/MobVector.java similarity index 73% rename from src/main/java/net/momirealms/customfishing/utils/Enchantment.java rename to src/main/java/net/momirealms/customfishing/object/MobVector.java index e97a720e..59abf6d5 100644 --- a/src/main/java/net/momirealms/customfishing/utils/Enchantment.java +++ b/src/main/java/net/momirealms/customfishing/object/MobVector.java @@ -15,11 +15,15 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.utils; +package net.momirealms.customfishing.object; -import org.bukkit.NamespacedKey; +public record MobVector(double horizontal, double vertical) { -public record Enchantment(NamespacedKey key, int level) { - public int getLevel() {return level;} - public NamespacedKey getKey() {return key;} + public double getHorizontal() { + return this.horizontal; + } + + public double getVertical() { + return this.vertical; + } } diff --git a/src/main/java/net/momirealms/customfishing/utils/Modifier.java b/src/main/java/net/momirealms/customfishing/object/Modifier.java similarity index 72% rename from src/main/java/net/momirealms/customfishing/utils/Modifier.java rename to src/main/java/net/momirealms/customfishing/object/Modifier.java index 8ed56d3b..e88d2b3c 100644 --- a/src/main/java/net/momirealms/customfishing/utils/Modifier.java +++ b/src/main/java/net/momirealms/customfishing/object/Modifier.java @@ -15,35 +15,44 @@ * along with this program. If not, see . */ -package net.momirealms.customfishing.utils; +package net.momirealms.customfishing.object; public class Modifier { private int difficulty; private double score; private boolean willDouble; + private boolean isVanilla; - public int getDifficultyModifier() { + public int getDifficulty() { return difficulty; } - public void setDifficultyModifier(int difficulty) { + public void setDifficulty(int difficulty) { this.difficulty = difficulty; } - public double getScoreModifier() { + public double getScore() { return score; } - public void setScoreModifier(double score) { + public void setScore(double score) { this.score = score; } - public boolean willDouble() { + public boolean isWillDouble() { return willDouble; } public void setWillDouble(boolean willDouble) { this.willDouble = willDouble; } + + public boolean isVanilla() { + return isVanilla; + } + + public void setVanilla(boolean vanilla) { + isVanilla = vanilla; + } } diff --git a/src/main/java/net/momirealms/customfishing/object/VanillaLoot.java b/src/main/java/net/momirealms/customfishing/object/VanillaLoot.java new file mode 100644 index 00000000..d969b7fe --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/object/VanillaLoot.java @@ -0,0 +1,22 @@ +package net.momirealms.customfishing.object; + +import org.bukkit.inventory.ItemStack; + +public class VanillaLoot { + + private final ItemStack itemStack; + private final int xp; + + public VanillaLoot(ItemStack itemStack, int xp) { + this.itemStack = itemStack; + this.xp = xp; + } + + public ItemStack getItemStack() { + return itemStack; + } + + public int getXp() { + return xp; + } +} diff --git a/src/main/java/net/momirealms/customfishing/object/action/ActionB.java b/src/main/java/net/momirealms/customfishing/object/action/ActionB.java new file mode 100644 index 00000000..e4174825 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/object/action/ActionB.java @@ -0,0 +1,7 @@ +package net.momirealms.customfishing.object.action; + +import org.bukkit.entity.Player; + +public interface ActionB { + void doOn(Player player); +} diff --git a/src/main/java/net/momirealms/customfishing/object/action/CommandA.java b/src/main/java/net/momirealms/customfishing/object/action/CommandA.java new file mode 100644 index 00000000..7c976424 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/object/action/CommandA.java @@ -0,0 +1,23 @@ +package net.momirealms.customfishing.object.action; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.util.List; + +public record CommandA(List commands, String nick) implements ActionB { + @Override + public void doOn(Player player) { + commands.forEach(command -> { + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), + command. + replaceAll("\\{x}", String.valueOf(Math.round(player.getLocation().getX()))). + replaceAll("\\{y}", String.valueOf(Math.round(player.getLocation().getY()))). + replaceAll("\\{z}", String.valueOf(Math.round(player.getLocation().getZ()))). + replaceAll("\\{player}", player.getName()). + replaceAll("\\{world}", player.getWorld().getName()). + replaceAll("\\{loot}", nick) + ); + }); + } +} diff --git a/src/main/java/net/momirealms/customfishing/object/action/CommandB.java b/src/main/java/net/momirealms/customfishing/object/action/CommandB.java new file mode 100644 index 00000000..98c4f16c --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/object/action/CommandB.java @@ -0,0 +1,23 @@ +package net.momirealms.customfishing.object.action; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.util.List; + +public record CommandB(List commands) implements ActionB{ + + @Override + public void doOn(Player player) { + commands.forEach(command -> { + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), + command. + replaceAll("\\{x}", String.valueOf(Math.round(player.getLocation().getX()))). + replaceAll("\\{y}", String.valueOf(Math.round(player.getLocation().getY()))). + replaceAll("\\{z}", String.valueOf(Math.round(player.getLocation().getZ()))). + replaceAll("\\{player}", player.getName()). + replaceAll("\\{world}", player.getWorld().getName()) + ); + }); + } +} diff --git a/src/main/java/net/momirealms/customfishing/object/action/FishingXPB.java b/src/main/java/net/momirealms/customfishing/object/action/FishingXPB.java new file mode 100644 index 00000000..5d5ced72 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/object/action/FishingXPB.java @@ -0,0 +1,14 @@ +package net.momirealms.customfishing.object.action; + +import net.momirealms.customfishing.ConfigReader; +import org.bukkit.entity.Player; + +public record FishingXPB(int amount) implements ActionB { + + @Override + public void doOn(Player player) { + if (ConfigReader.Config.skillXP != null){ + ConfigReader.Config.skillXP.addXp(player, amount); + } + } +} diff --git a/src/main/java/net/momirealms/customfishing/object/action/MessageA.java b/src/main/java/net/momirealms/customfishing/object/action/MessageA.java new file mode 100644 index 00000000..fdb5196d --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/object/action/MessageA.java @@ -0,0 +1,16 @@ +package net.momirealms.customfishing.object.action; + +import net.momirealms.customfishing.utils.AdventureUtil; +import org.bukkit.entity.Player; + +import java.util.List; + +public record MessageA(List messages, String loot) implements ActionB{ + + @Override + public void doOn(Player player) { + messages.forEach(message -> { + AdventureUtil.playerMessage(player, message.replace("{loot}", loot)); + }); + } +} diff --git a/src/main/java/net/momirealms/customfishing/object/action/MessageB.java b/src/main/java/net/momirealms/customfishing/object/action/MessageB.java new file mode 100644 index 00000000..49dba969 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/object/action/MessageB.java @@ -0,0 +1,16 @@ +package net.momirealms.customfishing.object.action; + +import net.momirealms.customfishing.utils.AdventureUtil; +import org.bukkit.entity.Player; + +import java.util.List; + +public record MessageB(List messages) implements ActionB { + + @Override + public void doOn(Player player) { + messages.forEach(message -> { + AdventureUtil.playerMessage(player, message); + }); + } +} diff --git a/src/main/java/net/momirealms/customfishing/object/action/XPA.java b/src/main/java/net/momirealms/customfishing/object/action/XPA.java new file mode 100644 index 00000000..b163d9ca --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/object/action/XPA.java @@ -0,0 +1,13 @@ +package net.momirealms.customfishing.object.action; + +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +public record XPA(int amount) implements ActionB { + + @Override + public void doOn(Player player) { + player.giveExp(amount, true); + player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1,1); + } +} \ No newline at end of file diff --git a/src/main/java/net/momirealms/customfishing/object/action/XPB.java b/src/main/java/net/momirealms/customfishing/object/action/XPB.java new file mode 100644 index 00000000..2cd72587 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/object/action/XPB.java @@ -0,0 +1,13 @@ +package net.momirealms.customfishing.object.action; + +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +public record XPB(int amount) implements ActionB { + + @Override + public void doOn(Player player) { + player.giveExp(amount, false); + player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1,1); + } +} diff --git a/src/main/java/net/momirealms/customfishing/object/loot/DroppedItem.java b/src/main/java/net/momirealms/customfishing/object/loot/DroppedItem.java new file mode 100644 index 00000000..5109e792 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/object/loot/DroppedItem.java @@ -0,0 +1,49 @@ +package net.momirealms.customfishing.object.loot; + +import net.momirealms.customfishing.object.LeveledEnchantment; + +import java.util.List; + +public class DroppedItem extends Loot{ + + boolean randomDurability; + List randomEnchants; + String type; + String id; + + public DroppedItem(String key) { + super(key); + } + + public boolean isRandomDurability() { + return randomDurability; + } + + public void setRandomDurability(boolean randomDurability) { + this.randomDurability = randomDurability; + } + + public List getRandomEnchants() { + return randomEnchants; + } + + public void setRandomEnchants(List randomEnchants) { + this.randomEnchants = randomEnchants; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } +} diff --git a/src/main/java/net/momirealms/customfishing/object/loot/Loot.java b/src/main/java/net/momirealms/customfishing/object/loot/Loot.java new file mode 100644 index 00000000..6255b6b3 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/object/loot/Loot.java @@ -0,0 +1,132 @@ +package net.momirealms.customfishing.object.loot; + +import net.momirealms.customfishing.object.Difficulty; +import net.momirealms.customfishing.object.action.ActionB; +import net.momirealms.customfishing.requirements.Requirement; + +import java.util.List; + +public class Loot { + + String key; + String nick; + Difficulty difficulty; + String group; + boolean showInFinder; + List layout; + List successActions; + List failureActions; + List hookActions; + int weight; + int time; + List requirements; + double score; + + public Loot(String key) { + this.key = key; + } + + public List getHookActions() { + return hookActions; + } + + public void setHookActions(List hookActions) { + this.hookActions = hookActions; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public List getSuccessActions() { + return successActions; + } + + public void setSuccessActions(List successActions) { + this.successActions = successActions; + } + + public List getFailureActions() { + return failureActions; + } + + public void setFailureActions(List failureActions) { + this.failureActions = failureActions; + } + + public String getNick() { + return nick; + } + + public void setNick(String nick) { + this.nick = nick; + } + + public List getLayout() { + return layout; + } + + public void setLayout(List layout) { + this.layout = layout; + } + + public Difficulty getDifficulty() { + return difficulty; + } + + public void setDifficulty(Difficulty difficulty) { + this.difficulty = difficulty; + } + + public String getGroup() { + return group; + } + + public void setGroup(String group) { + this.group = group; + } + + public boolean isShowInFinder() { + return showInFinder; + } + + public void setShowInFinder(boolean showInFinder) { + this.showInFinder = showInFinder; + } + + public int getWeight() { + return weight; + } + + public void setWeight(int weight) { + this.weight = weight; + } + + public int getTime() { + return time; + } + + public void setTime(int time) { + this.time = time; + } + + public List getRequirements() { + return requirements; + } + + public void setRequirements(List requirements) { + this.requirements = requirements; + } + + public double getScore() { + return score; + } + + public void setScore(double score) { + this.score = score; + } +} diff --git a/src/main/java/net/momirealms/customfishing/object/loot/Mob.java b/src/main/java/net/momirealms/customfishing/object/loot/Mob.java new file mode 100644 index 00000000..aaf94a11 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/object/loot/Mob.java @@ -0,0 +1,35 @@ +package net.momirealms.customfishing.object.loot; + +import net.momirealms.customfishing.object.MobVector; + +public class Mob extends Loot{ + + final String mmID; + int mmLevel; + MobVector mobVector; + + public Mob(String key, String mmID) { + super(key); + this.mmID = mmID; + } + + public String getMmID() { + return mmID; + } + + public int getMmLevel() { + return mmLevel; + } + + public void setMmLevel(int mmLevel) { + this.mmLevel = mmLevel; + } + + public MobVector getMobVector() { + return mobVector; + } + + public void setMobVector(MobVector mobVector) { + this.mobVector = mobVector; + } +} diff --git a/src/main/java/net/momirealms/customfishing/requirements/CustomPapi.java b/src/main/java/net/momirealms/customfishing/requirements/CustomPapi.java new file mode 100644 index 00000000..ffae01c6 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/requirements/CustomPapi.java @@ -0,0 +1,110 @@ +package net.momirealms.customfishing.requirements; + +import net.momirealms.customfishing.requirements.papi.*; +import org.bukkit.configuration.MemorySection; + +import java.util.*; + +public class CustomPapi implements Requirement { + + public static HashSet allPapi = new HashSet<>(); + + private PapiRequirement papiRequirement; + + public CustomPapi(Map expressions){ + expressions.keySet().forEach(key -> { + if (key.equals("&&")){ + List papiRequirements = new ArrayList<>(); + if (expressions.get(key) instanceof MemorySection map2){ + addAndRequirements(papiRequirements, map2.getValues(false)); + } + papiRequirement = new ExpressionAnd(papiRequirements); + }else if (key.equals("||")){ + List papiRequirements = new ArrayList<>(); + if (expressions.get(key) instanceof MemorySection map2){ + addOrRequirements(papiRequirements, map2.getValues(false)); + } + papiRequirement = new ExpressionOr(papiRequirements); + }else { + if (expressions.get(key) instanceof MemorySection map){ + String type = map.getString("type"); + String papi = map.getString("papi"); + String value = map.getString("value"); + allPapi.add(papi); + switch (type){ + case "==" -> papiRequirement = new PapiEquals(papi, value); + case ">=" -> papiRequirement = new PapiNoLess(papi, Double.parseDouble(value)); + case "<=" -> papiRequirement = new PapiNoLarger(papi, Double.parseDouble(value)); + case "<" -> papiRequirement = new PapiSmaller(papi, Double.parseDouble(value)); + case ">" -> papiRequirement = new PapiGreater(papi, Double.parseDouble(value)); + } + } + } + }); + } + + @Override + public boolean isConditionMet(FishingCondition fishingCondition) { + return papiRequirement.isMet(fishingCondition.getPapiMap()); + } + + private void addAndRequirements(List requirements, Map map){ + List andRequirements = new ArrayList<>(); + map.keySet().forEach(key -> { + if (key.equals("&&")){ + if (map.get(key) instanceof MemorySection map2){ + addAndRequirements(andRequirements, map2.getValues(false)); + } + }else if (key.equals("||")){ + if (map.get(key) instanceof MemorySection map2){ + addOrRequirements(andRequirements, map2.getValues(false)); + } + }else { + if (map.get(key) instanceof MemorySection map2){ + String type = map2.getString("type"); + String papi = map2.getString("papi"); + String value = map2.getString("value"); + allPapi.add(papi); + switch (type){ + case "==" -> andRequirements.add(new PapiEquals(papi, value)); + case ">=" -> andRequirements.add(new PapiNoLess(papi, Double.parseDouble(value))); + case "<=" -> andRequirements.add(new PapiNoLarger(papi, Double.parseDouble(value))); + case "<" -> andRequirements.add(new PapiSmaller(papi, Double.parseDouble(value))); + case ">" -> andRequirements.add(new PapiGreater(papi, Double.parseDouble(value))); + } + } + } + }); + requirements.add(new ExpressionAnd(andRequirements)); + } + + private void addOrRequirements(List requirements, Map map){ + List orRequirements = new ArrayList<>(); + map.keySet().forEach(key -> { + if (key.equals("&&")){ + if (map.get(key) instanceof MemorySection map2){ + addAndRequirements(orRequirements, map2.getValues(false)); + } + }else if (key.equals("||")){ + if (map.get(key) instanceof MemorySection map2){ + addOrRequirements(orRequirements, map2.getValues(false)); + } + }else { + if (map.get(key) instanceof MemorySection map2){ + String type = map2.getString("type"); + String papi = map2.getString("papi"); + String value = map2.getString("value"); + allPapi.add(papi); + switch (type){ + case "==" -> orRequirements.add(new PapiEquals(papi, value)); + case ">=" -> orRequirements.add(new PapiNoLess(papi, Double.parseDouble(value))); + case "<=" -> orRequirements.add(new PapiNoLarger(papi, Double.parseDouble(value))); + case "<" -> orRequirements.add(new PapiSmaller(papi, Double.parseDouble(value))); + case ">" -> orRequirements.add(new PapiGreater(papi, Double.parseDouble(value))); + } + } + } + }); + requirements.add(new ExpressionOr(orRequirements)); + } +} diff --git a/src/main/java/net/momirealms/customfishing/requirements/FishingCondition.java b/src/main/java/net/momirealms/customfishing/requirements/FishingCondition.java index 57686e32..0757ff31 100644 --- a/src/main/java/net/momirealms/customfishing/requirements/FishingCondition.java +++ b/src/main/java/net/momirealms/customfishing/requirements/FishingCondition.java @@ -17,13 +17,48 @@ package net.momirealms.customfishing.requirements; +import net.momirealms.customfishing.ConfigReader; +import net.momirealms.customfishing.hook.PapiHook; import org.bukkit.Location; import org.bukkit.entity.Player; -public record FishingCondition(Player player, Location location) { +import java.util.HashMap; + +public class FishingCondition{ + + private final Location location; + private final Player player; + private HashMap papiMap; + + public FishingCondition(Location location, Player player) { + this.location = location; + this.player = player; + if (ConfigReader.Config.papi){ + this.papiMap = new HashMap<>(); + CustomPapi.allPapi.forEach(papi -> { + this.papiMap.put(papi, PapiHook.parse(player, papi)); + }); + } + } + + public HashMap getPapiMap() { + return papiMap; + } + + public Location getLocation() { + return location; + } - public Location getLocation() { return location; } public Player getPlayer() { return player; } + + @Override + public String toString() { + return "FishingCondition{" + + "location=" + location + + ", player=" + player + + ", papiMap=" + papiMap + + '}'; + } } \ No newline at end of file diff --git a/src/main/java/net/momirealms/customfishing/requirements/Season.java b/src/main/java/net/momirealms/customfishing/requirements/Season.java index 51a07e5c..3e951f83 100644 --- a/src/main/java/net/momirealms/customfishing/requirements/Season.java +++ b/src/main/java/net/momirealms/customfishing/requirements/Season.java @@ -17,11 +17,7 @@ package net.momirealms.customfishing.requirements; -import me.clip.placeholderapi.PlaceholderAPI; import net.momirealms.customfishing.ConfigReader; -import net.momirealms.customfishing.hook.CustomCropsSeason; -import net.momirealms.customfishing.hook.RealisticSeason; -import org.bukkit.ChatColor; import java.util.List; @@ -33,14 +29,7 @@ public record Season(List seasons) implements Requirement { @Override public boolean isConditionMet(FishingCondition fishingCondition) { - String currentSeason; - if (ConfigReader.Config.rsSeason){ - currentSeason = RealisticSeason.getSeason(fishingCondition.getLocation().getWorld()); - }else if(ConfigReader.Config.ccSeason){ - currentSeason = CustomCropsSeason.getSeason(fishingCondition.getLocation().getWorld()); - }else { - currentSeason = ChatColor.stripColor(PlaceholderAPI.setPlaceholders(fishingCondition.getPlayer(), ConfigReader.Config.season_papi)); - } + String currentSeason = ConfigReader.Config.season.getSeason(fishingCondition.getLocation().getWorld()); for (String season : seasons) { if (season.equalsIgnoreCase(currentSeason)) { return true; diff --git a/src/main/java/net/momirealms/customfishing/requirements/SkillLevel.java b/src/main/java/net/momirealms/customfishing/requirements/SkillLevel.java new file mode 100644 index 00000000..35b716b4 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/requirements/SkillLevel.java @@ -0,0 +1,10 @@ +package net.momirealms.customfishing.requirements; + +import net.momirealms.customfishing.ConfigReader; + +public record SkillLevel(int level) implements Requirement{ + @Override + public boolean isConditionMet(FishingCondition fishingCondition) { + return level <= ConfigReader.Config.skillXP.getLevel(fishingCondition.getPlayer()); + } +} diff --git a/src/main/java/net/momirealms/customfishing/requirements/Weather.java b/src/main/java/net/momirealms/customfishing/requirements/Weather.java index cda9e0bc..a3fe5f6e 100644 --- a/src/main/java/net/momirealms/customfishing/requirements/Weather.java +++ b/src/main/java/net/momirealms/customfishing/requirements/Weather.java @@ -17,7 +17,7 @@ package net.momirealms.customfishing.requirements; -import net.momirealms.customfishing.utils.AdventureManager; +import net.momirealms.customfishing.utils.AdventureUtil; import org.bukkit.World; import java.util.List; @@ -47,7 +47,6 @@ public record Weather(List weathers) implements Requirement { } return false; } - AdventureManager.consoleMessage("[CustomFishing] 这条消息不应该出现,玩家钓鱼时所处的世界并不存在!"); return false; } } diff --git a/src/main/java/net/momirealms/customfishing/requirements/World.java b/src/main/java/net/momirealms/customfishing/requirements/World.java index 3319b0b8..46da8dbf 100644 --- a/src/main/java/net/momirealms/customfishing/requirements/World.java +++ b/src/main/java/net/momirealms/customfishing/requirements/World.java @@ -17,7 +17,7 @@ package net.momirealms.customfishing.requirements; -import net.momirealms.customfishing.utils.AdventureManager; +import net.momirealms.customfishing.utils.AdventureUtil; import java.util.List; @@ -33,7 +33,6 @@ public record World(List worlds) implements Requirement { if (world != null) { return worlds.contains(world.getName()); } - AdventureManager.consoleMessage("[CustomFishing] 这条消息不应该出现,玩家钓鱼时所处的世界并不存在!"); return false; } } \ No newline at end of file diff --git a/src/main/java/net/momirealms/customfishing/requirements/papi/ExpressionAnd.java b/src/main/java/net/momirealms/customfishing/requirements/papi/ExpressionAnd.java new file mode 100644 index 00000000..804f16a4 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/requirements/papi/ExpressionAnd.java @@ -0,0 +1,15 @@ +package net.momirealms.customfishing.requirements.papi; + +import java.util.HashMap; +import java.util.List; + +public record ExpressionAnd(List requirements) implements PapiRequirement{ + + @Override + public boolean isMet(HashMap papiMap) { + for (PapiRequirement requirement : requirements) { + if (!requirement.isMet(papiMap)) return false; + } + return true; + } +} \ No newline at end of file diff --git a/src/main/java/net/momirealms/customfishing/requirements/papi/ExpressionOr.java b/src/main/java/net/momirealms/customfishing/requirements/papi/ExpressionOr.java new file mode 100644 index 00000000..3400333f --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/requirements/papi/ExpressionOr.java @@ -0,0 +1,15 @@ +package net.momirealms.customfishing.requirements.papi; + +import java.util.HashMap; +import java.util.List; + +public record ExpressionOr(List requirements) implements PapiRequirement{ + + @Override + public boolean isMet(HashMap papiMap) { + for (PapiRequirement requirement : requirements) { + if (requirement.isMet(papiMap)) return true; + } + return false; + } +} \ No newline at end of file diff --git a/src/main/java/net/momirealms/customfishing/requirements/papi/PapiEquals.java b/src/main/java/net/momirealms/customfishing/requirements/papi/PapiEquals.java new file mode 100644 index 00000000..7515d309 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/requirements/papi/PapiEquals.java @@ -0,0 +1,13 @@ +package net.momirealms.customfishing.requirements.papi; + +import java.util.HashMap; +import java.util.Objects; + +public record PapiEquals(String papi, String requirement) implements PapiRequirement{ + + @Override + public boolean isMet(HashMap papiMap) { + String value = papiMap.get(papi); + return Objects.equals(value, requirement); + } +} diff --git a/src/main/java/net/momirealms/customfishing/requirements/papi/PapiGreater.java b/src/main/java/net/momirealms/customfishing/requirements/papi/PapiGreater.java new file mode 100644 index 00000000..8014abee --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/requirements/papi/PapiGreater.java @@ -0,0 +1,12 @@ +package net.momirealms.customfishing.requirements.papi; + +import java.util.HashMap; + +public record PapiGreater(String papi, double requirement) implements PapiRequirement{ + + @Override + public boolean isMet(HashMap papiMap) { + double value = Double.parseDouble(papiMap.get(papi)); + return value > requirement; + } +} diff --git a/src/main/java/net/momirealms/customfishing/requirements/papi/PapiNoLarger.java b/src/main/java/net/momirealms/customfishing/requirements/papi/PapiNoLarger.java new file mode 100644 index 00000000..f80a5d8d --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/requirements/papi/PapiNoLarger.java @@ -0,0 +1,12 @@ +package net.momirealms.customfishing.requirements.papi; + +import java.util.HashMap; + +public record PapiNoLarger(String papi, double requirement) implements PapiRequirement{ + + @Override + public boolean isMet(HashMap papiMap) { + double value = Double.parseDouble(papiMap.get(papi)); + return value <= requirement; + } +} diff --git a/src/main/java/net/momirealms/customfishing/requirements/papi/PapiNoLess.java b/src/main/java/net/momirealms/customfishing/requirements/papi/PapiNoLess.java new file mode 100644 index 00000000..ef2b51fa --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/requirements/papi/PapiNoLess.java @@ -0,0 +1,12 @@ +package net.momirealms.customfishing.requirements.papi; + +import java.util.HashMap; + +public record PapiNoLess(String papi, double requirement) implements PapiRequirement{ + + @Override + public boolean isMet(HashMap papiMap) { + double value = Double.parseDouble(papiMap.get(papi)); + return value >= requirement; + } +} diff --git a/src/main/java/net/momirealms/customfishing/requirements/papi/PapiRequirement.java b/src/main/java/net/momirealms/customfishing/requirements/papi/PapiRequirement.java new file mode 100644 index 00000000..a022bf1a --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/requirements/papi/PapiRequirement.java @@ -0,0 +1,7 @@ +package net.momirealms.customfishing.requirements.papi; + +import java.util.HashMap; + +public interface PapiRequirement { + boolean isMet(HashMap papiMap); +} diff --git a/src/main/java/net/momirealms/customfishing/requirements/papi/PapiSmaller.java b/src/main/java/net/momirealms/customfishing/requirements/papi/PapiSmaller.java new file mode 100644 index 00000000..94f86ce4 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/requirements/papi/PapiSmaller.java @@ -0,0 +1,12 @@ +package net.momirealms.customfishing.requirements.papi; + +import java.util.HashMap; + +public record PapiSmaller(String papi, double requirement) implements PapiRequirement{ + + @Override + public boolean isMet(HashMap papiMap) { + double value = Double.parseDouble(papiMap.get(papi)); + return value < requirement; + } +} diff --git a/src/main/java/net/momirealms/customfishing/titlebar/Timer.java b/src/main/java/net/momirealms/customfishing/titlebar/Timer.java index a0b70a4e..e21d5b34 100644 --- a/src/main/java/net/momirealms/customfishing/titlebar/Timer.java +++ b/src/main/java/net/momirealms/customfishing/titlebar/Timer.java @@ -18,6 +18,7 @@ package net.momirealms.customfishing.titlebar; import net.momirealms.customfishing.CustomFishing; +import net.momirealms.customfishing.object.Difficulty; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; diff --git a/src/main/java/net/momirealms/customfishing/titlebar/TimerTask.java b/src/main/java/net/momirealms/customfishing/titlebar/TimerTask.java index 1c86efb3..8c6b527f 100644 --- a/src/main/java/net/momirealms/customfishing/titlebar/TimerTask.java +++ b/src/main/java/net/momirealms/customfishing/titlebar/TimerTask.java @@ -17,11 +17,11 @@ package net.momirealms.customfishing.titlebar; -import net.momirealms.customfishing.utils.AdventureManager; +import net.momirealms.customfishing.object.Layout; +import net.momirealms.customfishing.utils.AdventureUtil; import net.momirealms.customfishing.ConfigReader; import net.momirealms.customfishing.CustomFishing; -import net.momirealms.customfishing.titlebar.Difficulty; -import net.momirealms.customfishing.titlebar.Layout; +import net.momirealms.customfishing.object.Difficulty; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -30,7 +30,7 @@ import org.bukkit.potion.PotionEffectType; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitScheduler; -import static net.momirealms.customfishing.listener.PlayerListener.fishingPlayers; +import static net.momirealms.customfishing.listener.FishListener.fishingPlayers; public class TimerTask extends BukkitRunnable { @@ -41,7 +41,7 @@ public class TimerTask extends BukkitRunnable { private int internalTimer; private final int size; private boolean face; - private BukkitScheduler bukkitScheduler; + private final BukkitScheduler bukkitScheduler; private final String start; private final String bar; @@ -83,6 +83,7 @@ public class TimerTask extends BukkitRunnable { } //移除超时玩家 if (System.currentTimeMillis() > fishingPlayers.get(player).getFishingTime()){ + AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.escape); fishingPlayers.remove(player); bukkitScheduler.cancelTask(taskID); return; @@ -118,7 +119,7 @@ public class TimerTask extends BukkitRunnable { } } stringBuilder.append(end); - AdventureManager.playerTitle(player, title, stringBuilder.toString(),0,300,0); + AdventureUtil.playerTitle(player, title, stringBuilder.toString(),0,300,0); //移除切换物品的玩家 PlayerInventory playerInventory = player.getInventory(); if (playerInventory.getItemInMainHand().getType() != Material.FISHING_ROD && playerInventory.getItemInOffHand().getType() != Material.FISHING_ROD){ diff --git a/src/main/java/net/momirealms/customfishing/utils/AdventureManager.java b/src/main/java/net/momirealms/customfishing/utils/AdventureUtil.java similarity index 85% rename from src/main/java/net/momirealms/customfishing/utils/AdventureManager.java rename to src/main/java/net/momirealms/customfishing/utils/AdventureUtil.java index 59234384..38d74951 100644 --- a/src/main/java/net/momirealms/customfishing/utils/AdventureManager.java +++ b/src/main/java/net/momirealms/customfishing/utils/AdventureUtil.java @@ -21,7 +21,6 @@ import net.kyori.adventure.audience.Audience; import net.kyori.adventure.key.Key; import net.kyori.adventure.sound.Sound; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.title.Title; import net.momirealms.customfishing.CustomFishing; import org.bukkit.Bukkit; @@ -29,7 +28,7 @@ import org.bukkit.entity.Player; import java.time.Duration; -public class AdventureManager { +public class AdventureUtil { public static void consoleMessage(String s) { Audience au = CustomFishing.adventure.sender(Bukkit.getConsoleSender()); @@ -50,6 +49,13 @@ public class AdventureManager { au.showTitle(title); } + public static void playerTitle(Player player, Component s1, Component s2, int in, int duration, int out) { + Audience au = CustomFishing.adventure.player(player); + Title.Times times = Title.Times.times(Duration.ofMillis(in), Duration.ofMillis(duration), Duration.ofMillis(out)); + Title title = Title.title(s1, s2, times); + au.showTitle(title); + } + public static void playerActionbar(Player player, String s) { Audience au = CustomFishing.adventure.player(player); au.sendActionBar(CustomFishing.miniMessage.deserialize(s)); diff --git a/src/main/java/net/momirealms/customfishing/utils/UpdateConfig.java b/src/main/java/net/momirealms/customfishing/utils/ConfigUtil.java similarity index 97% rename from src/main/java/net/momirealms/customfishing/utils/UpdateConfig.java rename to src/main/java/net/momirealms/customfishing/utils/ConfigUtil.java index 6e55c5a6..8649d058 100644 --- a/src/main/java/net/momirealms/customfishing/utils/UpdateConfig.java +++ b/src/main/java/net/momirealms/customfishing/utils/ConfigUtil.java @@ -12,7 +12,7 @@ import net.momirealms.customfishing.helper.Log; import java.io.File; import java.io.IOException; -public class UpdateConfig { +public class ConfigUtil { public static void update(){ try { diff --git a/src/main/java/net/momirealms/customfishing/utils/ItemStackGenerator.java b/src/main/java/net/momirealms/customfishing/utils/ItemStackUtil.java similarity index 55% rename from src/main/java/net/momirealms/customfishing/utils/ItemStackGenerator.java rename to src/main/java/net/momirealms/customfishing/utils/ItemStackUtil.java index 7cf0d3f5..2b3ae7e8 100644 --- a/src/main/java/net/momirealms/customfishing/utils/ItemStackGenerator.java +++ b/src/main/java/net/momirealms/customfishing/utils/ItemStackUtil.java @@ -22,19 +22,21 @@ import de.tr7zw.changeme.nbtapi.NBTItem; import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; -import net.momirealms.customfishing.item.Item; +import net.momirealms.customfishing.object.Item; +import net.momirealms.customfishing.object.LeveledEnchantment; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.Damageable; import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.ItemMeta; import java.util.List; +import java.util.Objects; -public class ItemStackGenerator { - - public static ItemStack fromItem(Item item){ +public class ItemStackUtil { + public static ItemStack getFromItem(Item item){ ItemStack itemStack = new ItemStack(Material.valueOf(item.getMaterial().toUpperCase())); ItemMeta itemMeta = itemStack.getItemMeta(); if (item.getCustomModelData() != 0){ @@ -46,49 +48,79 @@ public class ItemStackGenerator { if (item.getItemFlags() != null){ item.getItemFlags().forEach(itemMeta::addItemFlags); } - if (item.getEnchantments() != null) { + if (item.getEnchantment() != null) { if (itemStack.getType() == Material.ENCHANTED_BOOK){ EnchantmentStorageMeta meta = (EnchantmentStorageMeta)itemMeta; - item.getEnchantments().forEach(enchantment1 -> { - meta.addStoredEnchant(org.bukkit.enchantments.Enchantment.getByKey(enchantment1.getKey()),enchantment1.getLevel(),true); - }); + item.getEnchantment().forEach(enchantment -> meta.addStoredEnchant(Objects.requireNonNull(Enchantment.getByKey(enchantment.getKey())),enchantment.getLevel(),true)); itemStack.setItemMeta(meta); }else { - item.getEnchantments().forEach(enchantment1 -> { - itemMeta.addEnchant(Enchantment.getByKey(enchantment1.getKey()),enchantment1.getLevel(),true); - }); + item.getEnchantment().forEach(enchantment -> itemMeta.addEnchant(Objects.requireNonNull(Enchantment.getByKey(enchantment.getKey())),enchantment.getLevel(),true)); itemStack.setItemMeta(itemMeta); } - }else { + } + else { itemStack.setItemMeta(itemMeta); } - NBTItem nbtItem = new NBTItem(itemStack); - NBTCompound display = nbtItem.addCompound("display"); if (item.getName() != null){ + NBTCompound display = nbtItem.addCompound("display"); String name = item.getName(); if (name.contains("&") || name.contains("§")){ name = name.replaceAll("&","§"); display.setString("Name", GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacyAmpersand().deserialize(name))); }else { - display.setString("Name", GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize("" + name))); + display.setString("Name", GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize("" + name))); } } if(item.getLore() != null){ + NBTCompound display = nbtItem.addCompound("display"); List lore = display.getStringList("Lore"); item.getLore().forEach(line -> { if (line.contains("&") || line.contains("§")){ line = line.replaceAll("&","§"); lore.add(GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacyAmpersand().deserialize(line))); }else { - lore.add(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize("" + line))); + lore.add(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize("" + line))); } }); } if (item.getNbt() != null){ - NBTUtil nbtUtil = new NBTUtil(item.getNbt(), nbtItem.getItem()); - return nbtUtil.getNBTItem().getItem(); + NBTUtil.setTags(item.getNbt(), nbtItem); } return nbtItem.getItem(); } + + public static void addRandomEnchants(ItemStack itemStack, List enchantments){ + ItemMeta itemMeta = itemStack.getItemMeta(); + if (itemStack.getType() == Material.ENCHANTED_BOOK){ + EnchantmentStorageMeta meta = (EnchantmentStorageMeta)itemMeta; + enchantments.forEach(enchantment -> { + if (enchantment.getChance() > Math.random()){ + meta.addStoredEnchant(Objects.requireNonNull(Enchantment.getByKey(enchantment.getKey())),enchantment.getLevel(),true); + } + }); + itemStack.setItemMeta(meta); + } + else { + enchantments.forEach(enchantment -> { + if (enchantment.getChance() > Math.random()){ + itemMeta.addEnchant(Objects.requireNonNull(Enchantment.getByKey(enchantment.getKey())),enchantment.getLevel(),true); + } + }); + itemStack.setItemMeta(itemMeta); + } + } + + public static void addRandomDamage(ItemStack itemStack){ + if (itemStack.getItemMeta() instanceof Damageable damageable){ + damageable.setDamage((int) (itemStack.getType().getMaxDurability() * Math.random())); + itemStack.setItemMeta((ItemMeta) damageable); + } + } + + public static void addOwner(ItemStack itemStack, String name){ + NBTItem nbtItem = new NBTItem(itemStack); + nbtItem.setString("M_Owner", name); + itemStack.setItemMeta(nbtItem.getItem().getItemMeta()); + } } diff --git a/src/main/java/net/momirealms/customfishing/utils/SaveItem.java b/src/main/java/net/momirealms/customfishing/utils/ItemUtil.java similarity index 67% rename from src/main/java/net/momirealms/customfishing/utils/SaveItem.java rename to src/main/java/net/momirealms/customfishing/utils/ItemUtil.java index 24400e7b..bd0c8d26 100644 --- a/src/main/java/net/momirealms/customfishing/utils/SaveItem.java +++ b/src/main/java/net/momirealms/customfishing/utils/ItemUtil.java @@ -19,9 +19,11 @@ package net.momirealms.customfishing.utils; import de.tr7zw.changeme.nbtapi.NBTCompound; import de.tr7zw.changeme.nbtapi.NBTItem; +import net.momirealms.customfishing.ConfigReader; import net.momirealms.customfishing.CustomFishing; import org.bukkit.Material; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -29,7 +31,34 @@ import java.io.File; import java.io.IOException; import java.util.*; -public class SaveItem { +public class ItemUtil { + + public static void givePlayerLoot(Player player, String lootKey, int amount){ + ItemStack itemStack = ConfigReader.LootItem.get(lootKey); + if (itemStack == null) return; + itemStack.setAmount(amount); + player.getInventory().addItem(itemStack); + } + + public static void givePlayerRod(Player player, String rodKey, int amount){ + ItemStack itemStack = ConfigReader.RodItem.get(rodKey); + itemStack.setAmount(amount); + player.getInventory().addItem(itemStack); + } + + public static void givePlayerBait(Player player, String baitKey, int amount){ + ItemStack itemStack = ConfigReader.BaitItem.get(baitKey); + if (itemStack == null) return; + itemStack.setAmount(amount); + player.getInventory().addItem(itemStack); + } + + public static void givePlayerUtil(Player player, String utilKey, int amount){ + ItemStack itemStack = ConfigReader.UtilItem.get(utilKey); + if (itemStack == null) return; + itemStack.setAmount(amount); + player.getInventory().addItem(itemStack); + } public static void saveToFile(ItemStack itemStack, String fileName){ @@ -53,11 +82,11 @@ public class SaveItem { yamlConfiguration.set(fileName + ".unbreakable", itemMeta.isUnbreakable()); } if (itemMeta.hasEnchants()) { - ArrayList enchants = new ArrayList<>(); + Map map = new HashMap<>(); itemMeta.getEnchants().forEach((enchantment, level) -> { - enchants.add(enchantment.getKey() + "/" + level); + map.put(String.valueOf(enchantment.getKey()), level); }); - yamlConfiguration.set(fileName + ".enchantments", enchants); + yamlConfiguration.createSection(fileName + ".enchantments", map); } if (itemMeta.getItemFlags().size() > 0){ ArrayList itemFlags = new ArrayList<>(); @@ -70,16 +99,13 @@ public class SaveItem { NBTItem nbtItem = new NBTItem(itemStack); Map map0 = compoundToMap(nbtItem); - if (map0.size() != 0){ - ArrayList> mapArrayList = new ArrayList<>(); - mapArrayList.add(map0); - yamlConfiguration.set(fileName + ".nbt", mapArrayList); - } + yamlConfiguration.createSection(fileName + ".nbt", map0); - File file = new File(CustomFishing.instance.getDataFolder(), File.separator + "export" + File.separator + fileName + ".yml"); + File file = new File(CustomFishing.instance.getDataFolder(), File.separator + "loots" + File.separator + fileName + ".yml"); try { yamlConfiguration.save(file); + ConfigReader.loadLoot(); }catch (IOException e){ e.printStackTrace(); } @@ -88,12 +114,12 @@ public class SaveItem { public static Map compoundToMap(NBTCompound nbtCompound){ Map map = new HashMap<>(); nbtCompound.getKeys().forEach(key -> { - if (key.equals("Enchantments")) return; - if (key.equals("Name")) return; - if (key.equals("Lore")) return; - if (key.equals("HideFlags")) return; - if (key.equals("CustomModelData")) return; - if (key.equals("Unbreakable")) return; + if (key.equals("Enchantments") + || key.equals("Name") + || key.equals("Lore") + || key.equals("HideFlags") + || key.equals("CustomModelData") + || key.equals("Unbreakable")) return; switch (nbtCompound.getType(key)){ case NBTTagByte -> map.put(key, "(Byte) " + nbtCompound.getByte(key)); case NBTTagInt -> map.put(key, "(Int) " + nbtCompound.getInteger(key)); @@ -106,37 +132,19 @@ public class SaveItem { case NBTTagIntArray -> map.put(key, "(IntArray) " + Arrays.toString(nbtCompound.getIntArray(key))); case NBTTagCompound -> { Map map1 = compoundToMap(nbtCompound.getCompound(key)); - if (map1.size() != 0){ - map.put(key, map1); - } + if (map1.size() != 0) map.put(key, map1); } case NBTTagList -> { List list = new ArrayList<>(); switch (nbtCompound.getListType(key)){ - case NBTTagInt -> nbtCompound.getIntegerList(key).forEach(a -> { - list.add("(Int) " + a); - }); - case NBTTagDouble -> nbtCompound.getDoubleList(key).forEach(a -> { - list.add("(Double) " + a); - }); - case NBTTagString -> nbtCompound.getStringList(key).forEach(a -> { - list.add("(String) " + a); - }); - case NBTTagCompound -> nbtCompound.getCompoundList(key).forEach(a -> { - list.add(compoundToMap(a)); - }); - case NBTTagFloat -> nbtCompound.getFloatList(key).forEach(a -> { - list.add("(Float) " + a); - }); - case NBTTagLong -> nbtCompound.getLongList(key).forEach(a -> { - list.add("(Long) " + a); - }); - case NBTTagIntArray -> nbtCompound.getIntArrayList(key).forEach(a -> { - list.add("(IntArray) " + Arrays.toString(a)); - }); - default -> nbtCompound.getUUIDList(key).forEach(a -> { - list.add("(UUID) " + a); - }); + case NBTTagInt -> nbtCompound.getIntegerList(key).forEach(a -> list.add("(Int) " + a)); + case NBTTagDouble -> nbtCompound.getDoubleList(key).forEach(a -> list.add("(Double) " + a)); + case NBTTagString -> nbtCompound.getStringList(key).forEach(a -> list.add("(String) " + a)); + case NBTTagCompound -> nbtCompound.getCompoundList(key).forEach(a -> list.add(compoundToMap(a))); + case NBTTagFloat -> nbtCompound.getFloatList(key).forEach(a -> list.add("(Float) " + a)); + case NBTTagLong -> nbtCompound.getLongList(key).forEach(a -> list.add("(Long) " + a)); + case NBTTagIntArray -> nbtCompound.getIntArrayList(key).forEach(a -> list.add("(IntArray) " + Arrays.toString(a))); + default -> nbtCompound.getUUIDList(key).forEach(a -> list.add("(UUID) " + a)); } map.put(key, list); } diff --git a/src/main/java/net/momirealms/customfishing/utils/JedisUtil.java b/src/main/java/net/momirealms/customfishing/utils/JedisUtil.java index 5ab0b4a9..bc6c7cbb 100644 --- a/src/main/java/net/momirealms/customfishing/utils/JedisUtil.java +++ b/src/main/java/net/momirealms/customfishing/utils/JedisUtil.java @@ -29,7 +29,6 @@ import java.util.List; public class JedisUtil { private static JedisPool jedisPool; - public static boolean useRedis; public static Jedis getJedis(){ return jedisPool.getResource(); @@ -49,7 +48,7 @@ public class JedisUtil { jedisPool = new JedisPool(jedisPoolConfig, configuration.getString("redis.host","localhost"), configuration.getInt("redis.port",6379)); - AdventureManager.consoleMessage("[CustomFishing] Redis Enabled!"); + AdventureUtil.consoleMessage("[CustomFishing] Redis Enabled!"); List minIdleJedisList = new ArrayList<>(jedisPoolConfig.getMinIdle()); for (int i = 0; i < jedisPoolConfig.getMinIdle(); i++) { diff --git a/src/main/java/net/momirealms/customfishing/utils/NBTUtil.java b/src/main/java/net/momirealms/customfishing/utils/NBTUtil.java index af7253b4..b3184167 100644 --- a/src/main/java/net/momirealms/customfishing/utils/NBTUtil.java +++ b/src/main/java/net/momirealms/customfishing/utils/NBTUtil.java @@ -19,20 +19,13 @@ package net.momirealms.customfishing.utils; import de.tr7zw.changeme.nbtapi.NBTCompound; import de.tr7zw.changeme.nbtapi.NBTItem; +import org.bukkit.configuration.MemorySection; import org.bukkit.inventory.ItemStack; import java.util.*; public class NBTUtil { - private final Map nbt; - private final NBTItem nbtItem; - - public NBTUtil(Map nbt, ItemStack itemStack){ - this.nbt = nbt; - this.nbtItem = new NBTItem(itemStack); - } - public static ItemStack addIdentifier(ItemStack itemStack, String type, String id){ NBTItem nbtItem = new NBTItem(itemStack); nbtItem.addCompound("CustomFishing"); @@ -41,18 +34,23 @@ public class NBTUtil { return nbtItem.getItem(); } - public NBTItem getNBTItem(){ + public static NBTItem getNBTItem(Map nbt, ItemStack itemStack){ + NBTItem nbtItem = new NBTItem(itemStack); setTags(nbt, nbtItem); - return this.nbtItem; + return nbtItem; } - private void setTags(Map map, NBTCompound nbtCompound){ + public static void setTags(Map map, NBTCompound nbtCompound){ map.keySet().forEach(key -> { - if (map.get(key) instanceof Map map2){ + if (map.get(key) instanceof MemorySection map2){ nbtCompound.addCompound(key); - setTags(map2, nbtCompound.getCompound(key)); + setTags(map2.getValues(false), nbtCompound.getCompound(key)); } - else if(map.get(key) instanceof List list){ + else if (map.get(key) instanceof Map map1){ + nbtCompound.addCompound(key); + setTags((Map) map1, nbtCompound.getCompound(key)); + } + else if (map.get(key) instanceof List list){ for (Object o : list) { if (o instanceof String s) { if (s.startsWith("(String) ")) { @@ -72,7 +70,8 @@ public class NBTUtil { int[] array = Arrays.stream(split).mapToInt(Integer::parseInt).toArray(); nbtCompound.getIntArrayList(key).add(array); } - } else if (o instanceof Map map1) { + } + else if (o instanceof Map map1) { setTags(map1, nbtCompound.getCompoundList(key).addCompound()); } } diff --git a/src/main/java/net/momirealms/customfishing/utils/VectorUtil.java b/src/main/java/net/momirealms/customfishing/utils/VectorUtil.java deleted file mode 100644 index 96b4c73a..00000000 --- a/src/main/java/net/momirealms/customfishing/utils/VectorUtil.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) <2022> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.momirealms.customfishing.utils; - -public record VectorUtil(double horizontal, double vertical) { - public double getHorizontal() {return this.horizontal;} - public double getVertical() {return this.vertical;} -} diff --git a/src/main/resources/baits.yml b/src/main/resources/baits.yml deleted file mode 100644 index 92d0fea3..00000000 --- a/src/main/resources/baits.yml +++ /dev/null @@ -1,50 +0,0 @@ -baits: - simple_bait: - material: paper - display: - name: 'Common fishing lures' - lore: - - 'Reduce the time spent fishing' - - 'But make it more difficult to catch fish' - custom-model-data: 646 - #Bait Gain - modifier: - #Change the loot weight of the specified group - #Add or subtract weights - weight-PM: - silver: 5 - gold: 3 - #Multiply and divide weights - weight-MQ: - silver: 1.1 - gold: 1.1 - #Change the time to fish (>1 for longer, <1 for shorter) - time: 0.85 - #Change the difficulty, for example, if the original difficulty is (1-6), now it becomes (1-9) - difficulty: 3 - #Double drop probability - double-loot: 0.06 - #Multiply the score got in competition - score: 1.2 - - wild_bait: - material: paper - display: - name: 'Wild Bait' - lore: - - 'Decreases fishing time by 30%.' - custom-model-data: 696 - modifier: - time: 0.7 - - magnet_bait: - material: paper - display: - name: 'Magnet Bait' - lore: - - 'Increases the probability of better loot by 15%.' - custom-model-data: 695 - modifier: - weight-MQ: - silver: 1.15 - gold: 1.15 \ No newline at end of file diff --git a/src/main/resources/baits/default.yml b/src/main/resources/baits/default.yml new file mode 100644 index 00000000..c02ddc91 --- /dev/null +++ b/src/main/resources/baits/default.yml @@ -0,0 +1,49 @@ +simple_bait: + material: paper + display: + name: 'Common fishing lures' + lore: + - 'Reduce the time spent fishing' + - 'But make it more difficult to catch fish' + custom-model-data: 646 + # Bait Modifier + modifier: + # Change the loot weight of the specified group + # Add or subtract weights + weight-PM: + silver: 5 + gold: 3 + # Multiply or divide weights + weight-MQ: + silver: 1.1 + gold: 1.1 + # Change the time to fish (>1 for longer, <1 for shorter) + time: 0.85 + # Change the difficulty, for example, if the original difficulty is (1-6), now it becomes (1-9) + difficulty: 3 + # Double loot probability + double-loot: 0.06 + # Multiply the score got in competition + score: 1.2 + +wild_bait: + material: paper + display: + name: 'Wild Bait' + lore: + - 'Decreases fishing time by 30%.' + custom-model-data: 696 + modifier: + time: 0.7 + +magnet_bait: + material: paper + display: + name: 'Magnet Bait' + lore: + - 'Increases the probability of better loot by 15%.' + custom-model-data: 695 + modifier: + weight-MQ: + silver: 1.15 + gold: 1.15 \ No newline at end of file diff --git a/src/main/resources/bars.yml b/src/main/resources/bars.yml index 16baa687..9c5a6eea 100644 --- a/src/main/resources/bars.yml +++ b/src/main/resources/bars.yml @@ -4,7 +4,7 @@ bar1: subtitle: # # It's not recommended to use minecraft:default - # If you insists on that, use + # If you insist on doing that, use start: '' bar: '뀄' pointer_offset: '뀂' diff --git a/src/main/resources/competition.yml b/src/main/resources/competition.yml index e7856d1e..79d797d0 100644 --- a/src/main/resources/competition.yml +++ b/src/main/resources/competition.yml @@ -10,13 +10,15 @@ example: duration: 300 #seconds + # Min players to begin the competition min-players: 2 + # Competition information (it will only be shown to participants) bossbar: enable: true color: YELLOW overlay: PROGRESS - #https://docs.adventure.kyori.net/minimessage/format.html + # https://docs.adventure.kyori.net/minimessage/format.html text: 'Time Left: {time}s Rank: {rank} Time Left: {minute}m{second}s Points: {point}' refresh-rate: 10 @@ -25,8 +27,6 @@ example: - 'say competition started!' end: - 'say competition ended!' - # When player join the competition - # You can execute some commands on that player join: - 'money give {player} 10' @@ -51,6 +51,7 @@ example: - '' - '----------------------------------------' + # You can customize unlimited ranks' rewards by adding 4,5,6... prize: 1: commands: diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index cff7022e..e01ac4da 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,5 +1,5 @@ # don't change -config-version: '3' +config-version: '5' config: #en/es/cn @@ -8,51 +8,54 @@ config: integrations: # fishing region hook WorldGuard: false - # mobs hook MythicMobs: false - # Papi hook PlaceholderAPI: true - # Skill xp hook mcMMO: false MMOCore: false AureliumSkills: false EcoSkills: false - # Season hook CustomCrops: false RealisticSeasons: false - season: - # Season Papi - # If you enabled CustomCrops or RealisticSeasons season hook, this option will not take effect - enable: false - papi: '%customcrops_season%' + # Should the fishing bar only show after player reel in + # Otherwise the bar would show immediately the bobber is hooked + double-reel-in: true - # The same to vanilla + # This is useful for vanilla loots + # This should be compatible with other fishing plugin's loot system + vanilla-loot: + enable: true + # Bar and ratio only works when 'double-reel-in' is true + bar: true + ratio: 0.3 + + # The same to vanilla (refer to the wiki) + # https://technical-minecraft.fandom.com/wiki/Fishing need-open-water: true - # Players must use rods with CustomFishing's NBT Tags + # Players must use rods with CustomFishing's NBT Tags to get loots in CustomFishing need-special-rod: false # does rod lose durability when player successfully fish rod-lose-durability: true - # If there's no custom fish in this place or players don't have a special rod - # Should players get loots in vanilla way? - # This should be compatible with other fishing plugin's loot system - vanilla-loot-when-no-custom-fish: true - # Cool down time of fish finder fishfinder-cooldown: 3000 # Change the time bobber needs to be hooked time-multiply: 2 - # Enable Competition(Requires a restart) + # Competition (Requires a restart) fishing-competition: true # Convert MMOItems' rod into CustomFishing's rod (Requires a restart) - convert-MMOITEMS: true \ No newline at end of file + # keep the same key name both in MMOItems and CustomFishing and rods can extend the bonus of those in CustomFishing + convert-MMOITEMS: false + + # Prevent other players to pick up your fishing loot (Requires a restart) + # This is useful for players to fish in a public area + prevent-other-players-pick-up-loot: false \ No newline at end of file diff --git a/src/main/resources/custom-enchant-bonus.yml b/src/main/resources/custom-enchant-bonus.yml new file mode 100644 index 00000000..a484abdf --- /dev/null +++ b/src/main/resources/custom-enchant-bonus.yml @@ -0,0 +1,25 @@ +# Enchantment Name +minecraft:luck_of_the_sea: + #levels + 1: + weight-PM: + silver: 2 + gold: 1 + 2: + weight-PM: + silver: 3 + gold: 2 + 3: + weight-PM: + silver: 4 + gold: 3 + +# Supports Enchantments from Other plugins (for example EcoEnchants) +# lucky_catch from EcoEnchants +minecraft:lucky_catch: + 1: + double-loot: 0.1 + 2: + double-loot: 0.2 + 3: + double-loot: 0.3 \ No newline at end of file diff --git a/src/main/resources/loots.yml b/src/main/resources/loots.yml deleted file mode 100644 index 2fa8260b..00000000 --- a/src/main/resources/loots.yml +++ /dev/null @@ -1,594 +0,0 @@ -#MiniMessage Format is available in item name & lore -#https://docs.adventure.kyori.net/minimessage/format.html - -items: - # EXAMPLE - rainbow_fish: - material: cod - nick: 'Example Fish' - display: - name: '✖七✖色✖彩✖虹✖鱼✖' - lore: - - 'This is a rainbow fish!' - - ' 这是一条七色彩虹鱼' - custom-model-data: 1 - # Should it be displayed in fish finder? - show-in-fishfinder: false - # If you are not sure about NBT tag. You can use command '/customfishing export xxx' and get them in 'CustomFishing/export' folder - # (Int) (Byte) (String) (Float) (String) (Double) (Short) (Long) (UUID) (Boolean) (IntArray) (ByteArray) - nbt: - - itemsadder: - namespace: '(String) momirealms' - id: '(String) rainbow_fish' - SomeNBT: - NBTS: - byte: '(Byte) 127' - float: '(Float) 3.14159' - # Action to be triggered when fishing successfully - action: - message: 'You got a {loot} lol!' - command: - - 'say 玩家 {player} 在 {world}, {x},{y},{z} 钓到了一条 {loot}!' - exp: 10 - # Action to be triggered when fish is hooked - action-hook: - message: - - 'The fish is hooked!' - command: - - 'effect give {player} minecraft:slowness 30 10' - # The weight(relative chance) of getting this fish - weight: 10 - # Optional - group: normal - # The score to get when in competition - score: 10 - - # Fishing Skill xp add to skill plugin - #skill-xp: 100 - - # Difficulty - # '1' represents the pointer moves every 1 tick - # '7' represents the pointer moves 7 pixels each time - difficulty: 1-7 - - # Specify the bar. If not specified, it will be random - layout: bar1 - - enchantments: - - minecraft:sharpness/1 - - minecraft:flame/1 - - item_flags: - - HIDE_ENCHANTS - # - HIDE_ATTRIBUTES - # - HIDE_DESTROYS - # - HIDE_DYE - # - HIDE_PLACED_ON - # - HIDE_UNBREAKABLE - # - HIDE_POTION_EFFECTS - - # How long can a player fish on each bite(ms) - time: 5000 - # Optional - requirements: - biome: - - minecraft:plains - - minecraft:taiga - ypos: - - 50~100 - - 150~200 - weather: - - rain - - clear - - thunder - permission: 'customfishing.rainbowfish' - world: - - world - time: - - 0~12000 - #Requires WorldGuard - #region: - # - fishingpool - #Requires PlaceholderAPI - #season: - # - Spring - # - Autumn - - rubbish: - material: paper - show-in-fishfinder: false - display: - name: 'Garbage' - weight: 50 - time: 100000 - difficulty: 1-1 - custom-model-data: 640 - - Pufferfish: - material: pufferfish - display: - name: 'Pufferfish' - weight: 50 - time: 100000 - difficulty: 1-5 - requirements: - weather: - - clear - - cod: - material: cod - display: - name: 'Cod' - weight: 50 - time: 100000 - difficulty: 1-5 - requirements: - weather: - - clear - - salmon: - material: salmon - display: - name: 'Salmon' - weight: 50 - time: 100000 - difficulty: 1-5 - requirements: - weather: - - clear - - tropical_fish: - material: tropical_fish - display: - name: 'Tropical Fish' - weight: 50 - time: 100000 - difficulty: 1-5 - requirements: - weather: - - clear - biome: - - minecraft:jungle - - minecraft:bamboo_jungle - - tuna: - material: paper - display: - name: 'Tuna Fish' - weight: 50 - time: 100000 - difficulty: 1-1 - custom-model-data: 641 - - tuna_fish_silver_star: - material: paper - display: - name: 'Tuna Fish Silver Star' - weight: 50 - time: 100000 - difficulty: 1-1 - group: silver - custom-model-data: 666 - - tuna_fish_golden_star: - material: paper - display: - name: 'Tuna Fish Golden Star' - weight: 50 - time: 100000 - difficulty: 1-1 - group: gold - custom-model-data: 667 - - pike: - material: paper - display: - name: 'Pike Fish' - weight: 50 - time: 100000 - difficulty: 1-2 - custom-model-data: 642 - - pike_fish_silver_star: - material: paper - display: - name: 'Pike Fish Silver Star' - weight: 50 - time: 100000 - difficulty: 1-2 - group: silver - custom-model-data: 664 - - pike_fish_golden_star: - material: paper - display: - name: 'Pike Fish Golden Star' - weight: 50 - time: 100000 - difficulty: 1-2 - group: gold - custom-model-data: 665 - - golden: - material: paper - display: - name: 'Golden Fish' - weight: 50 - time: 100000 - difficulty: 1-2 - custom-model-data: 643 - - golden_fish_silver_star: - material: paper - display: - name: 'Golden Fish Silver Star' - weight: 50 - time: 100000 - difficulty: 1-2 - group: silver - custom-model-data: 658 - - golden_fish_golden_star: - material: paper - display: - name: 'Golden Fish Golden Star' - weight: 50 - time: 100000 - group: gold - difficulty: 1-2 - custom-model-data: 659 - - perch_fish: - material: paper - display: - name: 'Perch Fish' - weight: 50 - time: 100000 - difficulty: 1-2 - custom-model-data: 644 - - perch_fish_silver_star: - material: paper - display: - name: 'Perch Fish Silver Star' - weight: 50 - time: 100000 - group: silver - difficulty: 1-2 - custom-model-data: 660 - - perch_fish_golden_star: - material: paper - display: - name: 'Perch Fish Golden Star' - weight: 50 - group: gold - time: 100000 - difficulty: 1-2 - custom-model-data: 661 - - mullet_fish: - material: paper - display: - name: 'Mullet Fish' - weight: 50 - time: 100000 - difficulty: 1-2 - custom-model-data: 645 - - mullet_fish_silver_star: - material: paper - display: - name: 'Mullet Fish Silver Star' - weight: 50 - group: silver - time: 100000 - difficulty: 1-2 - custom-model-data: 662 - - mullet_fish_golden_star: - material: paper - display: - name: 'Mullet Fish Golden Star' - weight: 50 - time: 100000 - group: gold - difficulty: 1-2 - custom-model-data: 663 - - sardine_fish: - material: paper - display: - name: 'Sardine Fish' - weight: 50 - time: 100000 - difficulty: 1-2 - custom-model-data: 668 - - sardine_fish_silver_star: - material: paper - display: - name: 'Sardine Fish Silver Star' - weight: 50 - time: 100000 - group: silver - difficulty: 1-2 - custom-model-data: 669 - - sardine_fish_golden_star: - material: paper - display: - name: 'Sardine Fish Golden Star' - weight: 50 - time: 100000 - group: gold - difficulty: 1-2 - custom-model-data: 670 - - carp_fish: - material: paper - display: - name: 'Carp Fish' - weight: 50 - time: 100000 - difficulty: 1-2 - custom-model-data: 671 - - carp_fish_silver_star: - material: paper - display: - name: 'Carp Fish Silver Star' - weight: 50 - time: 100000 - group: silver - difficulty: 1-2 - custom-model-data: 672 - - carp_fish_golden_star: - material: paper - display: - name: 'Carp Fish Golden Star' - weight: 50 - time: 100000 - group: gold - difficulty: 1-2 - custom-model-data: 673 - - cat_fish: - material: paper - display: - name: 'Cat Fish' - weight: 50 - time: 100000 - difficulty: 1-2 - custom-model-data: 674 - - cat_fish_silver_star: - material: paper - display: - name: 'Cat Fish Silver Star' - weight: 50 - group: silver - time: 100000 - difficulty: 1-2 - custom-model-data: 675 - - cat_fish_golden_star: - material: paper - display: - name: 'Cat Fish Golden Star' - weight: 50 - time: 100000 - group: gold - difficulty: 1-2 - custom-model-data: 676 - - octopus_fish: - material: paper - display: - name: 'Octopus Fish' - weight: 50 - time: 100000 - difficulty: 1-2 - custom-model-data: 677 - - octopus_fish_silver_star: - material: paper - display: - name: 'Octopus Fish Silver Star' - weight: 50 - group: silver - time: 100000 - difficulty: 1-2 - custom-model-data: 678 - - octopus_fish_golden_star: - material: paper - display: - name: 'Octopus Fish Golden Star' - weight: 50 - time: 100000 - group: gold - difficulty: 1-2 - custom-model-data: 679 - - sunfish_fish: - material: paper - display: - name: 'Sunfish Fish' - weight: 50 - time: 100000 - difficulty: 1-2 - custom-model-data: 680 - - sunfish_fish_silver_star: - material: paper - display: - name: 'Sunfish Fish Silver Star' - weight: 50 - group: silver - time: 100000 - difficulty: 1-2 - custom-model-data: 681 - - sunfish_fish_golden_star: - material: paper - display: - name: 'Sunfish Fish Golden Star' - weight: 50 - time: 100000 - group: gold - difficulty: 1-2 - custom-model-data: 682 - - red_spnapper_fish: - material: paper - display: - name: 'Red Snapper Fish' - weight: 50 - time: 100000 - difficulty: 1-2 - custom-model-data: 683 - - red_spnapper_fish_silver_star: - material: paper - display: - name: 'Red Snapper Fish Silver Star' - weight: 50 - time: 100000 - group: silver - difficulty: 1-2 - custom-model-data: 684 - - red_spnapper_fish_golden_star: - material: paper - display: - name: 'Red Snapper Golden Star' - weight: 50 - time: 100000 - group: gold - difficulty: 1-2 - custom-model-data: 685 - - salmon_void_fish: - material: paper - display: - name: 'Salmon Void Fish' - weight: 50 - time: 100000 - difficulty: 1-2 - custom-model-data: 686 - - salmon_void_fish_silver_star: - material: paper - display: - name: 'Salmon Void Fish Silver Star' - weight: 50 - time: 100000 - group: silver - difficulty: 1-2 - custom-model-data: 687 - - salmon_void_fish_golden_star: - material: paper - display: - name: 'Salmon Void Fish Golden Star' - weight: 50 - time: 100000 - group: gold - difficulty: 1-2 - custom-model-data: 688 - - woodskip_fish: - material: paper - display: - name: 'Woodskip Fish' - weight: 50 - time: 100000 - difficulty: 1-2 - custom-model-data: 689 - - woodskip_fish_silver_star: - material: paper - display: - name: 'Woodskip Fish Silver Star' - weight: 50 - group: silver - time: 100000 - difficulty: 1-2 - custom-model-data: 690 - - woodskip_fish_golden_star: - material: paper - display: - name: 'Woodskip Fish Golden Star' - weight: 50 - group: gold - time: 100000 - difficulty: 1-2 - custom-model-data: 691 - - sturgeon_fish: - material: paper - display: - name: 'Sturgeon Fish' - weight: 50 - time: 100000 - difficulty: 1-2 - custom-model-data: 692 - - sturgeon_fish_silver_star: - material: paper - display: - name: 'Sturgeon Fish Silver Star' - weight: 50 - group: silver - time: 100000 - difficulty: 1-2 - custom-model-data: 693 - - sturgeon_fish_golden_star: - material: paper - display: - name: 'Sturgeon Fish Golden Star' - weight: 50 - time: 100000 - group: gold - difficulty: 1-2 - custom-model-data: 694 - -mobs: - skeletalknight: - mythicmobsID: SkeletalKnight - level: 0 - name: 'skeletalknight' - group: creature - # This decides how mythicmobs appears - vector: - horizontal: 1.1 - vertical: 1.2 - action: - message: '{loot} is coming!' - command: - - 'say 玩家{player}在{world},{x},{y},{z}被{loot}追杀!' - exp: 10 - weight: 10 - difficulty: 1-6 - time: 5000 - requirements: - weather: - - thunder - world: - - world - - piranha: - mythicmobsID: piranha - name: 'Piranha' - weight: 50 - time: 1000000 - difficulty: 1-1 - action: - command: 'say {player} Caught a piranha!' - vector: - #Vertical displacement multiplier - vertical: 2 \ No newline at end of file diff --git a/src/main/resources/loots/default.yml b/src/main/resources/loots/default.yml new file mode 100644 index 00000000..cf390f63 --- /dev/null +++ b/src/main/resources/loots/default.yml @@ -0,0 +1,462 @@ +rubbish: + material: paper + show-in-fishfinder: false + display: + name: 'Garbage' + weight: 50 + time: 100000 + difficulty: 1-1 + custom-model-data: 640 + +Pufferfish: + material: pufferfish + display: + name: 'Pufferfish' + weight: 50 + time: 100000 + difficulty: 1-5 + requirements: + weather: + - clear + +cod: + material: cod + display: + name: 'Cod' + weight: 50 + time: 100000 + difficulty: 1-5 + requirements: + weather: + - clear + +salmon: + material: salmon + display: + name: 'Salmon' + weight: 50 + time: 100000 + difficulty: 1-5 + requirements: + weather: + - clear + +tropical_fish: + material: tropical_fish + display: + name: 'Tropical Fish' + weight: 50 + time: 100000 + difficulty: 1-5 + requirements: + weather: + - clear + biome: + - minecraft:jungle + - minecraft:bamboo_jungle + +tuna: + material: paper + display: + name: 'Tuna Fish' + weight: 50 + time: 100000 + difficulty: 1-1 + custom-model-data: 641 + +tuna_fish_silver_star: + material: paper + display: + name: 'Tuna Fish Silver Star' + weight: 50 + time: 100000 + difficulty: 1-1 + group: silver + custom-model-data: 666 + +tuna_fish_golden_star: + material: paper + display: + name: 'Tuna Fish Golden Star' + weight: 50 + time: 100000 + difficulty: 1-1 + group: gold + custom-model-data: 667 + +pike: + material: paper + display: + name: 'Pike Fish' + weight: 50 + time: 100000 + difficulty: 1-2 + custom-model-data: 642 + +pike_fish_silver_star: + material: paper + display: + name: 'Pike Fish Silver Star' + weight: 50 + time: 100000 + difficulty: 1-2 + group: silver + custom-model-data: 664 + +pike_fish_golden_star: + material: paper + display: + name: 'Pike Fish Golden Star' + weight: 50 + time: 100000 + difficulty: 1-2 + group: gold + custom-model-data: 665 + +golden: + material: paper + display: + name: 'Golden Fish' + weight: 50 + time: 100000 + difficulty: 1-2 + custom-model-data: 643 + +golden_fish_silver_star: + material: paper + display: + name: 'Golden Fish Silver Star' + weight: 50 + time: 100000 + difficulty: 1-2 + group: silver + custom-model-data: 658 + +golden_fish_golden_star: + material: paper + display: + name: 'Golden Fish Golden Star' + weight: 50 + time: 100000 + group: gold + difficulty: 1-2 + custom-model-data: 659 + +perch_fish: + material: paper + display: + name: 'Perch Fish' + weight: 50 + time: 100000 + difficulty: 1-2 + custom-model-data: 644 + +perch_fish_silver_star: + material: paper + display: + name: 'Perch Fish Silver Star' + weight: 50 + time: 100000 + group: silver + difficulty: 1-2 + custom-model-data: 660 + +perch_fish_golden_star: + material: paper + display: + name: 'Perch Fish Golden Star' + weight: 50 + group: gold + time: 100000 + difficulty: 1-2 + custom-model-data: 661 + +mullet_fish: + material: paper + display: + name: 'Mullet Fish' + weight: 50 + time: 100000 + difficulty: 1-2 + custom-model-data: 645 + +mullet_fish_silver_star: + material: paper + display: + name: 'Mullet Fish Silver Star' + weight: 50 + group: silver + time: 100000 + difficulty: 1-2 + custom-model-data: 662 + +mullet_fish_golden_star: + material: paper + display: + name: 'Mullet Fish Golden Star' + weight: 50 + time: 100000 + group: gold + difficulty: 1-2 + custom-model-data: 663 + +sardine_fish: + material: paper + display: + name: 'Sardine Fish' + weight: 50 + time: 100000 + difficulty: 1-2 + custom-model-data: 668 + +sardine_fish_silver_star: + material: paper + display: + name: 'Sardine Fish Silver Star' + weight: 50 + time: 100000 + group: silver + difficulty: 1-2 + custom-model-data: 669 + +sardine_fish_golden_star: + material: paper + display: + name: 'Sardine Fish Golden Star' + weight: 50 + time: 100000 + group: gold + difficulty: 1-2 + custom-model-data: 670 + +carp_fish: + material: paper + display: + name: 'Carp Fish' + weight: 50 + time: 100000 + difficulty: 1-2 + custom-model-data: 671 + +carp_fish_silver_star: + material: paper + display: + name: 'Carp Fish Silver Star' + weight: 50 + time: 100000 + group: silver + difficulty: 1-2 + custom-model-data: 672 + +carp_fish_golden_star: + material: paper + display: + name: 'Carp Fish Golden Star' + weight: 50 + time: 100000 + group: gold + difficulty: 1-2 + custom-model-data: 673 + +cat_fish: + material: paper + display: + name: 'Cat Fish' + weight: 50 + time: 100000 + difficulty: 1-2 + custom-model-data: 674 + +cat_fish_silver_star: + material: paper + display: + name: 'Cat Fish Silver Star' + weight: 50 + group: silver + time: 100000 + difficulty: 1-2 + custom-model-data: 675 + +cat_fish_golden_star: + material: paper + display: + name: 'Cat Fish Golden Star' + weight: 50 + time: 100000 + group: gold + difficulty: 1-2 + custom-model-data: 676 + +octopus_fish: + material: paper + display: + name: 'Octopus Fish' + weight: 50 + time: 100000 + difficulty: 1-2 + custom-model-data: 677 + +octopus_fish_silver_star: + material: paper + display: + name: 'Octopus Fish Silver Star' + weight: 50 + group: silver + time: 100000 + difficulty: 1-2 + custom-model-data: 678 + +octopus_fish_golden_star: + material: paper + display: + name: 'Octopus Fish Golden Star' + weight: 50 + time: 100000 + group: gold + difficulty: 1-2 + custom-model-data: 679 + +sunfish_fish: + material: paper + display: + name: 'Sunfish Fish' + weight: 50 + time: 100000 + difficulty: 1-2 + custom-model-data: 680 + +sunfish_fish_silver_star: + material: paper + display: + name: 'Sunfish Fish Silver Star' + weight: 50 + group: silver + time: 100000 + difficulty: 1-2 + custom-model-data: 681 + +sunfish_fish_golden_star: + material: paper + display: + name: 'Sunfish Fish Golden Star' + weight: 50 + time: 100000 + group: gold + difficulty: 1-2 + custom-model-data: 682 + +red_spnapper_fish: + material: paper + display: + name: 'Red Snapper Fish' + weight: 50 + time: 100000 + difficulty: 1-2 + custom-model-data: 683 + +red_spnapper_fish_silver_star: + material: paper + display: + name: 'Red Snapper Fish Silver Star' + weight: 50 + time: 100000 + group: silver + difficulty: 1-2 + custom-model-data: 684 + +red_spnapper_fish_golden_star: + material: paper + display: + name: 'Red Snapper Golden Star' + weight: 50 + time: 100000 + group: gold + difficulty: 1-2 + custom-model-data: 685 + +salmon_void_fish: + material: paper + display: + name: 'Salmon Void Fish' + weight: 50 + time: 100000 + difficulty: 1-2 + custom-model-data: 686 + +salmon_void_fish_silver_star: + material: paper + display: + name: 'Salmon Void Fish Silver Star' + weight: 50 + time: 100000 + group: silver + difficulty: 1-2 + custom-model-data: 687 + +salmon_void_fish_golden_star: + material: paper + display: + name: 'Salmon Void Fish Golden Star' + weight: 50 + time: 100000 + group: gold + difficulty: 1-2 + custom-model-data: 688 + +woodskip_fish: + material: paper + display: + name: 'Woodskip Fish' + weight: 50 + time: 100000 + difficulty: 1-2 + custom-model-data: 689 + +woodskip_fish_silver_star: + material: paper + display: + name: 'Woodskip Fish Silver Star' + weight: 50 + group: silver + time: 100000 + difficulty: 1-2 + custom-model-data: 690 + +woodskip_fish_golden_star: + material: paper + display: + name: 'Woodskip Fish Golden Star' + weight: 50 + group: gold + time: 100000 + difficulty: 1-2 + custom-model-data: 691 + +sturgeon_fish: + material: paper + display: + name: 'Sturgeon Fish' + weight: 50 + time: 100000 + difficulty: 1-2 + custom-model-data: 692 + +sturgeon_fish_silver_star: + material: paper + display: + name: 'Sturgeon Fish Silver Star' + weight: 50 + group: silver + time: 100000 + difficulty: 1-2 + custom-model-data: 693 + +sturgeon_fish_golden_star: + material: paper + display: + name: 'Sturgeon Fish Golden Star' + weight: 50 + time: 100000 + group: gold + difficulty: 1-2 + custom-model-data: 694 \ No newline at end of file diff --git a/src/main/resources/loots/example.yml b/src/main/resources/loots/example.yml new file mode 100644 index 00000000..1152fe80 --- /dev/null +++ b/src/main/resources/loots/example.yml @@ -0,0 +1,184 @@ +rainbow_fish: + + # Enable + enable: false + + # Nick is what to show in fish finder + nick: 'Example Fish' + # Should it be displayed in fish finder? + show-in-fishfinder: false + # The weight(relative chance) of getting this fish + weight: 10 + # Optional + group: normal + # The score to get in competition + score: 10 + # Specify the bar. If not specified, it will be random + layout: + - bar1 + # Difficulty + # '1' represents the pointer moves every 1 tick + # '7' represents the pointer moves 7 pixels each time + difficulty: 1-7 + # How long can a player fish on each bite(ms) + time: 5000 + + # Basic elements of an item + # You can use MiniMessage format in name & lore + # legacy color code '&' is supported but not recommended + # https://docs.adventure.kyori.net/minimessage/format.html + material: COD + display: + name: '✖Example Rainbow Fish✖' + lore: + - 'This is a rainbow fish!' + custom-model-data: 1 + + # Custom NBT tags + # If you are not sure about the NBT tag. You can use command '/customfishing export xxx' and get it in 'CustomFishing/export' folder + # (Int) (Byte) (String) (Float) (String) (Double) (Short) (Long) (UUID) (Boolean) (IntArray) (ByteArray) + nbt: + itemsadder: + namespace: '(String) momirealms' + id: '(String) rainbow_fish' + SomeNBT: + NBTS: + byte: '(Byte) 127' + float: '(Float) 3.14159' + Price: '(Double) 10' + + # Available events: success/failure/hook + # Available actions: message/command/exp/mending/skill-xp + action: + success: + message: + - 'You got a {loot} lol!' + command: + - 'say Success command example!' + # Exp directly go to player's level + exp: 10 + # Exp that would apply to mending + mending: 5 + # Fishing Skill xp (requires skill plugin hook) + #skill-xp: 100 + failure: + message: + - 'The fish escaped!' + command: + - 'say Failure command example!' + hook: + message: + - 'The fish is hooked!' + command: + - 'say Hook command example' + + # Enchantments on the item + enchantments: + minecraft:sharpness: 1 + minecraft:flame: 1 + + # Random Durability (only available on damageable items) + random-durability: false + + # Random Enchantments + # Higher level enchantment should be below the lower ones + random-enchantments: + enchantment_1: + enchant: minecraft:sharpness + chance: 0.3 + level: 1 + enchantment_2: + enchant: minecraft:sharpness + chance: 0.2 + level: 2 + enchantment_3: + enchant: minecraft:sharpness + chance: 0.1 + level: 3 + enchantment_4: + enchant: minecraft:flame + chance: 0.5 + level: 1 + enchantment_5: + enchant: minecraft:unbreaking + chance: 0.2 + level: 1 + enchantment_6: + enchant: minecraft:unbreaking + chance: 0.2 + level: 2 + + # - HIDE_ATTRIBUTES + # - HIDE_DESTROYS + # - HIDE_DYE + # - HIDE_PLACED_ON + # - HIDE_UNBREAKABLE + # - HIDE_POTION_EFFECTS + item_flags: + - HIDE_ENCHANTS + + # Optional + requirements: + + #Biome + biome: + - minecraft:plains + - minecraft:taiga + + #Y coordinate + ypos: + - 50~100 + - 150~200 + + #World weather + weather: + - rain + - clear + - thunder + + #Player permission + permission: 'customfishing.rainbowfish' + + #Specified world + world: + - world + + #Game Time Range + time: + - 0~12000 + + #Requires skill plugin + skill-level: 10 + + #Requires WorldGuard + region: + - fishingpool + + #Requires Season Plugin + season: + - Spring + - Autumn + + #Requires PlaceholderAPI + #Create complex condition as you want + # "||" means one of the conditions is true, it would be true + # "&&" means all the conditions must be true to be true + papi-condition: + '||': + condition_1: + type: '==' + papi: '%player_world%' + value: world + condition_2: + type: '==' + papi: '%player_world%' + value: Island + '&&': + condition_1: + type: '>=' + papi: '%player_health%' + value: 5 + condition_2: + type: '<' + papi: '%player_health%' + value: 15 \ No newline at end of file diff --git a/src/main/resources/messages/messages_cn.yml b/src/main/resources/messages/messages_cn.yml index c79b38e5..c1a69755 100644 --- a/src/main/resources/messages/messages_cn.yml +++ b/src/main/resources/messages/messages_cn.yml @@ -24,5 +24,7 @@ messages: force-competition-failure: '此比赛不存在!' force-competition-end: '已强制结束当前正在进行的比赛!' force-competition-cancel: '已强制取消当前正在进行的比赛!' + hook-other-entity: '你的鱼钩被其他生物钩走了!' + no-rod: '你必须使用特殊鱼竿才能获得战利品!' no-player: '无' no-score: '无' \ No newline at end of file diff --git a/src/main/resources/messages/messages_en.yml b/src/main/resources/messages/messages_en.yml index d0810fe8..3f1c0b92 100644 --- a/src/main/resources/messages/messages_en.yml +++ b/src/main/resources/messages/messages_en.yml @@ -2,27 +2,29 @@ #https://docs.adventure.kyori.net/minimessage/format.html messages: prefix: '[CustomFishing] ' - reload: 'Reload successfully.' - no-perm: 'You dont have permission!' - not-online: 'Players are not online!' - not-exist: 'This item does not exist!' - escape: 'Its been too long since I pulled the hook and the fish ran away!' - give-item: 'Successfully giving players {Player} {Amount}x {Item}.' + reload: 'Reloaded' + no-perm: 'You don''t have permission!' + not-online: 'That player is not online!' + not-exist: 'That item does not exist!' + escape: 'It has been too long since I pulled the hook and the fish ran away!' + give-item: 'Successfully given players {Player} {Amount}x {Item}.' get-item: 'Successfully obtained {Amount}x {Item}.' - no-console: 'This command cannot be executed by the console!' + no-console: 'This command cannot be executed from the console!' wrong-amount: 'You cannot give a player an item with a negative quantity!' lack-args: 'Insufficient parameters.' cooldown: 'You''re using the fish finder too fast!' - possible-loots: 'Possible fishing here: ' + possible-loots: 'Possible loots here: ' split-char: ', ' - no-loot: 'There are no fish in this place!' + no-loot: 'There''s no fish in this place!' not-open-water: 'This is not open water and you will not be able to get any rewards!' competition-ongoing: 'There is currently a fishing tournament in progress! Start fishing to join the contest for a prize!' - players-not-enough: 'The number of players is not enough for the fishing tournament to be held as scheduled!' - no-rank: 'Not on the list' - force-competition-success: 'Successfully force a fishing contest!' - force-competition-failure: 'This contest does not exist!' - force-competition-end: 'Forced to end the current match in progress!' - force-competition-cancel: 'Forced cancellation of the current match in progress!' + players-not-enough: 'The number of players is not enough for the fishing contest to be held as scheduled!' + no-rank: 'No Rank' + force-competition-success: 'Forced to start a fishing contest' + force-competition-failure: 'This contest does not exist' + force-competition-end: 'Forced to end the current contest' + force-competition-cancel: 'Forced to cancel the contest' + hook-other-entity: 'The bobber is hooked on another entity!' + no-rod: 'You have to obtain a special rod to get loots!' no-player: 'No player' no-score: 'No score' \ No newline at end of file diff --git a/src/main/resources/messages/messages_es.yml b/src/main/resources/messages/messages_es.yml index f975f782..73d323fc 100644 --- a/src/main/resources/messages/messages_es.yml +++ b/src/main/resources/messages/messages_es.yml @@ -24,5 +24,7 @@ messages: force-competition-failure: '¡Este concurso no existe!' force-competition-end: '¡Obligado a terminar el partido en curso!' force-competition-cancel: '¡Cancelación forzosa del partido en curso!' + hook-other-entity: 'The bobber is hooked on another entity!' + no-rod: 'You have to obtain a special rod to get special loots!' no-player: 'Ningún jugador' no-score: 'Sin puntuación' \ No newline at end of file diff --git a/src/main/resources/mobs/example.yml b/src/main/resources/mobs/example.yml new file mode 100644 index 00000000..a459198a --- /dev/null +++ b/src/main/resources/mobs/example.yml @@ -0,0 +1,41 @@ +skeletalknight: + + enable: false + + # MythicMobsID + mythicmobsID: SkeletalKnight + + # The level of the mob + level: 0 + + # Name is what to show in fish finder + name: skeletalknight + + # This decides how mythic mob spawn + vector: + horizontal: 1.1 + vertical: 1.2 + + group: creature + weight: 10 + difficulty: 1-6 + time: 5000 + + requirements: + weather: + - thunder + world: + - world + +piranha: + mythicmobsID: piranha + name: 'Piranha' + weight: 50 + time: 1000000 + difficulty: 1-1 + action: + success: + command: + - 'say {player} Caught a piranha!' + vector: + vertical: 2 \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 9fe20932..a39668fc 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: CustomFishing version: '${version}' main: net.momirealms.customfishing.CustomFishing -api-version: 1.16 +api-version: 1.17 authors: [ XiaoMoMi ] softdepend: - MythicMobs @@ -11,8 +11,12 @@ softdepend: - AureliumSkills - MMOCore - EcoSkills + - EcoEnchants - RealisticSeasons - CustomCrops + - ItemsAdder + - Oraxen + - MMOItems commands: customfishing: usage: /customfishing diff --git a/src/main/resources/redis.yml b/src/main/resources/redis.yml index 619483e2..93dcd923 100644 --- a/src/main/resources/redis.yml +++ b/src/main/resources/redis.yml @@ -1,3 +1,5 @@ +# Redis server +# Sync competition scores between servers without lag! redis: enable: false host: localhost diff --git a/src/main/resources/rods.yml b/src/main/resources/rods.yml deleted file mode 100644 index 07eb44e3..00000000 --- a/src/main/resources/rods.yml +++ /dev/null @@ -1,43 +0,0 @@ -rods: - wooden_rod: - display: - name: 'Ordinary wooden fishing rod' - lore: - - 'Its just an ordinary fishing rod' - # The same to baits.yml - modifier: - difficulty: 1 - nature_fishing_cane: - display: - name: 'Nature Fishing Cane' - custom-model-data: 2 - modifier: - weight-PM: - silver: 5 - - silver_fishing_rod: - display: - name: 'Silver Fishing Rod' - custom-model-data: 3 - modifier: - weight-PM: - silver: 20 - gold: -10 - - golden_fishing_rod: - display: - name: 'Golden Fishing Rod' - custom-model-data: 4 - modifier: - weight-PM: - silver: -20 - gold: 20 - - star_fishing_rod: - display: - name: 'Star Fishing Rod' - custom-model-data: 5 - modifier: - weight-PM: - silver: 20 - gold: 10 \ No newline at end of file diff --git a/src/main/resources/rods/default.yml b/src/main/resources/rods/default.yml new file mode 100644 index 00000000..e2f9ee15 --- /dev/null +++ b/src/main/resources/rods/default.yml @@ -0,0 +1,42 @@ +wooden_rod: + display: + name: 'Ordinary wooden fishing rod' + lore: + - 'Its just an ordinary fishing rod' + # The same to baits.yml + modifier: + difficulty: 1 +nature_fishing_cane: + display: + name: 'Nature Fishing Cane' + custom-model-data: 2 + modifier: + weight-PM: + silver: 5 + +silver_fishing_rod: + display: + name: 'Silver Fishing Rod' + custom-model-data: 3 + modifier: + weight-PM: + silver: 20 + gold: -10 + +golden_fishing_rod: + display: + name: 'Golden Fishing Rod' + custom-model-data: 4 + modifier: + weight-PM: + silver: -20 + gold: 20 + +star_fishing_rod: + display: + name: 'Star Fishing Rod' + custom-model-data: 5 + modifier: + weight-PM: + silver: 20 + gold: 10 \ No newline at end of file diff --git a/src/main/resources/titles.yml b/src/main/resources/titles.yml index 02f5697e..8ea02a49 100644 --- a/src/main/resources/titles.yml +++ b/src/main/resources/titles.yml @@ -5,10 +5,10 @@ titles: title: - 'Real food!' - 'Failure!' + - 'Try next time!' subtitle: - - 'The fish have escaped' - - 'Lets try again next time' - #tick + - 'The fish escaped' + - 'Pay more attention on it!' fade: in: 10 stay: 30 @@ -16,7 +16,8 @@ titles: success: title: - 'Success!' - - 'Beautiful!' + - 'GG!' + - 'Good Job!' subtitle: - 'You have captured a {loot}' - 'Hi Harm Hi {loot} Here we go!' diff --git a/src/main/resources/utils.yml b/src/main/resources/utils.yml deleted file mode 100644 index 077ecebf..00000000 --- a/src/main/resources/utils.yml +++ /dev/null @@ -1,9 +0,0 @@ -utils: - fishfinder: - material: PAPER - display: - name: 'Fish Finder' - lore: - - 'Right click to see what fish can be caught in this place!' - nbt: - - CustomModelData: '(Int) 647' \ No newline at end of file diff --git a/src/main/resources/utils/fishfinder.yml b/src/main/resources/utils/fishfinder.yml new file mode 100644 index 00000000..fffc9c8d --- /dev/null +++ b/src/main/resources/utils/fishfinder.yml @@ -0,0 +1,7 @@ +fishfinder: + material: PAPER + display: + name: 'Fish Finder' + lore: + - 'Right click to see what fish can be caught in this place!' + custom-model-data: 647 \ No newline at end of file