mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-29 11:59:11 +00:00
Rod Update
This commit is contained in:
@@ -17,6 +17,8 @@ public class ConfigReader{
|
||||
public static HashMap<String, ItemStack> LOOTITEM = new HashMap<>();
|
||||
public static HashMap<String, UtilInstance> UTIL = new HashMap<>();
|
||||
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, LayoutUtil> LAYOUT = new HashMap<>();
|
||||
|
||||
private static YamlConfiguration getConfig(String configName) {
|
||||
@@ -33,6 +35,7 @@ public class ConfigReader{
|
||||
Title.loadTitle();
|
||||
loadLoot();
|
||||
loadUtil();
|
||||
loadRod();
|
||||
}
|
||||
|
||||
public static class Config {
|
||||
@@ -43,6 +46,7 @@ public class ConfigReader{
|
||||
public static boolean season;
|
||||
public static boolean vanillaDrop;
|
||||
public static boolean needOpenWater;
|
||||
public static boolean needSpecialRod;
|
||||
public static String season_papi;
|
||||
public static int fishFinderCoolDown;
|
||||
|
||||
@@ -79,12 +83,12 @@ public class ConfigReader{
|
||||
}
|
||||
}
|
||||
season = config.getBoolean("config.season.enable");
|
||||
if (!papi && season){
|
||||
if (!papi && season) {
|
||||
season = false;
|
||||
AdventureManager.consoleMessage("<red>[CustomFishing] 使用季节特性请先打开 PlaceholderAPI 兼容!</red>");
|
||||
}
|
||||
|
||||
if (season){
|
||||
if (season) {
|
||||
season_papi = config.getString("config.season.papi");
|
||||
}else {
|
||||
season_papi = null;
|
||||
@@ -92,6 +96,7 @@ public class ConfigReader{
|
||||
|
||||
vanillaDrop = config.getBoolean("config.vanilla-loot-when-no-custom-fish");
|
||||
needOpenWater = config.getBoolean("config.need-open-water");
|
||||
needSpecialRod = config.getBoolean("config.need-special-rod");
|
||||
fishFinderCoolDown = config.getInt("config.fishfinder-cooldown");
|
||||
|
||||
/*
|
||||
@@ -279,8 +284,12 @@ public class ConfigReader{
|
||||
loot.setMsg(config.getString("items." + key + ".action.message"));
|
||||
if (config.contains("items." + key + ".action.command"))
|
||||
loot.setCommands(config.getStringList("items." + key + ".action.command"));
|
||||
if (config.contains("items." + key + "layout"))
|
||||
loot.setLayout(config.getString("items." + key + "layout"));
|
||||
if (config.contains("items." + key + ".action.exp"))
|
||||
loot.setExp(config.getInt("items." + key + ".action.exp"));
|
||||
if (config.contains("items." + key + ".layout"))
|
||||
loot.setLayout(config.getString("items." + key + ".layout"));
|
||||
if (config.contains("items." + key + ".group"))
|
||||
loot.setGroup(config.getString("items." + key + ".group"));
|
||||
/*
|
||||
设置捕获条件
|
||||
*/
|
||||
@@ -315,7 +324,7 @@ public class ConfigReader{
|
||||
//添加单例进缓存
|
||||
LOOT.put(key, loot);
|
||||
//添加根据单例生成的NBT物品进缓存
|
||||
LootInstance.addLoot2cache(key);
|
||||
loot.addLoot2cache(key);
|
||||
});
|
||||
|
||||
if (config.contains("mobs") && Config.mm){
|
||||
@@ -392,8 +401,12 @@ public class ConfigReader{
|
||||
loot.setMsg(config.getString("mobs." + key + ".action.message"));
|
||||
if (config.contains("mobs." + key + ".action.command"))
|
||||
loot.setCommands(config.getStringList("mobs." + key + ".action.command"));
|
||||
if (config.contains("mobs." + key + "layout"))
|
||||
if (config.contains("mobs." + key + ".action.exp"))
|
||||
loot.setExp(config.getInt("mobs." + key + ".action.exp"));
|
||||
if (config.contains("mobs." + key + ".layout"))
|
||||
loot.setLayout(config.getString("mobs." + key + "layout"));
|
||||
if (config.contains("mobs." + key + ".group"))
|
||||
loot.setGroup(config.getString("mobs." + key + ".group"));
|
||||
/*
|
||||
设置捕获条件
|
||||
*/
|
||||
@@ -480,7 +493,7 @@ public class ConfigReader{
|
||||
utilInstance.setNbt(config.getMapList("utils." + key + ".nbt").get(0));
|
||||
|
||||
UTIL.put(key, utilInstance);
|
||||
UtilInstance.addUtil2cache(key);
|
||||
utilInstance.addUtil2cache(key);
|
||||
});
|
||||
if (keys.size() != UTILITEM.size()){
|
||||
AdventureManager.consoleMessage("<red>[CustomFishing] utils.yml 文件存在配置错误!</red>");
|
||||
@@ -488,4 +501,63 @@ public class ConfigReader{
|
||||
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><white>从 utils.yml 载入了<green>" + keys.size() + "<white>条工具数据");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
载入rod物品
|
||||
*/
|
||||
public static void loadRod() {
|
||||
|
||||
ROD.clear();
|
||||
RODITEM.clear();
|
||||
|
||||
YamlConfiguration config = getConfig("rods.yml");
|
||||
Set<String> keys = Objects.requireNonNull(config.getConfigurationSection("rods")).getKeys(false);
|
||||
|
||||
keys.forEach(key -> {
|
||||
String name;
|
||||
if (config.contains("rods." + key + ".display.name")) {
|
||||
name = config.getString("rods." + key + ".display.name");
|
||||
} else {
|
||||
AdventureManager.consoleMessage("<red>[CustomFishing] 错误! 未设置 " + key + " 的物品名称!</red>");
|
||||
return;
|
||||
}
|
||||
RodInstance rodInstance = new RodInstance(name);
|
||||
if (config.contains("rods." + key + ".display.lore")) {
|
||||
rodInstance.setLore(config.getStringList("rods." + key + ".display.lore"));
|
||||
}
|
||||
if (config.contains("rods." + key + ".nbt")) {
|
||||
rodInstance.setNbt(config.getMapList("rods." + key + ".nbt").get(0));
|
||||
}
|
||||
if (config.contains("rods." + key + ".modifier")){
|
||||
config.getConfigurationSection("rods." + key + ".modifier").getKeys(false).forEach(modifier -> {
|
||||
switch (modifier){
|
||||
case "weight-PM" -> {
|
||||
HashMap<String, Integer> pm = new HashMap<>();
|
||||
config.getConfigurationSection("rods." + key + ".modifier.weight-PM").getValues(false).forEach((group, value) -> {
|
||||
pm.put(group, (Integer) value);
|
||||
});
|
||||
rodInstance.setWeightPM(pm);
|
||||
}
|
||||
case "weight-MQ" -> {
|
||||
HashMap<String, Double> mq = new HashMap<>();
|
||||
config.getConfigurationSection("rods." + key + ".modifier.weight-MQ").getValues(false).forEach((group, value) -> {
|
||||
mq.put(group, (Double) value);
|
||||
});
|
||||
rodInstance.setWeightMQ(mq);
|
||||
}
|
||||
case "time" -> rodInstance.setTime(config.getDouble("rods." + key + ".modifier.time"));
|
||||
case "difficulty" -> rodInstance.setDifficulty(config.getInt("rods." + key + ".modifier.difficulty"));
|
||||
}
|
||||
});
|
||||
}
|
||||
ROD.put(key, rodInstance);
|
||||
rodInstance.addRod2Cache(key);
|
||||
});
|
||||
|
||||
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>条鱼竿数据");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.momirealms.customfishing.command;
|
||||
import net.momirealms.customfishing.AdventureManager;
|
||||
import net.momirealms.customfishing.ConfigReader;
|
||||
import net.momirealms.customfishing.utils.LootInstance;
|
||||
import net.momirealms.customfishing.utils.RodInstance;
|
||||
import net.momirealms.customfishing.utils.UtilInstance;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -103,7 +104,7 @@ public class Execute implements CommandExecutor {
|
||||
*/
|
||||
else if(args[1].equalsIgnoreCase("util")){
|
||||
if (args[2].equalsIgnoreCase("get")) {
|
||||
//检验参数长度 [0]items [1]loot [2]get [3]xxx [4](amount)
|
||||
//检验参数长度 [0]items [1]util [2]get [3]xxx [4](amount)
|
||||
if (sender instanceof Player player){
|
||||
//是否存在于缓存中
|
||||
if (!ConfigReader.UTIL.containsKey(args[3])){
|
||||
@@ -127,7 +128,7 @@ public class Execute implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
if (args[2].equalsIgnoreCase("give")) {
|
||||
//检验参数长度 [0]items [1]loot [2]give [3]player [4]xxx [5](amount)
|
||||
//检验参数长度 [0]items [1]util [2]give [3]player [4]xxx [5](amount)
|
||||
if (args.length < 5){
|
||||
lackArgs(sender);
|
||||
return true;
|
||||
@@ -157,6 +158,62 @@ public class Execute implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (args[1].equalsIgnoreCase("rod")){
|
||||
if (args[2].equalsIgnoreCase("get")) {
|
||||
//检验参数长度 [0]items [1]rod [2]get [3]xxx [4](amount)
|
||||
if (sender instanceof Player player){
|
||||
//是否存在于缓存中
|
||||
if (!ConfigReader.ROD.containsKey(args[3])){
|
||||
noItem(sender);
|
||||
return true;
|
||||
}
|
||||
if (args.length == 4){
|
||||
RodInstance.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]));
|
||||
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]rod [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.ROD.containsKey(args[4])){
|
||||
noItem(sender);
|
||||
return true;
|
||||
}
|
||||
if (args.length == 5){
|
||||
RodInstance.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]));
|
||||
giveItem(sender, args[3], args[4], Integer.parseInt(args[5]));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -43,13 +43,20 @@ public class TabComplete implements TabCompleter {
|
||||
if (args[2].equalsIgnoreCase("get")){
|
||||
return loots();
|
||||
}
|
||||
}else if(args[1].equalsIgnoreCase("util")){
|
||||
}else if (args[1].equalsIgnoreCase("util")){
|
||||
if (args[2].equalsIgnoreCase("give")){
|
||||
return online_players();
|
||||
}
|
||||
if (args[2].equalsIgnoreCase("get")){
|
||||
return utils();
|
||||
}
|
||||
}else if (args[1].equalsIgnoreCase("rod")){
|
||||
if (args[2].equalsIgnoreCase("give")){
|
||||
return online_players();
|
||||
}
|
||||
if (args[2].equalsIgnoreCase("get")){
|
||||
return rods();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,10 +66,14 @@ public class TabComplete implements TabCompleter {
|
||||
if (args[2].equalsIgnoreCase("give")){
|
||||
return loots();
|
||||
}
|
||||
}else if(args[1].equalsIgnoreCase("util")){
|
||||
}else if (args[1].equalsIgnoreCase("util")){
|
||||
if (args[2].equalsIgnoreCase("give")){
|
||||
return utils();
|
||||
}
|
||||
}else if (args[1].equalsIgnoreCase("rod")){
|
||||
if (args[2].equalsIgnoreCase("give")){
|
||||
return rods();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,4 +92,7 @@ public class TabComplete implements TabCompleter {
|
||||
private List<String> utils(){
|
||||
return new ArrayList<>(ConfigReader.UTIL.keySet());
|
||||
}
|
||||
private List<String> rods() {
|
||||
return new ArrayList<>(ConfigReader.ROD.keySet());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
package net.momirealms.customfishing.listener;
|
||||
|
||||
import de.tr7zw.changeme.nbtapi.NBTCompound;
|
||||
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.requirements.FishingCondition;
|
||||
import net.momirealms.customfishing.requirements.Requirement;
|
||||
import net.momirealms.customfishing.timer.Timer;
|
||||
import net.momirealms.customfishing.utils.FishingPlayer;
|
||||
import net.momirealms.customfishing.utils.LayoutUtil;
|
||||
import net.momirealms.customfishing.utils.LootInstance;
|
||||
import net.momirealms.customfishing.utils.MMUtil;
|
||||
import net.momirealms.customfishing.utils.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.FishHook;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -35,25 +36,70 @@ public class PlayerListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onFish(PlayerFishEvent event){
|
||||
|
||||
PlayerFishEvent.State state = event.getState();
|
||||
Player player = event.getPlayer();
|
||||
|
||||
//抛竿
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
coolDown.put(player, time);
|
||||
|
||||
FishHook hook = event.getHook();
|
||||
hook.setMaxWaitTime((int) (timeModifier * hook.getMaxWaitTime()));
|
||||
hook.setMinWaitTime((int) (timeModifier * hook.getMinWaitTime()));
|
||||
|
||||
//获取抛竿位置处可能的Loot实例列表
|
||||
List<LootInstance> possibleLoots = getPossibleLootList(new FishingCondition(player, event.getHook().getLocation()));
|
||||
List<LootInstance> possibleLoots = getPossibleLootList(new FishingCondition(player, hook.getLocation()));
|
||||
List<LootInstance> availableLoots = new ArrayList<>();
|
||||
if (possibleLoots.size() == 0){
|
||||
nextLoot.put(player, null);
|
||||
return;
|
||||
}
|
||||
//计算总权重
|
||||
int totalWeight = 0;
|
||||
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 (mq.get(group) != null){
|
||||
weight = weight * mq.get(group);
|
||||
}
|
||||
}
|
||||
//需要进行weight修改
|
||||
if (weight <= 0) continue;
|
||||
availableLoots.add(loot);
|
||||
totalWeight += loot.getWeight();
|
||||
}
|
||||
//计算每种鱼权重所占的比例并输入数组
|
||||
@@ -61,10 +107,21 @@ public class PlayerListener implements Listener {
|
||||
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 (mq.get(group) != null){
|
||||
weight = weight * mq.get(group);
|
||||
}
|
||||
}
|
||||
//需要进行weight修改
|
||||
if (weight <= 0) continue;
|
||||
weightRatios[index++] = weight / totalWeight;
|
||||
}
|
||||
//根据权重比例划分定义域
|
||||
double[] weights = new double[possibleLoots.size()];
|
||||
double[] weights = new double[availableLoots.size()];
|
||||
double startPos = 0;
|
||||
for (int i = 0; i < index; i++) {
|
||||
weights[i] = startPos + weightRatios[i];
|
||||
@@ -79,11 +136,11 @@ public class PlayerListener implements Listener {
|
||||
pos = -pos - 1;
|
||||
} else {
|
||||
//如果存在,那真是中大奖了!
|
||||
nextLoot.put(player, possibleLoots.get(pos));
|
||||
nextLoot.put(player, availableLoots.get(pos));
|
||||
return;
|
||||
}
|
||||
if (pos < weights.length && random < weights[pos]) {
|
||||
nextLoot.put(player, possibleLoots.get(pos));
|
||||
nextLoot.put(player, availableLoots.get(pos));
|
||||
return;
|
||||
}
|
||||
//以防万一,丢入空值
|
||||
@@ -103,6 +160,31 @@ public class PlayerListener implements Listener {
|
||||
Object[] values = ConfigReader.LAYOUT.keySet().toArray();
|
||||
return (String) values[generator.nextInt(values.length)];
|
||||
});
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//根据鱼的时间放入玩家实例,并应用药水效果
|
||||
fishingPlayers.put(player,
|
||||
new FishingPlayer(System.currentTimeMillis() + lootInstance.getTime(),
|
||||
@@ -119,6 +201,7 @@ public class PlayerListener implements Listener {
|
||||
//清除原版战利品
|
||||
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());
|
||||
@@ -158,6 +241,10 @@ public class PlayerListener implements Listener {
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), finalCommand);
|
||||
});
|
||||
}
|
||||
if (lootInstance.getExp() != 0){
|
||||
player.giveExp(lootInstance.getExp(),true);
|
||||
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1,1);
|
||||
}
|
||||
//发送Title
|
||||
AdventureManager.playerTitle(player, ConfigReader.Title.success_title.get((int) (ConfigReader.Title.success_title.size()*Math.random())).replace("{loot}",lootInstance.getNick()), ConfigReader.Title.success_subtitle.get((int) (ConfigReader.Title.success_subtitle.size()*Math.random())).replace("{loot}",lootInstance.getNick()), ConfigReader.Title.success_in, ConfigReader.Title.success_stay, ConfigReader.Title.success_out);
|
||||
}else {
|
||||
@@ -174,6 +261,7 @@ public class PlayerListener implements Listener {
|
||||
if (event.getCaught() != null){
|
||||
event.getCaught().remove();
|
||||
}
|
||||
event.setExpToDrop(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,4 +21,4 @@ public class Timer {
|
||||
public TimerTask getTimerTask(){ return this.timerTask; }
|
||||
public int getTaskID (){ return this.task.getTaskId(); }
|
||||
public String getLayout(){return this.layout;}
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,9 @@ public class LootInstance {
|
||||
private List<Requirement> requirements;
|
||||
private final int time;
|
||||
private int mmLevel;
|
||||
private int exp;
|
||||
private List<String> commands;
|
||||
private String group;
|
||||
|
||||
public LootInstance(String key, String name, Difficulty difficulty, int weight, int time){
|
||||
this.key = key;
|
||||
@@ -70,6 +72,14 @@ public class LootInstance {
|
||||
public int getMmLevel(){ return this.mmLevel; }
|
||||
public VectorUtil getVectorUtil(){ return this.vectorUtil; }
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public int getExp() {
|
||||
return exp;
|
||||
}
|
||||
|
||||
public void setLore(List<String> lore){
|
||||
this.lore = lore;
|
||||
}
|
||||
@@ -86,25 +96,31 @@ public class LootInstance {
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
将实例转换为缓存中的NBT物品
|
||||
*/
|
||||
public static void addLoot2cache(String lootKey){
|
||||
//从缓存中请求物品Item
|
||||
LootInstance loot = ConfigReader.LOOT.get(lootKey);
|
||||
ItemStack itemStack = new ItemStack(Material.valueOf(loot.material.toUpperCase()));
|
||||
将实例转换为缓存中的NBT物品
|
||||
*/
|
||||
public void addLoot2cache(String lootKey){
|
||||
ItemStack itemStack = new ItemStack(Material.valueOf(this.material.toUpperCase()));
|
||||
NBTItem nbtItem = new NBTItem(itemStack);
|
||||
//设置Name和Lore
|
||||
NBTCompound display = nbtItem.addCompound("display");
|
||||
display.setString("Name", GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize("<italic:false>"+loot.name)));
|
||||
if(loot.lore != null){
|
||||
display.setString("Name", GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize("<italic:false>" + this.name)));
|
||||
if(this.lore != null){
|
||||
List<String> lores = display.getStringList("Lore");
|
||||
loot.lore.forEach(lore -> lores.add(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize("<italic:false>"+lore))));
|
||||
this.lore.forEach(lore -> lores.add(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize("<italic:false>" + lore))));
|
||||
}
|
||||
//设置NBT
|
||||
//添加物品进入缓存
|
||||
if (loot.nbt != null){
|
||||
NBTUtil nbtUtil = new NBTUtil(loot.nbt, nbtItem.getItem());
|
||||
if (this.nbt != null){
|
||||
NBTUtil nbtUtil = new NBTUtil(this.nbt, nbtItem.getItem());
|
||||
ConfigReader.LOOTITEM.put(lootKey, nbtUtil.getNBTItem().getItem());
|
||||
}else {
|
||||
ConfigReader.LOOTITEM.put(lootKey, nbtItem.getItem());
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
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 RodInstance {
|
||||
|
||||
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;
|
||||
|
||||
public RodInstance(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void addRod2Cache(String rodKey){
|
||||
NBTItem nbtItem = new NBTItem(new ItemStack(Material.FISHING_ROD));
|
||||
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", "rod");
|
||||
nbtCompound.setString("id", rodKey);
|
||||
ConfigReader.RODITEM.put(rodKey, nbtItem.getItem());
|
||||
}
|
||||
|
||||
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 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 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;
|
||||
}
|
||||
}
|
||||
@@ -52,22 +52,17 @@ public class UtilInstance {
|
||||
/*
|
||||
将实例转换为缓存中的NBT物品
|
||||
*/
|
||||
public static void addUtil2cache(String utilKey){
|
||||
//从缓存中请求物品Item
|
||||
UtilInstance util = ConfigReader.UTIL.get(utilKey);
|
||||
ItemStack itemStack = new ItemStack(Material.valueOf(util.material.toUpperCase()));
|
||||
public void addUtil2cache(String utilKey){
|
||||
ItemStack itemStack = new ItemStack(Material.valueOf(this.material.toUpperCase()));
|
||||
NBTItem nbtItem = new NBTItem(itemStack);
|
||||
//设置Name和Lore
|
||||
NBTCompound display = nbtItem.addCompound("display");
|
||||
display.setString("Name", GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize("<italic:false>"+util.name)));
|
||||
if (util.lore != null){
|
||||
display.setString("Name", GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize("<italic:false>" + this.name)));
|
||||
if (this.lore != null){
|
||||
List<String> lores = display.getStringList("Lore");
|
||||
util.lore.forEach(lore -> lores.add(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize("<italic:false>"+lore))));
|
||||
this.lore.forEach(lore -> lores.add(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize("<italic:false>"+lore))));
|
||||
}
|
||||
//设置NBT
|
||||
//添加物品进入缓存
|
||||
if (util.nbt != null){
|
||||
NBTUtil nbtUtil = new NBTUtil(util.nbt, nbtItem.getItem());
|
||||
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());
|
||||
@@ -77,8 +72,8 @@ public class UtilInstance {
|
||||
/*
|
||||
给予玩家某NBT物品
|
||||
*/
|
||||
public static void givePlayerUtil(Player player, String UtilKey, int amount){
|
||||
ItemStack itemStack = ConfigReader.UTILITEM.get(UtilKey);
|
||||
public static void givePlayerUtil(Player player, String utilKey, int amount){
|
||||
ItemStack itemStack = ConfigReader.UTILITEM.get(utilKey);
|
||||
itemStack.setAmount(amount);
|
||||
player.getInventory().addItem(itemStack);
|
||||
}
|
||||
|
||||
0
src/main/resources/baits.yml
Normal file
0
src/main/resources/baits.yml
Normal file
@@ -23,6 +23,9 @@ config:
|
||||
#只有在开放水域才能钓到特殊鱼
|
||||
need-open-water: true
|
||||
|
||||
#是否只有本插件的鱼竿能钓到鱼
|
||||
need-special-rod: false
|
||||
|
||||
#成功率
|
||||
#你可以自定义区域数量,这为自定义UI提供了可能
|
||||
success-rate:
|
||||
@@ -34,9 +37,9 @@ config:
|
||||
title: '鱼上钩了,集中注意!'
|
||||
subtitle:
|
||||
start: '<font:customfishing:default>'
|
||||
bar: '뀃'
|
||||
bar: '뀄'
|
||||
pointer_offset: '뀂'
|
||||
pointer: '뀄'
|
||||
pointer: '뀃'
|
||||
offset: '뀁'
|
||||
end: '</font>'
|
||||
layout:
|
||||
@@ -56,9 +59,9 @@ config:
|
||||
title: '鱼上钩了,集中注意!'
|
||||
subtitle:
|
||||
start: '<font:customfishing:default>'
|
||||
bar: '뀃'
|
||||
bar: '뀅'
|
||||
pointer_offset: '뀂'
|
||||
pointer: '뀄'
|
||||
pointer: '뀃'
|
||||
offset: '뀁'
|
||||
end: '</font>'
|
||||
layout:
|
||||
|
||||
@@ -44,8 +44,11 @@ items:
|
||||
#钓到鱼后执行的指令
|
||||
command:
|
||||
- 'say 玩家{player}在{world},{x},{y},{z}钓到了一条{loot}!'
|
||||
exp: 10
|
||||
#钓到此鱼的权重
|
||||
weight: 10
|
||||
#此鱼所在的组名
|
||||
group: normal
|
||||
|
||||
# 钓此鱼的难度
|
||||
# 难度设置,左侧为每多少tick移动一个单位,右侧为一个单位的像素距离
|
||||
@@ -99,6 +102,8 @@ mobs:
|
||||
level: 0
|
||||
#这个怪物的名字,用于在消息中提示
|
||||
name: '骷髅骑士'
|
||||
|
||||
group: creature
|
||||
#决定了MM怪的出场方式
|
||||
vector:
|
||||
#水平位移乘数
|
||||
@@ -109,6 +114,7 @@ mobs:
|
||||
message: '{loot} 登场!'
|
||||
command:
|
||||
- 'say 玩家{player}在{world},{x},{y},{z}被{loot}追杀!'
|
||||
exp: 10
|
||||
weight: 10
|
||||
difficulty: 1-6
|
||||
time: 5000
|
||||
|
||||
23
src/main/resources/rods.yml
Normal file
23
src/main/resources/rods.yml
Normal file
@@ -0,0 +1,23 @@
|
||||
rods:
|
||||
wooden_rod:
|
||||
display:
|
||||
name: '普通的木鱼竿'
|
||||
lore:
|
||||
- '就是一把普通的鱼竿而已啦'
|
||||
nbt:
|
||||
- CustomModelData: '(Int) 1'
|
||||
#鱼竿增益
|
||||
modifier:
|
||||
#改变指定组的loot权重
|
||||
#加减权重
|
||||
weight-PM:
|
||||
normal: 20
|
||||
creature: -10
|
||||
#乘除权重
|
||||
weight-MQ:
|
||||
normal: 1.8
|
||||
creature: 0.8
|
||||
#改变上鱼的时间(>1为延长,<1为缩短)
|
||||
time: 1.5
|
||||
#更改难度,例如原来难度为(1-6),现在变成(1-5)
|
||||
difficulty: -1
|
||||
Reference in New Issue
Block a user