9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-29 11:59:11 +00:00
This commit is contained in:
Xiao-MoMi
2022-08-03 18:18:38 +08:00
parent 3cb64fc265
commit 24704f9105
21 changed files with 658 additions and 270 deletions

View File

@@ -1,6 +1,11 @@
package net.momirealms.customfishing;
import net.kyori.adventure.key.Key;
import net.momirealms.customfishing.bar.Difficulty;
import net.momirealms.customfishing.bar.Layout;
import net.momirealms.customfishing.item.Bait;
import net.momirealms.customfishing.item.Loot;
import net.momirealms.customfishing.item.Rod;
import net.momirealms.customfishing.item.Util;
import net.momirealms.customfishing.requirements.*;
import net.momirealms.customfishing.utils.*;
import org.apache.commons.lang.StringUtils;
@@ -16,15 +21,15 @@ import java.util.*;
public class ConfigReader{
public static HashMap<String, LootInstance> LOOT = new HashMap<>();
public static HashMap<String, Loot> LOOT = new HashMap<>();
public static HashMap<String, ItemStack> LOOTITEM = new HashMap<>();
public static HashMap<String, UtilInstance> UTIL = new HashMap<>();
public static HashMap<String, Util> UTIL = new HashMap<>();
public static HashMap<String, ItemStack> UTILITEM = new HashMap<>();
public static HashMap<String, RodInstance> ROD = new HashMap<>();
public static HashMap<String, Rod> ROD = new HashMap<>();
public static HashMap<String, ItemStack> RODITEM = new HashMap<>();
public static HashMap<String, BaitInstance> BAIT = new HashMap<>();
public static HashMap<String, Bait> BAIT = new HashMap<>();
public static HashMap<String, ItemStack> BAITITEM = new HashMap<>();
public static HashMap<String, LayoutUtil> LAYOUT = new HashMap<>();
public static HashMap<String, Layout> LAYOUT = new HashMap<>();
private static YamlConfiguration getConfig(String configName) {
File file = new File(CustomFishing.instance.getDataFolder(), configName);
@@ -54,10 +59,12 @@ public class ConfigReader{
public static boolean needOpenWater;
public static boolean needSpecialRod;
public static String season_papi;
public static String lang;
public static int fishFinderCoolDown;
public static double timeMultiply;
public static void loadConfig() {
CustomFishing.instance.saveDefaultConfig();
CustomFishing.instance.reloadConfig();
FileConfiguration config = CustomFishing.instance.getConfig();
@@ -65,34 +72,33 @@ 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] Failed to initialize WorldGuard!</red>");
wg = false;
}else {
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>检测到 <color:#00BFFF>WorldGuard <color:#E1FFFF>已启用区域限定!");
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#00BFFF>WorldGuard <color:#E1FFFF>Hooked!");
}
}
mm = config.getBoolean("config.integrations.MythicMobs");
if (mm){
if (Bukkit.getPluginManager().getPlugin("MythicMobs") == null){
AdventureManager.consoleMessage("<red>[CustomFishing] 未检测到插件 MythicMobs!</red>");
AdventureManager.consoleMessage("<red>[CustomFishing] Failed to initialize MythicMobs!</red>");
mm = false;
}else {
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>检测到 <color:#00BFFF>MythicMobs <color:#E1FFFF>已启用怪物拓展!");
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#00BFFF>MythicMobs <color:#E1FFFF>Hooked!");
}
}
papi = config.getBoolean("config.integrations.PlaceholderAPI");
if (papi){
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") == null){
AdventureManager.consoleMessage("<red>[CustomFishing] 未检测到插件 PlaceholderAPI!</red>");
AdventureManager.consoleMessage("<red>[CustomFishing] Failed to initialize PlaceholderAPI!</red>");
papi = false;
}else {
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>检测到 <color:#00BFFF>PlaceholderAPI <color:#E1FFFF>已启用变量解析!");
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#00BFFF>PlaceholderAPI <color:#E1FFFF>Hooked!");
}
}
season = config.getBoolean("config.season.enable");
if (!papi && season) {
season = false;
AdventureManager.consoleMessage("<red>[CustomFishing] 使用季节特性请先打开 PlaceholderAPI 兼容!</red>");
}
if (season) {
@@ -106,6 +112,7 @@ public class ConfigReader{
needSpecialRod = config.getBoolean("config.need-special-rod");
fishFinderCoolDown = config.getInt("config.fishfinder-cooldown");
timeMultiply = config.getDouble("config.time-multiply");
lang = config.getString("config.lang","cn");
/*
计算获取布局
@@ -120,7 +127,7 @@ public class ConfigReader{
successRate[i] = config.getDouble("config.success-rate." + key + ".layout." +(i + 1));
}
int size = rates.size()*range -1;
LayoutUtil layout = new LayoutUtil(key, range, successRate, size);
Layout layout = new Layout(key, range, successRate, size);
layout.setTitle(config.getString("config.success-rate." + key + ".title"," "));
layout.setBar(config.getString("config.success-rate." + key + ".subtitle.bar",""));
layout.setEnd(config.getString("config.success-rate." + key + ".subtitle.end","</font>"));
@@ -134,7 +141,6 @@ public class ConfigReader{
}
public static class Message {
public static String prefix;
public static String reload;
public static String escape;
@@ -151,10 +157,8 @@ public class ConfigReader{
public static String splitChar;
public static String noLoot;
public static String notOpenWater;
public static void loadMessage() {
YamlConfiguration config = getConfig("messages.yml");
YamlConfiguration config = getConfig("messages/messages_" + Config.lang +".yml");
prefix = config.getString("messages.prefix");
reload = config.getString("messages.reload");
escape = config.getString("messages.escape");
@@ -175,7 +179,6 @@ public class ConfigReader{
}
public static class Title {
public static List<String> success_title;
public static List<String> success_subtitle;
public static int success_in;
@@ -186,10 +189,8 @@ public class ConfigReader{
public static int failure_in;
public static int failure_out;
public static int failure_stay;
public static void loadTitle() {
YamlConfiguration config = getConfig("titles.yml");
success_title = config.getStringList("titles.success.title");
success_subtitle = config.getStringList("titles.success.subtitle");
success_in = config.getInt("titles.success.fade.in")*50;
@@ -258,7 +259,7 @@ public class ConfigReader{
}
//新建单例
LootInstance loot = new LootInstance(key, name, difficulty, weight, time);
Loot loot = new Loot(key, name, difficulty, weight, time);
/*
必须设置的内容,但并非构造所需
@@ -309,6 +310,11 @@ public class ConfigReader{
loot.setLayout(config.getString("items." + key + ".layout"));
if (config.contains("items." + key + ".group"))
loot.setGroup(config.getString("items." + key + ".group"));
if (config.contains("items." + key + ".show-in-fishfinder")){
loot.setShowInFinder(config.getBoolean("items." + key + ".show-in-fishfinder"));
}else {
loot.setShowInFinder(true);
}
/*
设置捕获条件
*/
@@ -340,10 +346,8 @@ public class ConfigReader{
});
loot.setRequirements(requirements);
}
//添加单例进缓存
LOOT.put(key, loot);
//添加根据单例生成的NBT物品进缓存
loot.addLoot2cache(key);
LOOTITEM.put(key, NBTUtil.addIdentifier(ItemStackGenerator.fromItem(loot), "loot", key));
});
if (config.contains("mobs") && Config.mm){
@@ -393,7 +397,7 @@ public class ConfigReader{
return;
}
//新建单例
LootInstance loot = new LootInstance(key, name, difficulty, weight, time);
Loot loot = new Loot(key, name, difficulty, weight, time);
//设置昵称
loot.setNick(name);
//设置MM怪ID
@@ -422,6 +426,11 @@ public class ConfigReader{
loot.setLayout(config.getString("mobs." + key + "layout"));
if (config.contains("mobs." + key + ".group"))
loot.setGroup(config.getString("mobs." + key + ".group"));
if (config.contains("mobs." + key + ".show-in-fishfinder")){
loot.setShowInFinder(config.getBoolean("mobs." + key + ".show-in-fishfinder"));
}else {
loot.setShowInFinder(true);
}
/*
设置捕获条件
*/
@@ -459,15 +468,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><color:#E1FFFF>已载入 <white>" + keys.size() + " <color:#E1FFFF>个战利品!");
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>已载入 <white>" + mobs.size() + " <color:#E1FFFF>个怪物!");
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><white>" + keys.size() + " <color:#E1FFFF>loots loaded!");
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><white>" + mobs.size() + " <color:#E1FFFF>mobs loaded!");
}
return;
}
if (keys.size() != LOOTITEM.size()){
AdventureManager.consoleMessage("<red>[CustomFishing] loots.yml 文件存在配置错误!</red>");
AdventureManager.consoleMessage("<red>[CustomFishing] loots.yml exists error!</red>");
} else {
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>已载入 <white>" + keys.size() + " <color:#E1FFFF>个战利品!");
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><white>" + keys.size() + " <color:#E1FFFF>loots loaded!");
}
}
@@ -489,18 +498,18 @@ public class ConfigReader{
if (config.contains("utils." + key + ".display.name")) {
name = config.getString("utils." + key + ".display.name");
} else {
AdventureManager.consoleMessage("<red>[CustomFishing] 错误! 未设置 " + key + " 的物品名称!</red>");
AdventureManager.consoleMessage("<red>[CustomFishing] Error! No name set for " + key + " !</red>");
return;
}
String material;
if (config.contains("utils." + key + ".material")) {
material = config.getString("utils." + key + ".material");
} else {
AdventureManager.consoleMessage("<red>[CustomFishing] 错误! 未设置 " + key + " 的物品材质!</red>");
AdventureManager.consoleMessage("<red>[CustomFishing] Error! No material set for " + key + " !</red>");
return;
}
//构造
UtilInstance utilInstance = new UtilInstance(key, name, material);
Util utilInstance = new Util(key, name, material);
if (config.contains("utils." + key + ".display.lore"))
utilInstance.setLore(config.getStringList("utils." + key + ".display.lore"));
@@ -523,12 +532,12 @@ public class ConfigReader{
utilInstance.setItemFlags(arrayList);
}
UTIL.put(key, utilInstance);
utilInstance.addUtil2cache(key);
UTILITEM.put(key, NBTUtil.addIdentifier(ItemStackGenerator.fromItem(utilInstance), "util", key));
});
if (keys.size() != UTILITEM.size()){
AdventureManager.consoleMessage("<red>[CustomFishing] utils.yml 文件存在配置错误!</red>");
AdventureManager.consoleMessage("<red>[CustomFishing] utils.yml exists error!</red>");
} else {
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>已载入 <white>" + keys.size() + " <color:#E1FFFF>个实用道具!");
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><white>" + keys.size() + " <color:#E1FFFF>utils loaded!");
}
}
@@ -551,7 +560,7 @@ public class ConfigReader{
AdventureManager.consoleMessage("<red>[CustomFishing] 错误! 未设置 " + key + " 的物品名称!</red>");
return;
}
RodInstance rodInstance = new RodInstance(name);
Rod rodInstance = new Rod(name);
if (config.contains("rods." + key + ".display.lore")) {
rodInstance.setLore(config.getStringList("rods." + key + ".display.lore"));
}
@@ -598,13 +607,13 @@ public class ConfigReader{
});
}
ROD.put(key, rodInstance);
rodInstance.addRod2Cache(key);
RODITEM.put(key, NBTUtil.addIdentifier(ItemStackGenerator.fromItem(rodInstance), "rod", key));
});
if (keys.size() != RODITEM.size()){
AdventureManager.consoleMessage("<red>[CustomFishing] rods.yml 文件存在配置错误!</red>");
AdventureManager.consoleMessage("<red>[CustomFishing] rods.yml exists error!</red>");
} else {
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>已载入 <white>" + keys.size() + " <color:#E1FFFF>把鱼竿!");
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><white>" + keys.size() + " <color:#E1FFFF>rods loaded!");
}
}
@@ -621,17 +630,17 @@ public class ConfigReader{
if (config.contains("baits." + key + ".display.name")) {
name = config.getString("baits." + key + ".display.name");
} else {
AdventureManager.consoleMessage("<red>[CustomFishing] 错误! 未设置 " + key + " 的物品名称!</red>");
AdventureManager.consoleMessage("<red>[CustomFishing] Error! No name set for " + key + " !</red>");
return;
}
String material;
if (config.contains("baits." + key + ".material")) {
material = config.getString("baits." + key + ".material");
} else {
AdventureManager.consoleMessage("<red>[CustomFishing] 错误! 未设置 " + key + " 的物品材质!</red>");
AdventureManager.consoleMessage("<red>[CustomFishing] Error! No material set for " + key + " !</red>");
return;
}
BaitInstance baitInstance = new BaitInstance(name, material);
Bait baitInstance = new Bait(name, material);
if (config.contains("baits." + key + ".display.lore")) {
baitInstance.setLore(config.getStringList("baits." + key + ".display.lore"));
}
@@ -678,13 +687,13 @@ public class ConfigReader{
});
}
BAIT.put(key, baitInstance);
baitInstance.addBait2Cache(key);
BAITITEM.put(key, NBTUtil.addIdentifier(ItemStackGenerator.fromItem(baitInstance), "bait", key));
});
if (keys.size() != BAITITEM.size()){
AdventureManager.consoleMessage("<red>[CustomFishing] baits.yml 文件存在配置错误!</red>");
AdventureManager.consoleMessage("<red>[CustomFishing] baits.yml exists error!</red>");
} else {
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>已载入 <white>" + keys.size() + " <color:#E1FFFF>条鱼饵!");
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><white>" + keys.size() + " <color:#E1FFFF>baits loaded!");
}
}
}

View File

@@ -14,24 +14,6 @@ public final class CustomFishing extends JavaPlugin {
public static JavaPlugin instance;
public static BukkitAudiences adventure;
@Override
public void onLoad(){
// Paper原生的adventure似乎存在冲突导致1.18.1以下版本无法使用,所以方法废弃
// LibraryLoader.load("net.kyori","adventure-api","4.11.0","https://oss.sonatype.org/content/groups/public");
// LibraryLoader.load("net.kyori","adventure-platform-api","4.1.1","https://oss.sonatype.org/content/groups/public");
// LibraryLoader.load("net.kyori","adventure-platform-bukkit","4.1.1","https://oss.sonatype.org/content/groups/public");
// LibraryLoader.load("net.kyori","adventure-platform-facet","4.1.1","https://oss.sonatype.org/content/groups/public");
// LibraryLoader.load("net.kyori","adventure-text-serializer-gson","4.11.0","https://oss.sonatype.org/content/groups/public");
// LibraryLoader.load("net.kyori","adventure-text-serializer-plain","4.11.0","https://oss.sonatype.org/content/groups/public");
// LibraryLoader.load("net.kyori","adventure-text-serializer-gson-legacy-impl","4.11.0","https://oss.sonatype.org/content/groups/public");
// LibraryLoader.load("net.kyori","adventure-text-serializer-legacy","4.11.0","https://oss.sonatype.org/content/groups/public");
// LibraryLoader.load("net.kyori","adventure-nbt","4.11.0","https://oss.sonatype.org/content/groups/public");
// LibraryLoader.load("net.kyori","adventure-key","4.11.0","https://oss.sonatype.org/content/groups/public");
// LibraryLoader.load("net.kyori","adventure-text-minimessage","4.11.0","https://oss.sonatype.org/content/groups/public");
}
@Override
public void onEnable() {
instance = this;
@@ -41,7 +23,7 @@ public final class CustomFishing extends JavaPlugin {
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><color:#E1FFFF>插件已加载! 作者:小默米 QQ:3266959688");
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>Plugin Enabled!");
}
@Override

View File

@@ -0,0 +1,12 @@
package net.momirealms.customfishing.bar;
public record Difficulty(int timer, int speed) {
public int getTimer() {
return this.timer;
}
public int getSpeed() {
return this.speed;
}
}

View File

@@ -0,0 +1,14 @@
package net.momirealms.customfishing.bar;
import net.momirealms.customfishing.timer.Timer;
public record FishingPlayer(Long fishingTime, Timer timer) {
public Long getFishingTime() {
return this.fishingTime;
}
public Timer getTimer() {
return this.timer;
}
}

View File

@@ -0,0 +1,44 @@
package net.momirealms.customfishing.bar;
public class Layout {
private final String key;
private final int range;
private final double[] successRate;
private final int size;
private String start;
private String bar;
private String pointer;
private String offset;
private String end;
private String pointerOffset;
private String title;
public Layout(String key, int range, double[] successRate, int size){
this.key = key;
this.range = range;
this.successRate = successRate;
this.size = size;
}
public void setBar(String bar) {this.bar = bar;}
public void setEnd(String end) {this.end = end;}
public void setOffset(String offset) {this.offset = offset;}
public void setPointer(String pointer) {this.pointer = pointer;}
public void setPointerOffset(String pointerOffset) {this.pointerOffset = pointerOffset;}
public void setStart(String start) {this.start = start;}
public void setTitle(String title) {this.title = title;}
public String getKey(){return this.key;}
public int getRange(){return this.range;}
public double[] getSuccessRate(){return this.successRate;}
public int getSize(){return this.size;}
public String getBar() {return bar;}
public String getEnd() {return end;}
public String getOffset() {return offset;}
public String getPointer() {return pointer;}
public String getPointerOffset() {return pointerOffset;}
public String getStart() {return start;}
public String getTitle() {return title;}
}

View File

@@ -2,10 +2,10 @@ 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;
import net.momirealms.customfishing.item.Bait;
import net.momirealms.customfishing.item.Loot;
import net.momirealms.customfishing.item.Rod;
import net.momirealms.customfishing.item.Util;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@@ -54,14 +54,14 @@ public class Execute implements CommandExecutor {
return true;
}
if (args.length == 4){
LootInstance.givePlayerLoot(player, args[3], 1);
Loot.givePlayerLoot(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;
}
LootInstance.givePlayerLoot(player, args[3], Integer.parseInt(args[4]));
Loot.givePlayerLoot(player, args[3], Integer.parseInt(args[4]));
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", args[4]).replace("{Item}",args[3]));
}
}else {
@@ -87,14 +87,14 @@ public class Execute implements CommandExecutor {
return true;
}
if (args.length == 5){
LootInstance.givePlayerLoot(player, args[4], 1);
Loot.givePlayerLoot(player, args[4], 1);
giveItem(sender, args[3], args[4], 1);
}else {
if (Integer.parseInt(args[5]) < 1){
wrongAmount(sender);
return true;
}
LootInstance.givePlayerLoot(player, args[4], Integer.parseInt(args[5]));
Loot.givePlayerLoot(player, args[4], Integer.parseInt(args[5]));
giveItem(sender, args[3], args[4], Integer.parseInt(args[5]));
}
return true;
@@ -113,14 +113,14 @@ public class Execute implements CommandExecutor {
return true;
}
if (args.length == 4){
UtilInstance.givePlayerUtil(player, args[3], 1);
Util.givePlayerUtil(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;
}
UtilInstance.givePlayerUtil(player, args[3], Integer.parseInt(args[4]));
Util.givePlayerUtil(player, args[3], Integer.parseInt(args[4]));
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", args[4]).replace("{Item}",args[3]));
}
}else {
@@ -146,14 +146,14 @@ public class Execute implements CommandExecutor {
return true;
}
if (args.length == 5){
UtilInstance.givePlayerUtil(player, args[4], 1);
Util.givePlayerUtil(player, args[4], 1);
giveItem(sender, args[3], args[4], 1);
}else {
if (Integer.parseInt(args[5]) < 1){
wrongAmount(sender);
return true;
}
UtilInstance.givePlayerUtil(player, args[4], Integer.parseInt(args[5]));
Util.givePlayerUtil(player, args[4], Integer.parseInt(args[5]));
giveItem(sender, args[3], args[4], Integer.parseInt(args[5]));
}
return true;
@@ -169,14 +169,14 @@ public class Execute implements CommandExecutor {
return true;
}
if (args.length == 4){
RodInstance.givePlayerRod(player, args[3], 1);
Rod.givePlayerRod(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;
}
RodInstance.givePlayerRod(player, args[3], Integer.parseInt(args[4]));
Rod.givePlayerRod(player, args[3], Integer.parseInt(args[4]));
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.getItem.replace("{Amount}", args[4]).replace("{Item}",args[3]));
}
}else {
@@ -202,14 +202,14 @@ public class Execute implements CommandExecutor {
return true;
}
if (args.length == 5){
RodInstance.givePlayerRod(player, args[4], 1);
Rod.givePlayerRod(player, args[4], 1);
giveItem(sender, args[3], args[4], 1);
}else {
if (Integer.parseInt(args[5]) < 1){
wrongAmount(sender);
return true;
}
RodInstance.givePlayerRod(player, args[4], Integer.parseInt(args[5]));
Rod.givePlayerRod(player, args[4], Integer.parseInt(args[5]));
giveItem(sender, args[3], args[4], Integer.parseInt(args[5]));
}
return true;
@@ -225,14 +225,14 @@ public class Execute implements CommandExecutor {
return true;
}
if (args.length == 4){
BaitInstance.givePlayerBait(player, args[3], 1);
Bait.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]));
Bait.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 {
@@ -258,14 +258,14 @@ public class Execute implements CommandExecutor {
return true;
}
if (args.length == 5){
BaitInstance.givePlayerBait(player, args[4], 1);
Bait.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]));
Bait.givePlayerBait(player, args[4], Integer.parseInt(args[5]));
giveItem(sender, args[3], args[4], Integer.parseInt(args[5]));
}
return true;

View File

@@ -0,0 +1,66 @@
package net.momirealms.customfishing.item;
import net.momirealms.customfishing.ConfigReader;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Bait implements Item{
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;
private List<net.momirealms.customfishing.utils.Enchantment> enchantment;
private List<ItemFlag> itemFlags;
public Bait(String name, String material) {
this.name = name;
this.material = material;
}
public static void givePlayerBait(Player player, String baitKey, int amount){
ItemStack itemStack = ConfigReader.BAITITEM.get(baitKey);
if (itemStack == null) return;
itemStack.setAmount(amount);
player.getInventory().addItem(itemStack);
}
public void setItemFlags(List<ItemFlag> itemFlags) {this.itemFlags = itemFlags;}
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 void setDoubleLoot(double doubleLoot) {this.doubleLoot = doubleLoot;}
public void setEnchantment(List<net.momirealms.customfishing.utils.Enchantment> enchantment) {this.enchantment = enchantment;}
public double getDoubleLoot() {return this.doubleLoot;}
public int getDifficulty() {return difficulty;}
public double getTime() {return time;}
public HashMap<String, Double> getWeightMQ() {return weightMQ;}
public HashMap<String, Integer> getWeightPM() {return weightPM;}
@Override
public List<String> getLore() {return lore;}
@Override
public Map<?, ?> getNbt() {return nbt;}
@Override
public String getMaterial() {return this.material;}
@Override
public List<net.momirealms.customfishing.utils.Enchantment> getEnchantments() {return this.enchantment;}
@Override
public List<ItemFlag> getItemFlags() {return this.itemFlags;}
@Override
public String getName() {return this.name;}
}

View File

@@ -0,0 +1,17 @@
package net.momirealms.customfishing.item;
import net.momirealms.customfishing.utils.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import java.util.List;
import java.util.Map;
public interface Item {
String getMaterial();
List<Enchantment> getEnchantments();
List<ItemFlag> getItemFlags();
String getName();
List<String> getLore();
Map<?, ?> getNbt();
}

View File

@@ -0,0 +1,97 @@
package net.momirealms.customfishing.item;
import net.momirealms.customfishing.ConfigReader;
import net.momirealms.customfishing.requirements.Requirement;
import net.momirealms.customfishing.bar.Difficulty;
import net.momirealms.customfishing.utils.VectorUtil;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import java.util.*;
public class Loot implements Item {
private final String key;
private final String name;
private String nick;
private List<String> lore;
private Map<?, ?> nbt;
private String material;
private String msg;
private String mm;
private String layout;
private VectorUtil vectorUtil;
private final Difficulty difficulty;
private final int weight;
private List<Requirement> requirements;
private final int time;
private int mmLevel;
private int exp;
private List<String> commands;
private String group;
private List<net.momirealms.customfishing.utils.Enchantment> enchantment;
private List<ItemFlag> itemFlags;
private boolean showInFinder;
public Loot(String key, String name, Difficulty difficulty, int weight, int time){
this.key = key;
this.name = name;
this.difficulty = difficulty;
this.weight = weight;
this.time = time;
}
public String getKey(){return this.key;}
public String getNick(){return this.nick;}
public String getMsg(){return this.msg;}
public String getLayout(){return this.layout;}
public String getMm(){return this.mm;}
public boolean isShowInFinder() {return this.showInFinder;}
public List<String> getCommands(){return this.commands;}
public Difficulty getDifficulty(){return this.difficulty;}
public int getWeight(){return this.weight;}
public List<Requirement> getRequirements() { return this.requirements; }
public int getTime(){ return this.time; }
public int getMmLevel(){ return this.mmLevel; }
public VectorUtil getVectorUtil(){ return this.vectorUtil; }
public String getGroup() {return group;}
public int getExp() {return exp;}
@Override
public List<String> getLore(){return this.lore;}
@Override
public String getName(){return this.name;}
@Override
public String getMaterial(){return this.material;}
@Override
public List<net.momirealms.customfishing.utils.Enchantment> getEnchantments() {return this.enchantment;}
@Override
public List<ItemFlag> getItemFlags() {return this.itemFlags;}
@Override
public Map<?, ?> getNbt(){return this.nbt;}
public void setShowInFinder(boolean showInFinder) {this.showInFinder = showInFinder;}
public void setLore(List<String> lore){this.lore = lore;}
public void setNbt(Map<?, ?> nbt){this.nbt = nbt;}
public void setRequirements(List<Requirement> requirements) {this.requirements = requirements;}
public void setMaterial(String material){this.material = material;}
public void setNick(String nick){this.nick = nick;}
public void setMsg(String msg){this.msg = msg;}
public void setMm(String mm){this.mm = mm;}
public void setLayout(String layout){this.layout = layout;}
public void setVectorUtil(VectorUtil vectorUtil){this.vectorUtil = vectorUtil;}
public void setCommands(List<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 setItemFlags(List<ItemFlag> itemFlags) {this.itemFlags = itemFlags;}
public void setEnchantment(List<net.momirealms.customfishing.utils.Enchantment> enchantment) {this.enchantment = enchantment;}
public static void givePlayerLoot(Player player, String lootKey, int amount){
ItemStack itemStack = ConfigReader.LOOTITEM.get(lootKey);
if (itemStack == null) return;
itemStack.setAmount(amount);
player.getInventory().addItem(itemStack);
}
}

View File

@@ -0,0 +1,64 @@
package net.momirealms.customfishing.item;
import net.momirealms.customfishing.ConfigReader;
import net.momirealms.customfishing.utils.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Rod implements Item{
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 int difficulty;
private double doubleLoot;
private List<net.momirealms.customfishing.utils.Enchantment> enchantment;
private List<ItemFlag> itemFlags;
public Rod(String name) {
this.name = name;
}
public static void givePlayerRod(Player player, String rodKey, int amount){
ItemStack itemStack = ConfigReader.RODITEM.get(rodKey);
itemStack.setAmount(amount);
player.getInventory().addItem(itemStack);
}
public void setDifficulty(int difficulty) {this.difficulty = difficulty;}
public void setDoubleLoot(double doubleLoot) {this.doubleLoot = doubleLoot;}
public void setNbt(Map<?, ?> nbt) {this.nbt = nbt;}
public void setLore(List<String> lore) {this.lore = lore;}
public void setEnchantment(List<net.momirealms.customfishing.utils.Enchantment> enchantment) {this.enchantment = enchantment;}
public void setItemFlags(List<ItemFlag> itemFlags) {this.itemFlags = itemFlags;}
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;}
@Override
public Map<?, ?> getNbt() {return nbt;}
@Override
public String getMaterial() {return "fishing_rod";}
@Override
public List<Enchantment> getEnchantments() {return this.enchantment;}
@Override
public List<ItemFlag> getItemFlags() {return this.itemFlags;}
@Override
public String getName() {return this.name;}
@Override
public List<String> getLore() {return this.lore;}
public double getTime() {return time;}
public HashMap<String, Double> getWeightMQ() {return weightMQ;}
public HashMap<String, Integer> getWeightPM() {return weightPM;}
}

View File

@@ -0,0 +1,51 @@
package net.momirealms.customfishing.item;
import net.momirealms.customfishing.ConfigReader;
import net.momirealms.customfishing.utils.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import java.util.List;
import java.util.Map;
public class Util implements Item{
private final String key;
private final String name;
private List<String> lore;
private Map<?, ?> nbt;
private final String material;
private List<net.momirealms.customfishing.utils.Enchantment> enchantment;
private List<ItemFlag> itemFlags;
public Util(String key, String name, String material){
this.key = key;
this.name = name;
this.material = material;
}
public String getKey(){return this.key;}
public List<String> getLore(){return this.lore;}
public String getMaterial(){return this.material;}
@Override
public String getName(){return this.name;}
@Override
public List<Enchantment> getEnchantments() {return this.enchantment;}
@Override
public List<ItemFlag> getItemFlags() {return this.itemFlags;}
@Override
public Map<?, ?> getNbt(){return this.nbt;}
public void setLore(List<String> lore){this.lore = lore;}
public void setNbt(Map<?, ?> nbt){this.nbt = nbt;}
public void setEnchantment(List<net.momirealms.customfishing.utils.Enchantment> enchantment) {this.enchantment = enchantment;}
public void setItemFlags(List<ItemFlag> itemFlags) {this.itemFlags = itemFlags;}
public static void givePlayerUtil(Player player, String utilKey, int amount){
ItemStack itemStack = ConfigReader.UTILITEM.get(utilKey);
itemStack.setAmount(amount);
player.getInventory().addItem(itemStack);
}
}

View File

@@ -5,6 +5,12 @@ import de.tr7zw.changeme.nbtapi.NBTItem;
import net.momirealms.customfishing.AdventureManager;
import net.momirealms.customfishing.ConfigReader;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.bar.Difficulty;
import net.momirealms.customfishing.bar.FishingPlayer;
import net.momirealms.customfishing.bar.Layout;
import net.momirealms.customfishing.item.Bait;
import net.momirealms.customfishing.item.Loot;
import net.momirealms.customfishing.item.Rod;
import net.momirealms.customfishing.requirements.FishingCondition;
import net.momirealms.customfishing.requirements.Requirement;
import net.momirealms.customfishing.timer.Timer;
@@ -22,7 +28,6 @@ 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.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.potion.PotionEffect;
@@ -35,7 +40,8 @@ import java.util.concurrent.ConcurrentHashMap;
public class PlayerListener implements Listener {
private final HashMap<Player, Long> coolDown = new HashMap<>();
private final HashMap<Player, LootInstance> nextLoot = new HashMap<>();
private final HashMap<Player, Loot> nextLoot = new HashMap<>();
private final HashMap<Player, Integer> modifier = new HashMap<>();
private final HashSet<Player> willDouble = new HashSet<>();
public static ConcurrentHashMap<Player, FishingPlayer> fishingPlayers = new ConcurrentHashMap<>();
@@ -56,12 +62,17 @@ 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;
int difficultyModifier = 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());
@@ -69,23 +80,25 @@ public class PlayerListener implements Listener {
if (nbtCompound != null){
if (nbtCompound.getString("type").equals("rod")) {
String key = nbtCompound.getString("id");
RodInstance rod = ConfigReader.ROD.get(key);
Rod rod = ConfigReader.ROD.get(key);
if (rod != null){
pm1 = rod.getWeightPM();
mq1 = rod.getWeightMQ();
if (rod.getTime() != 0) timeModifier *= rod.getTime();
if (rod.getDoubleLoot() != 0) doubleLoot += rod.getDoubleLoot();
if (rod.getDifficulty() != 0) difficultyModifier += rod.getDifficulty();
noRod = false;
}
}
else if (nbtCompound.getString("type").equals("bait")){
String key = nbtCompound.getString("id");
BaitInstance bait = ConfigReader.BAIT.get(key);
Bait bait = ConfigReader.BAIT.get(key);
if (bait != null){
pm1 = bait.getWeightPM();
mq1 = bait.getWeightMQ();
if (bait.getTime() != 0) timeModifier *= bait.getTime();
if (bait.getDoubleLoot() != 0) doubleLoot += bait.getDoubleLoot();
if (bait.getDifficulty() != 0) difficultyModifier += bait.getDifficulty();
mainHandItem.setAmount(mainHandItem.getAmount() - 1);
}
}
@@ -94,6 +107,7 @@ public class PlayerListener implements Listener {
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());
@@ -101,22 +115,24 @@ public class PlayerListener implements Listener {
if (offHandCompound != null){
if (offHandCompound.getString("type").equals("bait")) {
String key = offHandCompound.getString("id");
BaitInstance bait = ConfigReader.BAIT.get(key);
Bait bait = ConfigReader.BAIT.get(key);
if (bait != null){
pm2 = bait.getWeightPM();
mq2 = bait.getWeightMQ();
if (bait.getTime() != 0) timeModifier *= bait.getTime();
if (bait.getDoubleLoot() != 0) doubleLoot += bait.getDoubleLoot();
if (bait.getDifficulty() != 0) difficultyModifier += bait.getDifficulty();
offHandItem.setAmount(offHandItem.getAmount() - 1);
}
}else if (noRod && offHandCompound.getString("type").equals("rod")){
String key = offHandCompound.getString("id");
RodInstance rod = ConfigReader.ROD.get(key);
Rod rod = ConfigReader.ROD.get(key);
if (rod != null){
pm2 = rod.getWeightPM();
mq2 = rod.getWeightMQ();
if (rod.getTime() != 0) timeModifier *= rod.getTime();
if (rod.getDoubleLoot() != 0) doubleLoot += rod.getDoubleLoot();
if (rod.getDifficulty() != 0) difficultyModifier += rod.getDifficulty();
noRod = false;
}
}
@@ -129,34 +145,46 @@ public class PlayerListener implements Listener {
return;
}
//时间修改
FishHook hook = event.getHook();
hook.setMaxWaitTime((int) (timeModifier * hook.getMaxWaitTime()));
hook.setMinWaitTime((int) (timeModifier * hook.getMinWaitTime()));
//获取抛竿位置处可能的Loot实例列表
List<LootInstance> possibleLoots = getPossibleLootList(new FishingCondition(player, hook.getLocation()));
List<LootInstance> availableLoots = new ArrayList<>();
List<Loot> possibleLoots = getPossibleLootList(new FishingCondition(player, hook.getLocation()));
List<Loot> availableLoots = new ArrayList<>();
if (possibleLoots.size() == 0){
nextLoot.put(player, null);
return;
}
//双倍掉落
if (doubleLoot > Math.random()) {
willDouble.add(player);
}else {
willDouble.remove(player);
}
//难度修改
modifier.put(player, difficultyModifier);
double[] weights = new double[possibleLoots.size()];
int index = 0;
for (LootInstance loot : possibleLoots){
for (Loot loot : possibleLoots){
double weight = loot.getWeight();
String group =loot.getGroup();
String group = loot.getGroup();
if (group != null){
if (pm1.get(group) != null){
if (pm1 != null && pm1.get(group) != null){
weight += pm1.get(group);
}
if (pm2.get(group) != null){
if (pm2!= null && pm2.get(group) != null){
weight += pm2.get(group);
}
if (mq1.get(group) != null){
if (mq1 != null && mq1.get(group) != null){
weight *= mq1.get(group);
}
if (mq2.get(group) != null){
if (mq2 != null && mq2.get(group) != null){
weight *= mq2.get(group);
}
}
@@ -177,29 +205,17 @@ public class PlayerListener implements Listener {
weightRange[i] = startPos + weightRatios[i];
startPos += weightRatios[i];
}
//根据随机数所落区间获取Loot实例
double random = Math.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 < weightRange.length && random < weightRange[pos]) {
if (doubleLoot > Math.random()) {
willDouble.add(player);
}else {
willDouble.remove(player);
}
nextLoot.put(player, availableLoots.get(pos));
return;
}
@@ -217,7 +233,7 @@ public class PlayerListener implements Listener {
Bukkit.getScheduler().runTaskAsynchronously(CustomFishing.instance, ()-> {
LootInstance lootInstance = nextLoot.get(player);
Loot lootInstance = nextLoot.get(player);
//获取布局名,或是随机布局
String layout = Optional.ofNullable(lootInstance.getLayout()).orElseGet(() ->{
Random generator = new Random();
@@ -225,67 +241,21 @@ 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);
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;
}
}
}
}
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;
}
}
}
int difficulty = lootInstance.getDifficulty().getSpeed();
difficulty += modifier.get(player);
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, lootInstance.getDifficulty(), layout)
new Timer(player, difficult, layout)
)
);
Bukkit.getScheduler().callSyncMethod(CustomFishing.instance, ()->{
Bukkit.getScheduler().runTask(CustomFishing.instance, ()->{
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, lootInstance.getTime()/50,3));
return null;
});
});
}
@@ -295,13 +265,12 @@ public class PlayerListener implements Listener {
//发现有特殊鱼,那么必须掉落特殊鱼
if (fishingPlayers.get(player) != null){
//清除原版战利品
if (event.getCaught() != null){
event.getCaught().remove();
event.setExpToDrop(0);
}
LootInstance lootInstance = nextLoot.get(player);
LayoutUtil layout = ConfigReader.LAYOUT.get(fishingPlayers.get(player).getTimer().getLayout());
Loot lootInstance = nextLoot.get(player);
Layout layout = ConfigReader.LAYOUT.get(fishingPlayers.get(player).getTimer().getLayout());
int last = (fishingPlayers.get(player).getTimer().getTimerTask().getProgress() + 1)/layout.getRange();
fishingPlayers.remove(player);
player.removePotionEffect(PotionEffectType.SLOW);
@@ -374,19 +343,19 @@ public class PlayerListener implements Listener {
player.removePotionEffect(PotionEffectType.SLOW);
coolDown.remove(player);
nextLoot.remove(player);
modifier.remove(player);
willDouble.remove(player);
fishingPlayers.remove(player);
}
@EventHandler
public void onInteract(PlayerInteractEvent event){
if (!event.hasItem()) return;
if (!(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
ItemStack itemStack = event.getItem();
if (itemStack.getType() == Material.AIR) return;
if (itemStack == null || itemStack.getType() == Material.AIR) return;
NBTItem nbtItem = new NBTItem(itemStack);
if (nbtItem.getCompound("CustomFishing") == null) return;
if (nbtItem.getCompound("CustomFishing").getString("type").equals("util") || nbtItem.getCompound("CustomFishing").getString("id").equals("fishfinder")){
if (nbtItem.getCompound("CustomFishing").getString("type").equals("util") && nbtItem.getCompound("CustomFishing").getString("id").equals("fishfinder")){
Player player = event.getPlayer();
//设置冷却时间
long time = System.currentTimeMillis();
@@ -396,24 +365,24 @@ public class PlayerListener implements Listener {
}
coolDown.put(player, time);
//获取玩家位置处可能的Loot实例列表
List<LootInstance> possibleLoots = getPossibleLootList(new FishingCondition(player, player.getLocation()));
List<Loot> possibleLoots = getFinder(new FishingCondition(player, player.getLocation()));
if (possibleLoots.size() == 0){
AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.noLoot);
return;
}
StringBuilder stringBuilder = new StringBuilder(ConfigReader.Message.prefix + ConfigReader.Message.possibleLoots);
possibleLoots.forEach(loot -> stringBuilder.append(loot.getNick()).append(ConfigReader.Message.splitChar));
AdventureManager.playerMessage(player, stringBuilder.substring(0, stringBuilder.length()-1));
AdventureManager.playerMessage(player, stringBuilder.substring(0, stringBuilder.length()-ConfigReader.Message.splitChar.length()));
}
}
/*
获取可能的Loot列表
*/
private List<LootInstance> getPossibleLootList(FishingCondition fishingCondition) {
List<LootInstance> available = new ArrayList<>();
private List<Loot> getPossibleLootList(FishingCondition fishingCondition) {
List<Loot> available = new ArrayList<>();
ConfigReader.LOOT.keySet().forEach(key -> {
LootInstance loot = ConfigReader.LOOT.get(key);
Loot loot = ConfigReader.LOOT.get(key);
List<Requirement> requirements = loot.getRequirements();
if (requirements == null){
available.add(loot);
@@ -431,60 +400,27 @@ 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];
// }
private List<Loot> getFinder(FishingCondition fishingCondition) {
List<Loot> available = new ArrayList<>();
ConfigReader.LOOT.keySet().forEach(key -> {
Loot loot = ConfigReader.LOOT.get(key);
if (!loot.isShowInFinder()) return;
List<Requirement> requirements = loot.getRequirements();
if (requirements == null){
available.add(loot);
}else {
boolean isMet = true;
for (Requirement requirement : requirements){
if (!requirement.isConditionMet(fishingCondition)){
isMet = false;
}
}
if (isMet){
available.add(loot);
}
}
});
return available;
}
}

View File

@@ -1,7 +1,7 @@
package net.momirealms.customfishing.timer;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.utils.Difficulty;
import net.momirealms.customfishing.bar.Difficulty;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;

View File

@@ -3,14 +3,15 @@ package net.momirealms.customfishing.timer;
import net.momirealms.customfishing.AdventureManager;
import net.momirealms.customfishing.ConfigReader;
import net.momirealms.customfishing.CustomFishing;
import net.momirealms.customfishing.utils.Difficulty;
import net.momirealms.customfishing.utils.LayoutUtil;
import net.momirealms.customfishing.bar.Difficulty;
import net.momirealms.customfishing.bar.Layout;
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;
import org.bukkit.scheduler.BukkitScheduler;
import static net.momirealms.customfishing.listener.PlayerListener.fishingPlayers;
@@ -23,6 +24,7 @@ public class TimerTask extends BukkitRunnable {
private int internalTimer;
private final int size;
private boolean face;
private BukkitScheduler bukkitScheduler;
private final String start;
private final String bar;
@@ -38,7 +40,8 @@ public class TimerTask extends BukkitRunnable {
this.progress = 0;
this.internalTimer = 0;
this.face = true;
LayoutUtil layoutUtil = ConfigReader.LAYOUT.get(layout);
this.bukkitScheduler = Bukkit.getScheduler();
Layout layoutUtil = ConfigReader.LAYOUT.get(layout);
this.start = layoutUtil.getStart();
this.bar = layoutUtil.getBar();
this.pointer = layoutUtil.getPointer();
@@ -58,24 +61,13 @@ public class TimerTask extends BukkitRunnable {
public void run() {
//移除提前收杆玩家
if (fishingPlayers.get(player) == null){
Bukkit.getScheduler().cancelTask(taskID);
return;
}
//移除切换物品的玩家
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, ()-> {
player.removePotionEffect(PotionEffectType.SLOW);
return null;
});
bukkitScheduler.cancelTask(taskID);
return;
}
//移除超时玩家
if (System.currentTimeMillis() > fishingPlayers.get(player).getFishingTime()){
fishingPlayers.remove(player);
Bukkit.getScheduler().cancelTask(taskID);
bukkitScheduler.cancelTask(taskID);
return;
}
int timer = difficulty.getTimer() - 1;
@@ -89,6 +81,7 @@ public class TimerTask extends BukkitRunnable {
//内部计时器操控
if (internalTimer < timer){
internalTimer++;
return;
}else {
if (face){
internalTimer -= timer;
@@ -109,5 +102,14 @@ public class TimerTask extends BukkitRunnable {
}
stringBuilder.append(end);
AdventureManager.playerTitle(player, title, stringBuilder.toString(),0,300,0);
//移除切换物品的玩家
PlayerInventory playerInventory = player.getInventory();
if (playerInventory.getItemInMainHand().getType() != Material.FISHING_ROD && playerInventory.getItemInOffHand().getType() != Material.FISHING_ROD){
fishingPlayers.remove(player);
bukkitScheduler.cancelTask(taskID);
bukkitScheduler.runTask(CustomFishing.instance, ()-> {
player.removePotionEffect(PotionEffectType.SLOW);
});
}
}
}

View File

@@ -0,0 +1,72 @@
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.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.momirealms.customfishing.item.Item;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.List;
public class ItemStackGenerator {
public static ItemStack fromItem(Item item){
ItemStack itemStack = new ItemStack(Material.valueOf(item.getMaterial().toUpperCase()));
ItemMeta itemMeta = itemStack.getItemMeta();
if (item.getItemFlags() != null){
item.getItemFlags().forEach(itemMeta::addItemFlags);
}
if (item.getEnchantments() != null) {
if (itemStack.getType() == Material.ENCHANTED_BOOK){
EnchantmentStorageMeta meta = (EnchantmentStorageMeta)itemMeta;
item.getEnchantments().forEach(enchantment1 -> {
meta.addStoredEnchant(org.bukkit.enchantments.Enchantment.getByKey(enchantment1.getKey()),enchantment1.getLevel(),true);
});
itemStack.setItemMeta(meta);
}else {
item.getEnchantments().forEach(enchantment1 -> {
itemMeta.addEnchant(Enchantment.getByKey(enchantment1.getKey()),enchantment1.getLevel(),true);
});
itemStack.setItemMeta(itemMeta);
}
}else {
itemStack.setItemMeta(itemMeta);
}
NBTItem nbtItem = new NBTItem(itemStack);
NBTCompound display = nbtItem.addCompound("display");
String name = item.getName();
if (name.contains("&") || name.contains("§")){
name = name.replaceAll("&","§");
display.setString("Name", GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacyAmpersand().deserialize(name)));
}else {
display.setString("Name", GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize("<italic:false>" + name)));
}
if(item.getLore() != null){
List<String> lore = display.getStringList("Lore");
item.getLore().forEach(line -> {
if (line.contains("&") || line.contains("§")){
line = line.replaceAll("&","§");
lore.add(GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacyAmpersand().deserialize(line)));
}else {
lore.add(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize("<italic:false>" + line)));
}
});
}
if (item.getNbt() != null){
NBTUtil nbtUtil = new NBTUtil(item.getNbt(), nbtItem.getItem());
return nbtUtil.getNBTItem().getItem();
}
return nbtItem.getItem();
}
}

View File

@@ -7,6 +7,7 @@ import io.lumine.mythic.api.mobs.MythicMob;
import io.lumine.mythic.bukkit.MythicBukkit;
import io.lumine.mythic.bukkit.utils.serialize.Position;
import io.lumine.mythic.core.mobs.ActiveMob;
import net.momirealms.customfishing.item.Loot;
import org.bukkit.Location;
import org.bukkit.util.Vector;
@@ -14,7 +15,7 @@ import java.util.Optional;
public class MMUtil {
public static void summonMM(Location pLocation, Location bLocation, LootInstance loot){
public static void summonMM(Location pLocation, Location bLocation, Loot loot){
MobManager mobManager = MythicBukkit.inst().getMobManager();
Optional<MythicMob> mythicMob = mobManager.getMythicMob(loot.getMm());
if (mythicMob.isPresent()) {

View File

@@ -17,6 +17,14 @@ public class NBTUtil {
this.nbtItem = new NBTItem(itemStack);
}
public static ItemStack addIdentifier(ItemStack itemStack, String type, String id){
NBTItem nbtItem = new NBTItem(itemStack);
nbtItem.addCompound("CustomFishing");
nbtItem.getCompound("CustomFishing").setString("type", type);
nbtItem.getCompound("CustomFishing").setString("id", id);
return nbtItem.getItem();
}
public NBTItem getNBTItem(){
nbt.keySet().forEach(key -> {
if (nbt.get(key) instanceof Map<?,?> map){

View File

@@ -1,15 +1,12 @@
package net.momirealms.customfishing.utils;
public class VectorUtil {
public record VectorUtil(double horizontal, double vertical) {
private final double horizontal;
private final double vertical;
public VectorUtil(double horizontal, double vertical){
this.horizontal = horizontal;
this.vertical = vertical;
public double getHorizontal() {
return this.horizontal;
}
public double getHorizontal(){return this.horizontal;}
public double getVertical(){return this.vertical;}
public double getVertical() {
return this.vertical;
}
}

View File

@@ -1,12 +1,11 @@
config:
#插件兼容
lang: cn
integrations:
#限定区域钓鱼需要启用WorldGuard兼容
WorldGuard: false
#钓MM怪需要启用MythicMobs兼容
MythicMobs: false
#使用季节特性启用PlaceholderAPI兼容
PlaceholderAPI: false
PlaceholderAPI: true
#季节特性
season:

View File

@@ -1,6 +1,3 @@
#物品库说明:
#除了display.name/weight/difficulty/material/time为必填项目其他都是可选项目
#items与mobs不可重复否则无法正确进行权重分配
#物品支持MiniMessage Format
#https://docs.adventure.kyori.net/minimessage/format.html
@@ -12,6 +9,7 @@ items:
name: '垃圾'
weight: 50
time: 100000
show-in-fishfinder: false
difficulty: 1-1
#物品内部ID
@@ -29,7 +27,7 @@ items:
#自定义NBT
#可类型(Int) (Byte) (String) (Float) (String) (Double) (Short) (Long) (UUID) (Boolean)
nbt:
- Itemsadder:
- itemsadder:
namespace: '(String) momirealms'
id: '(String) rainbow_fish'
CustomModelData: '(Int) 1'

View File

@@ -0,0 +1,19 @@
#所有位置均可使用MiniMessage Format
#https://docs.adventure.kyori.net/minimessage/format.html
messages:
prefix: '<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient>'
reload: '重载成功.'
no-perm: '你没有权限!'
not-online: '玩家不在线!'
not-exist: '此物品不存在!'
escape: '太久没拉钩鱼儿跑走啦!'
give-item: '成功给予玩家 {Player} {Amount}x {Item}.'
get-item: '成功获得 {Amount}x {Item}.'
no-console: '这个指令不能由控制台执行!'
wrong-amount: '不能给玩家数量为负数的物品!'
lack-args: '参数不足.'
cooldown: '你使用找鱼器的速度太快了!'
possible-loots: '此处可能钓到: '
split-char: ','
no-loot: '这个地方什么鱼都没有!'
not-open-water: '这里不是开放水域,你将无法获得任何奖励!'