9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-19 15:09:24 +00:00
This commit is contained in:
Xiao-MoMi
2022-08-29 01:27:43 +08:00
parent b3c90ab917
commit 73b21baffa
7 changed files with 825 additions and 615 deletions

View File

@@ -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<String, Double> 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<String, Double> 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<String, Double> 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);
}

View File

@@ -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){

View File

@@ -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<Enchantment, Integer> 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<Enchantment, Integer> processMagicHunter(@NotNull ItemStack treasureDrop, int tier) {
Map<Enchantment, Integer> enchants = new HashMap<>();
List<EnchantmentTreasure> 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<FishingTreasure> 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;
}
}

View File

@@ -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
prevent-other-players-pick-up-loot: false
# If there's a plugin conflict, event priority sometimes works
# HIGHEST NORMAL LOWEST
event-priority: NORMAL

View File

@@ -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

View File

@@ -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'