diff --git a/src/main/java/net/momirealms/customfishing/ConfigReader.java b/src/main/java/net/momirealms/customfishing/ConfigReader.java index f4851d44..fc69fbaf 100644 --- a/src/main/java/net/momirealms/customfishing/ConfigReader.java +++ b/src/main/java/net/momirealms/customfishing/ConfigReader.java @@ -97,12 +97,15 @@ public class ConfigReader{ public static boolean doubleRealIn; public static boolean vanillaLoot; public static boolean showBar; + public static boolean mcMMOLoot; public static int fishFinderCoolDown; public static double timeMultiply; public static double vanillaRatio; + public static double mcMMOLootChance; public static SkillXP skillXP; public static String version; public static String lang; + public static String priority; public static SeasonInterface season; public static void loadConfig() { @@ -178,8 +181,14 @@ public class ConfigReader{ } doubleRealIn = config.getBoolean("config.double-reel-in", true); - vanillaLoot = config.getBoolean("config.vanilla-loot.enable", true); - showBar = config.getBoolean("config.vanilla-loot.bar", true); + + mcMMOLoot = config.getBoolean("config.other-loot.mcMMO", false); + mcMMOLootChance = config.getDouble("config.other-loot.mcMMO-chance", 0.5); + + vanillaLoot = config.getBoolean("config.other-loot.vanilla", true); + showBar = config.getBoolean("config.other-loot.bar", true); + vanillaRatio = config.getDouble("config.other-loot.vanilla-ratio"); + convertMMOItems = config.getBoolean("config.convert-MMOITEMS", false); needOpenWater = config.getBoolean("config.need-open-water", false); needSpecialRod = config.getBoolean("config.need-special-rod", false); @@ -187,9 +196,9 @@ public class ConfigReader{ preventPick = config.getBoolean("config.prevent-other-players-pick-up-loot", false); version = config.getString("config-version"); + priority = config.getString("config.event-priority"); 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); } @@ -734,7 +743,7 @@ public class ConfigReader{ 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))); + mq.put(group, Double.parseDouble(String.valueOf(value))-1); }); bonus.setWeightMQ(mq); } @@ -820,7 +829,7 @@ public class ConfigReader{ 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))); + mq.put(group, Double.parseDouble(String.valueOf(value))-1); }); bonus.setWeightMQ(mq); } @@ -947,7 +956,7 @@ public class ConfigReader{ case "weight-MQ" -> { HashMap mq = new HashMap<>(); config.getConfigurationSection(key + "." + level + ".weight-MQ").getValues(false).forEach((group, value) -> { - mq.put(group, Double.valueOf(String.valueOf(value))); + mq.put(group, Double.parseDouble(String.valueOf(value))-1); }); bonus.setWeightMQ(mq); } diff --git a/src/main/java/net/momirealms/customfishing/CustomFishing.java b/src/main/java/net/momirealms/customfishing/CustomFishing.java index be2c12ac..d4d953d1 100644 --- a/src/main/java/net/momirealms/customfishing/CustomFishing.java +++ b/src/main/java/net/momirealms/customfishing/CustomFishing.java @@ -24,11 +24,9 @@ import net.momirealms.customfishing.command.TabComplete; import net.momirealms.customfishing.competition.CompetitionSchedule; import net.momirealms.customfishing.competition.bossbar.BossBarManager; import net.momirealms.customfishing.helper.LibraryLoader; +import net.momirealms.customfishing.hook.McMMOTreasure; import net.momirealms.customfishing.hook.Placeholders; -import net.momirealms.customfishing.listener.MMOItemsConverter; -import net.momirealms.customfishing.listener.PapiUnregister; -import net.momirealms.customfishing.listener.PickUpListener; -import net.momirealms.customfishing.listener.FishListener; +import net.momirealms.customfishing.listener.*; import net.momirealms.customfishing.utils.AdventureUtil; import net.momirealms.customfishing.utils.ConfigUtil; import org.bukkit.Bukkit; @@ -84,7 +82,7 @@ public final class CustomFishing extends JavaPlugin { }); } ConfigReader.tryEnableJedis(); - if (!Objects.equals(ConfigReader.Config.version, "5")){ + if (!Objects.equals(ConfigReader.Config.version, "6")){ ConfigUtil.update(); } if (ConfigReader.Config.preventPick){ diff --git a/src/main/java/net/momirealms/customfishing/hook/McMMOTreasure.java b/src/main/java/net/momirealms/customfishing/hook/McMMOTreasure.java new file mode 100644 index 00000000..089aa2fa --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/hook/McMMOTreasure.java @@ -0,0 +1,161 @@ +package net.momirealms.customfishing.hook; + +import com.gmail.nossr50.config.treasure.FishingTreasureConfig; +import com.gmail.nossr50.datatypes.skills.SubSkillType; +import com.gmail.nossr50.datatypes.treasure.EnchantmentTreasure; +import com.gmail.nossr50.datatypes.treasure.FishingTreasure; +import com.gmail.nossr50.datatypes.treasure.FishingTreasureBook; +import com.gmail.nossr50.datatypes.treasure.Rarity; +import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.skills.fishing.FishingManager; +import com.gmail.nossr50.util.ItemUtils; +import com.gmail.nossr50.util.Misc; +import com.gmail.nossr50.util.Permissions; +import com.gmail.nossr50.util.player.UserManager; +import com.gmail.nossr50.util.skills.RankUtils; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.*; + +public class McMMOTreasure { + + /* + these codes are partly from mcMMO, because of the cancelled event limitation + Plugin has to get the loot in a raw way + */ + public static ItemStack getTreasure(Player player){ + FishingManager fishingManager = UserManager.getPlayer(player).getFishingManager(); + FishingTreasure treasure = getFishingTreasure(player, fishingManager.getLootTier()); + ItemStack treasureDrop; + if (treasure != null) { + if(treasure instanceof FishingTreasureBook) { + treasureDrop = ItemUtils.createEnchantBook((FishingTreasureBook) treasure); + } else { + treasureDrop = treasure.getDrop().clone(); + } + Map enchants = new HashMap<>(); + if(treasure instanceof FishingTreasureBook) { + if(treasureDrop.getItemMeta() != null) { + enchants = new HashMap<>(treasureDrop.getItemMeta().getEnchants()); + } + } else { + if (isMagicHunterEnabled(player) && ItemUtils.isEnchantable(treasureDrop)) { + enchants = processMagicHunter(treasureDrop, fishingManager.getLootTier()); + } + } + if (!enchants.isEmpty()) { + treasureDrop.addUnsafeEnchantments(enchants); + } + return treasureDrop; + } + return null; + } + + public static boolean isMagicHunterEnabled(Player player) { + return RankUtils.hasUnlockedSubskill(player, SubSkillType.FISHING_MAGIC_HUNTER) + && RankUtils.hasUnlockedSubskill(player, SubSkillType.FISHING_TREASURE_HUNTER) + && Permissions.isSubSkillEnabled(player, SubSkillType.FISHING_TREASURE_HUNTER); + } + + private static Map processMagicHunter(@NotNull ItemStack treasureDrop, int tier) { + Map enchants = new HashMap<>(); + List fishingEnchantments = null; + + double diceRoll = Misc.getRandom().nextDouble() * 100; + + for (Rarity rarity : Rarity.values()) { + + double dropRate = FishingTreasureConfig.getInstance().getEnchantmentDropRate(tier, rarity); + + if (diceRoll <= dropRate) { + + if (treasureDrop.getType() == Material.ENCHANTED_BOOK) { + diceRoll = dropRate + 1; + continue; + } + + fishingEnchantments = FishingTreasureConfig.getInstance().fishingEnchantments.get(rarity); + break; + } + + diceRoll -= dropRate; + } + + if (fishingEnchantments == null) { + return enchants; + } + + Collections.shuffle(fishingEnchantments, Misc.getRandom()); + + int specificChance = 1; + + for (EnchantmentTreasure enchantmentTreasure : fishingEnchantments) { + Enchantment possibleEnchantment = enchantmentTreasure.getEnchantment(); + + if (treasureDrop.getItemMeta().hasConflictingEnchant(possibleEnchantment) || Misc.getRandom().nextInt(specificChance) != 0) { + continue; + } + + enchants.put(possibleEnchantment, enchantmentTreasure.getLevel()); + + specificChance *= 2; + } + + return enchants; + } + + private static @Nullable FishingTreasure getFishingTreasure(Player player, int tier) { + double diceRoll = Misc.getRandom().nextDouble() * 100; + int luck; + + if (player.getInventory().getItemInMainHand().getType() == Material.FISHING_ROD) { + luck = player.getInventory().getItemInMainHand().getEnchantmentLevel(Enchantment.LUCK); + } + else { + luck = player.getInventory().getItemInOffHand().getEnchantmentLevel(Enchantment.LUCK); + } + + diceRoll *= (1.0 - luck * mcMMO.p.getGeneralConfig().getFishingLureModifier() / 100); + + FishingTreasure treasure = null; + + for (Rarity rarity : Rarity.values()) { + + double dropRate = FishingTreasureConfig.getInstance().getItemDropRate(tier, rarity); + + if (diceRoll <= dropRate) { + + List fishingTreasures = FishingTreasureConfig.getInstance().fishingRewards.get(rarity); + + if (fishingTreasures.isEmpty()) { + return null; + } + + treasure = fishingTreasures.get(Misc.getRandom().nextInt(fishingTreasures.size())); + break; + } + + diceRoll -= dropRate; + } + + if (treasure == null) { + return null; + } + + ItemStack treasureDrop = treasure.getDrop().clone(); + short maxDurability = treasureDrop.getType().getMaxDurability(); + + if (maxDurability > 0) { + treasureDrop.setDurability((short) (Misc.getRandom().nextInt(maxDurability))); + } + + treasure.setDrop(treasureDrop); + + return treasure; + } +} diff --git a/src/main/java/net/momirealms/customfishing/listener/FishListener.java b/src/main/java/net/momirealms/customfishing/listener/FishListener.java index 1a37986e..efba4271 100644 --- a/src/main/java/net/momirealms/customfishing/listener/FishListener.java +++ b/src/main/java/net/momirealms/customfishing/listener/FishListener.java @@ -43,6 +43,7 @@ import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.*; import org.bukkit.entity.Item; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerFishEvent; @@ -68,51 +69,104 @@ public class FishListener implements Listener { private final HashMap vanilla = new HashMap<>(); public static ConcurrentHashMap fishingPlayers = new ConcurrentHashMap<>(); - @EventHandler + @EventHandler(priority = EventPriority.HIGHEST) + public void onFishHighest(PlayerFishEvent event){ + if (ConfigReader.Config.priority.equals("HIGHEST")){ + onFish(event); + } + } + + @EventHandler(priority = EventPriority.NORMAL) + public void onFishNormal(PlayerFishEvent event){ + if (ConfigReader.Config.priority.equals("NORMAL")){ + onFish(event); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onFishLowest(PlayerFishEvent event){ + if (ConfigReader.Config.priority.equals("LOWEST")){ + onFish(event); + } + } + public void onFish(PlayerFishEvent event){ PlayerFishEvent.State state = event.getState(); Player player = event.getPlayer(); - if (state.equals(PlayerFishEvent.State.FISHING)){ + switch (state){ - long time = System.currentTimeMillis(); - if (time - (coolDown.getOrDefault(player, time - 2000)) < 2000) { - return; - } - coolDown.put(player, time); + case FISHING ->{ - hooks.put(player, event.getHook()); + long time = System.currentTimeMillis(); + if (time - (coolDown.getOrDefault(player, time - 2000)) < 2000) { + return; + } + coolDown.put(player, time); - Bukkit.getScheduler().runTaskAsynchronously(CustomFishing.instance, ()->{ + hooks.put(player, event.getHook()); - PlayerInventory inventory = player.getInventory(); + Bukkit.getScheduler().runTaskAsynchronously(CustomFishing.instance, ()->{ - boolean noSpecialRod = true; - boolean noRod = true; - double timeModifier = 1; - double doubleLoot = 0; - double scoreModifier = 1; - int difficultyModifier = 0; + PlayerInventory inventory = player.getInventory(); - HashMap pm = new HashMap<>(); - HashMap mq = new HashMap<>(); + boolean noSpecialRod = true; + boolean noRod = true; + double timeModifier = 1; + double doubleLoot = 0; + double scoreModifier = 1; + int difficultyModifier = 0; - ItemStack mainHandItem = inventory.getItemInMainHand(); + HashMap pm = new HashMap<>(); + HashMap mq = new HashMap<>(); - Material material1 = mainHandItem.getType(); - if (material1 != Material.AIR){ - if (material1 == Material.FISHING_ROD) { - noRod = false; - Map enchantments = mainHandItem.getEnchantments(); - Object[] enchantmentsArray = enchantments.keySet().toArray(); - for (Object o : enchantmentsArray) { - Enchantment enchantment = (Enchantment) o; - HashMap enchantMap = ConfigReader.ENCHANTS.get(enchantment.getKey().toString()); - if (enchantMap != null) { - Bonus enchantBonus = enchantMap.get(enchantments.get(enchantment)); - if (enchantBonus != null) { - HashMap weightPM = enchantBonus.getWeightPM(); + ItemStack mainHandItem = inventory.getItemInMainHand(); + + Material material1 = mainHandItem.getType(); + if (material1 != Material.AIR){ + if (material1 == Material.FISHING_ROD) { + noRod = false; + Map enchantments = mainHandItem.getEnchantments(); + Object[] enchantmentsArray = enchantments.keySet().toArray(); + for (Object o : enchantmentsArray) { + Enchantment enchantment = (Enchantment) o; + HashMap enchantMap = ConfigReader.ENCHANTS.get(enchantment.getKey().toString()); + if (enchantMap != null) { + Bonus enchantBonus = enchantMap.get(enchantments.get(enchantment)); + if (enchantBonus != null) { + HashMap weightPM = enchantBonus.getWeightPM(); + if (weightPM != null){ + Object[] bonus = weightPM.keySet().toArray(); + for (Object value : bonus) { + String group = (String) value; + pm.put(group, Optional.ofNullable(pm.get(group)).orElse(0) + weightPM.get(group)); + } + } + HashMap weightMQ = enchantBonus.getWeightMQ(); + if (weightMQ != null){ + Object[] bonus = weightMQ.keySet().toArray(); + for (Object value : bonus) { + String group = (String) value; + mq.put(group, Optional.ofNullable(mq.get(group)).orElse(1d) + weightMQ.get(group)); + } + } + if (enchantBonus.getTime() != 0) timeModifier *= enchantBonus.getTime(); + if (enchantBonus.getDoubleLoot() != 0) doubleLoot += enchantBonus.getDoubleLoot(); + if (enchantBonus.getDifficulty() != 0) difficultyModifier += enchantBonus.getDifficulty(); + if (enchantBonus.getScore() != 0) scoreModifier *= enchantBonus.getScore(); + } + } + } + } + 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){ + HashMap weightPM = rod.getWeightPM(); if (weightPM != null){ Object[] bonus = weightPM.keySet().toArray(); for (Object value : bonus) { @@ -120,95 +174,26 @@ public class FishListener implements Listener { pm.put(group, Optional.ofNullable(pm.get(group)).orElse(0) + weightPM.get(group)); } } - HashMap weightMQ = enchantBonus.getWeightPM(); + HashMap weightMQ = rod.getWeightMQ(); if (weightMQ != null){ Object[] bonus = weightMQ.keySet().toArray(); for (Object value : bonus) { String group = (String) value; - mq.put(group, Optional.ofNullable(mq.get(group)).orElse(0d) + weightMQ.get(group)); + mq.put(group, Optional.ofNullable(mq.get(group)).orElse(1d) + weightMQ.get(group)); } } - if (enchantBonus.getTime() != 0) timeModifier *= enchantBonus.getTime(); - if (enchantBonus.getDoubleLoot() != 0) doubleLoot += enchantBonus.getDoubleLoot(); - if (enchantBonus.getDifficulty() != 0) difficultyModifier += enchantBonus.getDifficulty(); - if (enchantBonus.getScore() != 0) scoreModifier *= enchantBonus.getScore(); + 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(); + noSpecialRod = false; } } - } - } - 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){ - HashMap weightPM = rod.getWeightPM(); - if (weightPM != null){ - Object[] bonus = weightPM.keySet().toArray(); - for (Object value : bonus) { - String group = (String) value; - pm.put(group, Optional.ofNullable(pm.get(group)).orElse(0) + weightPM.get(group)); - } - } - HashMap weightMQ = rod.getWeightPM(); - if (weightMQ != null){ - Object[] bonus = weightMQ.keySet().toArray(); - for (Object value : bonus) { - String group = (String) value; - mq.put(group, Optional.ofNullable(mq.get(group)).orElse(0d) + weightMQ.get(group)); - } - } - 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(); - noSpecialRod = false; - } - } - else if (nbtCompound.getString("type").equals("bait")){ - String key = nbtCompound.getString("id"); - Bonus bait = ConfigReader.BAIT.get(key); - if (bait != null){ - HashMap weightPM = bait.getWeightPM(); - if (weightPM != null){ - Object[] bonus = weightPM.keySet().toArray(); - for (Object value : bonus) { - String group = (String) value; - pm.put(group, Optional.ofNullable(pm.get(group)).orElse(0) + weightPM.get(group)); - } - } - HashMap weightMQ = bait.getWeightPM(); - if (weightMQ != null){ - Object[] bonus = weightMQ.keySet().toArray(); - for (Object value : bonus) { - String group = (String) value; - mq.put(group, Optional.ofNullable(mq.get(group)).orElse(0d) + weightMQ.get(group)); - } - } - 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); - } - } - } - } - - ItemStack offHandItem = inventory.getItemInOffHand(); - Material material2 = offHandItem.getType(); - if (material2 != Material.AIR){ - if (noRod && material2 == Material.FISHING_ROD) { - Map enchantments = mainHandItem.getEnchantments(); - Object[] enchantmentsArray = enchantments.keySet().toArray(); - for (Object o : enchantmentsArray) { - Enchantment enchantment = (Enchantment) o; - HashMap enchantMap = ConfigReader.ENCHANTS.get(enchantment.getKey().toString()); - if (enchantMap != null) { - Bonus enchantBonus = enchantMap.get(enchantments.get(enchantment)); - if (enchantBonus != null) { - HashMap weightPM = enchantBonus.getWeightPM(); + else if (nbtCompound.getString("type").equals("bait")){ + String key = nbtCompound.getString("id"); + Bonus bait = ConfigReader.BAIT.get(key); + if (bait != null){ + HashMap weightPM = bait.getWeightPM(); if (weightPM != null){ Object[] bonus = weightPM.keySet().toArray(); for (Object value : bonus) { @@ -216,243 +201,370 @@ public class FishListener implements Listener { pm.put(group, Optional.ofNullable(pm.get(group)).orElse(0) + weightPM.get(group)); } } - HashMap weightMQ = enchantBonus.getWeightPM(); + HashMap weightMQ = bait.getWeightMQ(); if (weightMQ != null){ Object[] bonus = weightMQ.keySet().toArray(); for (Object value : bonus) { String group = (String) value; - mq.put(group, Optional.ofNullable(mq.get(group)).orElse(0d) + weightMQ.get(group)); + mq.put(group, Optional.ofNullable(mq.get(group)).orElse(1d) + weightMQ.get(group)); } } - if (enchantBonus.getTime() != 0) timeModifier *= enchantBonus.getTime(); - if (enchantBonus.getDoubleLoot() != 0) doubleLoot += enchantBonus.getDoubleLoot(); - if (enchantBonus.getDifficulty() != 0) difficultyModifier += enchantBonus.getDifficulty(); - if (enchantBonus.getScore() != 0) scoreModifier *= enchantBonus.getScore(); + 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); } } } } - 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){ - HashMap weightPM = bait.getWeightPM(); - if (weightPM != null){ - Object[] bonus = weightPM.keySet().toArray(); - for (Object value : bonus) { - String group = (String) value; - pm.put(group, Optional.ofNullable(pm.get(group)).orElse(0) + weightPM.get(group)); - } - } - HashMap weightMQ = bait.getWeightPM(); - if (weightMQ != null){ - Object[] bonus = weightMQ.keySet().toArray(); - for (Object value : bonus) { - String group = (String) value; - mq.put(group, Optional.ofNullable(mq.get(group)).orElse(0d) + weightMQ.get(group)); - } - } - 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 (noSpecialRod && offHandCompound.getString("type").equals("rod")){ - String key = offHandCompound.getString("id"); - Bonus rod = ConfigReader.ROD.get(key); - if (rod != null){ - HashMap weightPM = rod.getWeightPM(); - if (weightPM != null){ - Object[] bonus = weightPM.keySet().toArray(); - for (Object value : bonus) { - String group = (String) value; - pm.put(group, Optional.ofNullable(pm.get(group)).orElse(0) + weightPM.get(group)); - } - } - HashMap weightMQ = rod.getWeightPM(); - if (weightMQ != null){ - Object[] bonus = weightMQ.keySet().toArray(); - for (Object value : bonus) { - String group = (String) value; - mq.put(group, Optional.ofNullable(mq.get(group)).orElse(0d) + weightMQ.get(group)); - } - } - 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(); - noSpecialRod = false; - } - } - } - } - if (ConfigReader.Config.needSpecialRod && noSpecialRod){ - if (!ConfigReader.Config.vanillaLoot) - AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.noRod); + ItemStack offHandItem = inventory.getItemInOffHand(); + Material material2 = offHandItem.getType(); + if (material2 != Material.AIR){ + if (noRod && material2 == Material.FISHING_ROD) { + Map enchantments = mainHandItem.getEnchantments(); + Object[] enchantmentsArray = enchantments.keySet().toArray(); + for (Object o : enchantmentsArray) { + Enchantment enchantment = (Enchantment) o; + HashMap enchantMap = ConfigReader.ENCHANTS.get(enchantment.getKey().toString()); + if (enchantMap != null) { + Bonus enchantBonus = enchantMap.get(enchantments.get(enchantment)); + if (enchantBonus != null) { + HashMap weightPM = enchantBonus.getWeightPM(); + if (weightPM != null){ + Object[] bonus = weightPM.keySet().toArray(); + for (Object value : bonus) { + String group = (String) value; + pm.put(group, Optional.ofNullable(pm.get(group)).orElse(0) + weightPM.get(group)); + } + } + HashMap weightMQ = enchantBonus.getWeightMQ(); + if (weightMQ != null){ + Object[] bonus = weightMQ.keySet().toArray(); + for (Object value : bonus) { + String group = (String) value; + mq.put(group, Optional.ofNullable(mq.get(group)).orElse(1d) + weightMQ.get(group)); + } + } + if (enchantBonus.getTime() != 0) timeModifier *= enchantBonus.getTime(); + if (enchantBonus.getDoubleLoot() != 0) doubleLoot += enchantBonus.getDoubleLoot(); + if (enchantBonus.getDifficulty() != 0) difficultyModifier += enchantBonus.getDifficulty(); + if (enchantBonus.getScore() != 0) scoreModifier *= enchantBonus.getScore(); + } + } + } + } + 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){ + HashMap weightPM = bait.getWeightPM(); + if (weightPM != null){ + Object[] bonus = weightPM.keySet().toArray(); + for (Object value : bonus) { + String group = (String) value; + pm.put(group, Optional.ofNullable(pm.get(group)).orElse(0) + weightPM.get(group)); + } + } + HashMap weightMQ = bait.getWeightMQ(); + if (weightMQ != null){ + Object[] bonus = weightMQ.keySet().toArray(); + for (Object value : bonus) { + String group = (String) value; + mq.put(group, Optional.ofNullable(mq.get(group)).orElse(1d) + weightMQ.get(group)); + } + } + 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 (noSpecialRod && offHandCompound.getString("type").equals("rod")){ + String key = offHandCompound.getString("id"); + Bonus rod = ConfigReader.ROD.get(key); + if (rod != null){ + HashMap weightPM = rod.getWeightPM(); + if (weightPM != null){ + Object[] bonus = weightPM.keySet().toArray(); + for (Object value : bonus) { + String group = (String) value; + pm.put(group, Optional.ofNullable(pm.get(group)).orElse(0) + weightPM.get(group)); + } + } + HashMap weightMQ = rod.getWeightMQ(); + if (weightMQ != null){ + Object[] bonus = weightMQ.keySet().toArray(); + for (Object value : bonus) { + String group = (String) value; + mq.put(group, Optional.ofNullable(mq.get(group)).orElse(1d) + weightMQ.get(group)); + } + } + 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(); + noSpecialRod = false; + } + } + } + } + + if (ConfigReader.Config.needSpecialRod && noSpecialRod){ + 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 (pm.get(group) != null){ + weight += pm.get(group); + } + if (mq.get(group) != null){ + weight *= mq.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); - 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 (pm.get(group) != null){ - weight += pm.get(group); - } - if (mq.get(group) != null){ - weight *= mq.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)]; + }); } + case CAUGHT_FISH -> { + //是否需要两次拉杆 + if (ConfigReader.Config.doubleRealIn) { - int difficulty = loot.getDifficulty().getSpeed(); - difficulty += Objects.requireNonNullElse(modifiers.get(player).getDifficulty(), 0);; - if (difficulty < 1){ - difficulty = 1; - } + FishingPlayer fishingPlayer = fishingPlayers.remove(player); - Difficulty difficult = new Difficulty(loot.getDifficulty().getTimer(), difficulty); - fishingPlayers.put(player, - new FishingPlayer(System.currentTimeMillis() + loot.getTime(), - new Timer(player, difficult, layout) - ) - ); + if (fishingPlayer == null){ - 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){ + 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); - vanilla.put(player, new VanillaLoot(item.getItemStack(), event.getExpToDrop())); 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){ + summonMob(player, loot, location, mob); + } + else if (loot instanceof DroppedItem droppedItem){ + if (vanillaLoot != null) { + dropVanillaLoot(player, vanillaLoot, location); + } + else if (ConfigReader.Config.mcMMOLoot && Math.random() < ConfigReader.Config.mcMMOLootChance){ + if(dropMcMMOLoot(player, location)){ + dropMyLoot(player, loot, location, droppedItem); + } + } + else { + dropMyLoot(player, loot, location, droppedItem); + } + } + } + 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){ + if (ConfigReader.Config.mcMMOLoot && ConfigReader.Config.mcMMOLootChance > Math.random()){ + if (dropMcMMOLoot(player, location)){ + dropLoot(player, location, droppedItem); + } + }else { + dropLoot(player, location, droppedItem); + } + } + 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); + } + 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 + ); + if (ConfigReader.Config.loseDurability) + loseDurability(player); + } + //捕鱼失败 + else { + fail(player, loot); + } + } else { - if (nextLoot.get(player) == null){ + if (!ConfigReader.Config.vanillaLoot) { 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); - } + } + case CAUGHT_ENTITY -> { + //理论是不存在实体的 + //说明在钓鱼的时候可能鱼钩勾上了鱿鱼之类的生物 + //直接按照失败处理 + if (fishingPlayers.remove(player) != null && event.getCaught() != null){ + AdventureUtil.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.hookOther); + } + } + case REEL_IN -> { + FishingPlayer fishingPlayer = fishingPlayers.remove(player); + //首先得是钓鱼中的玩家 + if (fishingPlayer != null){ + Loot loot = nextLoot.remove(player); VanillaLoot vanillaLoot = vanilla.remove(player); Timer timer = fishingPlayer.getTimer(); @@ -466,72 +578,24 @@ public class FishListener implements Listener { } 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); - } + summonMob(player, loot, location, mob); } 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); + dropVanillaLoot(player, vanillaLoot, location); + } + else if (ConfigReader.Config.mcMMOLoot && Math.random() < ConfigReader.Config.mcMMOLootChance){ + if (dropMcMMOLoot(player, location)){ + dropMyLoot(player, loot, location, droppedItem); } - 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 - ); + dropMyLoot(player, loot, location, droppedItem); } } } @@ -539,210 +603,200 @@ public class FishListener implements Listener { 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; + 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 { +// //啥也不干 +// } } - - //捕鱼成功 - 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 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 { - //钓上来的是物品 - 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); + case 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)); } } } + private void dropMyLoot(Player player, Loot loot, Location location, DroppedItem droppedItem) { + dropLoot(player, location, droppedItem); + 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); + 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 + ); + } + + private void summonMob(Player player, Loot loot, Location location, 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); + } + 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 + ); + } + + private void dropVanillaLoot(Player player, VanillaLoot vanillaLoot, Location location) { + + ItemStack itemStack; + itemStack = vanillaLoot.getItemStack(); + + if (ConfigReader.Config.mcMMOLoot && ConfigReader.Config.mcMMOLootChance > Math.random()){ + ItemStack itemStack1 = McMMOTreasure.getTreasure(player); + if (itemStack1 != null){ + itemStack = itemStack1; + } + } + + 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 + ); + } + + /* + 返回是否为mcmmo物品为空值 + */ + private boolean dropMcMMOLoot(Player player, Location location) { + ItemStack itemStack = McMMOTreasure.getTreasure(player); + + if (itemStack != null) { + 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); + } + } + else { + return true; + } + + if (CompetitionSchedule.competition != null && CompetitionSchedule.competition.isGoingOn()) { + CompetitionSchedule.competition.refreshRanking(player.getName(), 0); + BossBarManager.joinCompetition(player); + } + + 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 + ); + return false; + } + @NotNull private Component getTitleComponent(ItemStack itemStack, String text) { Component subtitleComponent; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index e01ac4da..6d58628b 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,5 +1,5 @@ # don't change -config-version: '5' +config-version: '6' config: #en/es/cn @@ -25,13 +25,22 @@ config: # Otherwise the bar would show immediately the bobber is hooked double-reel-in: true - # 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 + other-loot: + # This is useful for vanilla loots + # Vanilla loot is available only when 'double-reel-in' is true + vanilla: true + # This means 30% of the loots are from vanilla + # and 70% are from CustomFishing Loot system + vanilla-ratio: 0.4 + # Should vanilla loots have the same fishing mechanic CustomFishing provides bar: true - ratio: 0.3 + + # mcMMO treasure system + # chance represents the chance to try to be a mcMMO treasure + # But it doesn't mean 50% chance of the loot would be mcMMO treasure + # mcMMO has a complex treasure system + mcMMO: false + mcMMO-chance: 0.5 # The same to vanilla (refer to the wiki) # https://technical-minecraft.fandom.com/wiki/Fishing @@ -58,4 +67,8 @@ config: # 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 + prevent-other-players-pick-up-loot: false + + # If there's a plugin conflict, event priority sometimes works + # HIGHEST NORMAL LOWEST + event-priority: NORMAL \ No newline at end of file diff --git a/src/main/resources/custom-enchant-bonus.yml b/src/main/resources/custom-enchant-bonus.yml deleted file mode 100644 index a484abdf..00000000 --- a/src/main/resources/custom-enchant-bonus.yml +++ /dev/null @@ -1,25 +0,0 @@ -# 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/messages/messages_es.yml b/src/main/resources/messages/messages_es.yml index 73d323fc..b1d134bb 100644 --- a/src/main/resources/messages/messages_es.yml +++ b/src/main/resources/messages/messages_es.yml @@ -24,7 +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!' + hook-other-entity: '¡El bobber está enganchado a otra entidad!' + no-rod: 'Hay que obtener una vara especial para conseguir botines' no-player: 'Ningún jugador' no-score: 'Sin puntuación' \ No newline at end of file