9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-19 15:09:24 +00:00
This commit is contained in:
Xiao-MoMi
2022-07-16 12:36:20 +08:00
parent 39be85c2f9
commit ab9b580795
7 changed files with 192 additions and 17 deletions

View File

@@ -1,11 +1,14 @@
package net.momirealms.customfishing;
import net.kyori.adventure.key.Key;
import net.momirealms.customfishing.requirements.*;
import net.momirealms.customfishing.utils.*;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import java.io.File;
@@ -74,7 +77,7 @@ public class ConfigReader{
AdventureManager.consoleMessage("<red>[CustomFishing] 未检测到插件 MythicMobs!</red>");
mm = false;
}else {
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] <color:#E1FFFF>检测到 <color:#00BFFF>MythicMobs <color:#E1FFFF>已启用怪物拓展!");
AdventureManager.consoleMessage("<gradient:#0070B3:#A0EACF>[CustomFishing] </gradient><color:#E1FFFF>检测到 <color:#00BFFF>MythicMobs <color:#E1FFFF>已启用怪物拓展!");
}
}
papi = config.getBoolean("config.integrations.PlaceholderAPI");
@@ -238,10 +241,6 @@ public class ConfigReader{
int weight;
if (config.contains("items." + key + ".weight")) {
weight = config.getInt("items." + key + ".weight");
if (weight <= 0){
AdventureManager.consoleMessage("<red>[CustomFishing] 错误! " + key + " 的捕获权重必须为正整数!</red>");
return;
}
} else {
AdventureManager.consoleMessage("<red>[CustomFishing] 错误! 未设置 " + key + " 的捕获权重!</red>");
return;
@@ -275,7 +274,22 @@ public class ConfigReader{
*/
if (config.contains("items." + key + ".display.lore"))
loot.setLore(config.getStringList("items." + key + ".display.lore"));
if (config.contains("items." + key + ".enchantments")) {
ArrayList<Enchantment> arrayList = new ArrayList<>();
config.getStringList("items." + key + ".enchantments").forEach(enchant -> {
String[] split = StringUtils.split(enchant, "/");
NamespacedKey namespacedKey = NamespacedKey.fromString(split[0]);
arrayList.add(new Enchantment(namespacedKey, Integer.parseInt(split[1])));
});
loot.setEnchantment(arrayList);
}
if (config.contains("items." + key + ".item_flags")) {
ArrayList<ItemFlag> arrayList = new ArrayList<>();
config.getStringList("items." + key + ".item_flags").forEach(flag -> {
arrayList.add(ItemFlag.valueOf(flag));
});
loot.setItemFlags(arrayList);
}
if (config.contains("items." + key + ".nbt"))
loot.setNbt(config.getMapList("items." + key + ".nbt").get(0));
@@ -363,10 +377,6 @@ public class ConfigReader{
int weight;
if (config.contains("mobs." + key + ".weight")) {
weight = config.getInt("mobs." + key + ".weight");
if (weight <= 0){
AdventureManager.consoleMessage("<red>[CustomFishing] 错误! " + key + " 的捕获权重必须为正整数!</red>");
return;
}
} else {
AdventureManager.consoleMessage("<red>[CustomFishing] 错误! 未设置 " + key + " 的捕获权重!</red>");
return;
@@ -496,7 +506,22 @@ public class ConfigReader{
utilInstance.setLore(config.getStringList("utils." + key + ".display.lore"));
if (config.contains("utils." + key + ".nbt"))
utilInstance.setNbt(config.getMapList("utils." + key + ".nbt").get(0));
if (config.contains("utils." + key + ".enchantments")) {
ArrayList<Enchantment> arrayList = new ArrayList<>();
config.getStringList("utils." + key + ".enchantments").forEach(enchant -> {
String[] split = StringUtils.split(enchant, "/");
NamespacedKey namespacedKey = NamespacedKey.fromString(split[0]);
arrayList.add(new Enchantment(namespacedKey, Integer.parseInt(split[1])));
});
utilInstance.setEnchantment(arrayList);
}
if (config.contains("utils." + key + ".item_flags")) {
ArrayList<ItemFlag> arrayList = new ArrayList<>();
config.getStringList("utils." + key + ".item_flags").forEach(flag -> {
arrayList.add(ItemFlag.valueOf(flag));
});
utilInstance.setItemFlags(arrayList);
}
UTIL.put(key, utilInstance);
utilInstance.addUtil2cache(key);
});
@@ -533,6 +558,22 @@ public class ConfigReader{
if (config.contains("rods." + key + ".nbt")) {
rodInstance.setNbt(config.getMapList("rods." + key + ".nbt").get(0));
}
if (config.contains("rods." + key + ".enchantments")) {
ArrayList<Enchantment> arrayList = new ArrayList<>();
config.getStringList("rods." + key + ".enchantments").forEach(enchant -> {
String[] split = StringUtils.split(enchant, "/");
NamespacedKey namespacedKey = NamespacedKey.fromString(split[0]);
arrayList.add(new Enchantment(namespacedKey, Integer.parseInt(split[1])));
});
rodInstance.setEnchantment(arrayList);
}
if (config.contains("rods." + key + ".item_flags")) {
ArrayList<ItemFlag> arrayList = new ArrayList<>();
config.getStringList("rods." + key + ".item_flags").forEach(flag -> {
arrayList.add(ItemFlag.valueOf(flag));
});
rodInstance.setItemFlags(arrayList);
}
if (config.contains("rods." + key + ".modifier")){
config.getConfigurationSection("rods." + key + ".modifier").getKeys(false).forEach(modifier -> {
switch (modifier){
@@ -597,6 +638,22 @@ public class ConfigReader{
if (config.contains("baits." + key + ".nbt")) {
baitInstance.setNbt(config.getMapList("baits." + key + ".nbt").get(0));
}
if (config.contains("baits." + key + ".enchantments")) {
ArrayList<Enchantment> arrayList = new ArrayList<>();
config.getStringList("baits." + key + ".enchantments").forEach(enchant -> {
String[] split = StringUtils.split(enchant, "/");
NamespacedKey namespacedKey = NamespacedKey.fromString(split[0]);
arrayList.add(new Enchantment(namespacedKey, Integer.parseInt(split[1])));
});
baitInstance.setEnchantment(arrayList);
}
if (config.contains("baits." + key + ".item_flags")) {
ArrayList<ItemFlag> arrayList = new ArrayList<>();
config.getStringList("baits." + key + ".item_flags").forEach(flag -> {
arrayList.add(ItemFlag.valueOf(flag));
});
baitInstance.setItemFlags(arrayList);
}
if (config.contains("baits." + key + ".modifier")){
config.getConfigurationSection("baits." + key + ".modifier").getKeys(false).forEach(modifier -> {
switch (modifier){

View File

@@ -6,8 +6,11 @@ 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.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.HashMap;
import java.util.List;
@@ -24,6 +27,8 @@ public class BaitInstance {
private double doubleLoot;
private int difficulty;
private final String material;
private List<net.momirealms.customfishing.utils.Enchantment> enchantment;
private List<ItemFlag> itemFlags;
public BaitInstance(String name, String material) {
this.name = name;
@@ -31,7 +36,18 @@ public class BaitInstance {
}
public void addBait2Cache(String baitKey){
NBTItem nbtItem = new NBTItem(new ItemStack(Material.valueOf(this.material.toUpperCase())));
ItemStack itemStack = new ItemStack(Material.valueOf(this.material.toUpperCase()));
ItemMeta itemMeta = itemStack.getItemMeta();
if (enchantment != null){
enchantment.forEach(enchantment1 -> {
itemMeta.addEnchant(Enchantment.getByKey(enchantment1.getKey()),enchantment1.getLevel(),true);
});
}
if (itemFlags != null){
itemFlags.forEach(itemMeta::addItemFlags);
}
itemStack.setItemMeta(itemMeta);
NBTItem nbtItem = new NBTItem(itemStack);
NBTCompound display = nbtItem.addCompound("display");
display.setString("Name", GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize("<italic:false>" + this.name)));
if(this.lore != null){
@@ -55,6 +71,9 @@ public class BaitInstance {
player.getInventory().addItem(itemStack);
}
public void setItemFlags(List<ItemFlag> itemFlags) {
this.itemFlags = itemFlags;
}
public void setDifficulty(int difficulty) {
this.difficulty = difficulty;
}
@@ -79,6 +98,10 @@ public class BaitInstance {
return this.doubleLoot;
}
public void setEnchantment(List<net.momirealms.customfishing.utils.Enchantment> enchantment) {
this.enchantment = enchantment;
}
public Map<?, ?> getNbt() {
return nbt;
}

View File

@@ -0,0 +1,14 @@
package net.momirealms.customfishing.utils;
import org.bukkit.NamespacedKey;
public record Enchantment(NamespacedKey key, int level) {
public int getLevel() {
return level;
}
public NamespacedKey getKey() {
return key;
}
}

View File

@@ -2,13 +2,17 @@ package net.momirealms.customfishing.utils;
import de.tr7zw.changeme.nbtapi.NBTCompound;
import de.tr7zw.changeme.nbtapi.NBTItem;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.momirealms.customfishing.ConfigReader;
import net.momirealms.customfishing.requirements.Requirement;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.*;
@@ -32,6 +36,8 @@ public class LootInstance {
private int exp;
private List<String> commands;
private String group;
private List<net.momirealms.customfishing.utils.Enchantment> enchantment;
private List<ItemFlag> itemFlags;
public LootInstance(String key, String name, Difficulty difficulty, int weight, int time){
this.key = key;
@@ -95,11 +101,28 @@ public class LootInstance {
this.group = group;
}
public void setExp(int exp) {this.exp = exp;}
/*
将实例转换为缓存中的NBT物品
*/
public void setItemFlags(List<ItemFlag> itemFlags) {
this.itemFlags = itemFlags;
}
public void setEnchantment(List<net.momirealms.customfishing.utils.Enchantment> enchantment) {
this.enchantment = enchantment;
}
public void addLoot2cache(String lootKey){
ItemStack itemStack = new ItemStack(Material.valueOf(this.material.toUpperCase()));
ItemMeta itemMeta = itemStack.getItemMeta();
if (enchantment != null){
enchantment.forEach(enchantment1 -> {
itemMeta.addEnchant(Enchantment.getByKey(enchantment1.getKey()),enchantment1.getLevel(),true);
});
}
if (itemFlags != null){
itemFlags.forEach(itemMeta::addItemFlags);
}
itemStack.setItemMeta(itemMeta);
NBTItem nbtItem = new NBTItem(itemStack);
//设置Name和Lore
NBTCompound display = nbtItem.addCompound("display");

View File

@@ -6,8 +6,11 @@ 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.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.HashMap;
import java.util.List;
@@ -23,13 +26,27 @@ public class RodInstance {
private double time;
private int difficulty;
private double doubleLoot;
private List<net.momirealms.customfishing.utils.Enchantment> enchantment;
private List<ItemFlag> itemFlags;
public RodInstance(String name) {
this.name = name;
}
public void addRod2Cache(String rodKey){
NBTItem nbtItem = new NBTItem(new ItemStack(Material.FISHING_ROD));
ItemStack itemStack = new ItemStack(Material.FISHING_ROD);
ItemMeta itemMeta = itemStack.getItemMeta();
if (enchantment != null){
enchantment.forEach(enchantment1 -> {
itemMeta.addEnchant(Enchantment.getByKey(enchantment1.getKey()),enchantment1.getLevel(),true);
});
}
if (itemFlags != null){
itemFlags.forEach(itemMeta::addItemFlags);
}
itemStack.setItemMeta(itemMeta);
NBTItem nbtItem = new NBTItem(itemStack);
NBTCompound display = nbtItem.addCompound("display");
display.setString("Name", GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize("<italic:false>" + this.name)));
if(this.lore != null){
@@ -69,6 +86,12 @@ public class RodInstance {
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;
}

View File

@@ -6,8 +6,11 @@ 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.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.List;
import java.util.Map;
@@ -19,6 +22,8 @@ public class UtilInstance {
private List<String> lore;
private Map<?, ?> nbt;
private final String material;
private List<net.momirealms.customfishing.utils.Enchantment> enchantment;
private List<ItemFlag> itemFlags;
public UtilInstance(String key, String name, String material){
this.key = key;
@@ -48,12 +53,28 @@ public class UtilInstance {
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;
}
/*
将实例转换为缓存中的NBT物品
*/
public void addUtil2cache(String utilKey){
ItemStack itemStack = new ItemStack(Material.valueOf(this.material.toUpperCase()));
ItemMeta itemMeta = itemStack.getItemMeta();
if (enchantment != null){
enchantment.forEach(enchantment1 -> {
itemMeta.addEnchant(Enchantment.getByKey(enchantment1.getKey()),enchantment1.getLevel(),true);
});
}
if (itemFlags != null){
itemFlags.forEach(itemMeta::addItemFlags);
}
itemStack.setItemMeta(itemMeta);
NBTItem nbtItem = new NBTItem(itemStack);
NBTCompound display = nbtItem.addCompound("display");
display.setString("Name", GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize("<italic:false>" + this.name)));

View File

@@ -59,6 +59,20 @@ items:
#若不设置则每次都随机
layout: bar1
#附魔
enchantments:
- minecraft:sharpness/1
- minecraft:flames/1
item_flags:
- HIDE_ENCHANTS
# - HIDE_ATTRIBUTES
# - HIDE_DESTROYS
# - HIDE_DYE
# - HIDE_PLACED_ON
# - HIDE_UNBREAKABLE
# - HIDE_POTION_EFFECTS
# 玩家有多少时间捕鱼
# 超过指定时间鱼会跑(单位:毫秒)
time: 5000