This commit is contained in:
Xanadu13
2026-05-03 16:32:16 +09:00
parent 88bc3867d5
commit 9613e0333c
4 changed files with 253 additions and 201 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>pers.xanadu</groupId>
<artifactId>EnderDragon</artifactId>
<version>2.5.7</version>
<version>2.5.8</version>
<packaging>jar</packaging>
<name>EnderDragon</name>
@@ -100,6 +100,7 @@ public class DragonDeathListener implements Listener {
List<Pair<String,Double>> list = DamageManager.getDamageList(dragon.getUniqueId());
list.sort(DamageManager::sortByDamage);
List<SpecialLoot> participants = myDragon.lootMap.get(0);
// 是否给所有参与者发奖励
boolean tag = participants != null;
int size = list.size();
for(int i=0;i<size;i++){
@@ -51,7 +51,7 @@ public class NMSUtil {
public void init(){
String version = Version.getVersion();
try{
this.CraftWorldClass = Class.forName("org.bukkit.craftbukkit." + version + ".CraftWorld");
this.CraftWorldClass = ClassResolver.obc("CraftWorld");
this.getNMSWord = CraftWorldClass.getDeclaredMethod("getHandle");
this.WorldClass = this.getNMSWord.getReturnType().getSuperclass();
this.world_c_environment = CraftWorldClass.getDeclaredField("environment");
@@ -60,12 +60,12 @@ public class NMSUtil {
this.WorldProviderClass = Class.forName("net.minecraft.server."+version+".WorldProvider");
//this.WorldProviderTheEndClass = Class.forName("net.minecraft.server."+version+".WorldProviderTheEnd");
}
this.CraftItemStackClass = Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack");
this.CraftMetaItemClass = Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftMetaItem");
this.CraftItemStackClass = ClassResolver.obc("inventory.CraftItemStack");
this.CraftMetaItemClass = ClassResolver.obc("inventory.CraftMetaItem");
this.unhandledTags = CraftMetaItemClass.getDeclaredField("unhandledTags");
unhandledTags.setAccessible(true);
this.NMSItemStackClass = CraftItemStackClass.getDeclaredField("handle").getType();
this.CraftEntityClass = Class.forName("org.bukkit.craftbukkit."+version+".entity.CraftEntity");
this.CraftEntityClass = ClassResolver.obc("entity.CraftEntity");
init_NBTTagCompoundClass();
init_NBTBaseClass();
if (!Version.isNBT_UPDATE()){
@@ -83,11 +83,17 @@ public class NMSUtil {
if(Version.mcMainVersion<=16) this.MojangsonParserClass = Class.forName("net.minecraft.server."+version+".MojangsonParser");
else this.MojangsonParserClass = Class.forName("net.minecraft.nbt.MojangsonParser");
else if (Version.mcMainVersion < 26) this.MojangsonParserClass = Class.forName("net.minecraft.nbt.MojangsonParser");
else {
// TODO: 2026/5/3 16:21
this.MojangsonParserClass = null;
}
if (this.MojangsonParserClass != null) {
this.stringToCPD = MojangsonParserClass.getMethod(getMethodName(ReflectiveMethod.MojangsonParser_parse),String.class);
}
if(Version.mcMainVersion>=14){
this.CraftPersistentDataContainerClass = Class.forName("org.bukkit.craftbukkit." + version + ".persistence.CraftPersistentDataContainer");
this.CraftPersistentDataContainerClass = ClassResolver.obc("persistence.CraftPersistentDataContainer");
this.PDCtoCPD = CraftPersistentDataContainerClass.getDeclaredMethod("toTagCompound");
if (!Version.isNBT_UPDATE()){
this.PersistentDataContainer_putAll = CraftPersistentDataContainerClass.getDeclaredMethod("putAll",NBTTagCompoundClass);
@@ -101,6 +107,44 @@ public class NMSUtil {
}
if(Config.debug) check();
}
public static final class ClassResolver {
private static final String OBC_BASE = "org.bukkit.craftbukkit";
private static final String NMS_LEGACY_BASE = "net.minecraft.server";
private static final String NMS_MODERN_BASE = "net.minecraft";
private static final String VERSION = Version.getVersion();
private static boolean isModern() {
return Version.mcMainVersion >= 26;
}
public static Class<?> obc(String path) throws ClassNotFoundException {
String fullName;
if (isModern()) {
fullName = OBC_BASE + "." + path;
} else {
fullName = OBC_BASE + "." + VERSION + "." + path;
}
return Class.forName(fullName);
}
public static Class<?> nms(String path) throws ClassNotFoundException {
String fullName;
if (isModern()) {
fullName = NMS_MODERN_BASE + "." + path;
} else {
fullName = NMS_LEGACY_BASE + "." + VERSION + "." + path;
}
return Class.forName(fullName);
}
}
public void check(){
try{
Field[] fields = NMSUtil.class.getDeclaredFields();
@@ -303,7 +347,7 @@ public class NMSUtil {
}
private void init_NBTTagCompoundClass(){
try{
Class<?> CraftMetaBlockStateClass = Class.forName("org.bukkit.craftbukkit."+Version.getVersion()+".inventory.CraftMetaBlockState");
Class<?> CraftMetaBlockStateClass = ClassResolver.obc("inventory.CraftMetaBlockState");
Field field = CraftMetaBlockStateClass.getDeclaredField("blockEntityTag");
this.NBTTagCompoundClass = field.getType();
return;
@@ -35,15 +35,22 @@ public class Version {
Field LEGACY_CB_VERSION = clazz.getField("LEGACY_CB_VERSION");
version = (String) LEGACY_CB_VERSION.get(null);
}catch (ReflectiveOperationException e){
throwable.printStackTrace();
Lang.warn("Failed to get nms-version!");
Bukkit.getServer().getPluginManager().disablePlugin(EnderDragon.plugin);
version = Bukkit.getVersion().split("-")[0];
}
}
String[] mc_version = getServer().getBukkitVersion().split("-")[0].split("\\.");
int first = Integer.parseInt(mc_version[0]);
// e.g. 26.1.2.build.53
if (first >= 26) {
mcMainVersion = first;
mcPatchVersion = Integer.parseInt(mc_version[1]);
} else {
mcMainVersion = Integer.parseInt(mc_version[1]);
if(mc_version.length<=2) mcPatchVersion = 0;
else mcPatchVersion = Integer.parseInt(mc_version[2]);
}
Lang.info("Found version: " + version);
try{
Class.forName("net.minecraftforge.server.ServerMain");