fix #49
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>pers.xanadu</groupId>
|
<groupId>pers.xanadu</groupId>
|
||||||
<artifactId>EnderDragon</artifactId>
|
<artifactId>EnderDragon</artifactId>
|
||||||
<version>2.5.7</version>
|
<version>2.5.8</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>EnderDragon</name>
|
<name>EnderDragon</name>
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ public class DragonDeathListener implements Listener {
|
|||||||
List<Pair<String,Double>> list = DamageManager.getDamageList(dragon.getUniqueId());
|
List<Pair<String,Double>> list = DamageManager.getDamageList(dragon.getUniqueId());
|
||||||
list.sort(DamageManager::sortByDamage);
|
list.sort(DamageManager::sortByDamage);
|
||||||
List<SpecialLoot> participants = myDragon.lootMap.get(0);
|
List<SpecialLoot> participants = myDragon.lootMap.get(0);
|
||||||
|
// 是否给所有参与者发奖励
|
||||||
boolean tag = participants != null;
|
boolean tag = participants != null;
|
||||||
int size = list.size();
|
int size = list.size();
|
||||||
for(int i=0;i<size;i++){
|
for(int i=0;i<size;i++){
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class NMSUtil {
|
|||||||
public void init(){
|
public void init(){
|
||||||
String version = Version.getVersion();
|
String version = Version.getVersion();
|
||||||
try{
|
try{
|
||||||
this.CraftWorldClass = Class.forName("org.bukkit.craftbukkit." + version + ".CraftWorld");
|
this.CraftWorldClass = ClassResolver.obc("CraftWorld");
|
||||||
this.getNMSWord = CraftWorldClass.getDeclaredMethod("getHandle");
|
this.getNMSWord = CraftWorldClass.getDeclaredMethod("getHandle");
|
||||||
this.WorldClass = this.getNMSWord.getReturnType().getSuperclass();
|
this.WorldClass = this.getNMSWord.getReturnType().getSuperclass();
|
||||||
this.world_c_environment = CraftWorldClass.getDeclaredField("environment");
|
this.world_c_environment = CraftWorldClass.getDeclaredField("environment");
|
||||||
@@ -60,12 +60,12 @@ public class NMSUtil {
|
|||||||
this.WorldProviderClass = Class.forName("net.minecraft.server."+version+".WorldProvider");
|
this.WorldProviderClass = Class.forName("net.minecraft.server."+version+".WorldProvider");
|
||||||
//this.WorldProviderTheEndClass = Class.forName("net.minecraft.server."+version+".WorldProviderTheEnd");
|
//this.WorldProviderTheEndClass = Class.forName("net.minecraft.server."+version+".WorldProviderTheEnd");
|
||||||
}
|
}
|
||||||
this.CraftItemStackClass = Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftItemStack");
|
this.CraftItemStackClass = ClassResolver.obc("inventory.CraftItemStack");
|
||||||
this.CraftMetaItemClass = Class.forName("org.bukkit.craftbukkit." + version + ".inventory.CraftMetaItem");
|
this.CraftMetaItemClass = ClassResolver.obc("inventory.CraftMetaItem");
|
||||||
this.unhandledTags = CraftMetaItemClass.getDeclaredField("unhandledTags");
|
this.unhandledTags = CraftMetaItemClass.getDeclaredField("unhandledTags");
|
||||||
unhandledTags.setAccessible(true);
|
unhandledTags.setAccessible(true);
|
||||||
this.NMSItemStackClass = CraftItemStackClass.getDeclaredField("handle").getType();
|
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_NBTTagCompoundClass();
|
||||||
init_NBTBaseClass();
|
init_NBTBaseClass();
|
||||||
if (!Version.isNBT_UPDATE()){
|
if (!Version.isNBT_UPDATE()){
|
||||||
@@ -83,11 +83,17 @@ public class NMSUtil {
|
|||||||
|
|
||||||
|
|
||||||
if(Version.mcMainVersion<=16) this.MojangsonParserClass = Class.forName("net.minecraft.server."+version+".MojangsonParser");
|
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");
|
||||||
this.stringToCPD = MojangsonParserClass.getMethod(getMethodName(ReflectiveMethod.MojangsonParser_parse),String.class);
|
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){
|
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");
|
this.PDCtoCPD = CraftPersistentDataContainerClass.getDeclaredMethod("toTagCompound");
|
||||||
if (!Version.isNBT_UPDATE()){
|
if (!Version.isNBT_UPDATE()){
|
||||||
this.PersistentDataContainer_putAll = CraftPersistentDataContainerClass.getDeclaredMethod("putAll",NBTTagCompoundClass);
|
this.PersistentDataContainer_putAll = CraftPersistentDataContainerClass.getDeclaredMethod("putAll",NBTTagCompoundClass);
|
||||||
@@ -101,6 +107,44 @@ public class NMSUtil {
|
|||||||
}
|
}
|
||||||
if(Config.debug) check();
|
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(){
|
public void check(){
|
||||||
try{
|
try{
|
||||||
Field[] fields = NMSUtil.class.getDeclaredFields();
|
Field[] fields = NMSUtil.class.getDeclaredFields();
|
||||||
@@ -303,7 +347,7 @@ public class NMSUtil {
|
|||||||
}
|
}
|
||||||
private void init_NBTTagCompoundClass(){
|
private void init_NBTTagCompoundClass(){
|
||||||
try{
|
try{
|
||||||
Class<?> CraftMetaBlockStateClass = Class.forName("org.bukkit.craftbukkit."+Version.getVersion()+".inventory.CraftMetaBlockState");
|
Class<?> CraftMetaBlockStateClass = ClassResolver.obc("inventory.CraftMetaBlockState");
|
||||||
Field field = CraftMetaBlockStateClass.getDeclaredField("blockEntityTag");
|
Field field = CraftMetaBlockStateClass.getDeclaredField("blockEntityTag");
|
||||||
this.NBTTagCompoundClass = field.getType();
|
this.NBTTagCompoundClass = field.getType();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -35,15 +35,22 @@ public class Version {
|
|||||||
Field LEGACY_CB_VERSION = clazz.getField("LEGACY_CB_VERSION");
|
Field LEGACY_CB_VERSION = clazz.getField("LEGACY_CB_VERSION");
|
||||||
version = (String) LEGACY_CB_VERSION.get(null);
|
version = (String) LEGACY_CB_VERSION.get(null);
|
||||||
}catch (ReflectiveOperationException e){
|
}catch (ReflectiveOperationException e){
|
||||||
throwable.printStackTrace();
|
version = Bukkit.getVersion().split("-")[0];
|
||||||
Lang.warn("Failed to get nms-version!");
|
|
||||||
Bukkit.getServer().getPluginManager().disablePlugin(EnderDragon.plugin);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String[] mc_version = getServer().getBukkitVersion().split("-")[0].split("\\.");
|
String[] mc_version = getServer().getBukkitVersion().split("-")[0].split("\\.");
|
||||||
mcMainVersion = Integer.parseInt(mc_version[1]);
|
|
||||||
if(mc_version.length<=2) mcPatchVersion = 0;
|
int first = Integer.parseInt(mc_version[0]);
|
||||||
else mcPatchVersion = Integer.parseInt(mc_version[2]);
|
// 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);
|
Lang.info("Found version: " + version);
|
||||||
try{
|
try{
|
||||||
Class.forName("net.minecraftforge.server.ServerMain");
|
Class.forName("net.minecraftforge.server.ServerMain");
|
||||||
|
|||||||
Reference in New Issue
Block a user