mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-11-23 18:45:34 +01:00
Fix ServerVersion#UNKNOWN being treated like a normal version
This is required for unit tests (especially the `Bukkit#getServer != null` check). But it seems faulty to even trat an unknown version like a normal one.
This commit is contained in:
parent
02ab8d4bb2
commit
8310541b91
@ -6,26 +6,27 @@ import org.bukkit.Bukkit;
|
||||
public enum ServerVersion {
|
||||
UNKNOWN, V1_7, V1_8, V1_9, V1_10, V1_11, V1_12, V1_13, V1_14, V1_15, V1_16, V1_17, V1_18, V1_19, V1_20, V1_21;
|
||||
|
||||
private final static String serverPackagePath;
|
||||
private final static String serverPackageVersion;
|
||||
private final static String serverReleaseVersion;
|
||||
private final static ServerVersion serverVersion;
|
||||
private final static boolean isMocked;
|
||||
|
||||
static {
|
||||
String srvPackage = Bukkit.getServer().getClass().getPackage().getName();
|
||||
isMocked = srvPackage.equals("be.seeseemelk.mockbukkit");
|
||||
if (Bukkit.getServer() != null) {
|
||||
String srvPackage = Bukkit.getServer().getClass().getPackage().getName();
|
||||
isMocked = srvPackage.equals("be.seeseemelk.mockbukkit");
|
||||
|
||||
if (isMocked) {
|
||||
String packageVersionShard = "v" + Bukkit.getServer().getBukkitVersion().replace('.', '_') + "_R0";
|
||||
|
||||
serverPackagePath = "org.bukkit.craftbukkit." + packageVersionShard;
|
||||
serverPackageVersion = packageVersionShard;
|
||||
serverReleaseVersion = "0";
|
||||
if (isMocked) {
|
||||
serverPackageVersion = "v" + Bukkit.getServer().getBukkitVersion().replace('.', '_') + "_R0";
|
||||
serverReleaseVersion = "0";
|
||||
} else {
|
||||
serverPackageVersion = srvPackage.substring(srvPackage.lastIndexOf('.') + 1);
|
||||
serverReleaseVersion = serverPackageVersion.indexOf('R') != -1 ? serverPackageVersion.substring(serverPackageVersion.indexOf('R') + 1) : "";
|
||||
}
|
||||
} else {
|
||||
serverPackagePath = srvPackage;
|
||||
serverPackageVersion = serverPackagePath.substring(serverPackagePath.lastIndexOf('.') + 1);
|
||||
serverReleaseVersion = serverPackageVersion.indexOf('R') != -1 ? serverPackageVersion.substring(serverPackageVersion.indexOf('R') + 1) : "";
|
||||
serverPackageVersion = "Bukkit-not-initialized";
|
||||
serverReleaseVersion = "Bukkit-not-initialized";
|
||||
isMocked = false;
|
||||
}
|
||||
|
||||
serverVersion = getVersion();
|
||||
@ -42,18 +43,34 @@ public enum ServerVersion {
|
||||
}
|
||||
|
||||
public boolean isLessThan(ServerVersion other) {
|
||||
if (serverVersion == UNKNOWN) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.ordinal() < other.ordinal();
|
||||
}
|
||||
|
||||
public boolean isAtOrBelow(ServerVersion other) {
|
||||
if (serverVersion == UNKNOWN && other != UNKNOWN) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.ordinal() <= other.ordinal();
|
||||
}
|
||||
|
||||
public boolean isGreaterThan(ServerVersion other) {
|
||||
if (serverVersion == UNKNOWN) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.ordinal() > other.ordinal();
|
||||
}
|
||||
|
||||
public boolean isAtLeast(ServerVersion other) {
|
||||
if (serverVersion == UNKNOWN && other != UNKNOWN) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.ordinal() >= other.ordinal();
|
||||
}
|
||||
|
||||
@ -78,18 +95,34 @@ public enum ServerVersion {
|
||||
}
|
||||
|
||||
public static boolean isServerVersionAbove(ServerVersion version) {
|
||||
if (serverVersion == UNKNOWN) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return serverVersion.ordinal() > version.ordinal();
|
||||
}
|
||||
|
||||
public static boolean isServerVersionAtLeast(ServerVersion version) {
|
||||
if (serverVersion == UNKNOWN && version != UNKNOWN) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return serverVersion.ordinal() >= version.ordinal();
|
||||
}
|
||||
|
||||
public static boolean isServerVersionAtOrBelow(ServerVersion version) {
|
||||
if (serverVersion == UNKNOWN && version != UNKNOWN) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return serverVersion.ordinal() <= version.ordinal();
|
||||
}
|
||||
|
||||
public static boolean isServerVersionBelow(ServerVersion version) {
|
||||
if (serverVersion == UNKNOWN) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return serverVersion.ordinal() < version.ordinal();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user