feat(bukkit): 支持 1.20.6 版本
This commit is contained in:
@@ -7,18 +7,18 @@ import org.jetbrains.annotations.NotNull;
|
||||
@SuppressWarnings("unused")
|
||||
public class MinecraftVersion {
|
||||
@Getter
|
||||
public static final int Version1;
|
||||
public static final int version1;
|
||||
@Getter
|
||||
public static final int Version2;
|
||||
public static final int version2;
|
||||
@Getter
|
||||
public static final int Version3;
|
||||
public static final int version3;
|
||||
|
||||
static {
|
||||
String version = getMCVersion();
|
||||
String[] split = version.split("\\.");
|
||||
Version1 = Integer.parseInt(split[0]);
|
||||
Version2 = Integer.parseInt(split[1]);
|
||||
Version3 = split.length >= 3 ? Integer.parseInt(split[2]) : 0;
|
||||
version1 = Integer.parseInt(split[0]);
|
||||
version2 = Integer.parseInt(split[1]);
|
||||
version3 = split.length >= 3 ? Integer.parseInt(split[2]) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,18 +35,18 @@ public class MinecraftVersion {
|
||||
*/
|
||||
public static int compareTo(@NotNull String version) {
|
||||
String[] split = version.split("\\.");
|
||||
int version1 = Integer.parseInt(split[0]);
|
||||
int version2 = Integer.parseInt(split[1]);
|
||||
int version3 = split.length >= 3 ? Integer.parseInt(split[2]) : 0;
|
||||
int compare = Integer.compare(Version1, version1);
|
||||
int compareVersion1 = Integer.parseInt(split[0]);
|
||||
int compareVersion2 = Integer.parseInt(split[1]);
|
||||
int compareVersion3 = split.length >= 3 ? Integer.parseInt(split[2]) : 0;
|
||||
int compare = Integer.compare(compareVersion1, MinecraftVersion.version1);
|
||||
if (compare != 0) {
|
||||
return compare;
|
||||
}
|
||||
compare = Integer.compare(Version2, version2);
|
||||
compare = Integer.compare(compareVersion2, MinecraftVersion.version2);
|
||||
if (compare != 0) {
|
||||
return compare;
|
||||
}
|
||||
return Integer.compare(Version3, version3);
|
||||
return Integer.compare(compareVersion3, MinecraftVersion.version3);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -61,7 +61,7 @@ public class MinecraftVersion {
|
||||
|
||||
@NotNull
|
||||
public static Class<?> getNMSClass(@NotNull String className) throws ClassNotFoundException {
|
||||
if (Version2 >= 17) {
|
||||
if (version1 >= 1 && version2 >= 17) {
|
||||
return Class.forName("net.minecraft.server." + className);
|
||||
}
|
||||
String nmsVersion = getNMSVersion();
|
||||
@@ -70,9 +70,8 @@ public class MinecraftVersion {
|
||||
|
||||
@NotNull
|
||||
public static Class<?> getNMSClassSilent(@NotNull String className) {
|
||||
String nmsVersion = getNMSVersion();
|
||||
try {
|
||||
return Class.forName("net.minecraft.server." + nmsVersion + "." + className);
|
||||
return getNMSClass(className);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -80,15 +79,17 @@ public class MinecraftVersion {
|
||||
|
||||
@NotNull
|
||||
public static Class<?> getCraftBukkitClass(@NotNull String className) throws ClassNotFoundException {
|
||||
if (version1 >= 1 && version2 >= 20 && version3 >= 6) {
|
||||
return Class.forName("org.bukkit.craftbukkit." + className);
|
||||
}
|
||||
String nmsVersion = getNMSVersion();
|
||||
return Class.forName("org.bukkit.craftbukkit." + nmsVersion + "." + className);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Class<?> getCraftBukkitClassSilent(@NotNull String className) {
|
||||
String nmsVersion = getNMSVersion();
|
||||
try {
|
||||
return Class.forName("org.bukkit.craftbukkit." + nmsVersion + "." + className);
|
||||
return getCraftBukkitClass(className);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
Reference in New Issue
Block a user