feat(bukkit): 支持 1.20.6 版本
This commit is contained in:
@@ -29,7 +29,7 @@ dependencies {
|
||||
api("com.sun.mail:jakarta.mail:2.0.1")
|
||||
|
||||
// https://www.spigotmc.org/resources/nbt-api.7939/
|
||||
implementation("de.tr7zw:item-nbt-api:2.12.2")
|
||||
implementation("de.tr7zw:item-nbt-api:+")
|
||||
// https://mvnrepository.com/artifact/com.zaxxer/HikariCP
|
||||
implementation("com.zaxxer:HikariCP:4.0.3") { exclude(group = "org.slf4j") }
|
||||
// https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib-jdk8
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -118,42 +118,24 @@ public class CompletableTask<T> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public T get() throws Throwable {
|
||||
public T get() throws InterruptedException {
|
||||
if (state == State.WAITING) {
|
||||
synchronized (this) {
|
||||
try {
|
||||
wait();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
wait();
|
||||
}
|
||||
}
|
||||
switch (state) {
|
||||
case SUCCESS:
|
||||
return value;
|
||||
case FAILED:
|
||||
throw throwable;
|
||||
if (state == State.SUCCESS) {
|
||||
return value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public T getOrDefault(T defaultValue) {
|
||||
if (state == State.WAITING) {
|
||||
synchronized (this) {
|
||||
try {
|
||||
wait();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public T join() {
|
||||
try {
|
||||
return get();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
switch (state) {
|
||||
case SUCCESS:
|
||||
return value;
|
||||
case FAILED:
|
||||
return defaultValue;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public enum State {
|
||||
|
Reference in New Issue
Block a user