feat(bukkit): 支持 1.20.6 版本
This commit is contained in:
@@ -29,7 +29,7 @@ dependencies {
|
|||||||
api("com.sun.mail:jakarta.mail:2.0.1")
|
api("com.sun.mail:jakarta.mail:2.0.1")
|
||||||
|
|
||||||
// https://www.spigotmc.org/resources/nbt-api.7939/
|
// 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
|
// https://mvnrepository.com/artifact/com.zaxxer/HikariCP
|
||||||
implementation("com.zaxxer:HikariCP:4.0.3") { exclude(group = "org.slf4j") }
|
implementation("com.zaxxer:HikariCP:4.0.3") { exclude(group = "org.slf4j") }
|
||||||
// https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib-jdk8
|
// https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib-jdk8
|
||||||
|
@@ -7,18 +7,18 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class MinecraftVersion {
|
public class MinecraftVersion {
|
||||||
@Getter
|
@Getter
|
||||||
public static final int Version1;
|
public static final int version1;
|
||||||
@Getter
|
@Getter
|
||||||
public static final int Version2;
|
public static final int version2;
|
||||||
@Getter
|
@Getter
|
||||||
public static final int Version3;
|
public static final int version3;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
String version = getMCVersion();
|
String version = getMCVersion();
|
||||||
String[] split = version.split("\\.");
|
String[] split = version.split("\\.");
|
||||||
Version1 = Integer.parseInt(split[0]);
|
version1 = Integer.parseInt(split[0]);
|
||||||
Version2 = Integer.parseInt(split[1]);
|
version2 = Integer.parseInt(split[1]);
|
||||||
Version3 = split.length >= 3 ? Integer.parseInt(split[2]) : 0;
|
version3 = split.length >= 3 ? Integer.parseInt(split[2]) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,18 +35,18 @@ public class MinecraftVersion {
|
|||||||
*/
|
*/
|
||||||
public static int compareTo(@NotNull String version) {
|
public static int compareTo(@NotNull String version) {
|
||||||
String[] split = version.split("\\.");
|
String[] split = version.split("\\.");
|
||||||
int version1 = Integer.parseInt(split[0]);
|
int compareVersion1 = Integer.parseInt(split[0]);
|
||||||
int version2 = Integer.parseInt(split[1]);
|
int compareVersion2 = Integer.parseInt(split[1]);
|
||||||
int version3 = split.length >= 3 ? Integer.parseInt(split[2]) : 0;
|
int compareVersion3 = split.length >= 3 ? Integer.parseInt(split[2]) : 0;
|
||||||
int compare = Integer.compare(Version1, version1);
|
int compare = Integer.compare(compareVersion1, MinecraftVersion.version1);
|
||||||
if (compare != 0) {
|
if (compare != 0) {
|
||||||
return compare;
|
return compare;
|
||||||
}
|
}
|
||||||
compare = Integer.compare(Version2, version2);
|
compare = Integer.compare(compareVersion2, MinecraftVersion.version2);
|
||||||
if (compare != 0) {
|
if (compare != 0) {
|
||||||
return compare;
|
return compare;
|
||||||
}
|
}
|
||||||
return Integer.compare(Version3, version3);
|
return Integer.compare(compareVersion3, MinecraftVersion.version3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -61,7 +61,7 @@ public class MinecraftVersion {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Class<?> getNMSClass(@NotNull String className) throws ClassNotFoundException {
|
public static Class<?> getNMSClass(@NotNull String className) throws ClassNotFoundException {
|
||||||
if (Version2 >= 17) {
|
if (version1 >= 1 && version2 >= 17) {
|
||||||
return Class.forName("net.minecraft.server." + className);
|
return Class.forName("net.minecraft.server." + className);
|
||||||
}
|
}
|
||||||
String nmsVersion = getNMSVersion();
|
String nmsVersion = getNMSVersion();
|
||||||
@@ -70,9 +70,8 @@ public class MinecraftVersion {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Class<?> getNMSClassSilent(@NotNull String className) {
|
public static Class<?> getNMSClassSilent(@NotNull String className) {
|
||||||
String nmsVersion = getNMSVersion();
|
|
||||||
try {
|
try {
|
||||||
return Class.forName("net.minecraft.server." + nmsVersion + "." + className);
|
return getNMSClass(className);
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -80,15 +79,17 @@ public class MinecraftVersion {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Class<?> getCraftBukkitClass(@NotNull String className) throws ClassNotFoundException {
|
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();
|
String nmsVersion = getNMSVersion();
|
||||||
return Class.forName("org.bukkit.craftbukkit." + nmsVersion + "." + className);
|
return Class.forName("org.bukkit.craftbukkit." + nmsVersion + "." + className);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Class<?> getCraftBukkitClassSilent(@NotNull String className) {
|
public static Class<?> getCraftBukkitClassSilent(@NotNull String className) {
|
||||||
String nmsVersion = getNMSVersion();
|
|
||||||
try {
|
try {
|
||||||
return Class.forName("org.bukkit.craftbukkit." + nmsVersion + "." + className);
|
return getCraftBukkitClass(className);
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@@ -118,42 +118,24 @@ public class CompletableTask<T> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T get() throws Throwable {
|
public T get() throws InterruptedException {
|
||||||
if (state == State.WAITING) {
|
if (state == State.WAITING) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
try {
|
wait();
|
||||||
wait();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch (state) {
|
if (state == State.SUCCESS) {
|
||||||
case SUCCESS:
|
return value;
|
||||||
return value;
|
|
||||||
case FAILED:
|
|
||||||
throw throwable;
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T getOrDefault(T defaultValue) {
|
public T join() {
|
||||||
if (state == State.WAITING) {
|
try {
|
||||||
synchronized (this) {
|
return get();
|
||||||
try {
|
} catch (Exception e) {
|
||||||
wait();
|
throw new RuntimeException(e);
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
switch (state) {
|
|
||||||
case SUCCESS:
|
|
||||||
return value;
|
|
||||||
case FAILED:
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
return defaultValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum State {
|
public enum State {
|
||||||
|
Reference in New Issue
Block a user