mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-19 15:09:24 +00:00
async
This commit is contained in:
@@ -19,6 +19,8 @@ public class ConfigReader{
|
||||
public static HashMap<String, ItemStack> UTILITEM = new HashMap<>();
|
||||
public static HashMap<String, RodInstance> ROD = new HashMap<>();
|
||||
public static HashMap<String, ItemStack> RODITEM = new HashMap<>();
|
||||
public static HashMap<String, BaitInstance> BAIT = new HashMap<>();
|
||||
public static HashMap<String, ItemStack> BAITITEM = new HashMap<>();
|
||||
public static HashMap<String, LayoutUtil> LAYOUT = new HashMap<>();
|
||||
|
||||
private static YamlConfiguration getConfig(String configName) {
|
||||
@@ -36,6 +38,7 @@ public class ConfigReader{
|
||||
loadLoot();
|
||||
loadUtil();
|
||||
loadRod();
|
||||
loadBait();
|
||||
}
|
||||
|
||||
public static class Config {
|
||||
@@ -49,6 +52,7 @@ public class ConfigReader{
|
||||
public static boolean needSpecialRod;
|
||||
public static String season_papi;
|
||||
public static int fishFinderCoolDown;
|
||||
public static double timeMultiply;
|
||||
|
||||
public static void loadConfig() {
|
||||
CustomFishing.instance.saveDefaultConfig();
|
||||
@@ -58,28 +62,28 @@ public class ConfigReader{
|
||||
wg = config.getBoolean("config.integrations.WorldGuard");
|
||||
if (wg){
|
||||
if (Bukkit.getPluginManager().getPlugin("WorldGuard") == null){
|
||||
AdventureManager.consoleMessage("<red>[CustomFishing] 未检测到 WorldGuard!</red>");
|
||||
AdventureManager.consoleMessage("<red>[CustomFishing] 未检测到插件 WorldGuard!</red>");
|
||||
wg = false;
|
||||
}else {
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><green>WorldGuard Hooked!");
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>检测到 <color:#00BFFF>WorldGuard <color:#E1FFFF>已启用区域限定!");
|
||||
}
|
||||
}
|
||||
mm = config.getBoolean("config.integrations.MythicMobs");
|
||||
if (mm){
|
||||
if (Bukkit.getPluginManager().getPlugin("MythicMobs") == null){
|
||||
AdventureManager.consoleMessage("<red>[CustomFishing] 未检测到 MythicMobs!</red>");
|
||||
AdventureManager.consoleMessage("<red>[CustomFishing] 未检测到插件 MythicMobs!</red>");
|
||||
mm = false;
|
||||
}else {
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><green>MythicMobs Hooked!");
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] <color:#E1FFFF>检测到 <color:#00BFFF>MythicMobs <color:#E1FFFF>已启用怪物拓展!");
|
||||
}
|
||||
}
|
||||
papi = config.getBoolean("config.integrations.PlaceholderAPI");
|
||||
if (papi){
|
||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") == null){
|
||||
AdventureManager.consoleMessage("<red>[CustomFishing] 未检测到 PlaceholderAPI!</red>");
|
||||
AdventureManager.consoleMessage("<red>[CustomFishing] 未检测到插件 PlaceholderAPI!</red>");
|
||||
papi = false;
|
||||
}else {
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><green>PlaceholderAPI Hooked!");
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>检测到 <color:#00BFFF>PlaceholderAPI <color:#E1FFFF>已启用变量解析!");
|
||||
}
|
||||
}
|
||||
season = config.getBoolean("config.season.enable");
|
||||
@@ -98,6 +102,7 @@ public class ConfigReader{
|
||||
needOpenWater = config.getBoolean("config.need-open-water");
|
||||
needSpecialRod = config.getBoolean("config.need-special-rod");
|
||||
fishFinderCoolDown = config.getInt("config.fishfinder-cooldown");
|
||||
timeMultiply = config.getDouble("config.time-multiply");
|
||||
|
||||
/*
|
||||
计算获取布局
|
||||
@@ -444,15 +449,15 @@ public class ConfigReader{
|
||||
if (keys.size() != LOOTITEM.size() || mobs.size() != LOOT.size()- LOOTITEM.size()) {
|
||||
AdventureManager.consoleMessage("<red>[CustomFishing] loots.yml 文件存在配置错误!</red>");
|
||||
} else {
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><white>从 loots.yml 载入了<green>" + keys.size() + "<white>条物品数据");
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><white>从 loots.yml 载入了<green>" + mobs.size() + "<white>条怪物数据");
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>已载入 <white>" + keys.size() + " <color:#E1FFFF>个战利品!");
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>已载入 <white>" + mobs.size() + " <color:#E1FFFF>个怪物!");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (keys.size() != LOOTITEM.size()){
|
||||
AdventureManager.consoleMessage("<red>[CustomFishing] loots.yml 文件存在配置错误!</red>");
|
||||
} else {
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><white>从 loots.yml 载入了<green>" + keys.size() + "<white>条物品数据");
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>已载入 <white>" + keys.size() + " <color:#E1FFFF>个战利品!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -498,7 +503,7 @@ public class ConfigReader{
|
||||
if (keys.size() != UTILITEM.size()){
|
||||
AdventureManager.consoleMessage("<red>[CustomFishing] utils.yml 文件存在配置错误!</red>");
|
||||
} else {
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><white>从 utils.yml 载入了<green>" + keys.size() + "<white>条工具数据");
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>已载入 <white>" + keys.size() + " <color:#E1FFFF>个实用道具!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -547,6 +552,7 @@ public class ConfigReader{
|
||||
}
|
||||
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"));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -557,7 +563,71 @@ public class ConfigReader{
|
||||
if (keys.size() != RODITEM.size()){
|
||||
AdventureManager.consoleMessage("<red>[CustomFishing] rods.yml 文件存在配置错误!</red>");
|
||||
} else {
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><white>从 rods.yml 载入了<green>" + keys.size() + "<white>条鱼竿数据");
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>已载入 <white>" + keys.size() + " <color:#E1FFFF>把鱼竿!");
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadBait(){
|
||||
|
||||
BAITITEM.clear();
|
||||
BAIT.clear();
|
||||
|
||||
YamlConfiguration config = getConfig("baits.yml");
|
||||
Set<String> keys = config.getConfigurationSection("baits").getKeys(false);
|
||||
|
||||
keys.forEach(key -> {
|
||||
String name;
|
||||
if (config.contains("baits." + key + ".display.name")) {
|
||||
name = config.getString("baits." + key + ".display.name");
|
||||
} else {
|
||||
AdventureManager.consoleMessage("<red>[CustomFishing] 错误! 未设置 " + key + " 的物品名称!</red>");
|
||||
return;
|
||||
}
|
||||
String material;
|
||||
if (config.contains("baits." + key + ".material")) {
|
||||
material = config.getString("baits." + key + ".material");
|
||||
} else {
|
||||
AdventureManager.consoleMessage("<red>[CustomFishing] 错误! 未设置 " + key + " 的物品材质!</red>");
|
||||
return;
|
||||
}
|
||||
BaitInstance baitInstance = new BaitInstance(name, material);
|
||||
if (config.contains("baits." + key + ".display.lore")) {
|
||||
baitInstance.setLore(config.getStringList("baits." + key + ".display.lore"));
|
||||
}
|
||||
if (config.contains("baits." + key + ".nbt")) {
|
||||
baitInstance.setNbt(config.getMapList("baits." + key + ".nbt").get(0));
|
||||
}
|
||||
if (config.contains("baits." + key + ".modifier")){
|
||||
config.getConfigurationSection("baits." + key + ".modifier").getKeys(false).forEach(modifier -> {
|
||||
switch (modifier){
|
||||
case "weight-PM" -> {
|
||||
HashMap<String, Integer> 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<String, Double> 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"));
|
||||
}
|
||||
});
|
||||
}
|
||||
BAIT.put(key, baitInstance);
|
||||
baitInstance.addBait2Cache(key);
|
||||
});
|
||||
|
||||
if (keys.size() != BAITITEM.size()){
|
||||
AdventureManager.consoleMessage("<red>[CustomFishing] baits.yml 文件存在配置错误!</red>");
|
||||
} else {
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>已载入 <white>" + keys.size() + " <color:#E1FFFF>条鱼饵!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,13 +21,14 @@ public final class CustomFishing extends JavaPlugin {
|
||||
Objects.requireNonNull(Bukkit.getPluginCommand("customfishing")).setExecutor(new Execute());
|
||||
Objects.requireNonNull(Bukkit.getPluginCommand("customfishing")).setTabCompleter(new TabComplete());
|
||||
Bukkit.getPluginManager().registerEvents(new PlayerListener(),this);
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>Running on " + Bukkit.getVersion());
|
||||
ConfigReader.Reload();
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><gray>插件已加载! 作者:小默米 QQ:3266959688");
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>插件已加载! 作者:小默米 QQ:3266959688");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><gray>插件已卸载! 作者:小默米 QQ:3266959688");
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>插件已卸载! 作者:小默米 QQ:3266959688");
|
||||
if(adventure != null) {
|
||||
adventure.close();
|
||||
adventure = null;
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.momirealms.customfishing.command;
|
||||
|
||||
import net.momirealms.customfishing.AdventureManager;
|
||||
import net.momirealms.customfishing.ConfigReader;
|
||||
import net.momirealms.customfishing.utils.BaitInstance;
|
||||
import net.momirealms.customfishing.utils.LootInstance;
|
||||
import net.momirealms.customfishing.utils.RodInstance;
|
||||
import net.momirealms.customfishing.utils.UtilInstance;
|
||||
@@ -214,6 +215,62 @@ public class Execute implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (args[1].equalsIgnoreCase("bait")){
|
||||
if (args[2].equalsIgnoreCase("get")) {
|
||||
//检验参数长度 [0]items [1]bait [2]get [3]xxx [4](amount)
|
||||
if (sender instanceof Player player){
|
||||
//是否存在于缓存中
|
||||
if (!ConfigReader.BAIT.containsKey(args[3])){
|
||||
noItem(sender);
|
||||
return true;
|
||||
}
|
||||
if (args.length == 4){
|
||||
BaitInstance.givePlayerBait(player, args[3], 1);
|
||||
AdventureManager.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;
|
||||
}
|
||||
BaitInstance.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]));
|
||||
}
|
||||
}else {
|
||||
AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.noConsole);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (args[2].equalsIgnoreCase("give")) {
|
||||
//检验参数长度 [0]items [1]bait [2]give [3]player [4]xxx [5](amount)
|
||||
if (args.length < 5){
|
||||
lackArgs(sender);
|
||||
return true;
|
||||
}
|
||||
Player player = Bukkit.getPlayer(args[3]);
|
||||
//玩家是否在线
|
||||
if (player == null){
|
||||
notOnline(sender);
|
||||
return true;
|
||||
}
|
||||
//是否存在于缓存中
|
||||
if (!ConfigReader.BAIT.containsKey(args[4])){
|
||||
noItem(sender);
|
||||
return true;
|
||||
}
|
||||
if (args.length == 5){
|
||||
BaitInstance.givePlayerBait(player, args[4], 1);
|
||||
giveItem(sender, args[3], args[4], 1);
|
||||
}else {
|
||||
if (Integer.parseInt(args[5]) < 1){
|
||||
wrongAmount(sender);
|
||||
return true;
|
||||
}
|
||||
BaitInstance.givePlayerBait(player, args[4], Integer.parseInt(args[5]));
|
||||
giveItem(sender, args[3], args[4], Integer.parseInt(args[5]));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -57,6 +57,13 @@ public class TabComplete implements TabCompleter {
|
||||
if (args[2].equalsIgnoreCase("get")){
|
||||
return rods();
|
||||
}
|
||||
}else if (args[1].equalsIgnoreCase("bait")){
|
||||
if (args[2].equalsIgnoreCase("give")){
|
||||
return online_players();
|
||||
}
|
||||
if (args[2].equalsIgnoreCase("get")){
|
||||
return baits();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,6 +82,11 @@ public class TabComplete implements TabCompleter {
|
||||
return rods();
|
||||
}
|
||||
}
|
||||
else if (args[1].equalsIgnoreCase("bait")){
|
||||
if (args[2].equalsIgnoreCase("give")){
|
||||
return baits();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -95,4 +107,7 @@ public class TabComplete implements TabCompleter {
|
||||
private List<String> rods() {
|
||||
return new ArrayList<>(ConfigReader.ROD.keySet());
|
||||
}
|
||||
private List<String> baits() {
|
||||
return new ArrayList<>(ConfigReader.BAIT.keySet());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import net.momirealms.customfishing.timer.Timer;
|
||||
import net.momirealms.customfishing.utils.*;
|
||||
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;
|
||||
@@ -21,6 +22,8 @@ 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.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.Vector;
|
||||
@@ -32,6 +35,7 @@ public class PlayerListener implements Listener {
|
||||
|
||||
private final HashMap<Player, Long> coolDown = new HashMap<>();
|
||||
private final HashMap<Player, LootInstance> nextLoot = new HashMap<>();
|
||||
private final HashSet<Player> willDouble = new HashSet<>();
|
||||
public static ConcurrentHashMap<Player, FishingPlayer> fishingPlayers = new ConcurrentHashMap<>();
|
||||
|
||||
@EventHandler
|
||||
@@ -43,29 +47,6 @@ public class PlayerListener implements Listener {
|
||||
//抛竿
|
||||
if (state.equals(PlayerFishEvent.State.FISHING)){
|
||||
|
||||
NBTItem nbtItem = new NBTItem(player.getInventory().getItemInMainHand());
|
||||
NBTCompound nbtCompound = nbtItem.getCompound("CustomFishing");
|
||||
|
||||
//是否需要特殊鱼竿
|
||||
if (ConfigReader.Config.needSpecialRod && nbtCompound == null){
|
||||
nextLoot.put(player, null);
|
||||
return;
|
||||
}
|
||||
|
||||
double timeModifier = 1;
|
||||
|
||||
HashMap<String, Integer> pm = new HashMap<>();
|
||||
HashMap<String, Double> mq = new HashMap<>();
|
||||
if (nbtCompound != null){
|
||||
String rodKey = nbtCompound.getString("id");
|
||||
RodInstance rod = ConfigReader.ROD.get(rodKey);
|
||||
if (rod != null){
|
||||
if (rod.getWeightPM() != null) pm = rod.getWeightPM();
|
||||
if (rod.getWeightMQ() != null) mq = rod.getWeightMQ();
|
||||
if (rod.getTime() != 0) timeModifier = rod.getTime();
|
||||
}
|
||||
}
|
||||
|
||||
//设置冷却时间
|
||||
long time = System.currentTimeMillis();
|
||||
if (time - (coolDown.getOrDefault(player, time - 1000)) < 1000) {
|
||||
@@ -73,6 +54,80 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
coolDown.put(player, time);
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(CustomFishing.instance, ()->{
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
boolean noRod = true;
|
||||
double timeModifier = 1;
|
||||
double doubleLoot = 0;
|
||||
HashMap<String, Integer> pm1 = new HashMap<>();
|
||||
HashMap<String, Double> 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");
|
||||
RodInstance 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();
|
||||
noRod = false;
|
||||
}
|
||||
}
|
||||
else if (nbtCompound.getString("type").equals("bait")){
|
||||
String key = nbtCompound.getString("id");
|
||||
BaitInstance 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();
|
||||
mainHandItem.setAmount(mainHandItem.getAmount() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HashMap<String, Integer> pm2 = new HashMap<>();
|
||||
HashMap<String, Double> 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");
|
||||
BaitInstance 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();
|
||||
offHandItem.setAmount(offHandItem.getAmount() - 1);
|
||||
}
|
||||
}else if (noRod && offHandCompound.getString("type").equals("rod")){
|
||||
String key = offHandCompound.getString("id");
|
||||
RodInstance 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();
|
||||
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()));
|
||||
@@ -84,67 +139,72 @@ public class PlayerListener implements Listener {
|
||||
nextLoot.put(player, null);
|
||||
return;
|
||||
}
|
||||
//计算总权重
|
||||
double totalWeight = 0;
|
||||
|
||||
double[] weights = new double[possibleLoots.size()];
|
||||
int index = 0;
|
||||
for (LootInstance loot : possibleLoots){
|
||||
double weight = loot.getWeight();
|
||||
String group = loot.getGroup();
|
||||
String group =loot.getGroup();
|
||||
if (group != null){
|
||||
if (pm.get(group) != null){
|
||||
weight += pm.get(group);
|
||||
if (pm1.get(group) != null){
|
||||
weight += pm1.get(group);
|
||||
}
|
||||
if (mq.get(group) != null){
|
||||
weight = weight * mq.get(group);
|
||||
if (pm2.get(group) != null){
|
||||
weight += pm2.get(group);
|
||||
}
|
||||
if (mq1.get(group) != null){
|
||||
weight *= mq1.get(group);
|
||||
}
|
||||
if (mq2.get(group) != null){
|
||||
weight *= mq2.get(group);
|
||||
}
|
||||
}
|
||||
//需要进行weight修改
|
||||
if (weight <= 0) continue;
|
||||
availableLoots.add(loot);
|
||||
totalWeight += loot.getWeight();
|
||||
weights[index++] = weight;
|
||||
}
|
||||
//计算每种鱼权重所占的比例并输入数组
|
||||
double[] weightRatios = new double[possibleLoots.size()];
|
||||
int index = 0;
|
||||
for (LootInstance loot : possibleLoots) {
|
||||
double weight = loot.getWeight();
|
||||
String group = loot.getGroup();
|
||||
if (group != null){
|
||||
if (pm.get(group) != null){
|
||||
weight += pm.get(group);
|
||||
|
||||
double total = Arrays.stream(weights).sum();
|
||||
double[] weightRatios = new double[index];
|
||||
for (int i = 0; i < index; i++){
|
||||
weightRatios[i] = weights[i]/total;
|
||||
}
|
||||
if (mq.get(group) != null){
|
||||
weight = weight * mq.get(group);
|
||||
}
|
||||
}
|
||||
//需要进行weight修改
|
||||
if (weight <= 0) continue;
|
||||
weightRatios[index++] = weight / totalWeight;
|
||||
}
|
||||
//根据权重比例划分定义域
|
||||
double[] weights = new double[availableLoots.size()];
|
||||
|
||||
double[] weightRange = new double[index];
|
||||
double startPos = 0;
|
||||
for (int i = 0; i < index; i++) {
|
||||
weights[i] = startPos + weightRatios[i];
|
||||
weightRange[i] = startPos + weightRatios[i];
|
||||
startPos += weightRatios[i];
|
||||
}
|
||||
//根据随机数所落区间获取Loot实例
|
||||
double random = Math.random();
|
||||
int pos = Arrays.binarySearch(weights, random);
|
||||
int pos = Arrays.binarySearch(weightRange, random);
|
||||
|
||||
if (pos < 0) {
|
||||
//二分法,数组中不存在该元素,则会返回 -(插入点 + 1)
|
||||
pos = -pos - 1;
|
||||
} else {
|
||||
//如果存在,那真是中大奖了!
|
||||
if (doubleLoot > Math.random()) {
|
||||
willDouble.add(player);
|
||||
}else {
|
||||
willDouble.remove(player);
|
||||
}
|
||||
nextLoot.put(player, availableLoots.get(pos));
|
||||
return;
|
||||
}
|
||||
if (pos < weights.length && random < weights[pos]) {
|
||||
if (pos < weightRange.length && random < weightRange[pos]) {
|
||||
if (doubleLoot > Math.random()) {
|
||||
willDouble.add(player);
|
||||
}else {
|
||||
willDouble.remove(player);
|
||||
}
|
||||
nextLoot.put(player, availableLoots.get(pos));
|
||||
return;
|
||||
}
|
||||
//以防万一,丢入空值
|
||||
nextLoot.put(player, null);
|
||||
});
|
||||
}
|
||||
|
||||
//咬钩
|
||||
@@ -153,6 +213,9 @@ public class PlayerListener implements Listener {
|
||||
if (nextLoot.get(player) == null) return;
|
||||
//如果正在钓一个鱼了,那么也返回
|
||||
if (fishingPlayers.get(player) != null) return;
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(CustomFishing.instance, ()-> {
|
||||
|
||||
LootInstance lootInstance = nextLoot.get(player);
|
||||
//获取布局名,或是随机布局
|
||||
String layout = Optional.ofNullable(lootInstance.getLayout()).orElseGet(() ->{
|
||||
@@ -161,9 +224,11 @@ public class PlayerListener implements Listener {
|
||||
return (String) values[generator.nextInt(values.length)];
|
||||
});
|
||||
|
||||
PlayerInventory playerInventory = player.getInventory();
|
||||
ItemStack mainHandItem = playerInventory.getItemInMainHand();
|
||||
if (mainHandItem.getType() != Material.AIR){
|
||||
NBTItem nbtItem = new NBTItem(player.getInventory().getItemInMainHand());
|
||||
NBTCompound nbtCompound = nbtItem.getCompound("CustomFishing");
|
||||
|
||||
if (nbtCompound != null){
|
||||
String rodKey = nbtCompound.getString("id");
|
||||
RodInstance rod = ConfigReader.ROD.get(rodKey);
|
||||
@@ -184,6 +249,32 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ItemStack offHandItem = playerInventory.getItemInOffHand();
|
||||
if (offHandItem.getType() != Material.AIR){
|
||||
NBTItem nbtItem = new NBTItem(player.getInventory().getItemInOffHand());
|
||||
NBTCompound nbtCompound = nbtItem.getCompound("CustomFishing");
|
||||
if (nbtCompound != null){
|
||||
String rodKey = nbtCompound.getString("id");
|
||||
RodInstance rod = ConfigReader.ROD.get(rodKey);
|
||||
if (rod != null){
|
||||
if (rod.getDifficulty() != 0) {
|
||||
int difficulty = lootInstance.getDifficulty().getSpeed();
|
||||
difficulty += rod.getDifficulty();
|
||||
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)
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//根据鱼的时间放入玩家实例,并应用药水效果
|
||||
fishingPlayers.put(player,
|
||||
@@ -191,7 +282,11 @@ public class PlayerListener implements Listener {
|
||||
new Timer(player, lootInstance.getDifficulty(), layout)
|
||||
)
|
||||
);
|
||||
Bukkit.getScheduler().callSyncMethod(CustomFishing.instance, ()->{
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, lootInstance.getTime()/50,3));
|
||||
return null;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//正常钓到鱼 & 正常收杆
|
||||
@@ -199,6 +294,7 @@ public class PlayerListener implements Listener {
|
||||
//发现有特殊鱼,那么必须掉落特殊鱼
|
||||
if (fishingPlayers.get(player) != null){
|
||||
//清除原版战利品
|
||||
|
||||
if (event.getCaught() != null){
|
||||
event.getCaught().remove();
|
||||
event.setExpToDrop(0);
|
||||
@@ -223,6 +319,10 @@ public class PlayerListener implements Listener {
|
||||
Vector vector = player.getLocation().subtract(location).toVector().multiply(0.1);
|
||||
vector = vector.setY((vector.getY()+0.2)*1.2);
|
||||
item.setVelocity(vector);
|
||||
if (willDouble.contains(player)){
|
||||
Entity item2 = location.getWorld().dropItem(location, ConfigReader.LOOTITEM.get(lootInstance.getKey()));
|
||||
item2.setVelocity(vector);
|
||||
}
|
||||
}
|
||||
if (lootInstance.getMsg() != null){
|
||||
//发送消息
|
||||
@@ -273,6 +373,7 @@ public class PlayerListener implements Listener {
|
||||
player.removePotionEffect(PotionEffectType.SLOW);
|
||||
coolDown.remove(player);
|
||||
nextLoot.remove(player);
|
||||
willDouble.remove(player);
|
||||
fishingPlayers.remove(player);
|
||||
}
|
||||
|
||||
@@ -328,3 +429,59 @@ public class PlayerListener implements Listener {
|
||||
return available;
|
||||
}
|
||||
}
|
||||
|
||||
// //计算总权重
|
||||
// double totalWeight = 0;
|
||||
// for (LootInstance loot : possibleLoots){
|
||||
// double weight = loot.getWeight();
|
||||
// String group = loot.getGroup();
|
||||
// if (group != null){
|
||||
// if (pm.get(group) != null){
|
||||
// weight += pm.get(group);
|
||||
// }
|
||||
// if (pm2.get(group) != null){
|
||||
// weight += pm2.get(group);
|
||||
// }
|
||||
// if (mq.get(group) != null){
|
||||
// weight *= mq.get(group);
|
||||
// }
|
||||
// if (mq2.get(group) != null){
|
||||
// weight *= mq2.get(group);
|
||||
// }
|
||||
// }
|
||||
// //需要进行weight修改
|
||||
// if (weight <= 0) continue;
|
||||
// availableLoots.add(loot);
|
||||
// totalWeight += loot.getWeight();
|
||||
// }
|
||||
//计算每种鱼权重所占的比例并输入数组
|
||||
// double[] weightRatios = new double[possibleLoots.size()];
|
||||
// int index = 0;
|
||||
// for (LootInstance loot : possibleLoots) {
|
||||
// double weight = loot.getWeight();
|
||||
// String group = loot.getGroup();
|
||||
// if (group != null){
|
||||
// if (pm.get(group) != null){
|
||||
// weight += pm.get(group);
|
||||
// }
|
||||
// if (pm2.get(group) != null){
|
||||
// weight += pm2.get(group);
|
||||
// }
|
||||
// if (mq.get(group) != null){
|
||||
// weight *= mq.get(group);
|
||||
// }
|
||||
// if (mq2.get(group) != null){
|
||||
// weight *= mq2.get(group);
|
||||
// }
|
||||
// }
|
||||
// //需要进行weight修改
|
||||
// if (weight <= 0) continue;
|
||||
// weightRatios[index++] = weight / totalWeight;
|
||||
// }
|
||||
// //根据权重比例划分定义域
|
||||
// double[] weights = new double[availableLoots.size()];
|
||||
// double startPos = 0;
|
||||
// for (int i = 0; i < index; i++) {
|
||||
// weights[i] = startPos + weightRatios[i];
|
||||
// startPos += weightRatios[i];
|
||||
// }
|
||||
@@ -8,6 +8,7 @@ import net.momirealms.customfishing.utils.LayoutUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
@@ -61,7 +62,8 @@ public class TimerTask extends BukkitRunnable {
|
||||
return;
|
||||
}
|
||||
//移除切换物品的玩家
|
||||
if (player.getInventory().getItemInMainHand().getType() != Material.FISHING_ROD){
|
||||
PlayerInventory playerInventory = player.getInventory();
|
||||
if (playerInventory.getItemInMainHand().getType() != Material.FISHING_ROD && playerInventory.getItemInOffHand().getType() != Material.FISHING_ROD){
|
||||
fishingPlayers.remove(player);
|
||||
Bukkit.getScheduler().cancelTask(taskID);
|
||||
Bukkit.getScheduler().callSyncMethod(CustomFishing.instance, ()-> {
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
package net.momirealms.customfishing.utils;
|
||||
|
||||
import de.tr7zw.changeme.nbtapi.NBTCompound;
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.momirealms.customfishing.ConfigReader;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class BaitInstance {
|
||||
|
||||
private final String name;
|
||||
private List<String> lore;
|
||||
private Map<?, ?> nbt;
|
||||
private HashMap<String, Double> weightMQ;
|
||||
private HashMap<String, Integer> weightPM;
|
||||
private double time;
|
||||
private double doubleLoot;
|
||||
private int difficulty;
|
||||
private final String material;
|
||||
|
||||
public BaitInstance(String name, String material) {
|
||||
this.name = name;
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
public void addBait2Cache(String baitKey){
|
||||
NBTItem nbtItem = new NBTItem(new ItemStack(Material.valueOf(this.material.toUpperCase())));
|
||||
NBTCompound display = nbtItem.addCompound("display");
|
||||
display.setString("Name", GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize("<italic:false>" + this.name)));
|
||||
if(this.lore != null){
|
||||
List<String> lores = display.getStringList("Lore");
|
||||
this.lore.forEach(lore -> lores.add(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize("<italic:false>" + lore))));
|
||||
}
|
||||
if (this.nbt != null){
|
||||
NBTUtil nbtUtil = new NBTUtil(this.nbt, nbtItem.getItem());
|
||||
nbtItem = nbtUtil.getNBTItem();
|
||||
}
|
||||
nbtItem.addCompound("CustomFishing");
|
||||
NBTCompound nbtCompound = nbtItem.getCompound("CustomFishing");
|
||||
nbtCompound.setString("type", "bait");
|
||||
nbtCompound.setString("id", baitKey);
|
||||
ConfigReader.BAITITEM.put(baitKey, nbtItem.getItem());
|
||||
}
|
||||
|
||||
public static void givePlayerBait(Player player, String baitKey, int amount){
|
||||
ItemStack itemStack = ConfigReader.BAITITEM.get(baitKey);
|
||||
itemStack.setAmount(amount);
|
||||
player.getInventory().addItem(itemStack);
|
||||
}
|
||||
|
||||
public void setDifficulty(int difficulty) {
|
||||
this.difficulty = difficulty;
|
||||
}
|
||||
public void setNbt(Map<?, ?> nbt) {
|
||||
this.nbt = nbt;
|
||||
}
|
||||
public void setLore(List<String> lore) {
|
||||
this.lore = lore;
|
||||
}
|
||||
public void setTime(double time) {
|
||||
this.time = time;
|
||||
}
|
||||
public void setWeightMQ(HashMap<String, Double> weightMQ) {
|
||||
this.weightMQ = weightMQ;
|
||||
}
|
||||
public void setWeightPM(HashMap<String, Integer> weightPM) {
|
||||
this.weightPM = weightPM;
|
||||
}
|
||||
public int getDifficulty() { return difficulty; }
|
||||
|
||||
public double getDoubleLoot() {
|
||||
return this.doubleLoot;
|
||||
}
|
||||
|
||||
public Map<?, ?> getNbt() {
|
||||
return nbt;
|
||||
}
|
||||
public List<String> getLore() {
|
||||
return lore;
|
||||
}
|
||||
public double getTime() {
|
||||
return time;
|
||||
}
|
||||
public HashMap<String, Double> getWeightMQ() {
|
||||
return weightMQ;
|
||||
}
|
||||
public HashMap<String, Integer> getWeightPM() {
|
||||
return weightPM;
|
||||
}
|
||||
|
||||
public void setDoubleLoot(double doubleLoot) {
|
||||
this.doubleLoot = doubleLoot;
|
||||
}
|
||||
}
|
||||
@@ -71,14 +71,10 @@ public class LootInstance {
|
||||
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 int getExp() {return exp;}
|
||||
|
||||
public void setLore(List<String> lore){
|
||||
this.lore = lore;
|
||||
@@ -95,15 +91,10 @@ public class LootInstance {
|
||||
public void setVectorUtil(VectorUtil vectorUtil){ this.vectorUtil = vectorUtil; }
|
||||
public void setCommands(List<String> 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 setExp(int exp) {this.exp = exp;}
|
||||
/*
|
||||
将实例转换为缓存中的NBT物品
|
||||
*/
|
||||
|
||||
@@ -22,6 +22,7 @@ public class RodInstance {
|
||||
private HashMap<String, Integer> weightPM;
|
||||
private double time;
|
||||
private int difficulty;
|
||||
private double doubleLoot;
|
||||
|
||||
public RodInstance(String name) {
|
||||
this.name = name;
|
||||
@@ -56,6 +57,10 @@ public class RodInstance {
|
||||
this.difficulty = difficulty;
|
||||
}
|
||||
|
||||
public void setDoubleLoot(double doubleLoot) {
|
||||
this.doubleLoot = doubleLoot;
|
||||
}
|
||||
|
||||
public void setNbt(Map<?, ?> nbt) {
|
||||
this.nbt = nbt;
|
||||
}
|
||||
@@ -80,6 +85,10 @@ public class RodInstance {
|
||||
return difficulty;
|
||||
}
|
||||
|
||||
public double getDoubleLoot() {
|
||||
return this.doubleLoot;
|
||||
}
|
||||
|
||||
public Map<?, ?> getNbt() {
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@@ -63,10 +63,15 @@ public class UtilInstance {
|
||||
}
|
||||
if (this.nbt != null){
|
||||
NBTUtil nbtUtil = new NBTUtil(this.nbt, nbtItem.getItem());
|
||||
ConfigReader.UTILITEM.put(utilKey, nbtUtil.getNBTItem().getItem());
|
||||
}else {
|
||||
ConfigReader.UTILITEM.put(utilKey, nbtItem.getItem());
|
||||
nbtItem = nbtUtil.getNBTItem();
|
||||
}
|
||||
if (utilKey.equals("fishfinder")){
|
||||
nbtItem.addCompound("CustomFishing");
|
||||
NBTCompound nbtCompound = nbtItem.getCompound("CustomFishing");
|
||||
nbtCompound.setString("type", "util");
|
||||
nbtCompound.setString("id", "fishfinder");
|
||||
}
|
||||
ConfigReader.UTILITEM.put(utilKey, nbtItem.getItem());
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
baits:
|
||||
simple_bait:
|
||||
material: paper
|
||||
display:
|
||||
name: '普通的钓饵'
|
||||
lore:
|
||||
- '<white>减少捕鱼的时间'
|
||||
- '<white>但是加大捕鱼的难度'
|
||||
nbt:
|
||||
- CustomModelData: '(Int) 1'
|
||||
#钓饵增益
|
||||
modifier:
|
||||
#改变指定组的loot权重
|
||||
#加减权重
|
||||
weight-PM:
|
||||
normal: 20
|
||||
creature: -10
|
||||
#乘除权重
|
||||
weight-MQ:
|
||||
normal: 1.8
|
||||
creature: 0.8
|
||||
#改变上鱼的时间(>1为延长,<1为缩短)
|
||||
time: 0.95
|
||||
#更改难度,例如原来难度为(1-6),现在变成(1-5)
|
||||
difficulty: 3
|
||||
#双倍掉落概率
|
||||
double-loot: 0.05
|
||||
@@ -90,3 +90,7 @@ config:
|
||||
|
||||
#使用找鱼器的冷却时间(ms)
|
||||
fishfinder-cooldown: 3000
|
||||
|
||||
#修改捕鱼所需的时间
|
||||
#在paper.yml中可以修改默认最少最长上钩时间
|
||||
time-multiply: 2
|
||||
@@ -21,3 +21,5 @@ rods:
|
||||
time: 1.5
|
||||
#更改难度,例如原来难度为(1-6),现在变成(1-5)
|
||||
difficulty: -1
|
||||
#双倍掉落概率
|
||||
double-loot: 0.05
|
||||
@@ -5,10 +5,5 @@ utils:
|
||||
name: '找鱼器'
|
||||
lore:
|
||||
- '右键查看这个地方能钓到什么鱼吧!'
|
||||
#NBT是本插件识别找鱼器的唯一方法
|
||||
#如果你想使用IA物品那请在IA的物品配置里增加 nbt: {CustomFishing: fishfinder}
|
||||
nbt:
|
||||
- CustomModelData: '(Int) 1'
|
||||
CustomFishing:
|
||||
type: '(String) util'
|
||||
id: '(String) fishfinder'
|
||||
Reference in New Issue
Block a user