This commit is contained in:
Xanadu13
2024-04-29 15:46:38 +08:00
parent 1d6559d6c7
commit 894caaa20c
13 changed files with 73 additions and 327 deletions
@@ -106,7 +106,6 @@ public final class EnderDragon extends JavaPlugin {
finish = true;
}
public static void reloadAll(){
ItemManager.getLegacy().set(false);
WorldManager.reload();
GlowManager.reload();
EnderDragon.getInstance().loadFiles();
@@ -129,11 +128,6 @@ public final class EnderDragon extends JavaPlugin {
this.cancel();
DragonManager.reload();
GuiManager.loadGui();
if (ItemManager.getLegacy().get()){
Lang.error("I'm sorry that data_type 'nbt' and 'advanced' probably will be disabled in 1.20.5+");
Lang.error("It is recommended to migrate item configuration to bukkit format for compatibility.");
Lang.error("You can use /ed migrate to generate new config.");
}
runnable.runTaskTimer(plugin,0,1);
}
@@ -36,11 +36,6 @@ public class MainCommand implements CommandExecutor {
else if(args.length == 3) GroovyManager.invoke("test.groovy",args[1],args[2]);
return true;
}
case "migrate" : {
if (!sender.isOp()) return false;
FileUpdater.migrate();
return true;
}
// case "worlds" : {
// if(!sender.isOp()){
// Lang.sendFeedback(sender,Lang.command_no_permission);
@@ -1,267 +1,10 @@
package pers.xanadu.enderdragon.config;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.Repairable;
import org.bukkit.persistence.PersistentDataContainer;
import pers.xanadu.enderdragon.EnderDragon;
import pers.xanadu.enderdragon.manager.ItemManager;
import pers.xanadu.enderdragon.manager.TaskManager;
import pers.xanadu.enderdragon.reward.Chance;
import pers.xanadu.enderdragon.reward.Reward;
import pers.xanadu.enderdragon.util.Version;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static pers.xanadu.enderdragon.EnderDragon.*;
public class FileUpdater {
public static void update() throws IOException {
Lang.warn("Nothing to update. Maybe you need '/ed migrate'?");
// FileConfiguration config_old = plugin.getConfig();
// boolean chinese = "Chinese".equals(config_old.getString("lang"));
// File folder = new File(plugin.getDataFolder(),"setting");
// if(folder.exists()){
// File[] files = folder.listFiles();
// if(files != null){
// for(File file : files){
// FileConfiguration config = YamlConfiguration.loadConfiguration(file);
// String ver = config.getString("version");
// if(!"2.2.0".equals(ver)) {
// Lang.error("The version of setting/"+file.getName()+" is not supported!");
// continue;
// }
// String name = file.getName();
// Config.copyFile("setting/"+name,"new/setting/"+name,true);
// }
// File new_folder = new File(plugin.getDataFolder(),"new/setting/");
// files = new_folder.listFiles();
// if(files != null){
// for(File file : files){
// FileOutputStream out = new FileOutputStream(file,true);
// if (chinese){
// out.write(("\n\n" +
// "# 一些特殊的战利品\n" +
// "special_loot:\n" +
// " # 你可以按格式添加更多条目,但是名称不能重复\n" +
// " # 如果找不到执行目标(target),所在战利品条目会被忽略\n" +
// " # 目前支持的type: exp(经验), command(执行指令,可解析伤害排名)\n" +
// " loot1:\n" +
// " # [true/false]\n" +
// " enable: false\n" +
// " type: command\n" +
// " # %attacker% -> 所有参与屠龙的玩家\n" +
// " target: \"%attacker%\"\n" +
// " # %player% -> 目标, %damage% -> 该玩家造成的总伤害\n" +
// " data:\n" +
// " - 'give %player% stone 1'\n" +
// " - 'ed action %player% tell: 你获得了保底奖励.'\n" +
// " loot2:\n" +
// " enable: false\n" +
// " type: command\n" +
// " # %attacker_top_<rank>% -> 在屠龙中取得此排名的玩家\n" +
// " target: \"%attacker_top_1%\"\n" +
// " data:\n" +
// " - 'ed action %player% tell: 你的伤害占比是最高的!'\n" +
// " - 'ed action %player% tell: 你造成的伤害: %damage%'\n" +
// " loot_exp1:\n" +
// " enable: false\n" +
// " type: exp\n" +
// " target: \"%attacker_top_2%\"\n" +
// " data:\n" +
// " # 给予排名第二的玩家20点经验\n" +
// " amount: 20\n" +
// "\n\n"
// ).getBytes());
// }
// else{
// out.write(("\n\n" +
// "special_loot:\n" +
// " # You can add more entries with DIFFERENT name according to the format.\n" +
// " # If such target not exists, this option will be ignored.\n" +
// " # type: exp, command\n" +
// " loot1:\n" +
// " # [true/false]\n" +
// " enable: false\n" +
// " type: command\n" +
// " # %attacker% -> all participants in dragon slaying\n" +
// " target: \"%attacker%\"\n" +
// " # %player% -> target, %damage% -> this player's damage to EnderDragon\n" +
// " data:\n" +
// " - 'give %player% stone 1'\n" +
// " - 'ed action %player% tell: This is a guaranteed reward.'\n" +
// " loot2:\n" +
// " enable: false\n" +
// " type: command\n" +
// " # %attacker_top_<rank>% -> the player with exactly this rank\n" +
// " target: \"%attacker_top_1%\"\n" +
// " data:\n" +
// " - 'ed action %player% tell: You are the one who causes the highest damage!'\n" +
// " - 'ed action %player% tell: Your damage: %damage%'\n" +
// " loot_exp1:\n" +
// " enable: false\n" +
// " type: exp\n" +
// " target: \"%attacker_top_2%\"\n" +
// " data:\n" +
// " # add 20 exp for the rank_2 player\n" +
// " amount: 20\n" +
// "\n\n"
// ).getBytes());
// }
// out.close();
// FileConfiguration fc = YamlConfiguration.loadConfiguration(file);
// fc.set("version","2.4.0");
// fc.save(file);
// }
// }
// }
// }
// Lang.info("New config files are generated in plugins/EnderDragon/new.");
// Lang.warn("Attention: Please confirm the accuracy before using new config!");
}
public static void migrate(){
boolean b1 = handleRewards();
boolean b2 = handleGuiItems();
if (b1 || b2) Lang.info("New reward configuration files are generated in plugins/EnderDragon/migrate.");
else Lang.warn("No files need to be migrated!");
}
private static boolean handleGuiItems(){
File folder = new File(plugin.getDataFolder(),"gui");
if (!folder.exists()) return false;
File[] files = folder.listFiles(f -> f.getName().endsWith(".yml"));
if (files == null || files.length == 0) {
return false;
}
for (File file : files){
Config.copyFile(file,"new/gui/"+file.getName(),true);
File gen_file = new File(plugin.getDataFolder(),"new/gui/"+file.getName());
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(gen_file);
cfg.getKeys(false).forEach(key->{
ConfigurationSection gui = cfg.getConfigurationSection(key);
if (gui == null) return;
ConfigurationSection Items = gui.getConfigurationSection("Items");
if (Items == null) return;
Items.getKeys(false).forEach(ch -> {
ConfigurationSection slot = Items.getConfigurationSection(ch);
if (slot == null) return;
if (!slot.contains("data")) return;
ItemStack itemStack = readItemStack(slot,"data");
ItemManager.save2section_simple(itemStack,slot,"data");
if (!slot.contains("data_disable")) return;
itemStack = readItemStack(slot,"data_disable");
ItemManager.save2section_simple(itemStack,slot,"data_disable");
});
Items.getKeys(false).forEach(ch -> {
ConfigurationSection slot = Items.getConfigurationSection(ch);
if (slot == null) return;
if (slot.contains("data_type")){
slot.set("data_type","simple");
}
else if (slot.contains("data") || slot.contains("data_disable")) {
slot.set("data_type","simple");
}
});
});
try{
cfg.save(gen_file);
}catch (IOException e){
e.printStackTrace();
}
}
return true;
}
private static ItemStack readItemStack(ConfigurationSection section,final String path){
ItemStack itemStack;
final String type = section.getString("data_type","");
switch (type){
case "nbt":
itemStack = ItemManager.readFromNBT(section,path);
ItemManager.getLegacy().compareAndSet(false,true);
break;
case "advanced":
itemStack = ItemManager.readFromAdvData(section,path);
ItemManager.getLegacy().compareAndSet(false,true);
break;
case "simple":
itemStack = ItemManager.readFromSimple(section,path);
break;
default:
itemStack = ItemManager.readFromBukkit(section,path);
}
return itemStack;
}
private static boolean handleRewards(){
File folder = new File(plugin.getDataFolder(),"reward");
if (!folder.exists()) return false;
File[] files = folder.listFiles(f -> f.getName().endsWith(".yml"));
if (files == null || files.length == 0) {
return false;
}
for (File file : files){
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
Config.copyFile(file,"new/reward/"+file.getName(),true);
File gen_file = new File(plugin.getDataFolder(),"new/reward/"+file.getName());
YamlConfiguration new_cfg = YamlConfiguration.loadConfiguration(gen_file);
if(Config.advanced_setting_backslash_split_reward) new_cfg.options().pathSeparator('\\');
List<String> gen = new ArrayList<>();
List<String> list = config.getStringList("list");
for(String str : list){
YamlConfiguration yml = new YamlConfiguration();
if(Config.advanced_setting_backslash_split_reward) yml.options().pathSeparator('\\');
try{
yml.loadFromString(str);
Reward reward = ItemManager.readAsReward(yml);
if (reward == null) continue;
gen.add(saveReward(reward));
}catch (InvalidConfigurationException e){
Lang.error(Lang.plugin_item_read_error + str);
}
}
new_cfg.set("list",gen);
try{
new_cfg.save(gen_file);
}catch (IOException e){
e.printStackTrace();
}
}
return true;
}
private static String saveReward(Reward reward){
Chance chance = reward.getChance();
ItemStack item = reward.getItem();
double value = chance.getValue();
String str = chance.getStr();
String name = reward.getName();
YamlConfiguration yaml = new YamlConfiguration();
if(Config.advanced_setting_backslash_split_reward) yaml.options().pathSeparator('\\');
if(name == null){
ItemMeta meta = item.getItemMeta();
if(meta != null) {
String displayName = meta.getDisplayName();
if("".equals(displayName) || displayName == null){
name = item.getType().name().toLowerCase() + "(" + TaskManager.getCurrentTimeWithSpecialFormat() + ")";
}
else name = meta.getDisplayName();
}
else name = item.getType().name().toLowerCase() + "(" + TaskManager.getCurrentTimeWithSpecialFormat() + ")";
}
ConfigurationSection section = yaml.createSection(name);
section.set("data_type", "default");
section.set("data", item);
ConfigurationSection drop_section = section.createSection("drop_chance");
drop_section.set("value",value);
drop_section.set("format",str);
return yaml.saveToString();
Lang.warn("Nothing to update.");
}
}
@@ -118,7 +118,7 @@ public class GUI {
resetPagedItem(key,cmd);
}
else if(type == 2){
for(MyDragon myDragon : DragonManager.get_dragons()){
for(MyDragon myDragon : DragonManager.getDragons()){
this.addDragon(myDragon.icon.clone(),myDragon.unique_name);
}
}
@@ -6,7 +6,6 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import pers.xanadu.enderdragon.gui.GUISlot;
import pers.xanadu.enderdragon.gui.GUISlotType;
import pers.xanadu.enderdragon.manager.ItemManager;
import static pers.xanadu.enderdragon.manager.ItemManager.*;
@@ -33,12 +32,10 @@ public class TipSlot extends GUISlot {
this.data_type = DataType.fromString(section.getString("data_type"));
switch (data_type) {
case NBT:
ItemManager.getLegacy().compareAndSet(false,true);
this.item = readFromNBT(section,"data");
if(hasDisableMode) this.itemOnDisable = readFromNBT(section,"data_disable");
break;
case ADVANCED:
ItemManager.getLegacy().compareAndSet(false,true);
this.item = readFromAdvData(section,"data");
if(hasDisableMode) this.itemOnDisable = readFromAdvData(section,"data_disable");
break;
@@ -1,5 +1,6 @@
package pers.xanadu.enderdragon.manager;
import lombok.Getter;
import org.bukkit.*;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
@@ -12,7 +13,6 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.*;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.Nullable;
import pers.xanadu.enderdragon.config.Config;
import pers.xanadu.enderdragon.config.Lang;
@@ -35,7 +35,11 @@ import java.util.regex.Pattern;
import static pers.xanadu.enderdragon.EnderDragon.*;
public class DragonManager {
static final ArrayList<MyDragon> dragons = new ArrayList<>();
/**
* 底层是unmodifiableList
*/
@Getter
static List<MyDragon> dragons;
static final Map<String, MyDragon> mp = new HashMap<>();
public static List<String> dragon_names = new ArrayList<>();
public static final Map<UUID,DragonInfo> existing_dragon = new ConcurrentHashMap<>();
@@ -54,7 +58,7 @@ public class DragonManager {
private static final Pattern pattern_attacker_top = Pattern.compile("%attacker_top_(\\d+)%");
public static void reload(){
dragons.clear();
final List<MyDragon> dragons = new ArrayList<>();
mp.clear();
dragon_names.clear();
sum = 0;
@@ -94,9 +98,10 @@ public class DragonManager {
if(!Version.setting_dragon.equals(fc.getString("version"))){
Lang.warn(Lang.plugin_wrong_file_version.replace("{file_name}", file.getName()));
}
readSettingFile(fc,edge);
readSettingFile(fc,edge,dragons);
}
dragons.sort((o1, o2) -> o2.priority - o1.priority);
DragonManager.dragons = Collections.unmodifiableList(dragons);
RewardManager.reload();
}
public static MyDragon judge(){
@@ -119,16 +124,11 @@ public class DragonManager {
}
return cur;
}
else if(Config.special_dragon_jude_mode.equalsIgnoreCase("edge")){
int cnt = 0, random = ThreadLocalRandom.current().nextInt(0, sum);
for(MyDragon cur : dragons){
if(cnt <= random && cnt + cur.edge > random){
return cur;
}
cnt += cur.edge;
}
Lang.error("\"edge\" in \"special_dragon_jude_mode\" of config.yml is deprecated!Please use \"weight\" instead.");
else{
Lang.error("Unknown 'special_dragon_jude_mode' of config.yml.");
Lang.error("Possible solutions: pc, weight(named 'edge' in old versions).");
}
//unreachable
return null;
}
public static void setSpecialKey(Entity e, String key){
@@ -140,7 +140,7 @@ public class DragonManager {
}
return null;
}
public static void readSettingFile(FileConfiguration f,int edge){
public static void readSettingFile(FileConfiguration f,int edge,List<MyDragon> dragons){
MyDragon myDragon = new MyDragon();
myDragon.unique_name = f.getString("unique_name","default");
if(mp.containsKey(myDragon.unique_name)){
@@ -330,7 +330,7 @@ public class DragonManager {
}
}
public static void disable(){
dragons.clear();
dragons = null;
mp.clear();
dragon_names.clear();
}
@@ -345,13 +345,6 @@ public class DragonManager {
return mp.get(unique_name);
}
/**
* 请勿修改得到的List
*/
@Deprecated
public static List<MyDragon> get_dragons(){
return dragons;
}
@Nullable
public static MyDragon getFromInfo(DragonInfo info){
return mp.get(info.unique_name);
@@ -486,7 +479,7 @@ public class DragonManager {
/**
* Only used to initialize. DON'T use this if speed is essential.
* @param world world
* @return The dragon found in this world.
* @return The dragon found in this world, or null if not found.
*/
public static EnderDragon getEnderDragon(final World world){
if(world.getEnvironment() != World.Environment.THE_END){
@@ -6,6 +6,7 @@ import io.netty.util.internal.ConcurrentSet;
import org.bukkit.entity.Player;
import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.control.customizers.ImportCustomizer;
import pers.xanadu.enderdragon.EnderDragon;
import pers.xanadu.enderdragon.config.Config;
import pers.xanadu.enderdragon.script.Events;
import pers.xanadu.enderdragon.script.tool.ScriptCommand;
@@ -39,7 +40,7 @@ public class GroovyManager {
importCustomizer.addImport("Command","pers.xanadu.enderdragon.script.tool.ScriptCommand");
importCustomizer.addStaticImport("plugin","pers.xanadu.enderdragon.EnderDragon","plugin");
compilerConfig.addCompilationCustomizers(importCustomizer);
GroovyClassLoader classLoader = new GroovyClassLoader(GroovyManager.class.getClassLoader(),compilerConfig);
GroovyClassLoader classLoader = new GroovyClassLoader(EnderDragon.class.getClassLoader(),compilerConfig);
engine = new GroovyScriptEngine(new URL[]{baseDir.toURI().toURL()}, classLoader);
InputStream inputStream = plugin.getResource("script/lib.groovy");
lib = Config.convertInputStreamToString(inputStream);
@@ -1,6 +1,5 @@
package pers.xanadu.enderdragon.manager;
import lombok.Getter;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier;
@@ -20,11 +19,8 @@ import pers.xanadu.enderdragon.reward.Chance;
import pers.xanadu.enderdragon.util.Version;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
public class ItemManager {
@Getter
private static final AtomicBoolean legacy = new AtomicBoolean(false);
public static String write(Reward reward){
Chance chance = reward.getChance();
return write(reward.getItem(),chance.getValue(),chance.getStr(),reward.getName());
@@ -84,11 +80,9 @@ public class ItemManager {
//data_type may be null
ItemStack item;
if("nbt".equals(data_type)) {
legacy.compareAndSet(false,true);
item = readFromNBT(section0,"data");
}
else if("advanced".equals(data_type)) {
legacy.compareAndSet(false,true);
item = readFromAdvData(section0, "data");
}
else {
@@ -101,6 +95,13 @@ public class ItemManager {
return new Reward(item,new Chance(d0, str));
}
public static ItemStack readFromAdvData(ConfigurationSection section, String path){
if (Version.isNBT_UPDATE()){
throw new UnsupportedOperationException(
"I'm sorry that data_type 'nbt' and 'advanced' have been temporarily disabled since 1.20.5.\n"+
"You can migrate configurations through '/ed migrate' EnderDragon v2.5.1.\n"+
"I will reconstruct this plugin add restore this function in the future."
);
}
ConfigurationSection data = section.getConfigurationSection(path);
if(data == null) return new ItemStack(Material.AIR);
String type = data.getString("type");
@@ -221,6 +222,13 @@ public class ItemManager {
return item;
}
public static ItemStack readFromNBT(ConfigurationSection section, String path){
if (Version.isNBT_UPDATE()){
throw new UnsupportedOperationException(
"I'm sorry that data_type 'nbt' and 'advanced' have been temporarily disabled since 1.20.5.\n"+
"You can migrate configurations through '/ed migrate' EnderDragon v2.5.1.\n"+
"I will reconstruct this plugin add restore this function in the future."
);
}
String nbt = section.getString(path);
if (nbt == null) return new ItemStack(Material.AIR);
return EnderDragon.getInstance().getNMSItemManager().readAsItem(nbt);
@@ -1,5 +1,6 @@
package pers.xanadu.enderdragon.util;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.inventory.ItemStack;
@@ -14,19 +15,20 @@ import java.util.Map;
public class NMSUtil {
private Method getNMSWord;
private Method asNMSCopy;
private Method copyNMSStack;
private Method asBukkitCopy;
private Method asCraftMirror;
/**
* 浅拷贝unhandledTags
*/
private Method asCraftCopy;
@Deprecated
private Method NMSItemStack_save;
@Deprecated
private Method cpdToEi;
private Method stringToCPD;
private Method stringToNBTBase;
private Method PDCtoCPD;
@Deprecated
private Method PersistentDataContainer_putAll;
@Deprecated
private Method NBTTagCompound_set;
private Field unhandledTags;
private Field world_c_environment;
@@ -35,11 +37,14 @@ public class NMSUtil {
private Class<?> CraftWorldClass;
private Class<?> WorldProviderClass;
private Class<?> CraftItemStackClass;
@Getter
private Class<?> CraftMetaItemClass;
@Getter
private Class<?> NMSItemStackClass;
private Class<?> CraftEntityClass;
private Class<?> NBTTagCompoundClass;
private Class<?> NBTBaseClass;
@Getter
private Class<?> MojangsonParserClass;
private Class<?> CraftPersistentDataContainerClass;
@@ -63,27 +68,31 @@ public class NMSUtil {
this.CraftEntityClass = Class.forName("org.bukkit.craftbukkit."+version+".entity.CraftEntity");
init_NBTTagCompoundClass();
init_NBTBaseClass();
if (!Version.isNBT_UPDATE()){
init_NBTTagCompound_map();
this.NBTTagCompound_set = NBTTagCompoundClass.getMethod(getMethodName(ReflectiveMethod.NBTTagCompound_set),String.class,NBTBaseClass);
}
this.asNMSCopy = CraftItemStackClass.getMethod("asNMSCopy",ItemStack.class);
this.copyNMSStack = CraftItemStackClass.getMethod("copyNMSStack",NMSItemStackClass,int.class);
this.asBukkitCopy = CraftItemStackClass.getMethod("asBukkitCopy",NMSItemStackClass);
this.asCraftMirror = CraftItemStackClass.getMethod("asCraftMirror",NMSItemStackClass);
this.asCraftCopy = CraftItemStackClass.getMethod("asCraftCopy",ItemStack.class);
if (!Version.isNBT_UPDATE()){
this.NMSItemStack_save = NMSItemStackClass.getMethod(getMethodName(ReflectiveMethod.NMSItemStack_save),NBTTagCompoundClass);
if(Version.mcMainVersion>=13) this.cpdToEi = NMSItemStackClass.getMethod("a",NBTTagCompoundClass);
}
if(Version.mcMainVersion<=16) this.MojangsonParserClass = Class.forName("net.minecraft.server."+version+".MojangsonParser");
else this.MojangsonParserClass = Class.forName("net.minecraft.nbt.MojangsonParser");
this.stringToCPD = MojangsonParserClass.getMethod(getMethodName(ReflectiveMethod.MojangsonParser_parse),String.class);
this.stringToNBTBase = MojangsonParserClass.getDeclaredMethod(getMethodName(ReflectiveMethod.MojangsonParser_parseLiteral),String.class);
stringToNBTBase.setAccessible(true);
if(Version.mcMainVersion>=14){
this.CraftPersistentDataContainerClass = Class.forName("org.bukkit.craftbukkit." + version + ".persistence.CraftPersistentDataContainer");
this.PDCtoCPD = CraftPersistentDataContainerClass.getDeclaredMethod("toTagCompound");
if (!Version.isNBT_UPDATE()){
this.PersistentDataContainer_putAll = CraftPersistentDataContainerClass.getDeclaredMethod("putAll",NBTTagCompoundClass);
}
}
@@ -115,6 +124,7 @@ public class NMSUtil {
Object new_cpd = getNBTTagCompound(self);
return EnderDragon.getInstance().getNMSItemManager().cpdToItem(new_cpd);
}
@SuppressWarnings("unchecked")
public Map<String,Object> cpdToMap(final Object cpd){
try{
return (Map<String, Object>) NBTTagCompound_map.get(cpd);
@@ -123,6 +133,8 @@ public class NMSUtil {
return null;
}
}
@SuppressWarnings({"unchecked"})
@Deprecated
public Object getNBTTagCompound(final Map<String,Object> mp){
try{
Object cpd = NBTTagCompoundClass.newInstance();
@@ -144,6 +156,7 @@ public class NMSUtil {
return null;
}
}
@Deprecated
public void setPersistentDataContainer(final PersistentDataContainer dataContainer,final Object cpd){
try{
Object PDC = CraftPersistentDataContainerClass.cast(dataContainer);
@@ -162,6 +175,7 @@ public class NMSUtil {
}
}
@Deprecated
public String getNBT(final ItemStack item){
try{
Object ci = CraftItemStackClass.isInstance(item)?CraftItemStackClass.cast(item):asCraftCopy.invoke(null,item);//浅拷贝unhandledTags
@@ -173,6 +187,7 @@ public class NMSUtil {
return "{id:\"minecraft:air\"}";
}
}
@Deprecated
public Object getCPD(final ItemStack item){
try{
Object ci = CraftItemStackClass.isInstance(item)?CraftItemStackClass.cast(item):asCraftCopy.invoke(null,item);//浅拷贝unhandledTags
@@ -194,6 +209,7 @@ public class NMSUtil {
/**
* 仅1.13+可用
*/
@Deprecated
public ItemStack getItemStack(final Object cpd){
try{
Object ei = cpdToEi.invoke(null,cpd);
@@ -207,6 +223,7 @@ public class NMSUtil {
/**
* 仅1.13+可用
*/
@Deprecated
public ItemStack getItemStack(final String nbt){
try{
Object cpd = stringToCPD.invoke(null,nbt);
@@ -241,6 +258,7 @@ public class NMSUtil {
if (this.CraftWorldClass.isInstance(ThisWorld)) return this.CraftWorldClass.cast(ThisWorld);
return null;
}
@SuppressWarnings("unused")
public Object getWorld_e(final World world){
try {
Object world_c = getCraftWorld(world);
@@ -250,12 +268,6 @@ public class NMSUtil {
}
return null;
}
public Class<?> getNBTBaseClass(){
return this.NBTBaseClass;
}
public Class<?> getNBTTagCompoundClass(){
return this.NBTTagCompoundClass;
}
public Class<?> getWorldClass(){
return this.WorldClass;
}
@@ -320,7 +332,7 @@ public class NMSUtil {
e.printStackTrace();
}
}
private static enum ReflectiveMethod {
private enum ReflectiveMethod {
NMSItemStack_save,
NMSItemStack_setTag,
MojangsonParser_parse,
@@ -1,5 +1,6 @@
package pers.xanadu.enderdragon.util;
import lombok.Getter;
import pers.xanadu.enderdragon.config.Lang;
import pers.xanadu.enderdragon.nms.BossBar.IBossBarManager;
import pers.xanadu.enderdragon.nms.NMSItem.INMSItemManager;
@@ -16,6 +17,8 @@ public class Version {
public static final String reward = "2.1.0";
public static int mcMainVersion;
public static int mcPatchVersion;
@Getter
public static boolean NBT_UPDATE;
private static String version = "no version found";
private static boolean isMohist = false;
public static void init(){
@@ -34,7 +37,7 @@ public class Version {
Class.forName("net.minecraftforge.server.ServerMain");
isMohist = true;
}catch(ReflectiveOperationException ignored){}
NBT_UPDATE = mcMainVersion > 20 || mcMainVersion == 20 && mcPatchVersion >=5;
}
public static INMSItemManager getNMSItemManager(){
switch (version){
+1 -1
View File
@@ -74,7 +74,7 @@ blacklist_worlds:
#写法示例: [COMMAND,CUSTOM]
blacklist_spawn_reason: []
#可选: [default/nbt/advanced]
#可选: [default/nbt(<=1.20.4)/advanced(<=1.20.4)]
item_format:
reward: default
+1 -1
View File
@@ -73,7 +73,7 @@ blacklist_worlds:
# example: [COMMAND,CUSTOM]
blacklist_spawn_reason: []
#optional: [default/nbt/advanced]
#optional: [default/nbt(<=1.20.4)/advanced(<=1.20.4)]
item_format:
reward: default
+1 -1
View File
@@ -1,5 +1,5 @@
name: EnderDragon
version: 2.5.1
version: 2.5.2
main: pers.xanadu.enderdragon.EnderDragon
author: Xanadu13
api-version: 1.13