From c5973e98751ab99afb6cb021b9d2b6dc3ead18cb Mon Sep 17 00:00:00 2001 From: XiaoMoMi <972454774@qq.com> Date: Sat, 17 Jun 2023 00:29:04 +0800 Subject: [PATCH] 1.3.1.5 --- build.gradle | 13 ++-- libs/BiomeAPI.jar | Bin 9255 -> 10488 bytes .../commands/subcmd/DebugCommand.java | 45 ++++++++++- .../manager/BarMechanicManager.java | 6 +- .../customfishing/manager/EffectManager.java | 2 +- .../customfishing/manager/FishingManager.java | 73 ++++++++++++++++++ .../customfishing/manager/LootManager.java | 16 ++-- src/main/resources/baits/default.yml | 16 ++-- 8 files changed, 145 insertions(+), 26 deletions(-) diff --git a/build.gradle b/build.gradle index abc7df44..5b5d6760 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'net.momirealms' -version = '1.3.1.3' +version = '1.3.1.5' repositories { maven {name = "aliyun-repo"; url = "https://maven.aliyun.com/repository/public/"} @@ -17,6 +17,7 @@ repositories { maven {name = "jitpack-repo"; url = "https://jitpack.io"} maven {name = "Lumine-repo"; url = "https://mvn.lumine.io/repository/maven-public"} maven {name = 'glaremasters-repo'; url = 'https://repo.glaremasters.me/repository/towny/'} + maven {name = 'mmo-repo'; url = 'https://nexus.phoenixdevt.fr/repository/maven-public/'} mavenCentral() } @@ -36,14 +37,16 @@ dependencies { compileOnly('org.mariadb.jdbc:mariadb-java-client:3.1.4') compileOnly('com.google.code.gson:gson:2.10.1') compileOnly('com.willfp:EcoEnchants:10.13.0') + compileOnly('net.Indyuce:MMOItems-API:6.9.2-SNAPSHOT') + //repo is private access //compileOnly('com.willfp:EcoSkills:3.0.0-b2') compileOnly('com.willfp:eco:6.60.0') compileOnly('com.willfp:EcoJobs:3.13.0') - implementation('net.kyori:adventure-api:4.13.1') + implementation('net.kyori:adventure-api:4.14.0') implementation('net.kyori:adventure-platform-bukkit:4.3.0') - implementation('net.kyori:adventure-text-minimessage:4.13.1') - implementation('net.kyori:adventure-text-serializer-legacy:4.13.1') - implementation('de.tr7zw:item-nbt-api:2.11.2') + implementation('net.kyori:adventure-text-minimessage:4.14.0') + implementation('net.kyori:adventure-text-serializer-legacy:4.14.0') + implementation('de.tr7zw:item-nbt-api:2.11.3') implementation('org.bstats:bstats-bukkit:3.0.1') } diff --git a/libs/BiomeAPI.jar b/libs/BiomeAPI.jar index a0a1f7496ef0f07480233b93f8c945d97860be17..00c06717792bd9929cb8177b8d3784f4a8d57471 100644 GIT binary patch delta 2601 zcmZuz2{_bS8=o=Ou@^FpWyV(ab!3UTxYjAlFk>%rF(P|Nn2c$XT+!bauI1XwMHI3x zxz|{}&`o3(vQv>#Bs6z)zx#dne$RK#^PKnm-}m>P_x#`IIlt#uZS&bl&=CXSgn~f4 zyrA0!BUyqS&znPZ6Er6RcihuV-M>LXxd;E&t|uOtZchugK`1H+a5y2K%MW89H&VPnH;v7_O;`?sEsKdbHYE9Ii}UN7>7 z25z}m`*_|B(JqSq;7+GSJSqRMOnX~#t@w27`b}2J)rtO34w3{*xSuV(GS1XLrzpYR zkoR-q`vj!4{YGe*apfj3bPs)w-`GjTpe@>k`{Hqfn?hg3HmAa5;c zvN#gn9&Xnk1PKhsmmZAwTjz)p0vV##R0MVV%amMVaMZ!??@Bkrb0vfM+p_9IJzLMd zmY1Y8$&Tj|X6dY?#bY$J^#@JCO+C+MUb3z%YSJ1@4IKx@scsR!ZTKPy-SsDDYzlY_ z!cL~4vM8iwlx1QlHf&tVd7?b4J!QEt%_tfhJYM9u7#c-wN8_}UQiqoU-uS~W6#97j zU>ceJSJ9gyL|{aCb99Q(b3;Mdz5uW1P=I7Q>e&~_KUF=hpq?430?o{|QB4~K@V1Y| ze?l;kU6?zCBTt(a*IFmm$obIkjK`*al|6Htx?c}l6$^Z(m|&n-Ki|}vp?e{tG8q z8x@s-7|Z?6BtkQM{{y+4}kw29372oNazj8QvZc%~fxtNGN*f=h!{nbe*a=+zsJ+frt}^yg&KxxWVLeii3ykPvkE>B>Z91Ok2#D z1Et6Sqih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e0`#ai00_{3|xtrPWLFMw=4(6q(->C5a(HynT*z`R|>Z8kY0|b zp}UsI6nt)P@UChJ?5DemJ#7`Lg@NAeD9TZ~)BVQw9FF8^P6hLd z#{LhZb8_9?VZQOqHZ-JttjCF18v$@ljLyr1V9;qzDZYTo*ap)gM?Tt)bfG(;LA2P|x|Lnr9JQ_r#Y7}+k151Kv8 z@tYVv*)VA{(&qMzq4kk>Lql16H1k~4&34(TqWj`1f{151nR*YmOPM8oQ;+=f&CP0q zEWRL`_lEKyuOzE9t0X+pW$y+io3-GziN=n!$qCLECEYhDLKRisnlw9A6mYBE%%CWh zoQ$L4PG{>KVL!15g%VPeQhby7!!-UOZ1URfMt#tBrdL=HAjGLfaO?}G${8tMstMZK z$-$9Y#knNaLGH=uDT3Teh6gs5?PcATf%#l)ZGl^n%$S{i2=|FvWe&^D4DFa<)4xbMf`y_$fnZ& z2M}bfevI^^2T>!i5x+Zl-ww>1XrdqzURlP@QVf9yzf(^1_P9C$;VlYjLSv|H5RHNr z^$O)v2na_sEFXZRuxR{N74W?Z4znI!JjjDgC<+Ky$*mmQJ$N)s#3thW@hv$^2A1g% zcMp~Xf0Q+5EU2r7Ng0g+0R10bi4FoBoJfP@G!#UGfT$V-M4#f8#34#RYz?evE>H?A b_Y)uw5?#U0617cKC=IVDBmiWqh;IJ^++=8z diff --git a/src/main/java/net/momirealms/customfishing/commands/subcmd/DebugCommand.java b/src/main/java/net/momirealms/customfishing/commands/subcmd/DebugCommand.java index 56d97641..7a9791a3 100644 --- a/src/main/java/net/momirealms/customfishing/commands/subcmd/DebugCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/subcmd/DebugCommand.java @@ -2,11 +2,18 @@ package net.momirealms.customfishing.commands.subcmd; import net.momirealms.biomeapi.BiomeAPI; import net.momirealms.customfishing.CustomFishing; +import net.momirealms.customfishing.api.CustomFishingAPI; import net.momirealms.customfishing.commands.AbstractSubCommand; +import net.momirealms.customfishing.fishing.Effect; +import net.momirealms.customfishing.fishing.loot.Loot; import net.momirealms.customfishing.integration.SeasonInterface; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; import java.util.List; public class DebugCommand extends AbstractSubCommand { @@ -36,6 +43,13 @@ public class DebugCommand extends AbstractSubCommand { if (seasonInterface == null) return true; sender.sendMessage(seasonInterface.getSeason(player.getLocation().getWorld())); } + case "loot-chance" -> { + Effect initial = CustomFishing.getInstance().getFishingManager().getInitialEffect(player); + List lootProbability = getLootProbability(initial, CustomFishingAPI.getLootsAt(player.getLocation(), player)); + for (String msg : lootProbability) { + AdventureUtils.playerMessage(player, msg); + } + } } return true; @@ -44,8 +58,37 @@ public class DebugCommand extends AbstractSubCommand { @Override public List onTabComplete(CommandSender sender, List args) { if (args.size() == 1) { - return filterStartingWith(List.of("biome", "time", "world", "season"), args.get(0)); + return filterStartingWith(List.of("biome", "time", "world", "season", "loot-chance"), args.get(0)); } return null; } + + public ArrayList getLootProbability(Effect initialEffect, List possibleLoots) { + List availableLoots = new ArrayList<>(); + HashMap as = initialEffect.getWeightAS(); + HashMap md = initialEffect.getWeightMD(); + 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 (as.get(group) != null){ + weight += as.get(group); + } + if (md.get(group) != null){ + weight *= md.get(group); + } + } + if (weight <= 0) continue; + availableLoots.add(loot); + weights[index++] = weight; + } + ArrayList lootWithChance = new ArrayList<>(availableLoots.size()); + double total = Arrays.stream(weights).sum(); + for (int i = 0; i < index; i++){ + lootWithChance.add(availableLoots.get(i).getKey() + ": " + String.format("%.2f", weights[i]*100/total) + "%"); + } + return lootWithChance; + } } diff --git a/src/main/java/net/momirealms/customfishing/manager/BarMechanicManager.java b/src/main/java/net/momirealms/customfishing/manager/BarMechanicManager.java index 261f8b1e..eb6258fb 100644 --- a/src/main/java/net/momirealms/customfishing/manager/BarMechanicManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/BarMechanicManager.java @@ -112,12 +112,10 @@ public class BarMechanicManager extends Function { if (type == 1) { ModeOneBar modeOneBar = new ModeOneBar(section); bars.put(key, modeOneBar); - } - else if (type == 2) { + } else if (type == 2) { ModeTwoBar modeTwoBar = new ModeTwoBar(section); bars.put(key, modeTwoBar); - } - else if (type == 3) { + } else if (type == 3) { ModeThreeBar modeThreeBar = new ModeThreeBar(section); bars.put(key, modeThreeBar); } diff --git a/src/main/java/net/momirealms/customfishing/manager/EffectManager.java b/src/main/java/net/momirealms/customfishing/manager/EffectManager.java index 57d85f9f..32c6a336 100644 --- a/src/main/java/net/momirealms/customfishing/manager/EffectManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/EffectManager.java @@ -152,7 +152,7 @@ public class EffectManager extends Function { baitItems.put(key, item); Effect effect = ConfigUtils.getEffect(baitSection.getConfigurationSection("effect")); if (baitSection.contains("requirements")) { - effect.setRequirements(ConfigUtils.getRequirements(baitSection.getConfigurationSection("requirements"))); + effect.setRequirements(ConfigUtils.getRequirementsWithMsg(baitSection.getConfigurationSection("requirements"))); } baitEffects.put(key, effect); } diff --git a/src/main/java/net/momirealms/customfishing/manager/FishingManager.java b/src/main/java/net/momirealms/customfishing/manager/FishingManager.java index 63c15bb7..9a54c1c5 100644 --- a/src/main/java/net/momirealms/customfishing/manager/FishingManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/FishingManager.java @@ -1041,4 +1041,77 @@ public class FishingManager extends Function { for (Action action : droppedItem.getConsumeActions()) action.doOn(player, null); } + + public Effect getInitialEffect(Player player) { + boolean noBait = true; + boolean rodOnMainHand = false; + + Effect initialEffect = new Effect(); + initialEffect.setWeightMD(new HashMap<>(8)); + initialEffect.setWeightAS(new HashMap<>(8)); + + final PlayerInventory inventory = player.getInventory(); + final ItemStack mainHandItem = inventory.getItemInMainHand(); + final ItemStack offHandItem = inventory.getItemInOffHand(); + + if (mainHandItem.getType() == Material.FISHING_ROD) { + rodOnMainHand = true; + } + String rod_id = Optional.ofNullable(rodOnMainHand ? CustomFishingAPI.getRodID(mainHandItem) : CustomFishingAPI.getRodID(offHandItem)).orElse("vanilla"); + final FishingCondition fishingCondition = new FishingCondition(player.getLocation(), player, rod_id, null); + + String bait_id = Optional.ofNullable(rodOnMainHand ? CustomFishingAPI.getBaitID(offHandItem) : CustomFishingAPI.getBaitID(mainHandItem)).orElse(""); + Effect baitEffect = plugin.getEffectManager().getBaitEffect(bait_id); + if (baitEffect != null && initialEffect.canAddEffect(baitEffect, fishingCondition)) { + initialEffect.addEffect(baitEffect); + noBait = false; + } + + for (ActivatedTotem activatedTotem : activeTotemMap.values()) { + if (activatedTotem.getNearbyPlayerSet().contains(player)) { + initialEffect.addEffect(activatedTotem.getTotem().getEffect()); + break; + } + } + + if (ConfigManager.enableFishingBag) { + Inventory fishingBag = plugin.getBagDataManager().getPlayerBagData(player.getUniqueId()); + HashSet uniqueUtils = new HashSet<>(4); + if (fishingBag != null) { + for (int i = 0; i < fishingBag.getSize(); i++) { + ItemStack itemStack = fishingBag.getItem(i); + if (itemStack == null || itemStack.getType() == Material.AIR) continue; + NBTCompound cfCompound = new NBTItem(itemStack).getCompound("CustomFishing"); + if (cfCompound == null) continue; + String type = cfCompound.getString("type"); String id = cfCompound.getString("id"); + if (noBait && type.equals("bait")) { + Effect effect = plugin.getEffectManager().getBaitEffect(id); + if (effect != null && itemStack.getAmount() > 0 && initialEffect.canAddEffect(effect, fishingCondition)) { + initialEffect.addEffect(effect); + noBait = false; + bait_id = id; + } + } else if (type.equals("util")) { + Effect utilEffect = plugin.getEffectManager().getUtilEffect(id); + if (utilEffect != null && !uniqueUtils.contains(id)) { + initialEffect.addEffect(utilEffect); + uniqueUtils.add(id); + } + } + } + } + } + + Effect rod_effect = plugin.getEffectManager().getRodEffect(rod_id); + if (rod_effect != null) { + if (initialEffect.canAddEffect(rod_effect, new FishingCondition(player.getLocation(), player, rod_id, bait_id))) { + initialEffect.addEffect(rod_effect); + } else { + return null; + } + initialEffect.setSpecialRodID(rod_id); + } + this.addEnchantEffect(initialEffect, rodOnMainHand ? mainHandItem : offHandItem, fishingCondition); + return initialEffect; + } } \ No newline at end of file diff --git a/src/main/java/net/momirealms/customfishing/manager/LootManager.java b/src/main/java/net/momirealms/customfishing/manager/LootManager.java index 81f719e5..f26b197a 100644 --- a/src/main/java/net/momirealms/customfishing/manager/LootManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/LootManager.java @@ -118,17 +118,15 @@ public class LootManager extends Function { for (File file : files) { if (!file.getName().endsWith(".yml")) continue; YamlConfiguration config = YamlConfiguration.loadConfiguration(file); - outer: - for (String key : config.getKeys(false)) { - List fishIDs = config.getStringList(key); - for (String id : fishIDs) { - if (!waterLoots.containsKey(id) && !lavaLoots.containsKey(id)) { - AdventureUtils.consoleMessage("[CustomFishing] Fish ID " + id + " doesn't exist in category " + key); - continue outer; - } + for (String key : config.getKeys(false)) { + List fishIDs = config.getStringList(key); + for (String id : fishIDs) { + if (!waterLoots.containsKey(id) && !lavaLoots.containsKey(id)) { + AdventureUtils.consoleMessage("[CustomFishing] Loot ID " + id + " doesn't exist in category " + key); } - category.put(key, fishIDs); } + category.put(key, fishIDs); + } } } diff --git a/src/main/resources/baits/default.yml b/src/main/resources/baits/default.yml index 1e4cb30b..f3d65af2 100644 --- a/src/main/resources/baits/default.yml +++ b/src/main/resources/baits/default.yml @@ -33,9 +33,13 @@ magnet_bait: gold: 1.15 # https://mo-mi.gitbook.io/xiaomomi-plugins/plugin-wiki/customfishing/requirements requirements: - permission: magnet_bait.use - rod: - - nature_fishing_cane - - silver_fishing_rod - - golden_fishing_rod - - star_fishing_rod + requirement_1: + type: permission + value: magnet_bait.use + requirement_2: + type: rod + value: + - nature_fishing_cane + - silver_fishing_rod + - golden_fishing_rod + - star_fishing_rod \ No newline at end of file