Use a blacklist for the server version check.
The whitelisting approach works well for the legacy builds, because the version landscape doesn't change with those. However, the main build on the master branch will not run on a server version other than 1.13, so come 1.14, MobArena will be broken. This commit fixes this problem by changing to a blacklisting approach for the main build on the master branch. Checking for versions that the build *can't* run on brings back MobArena's old resilience to version changes on the Minecraft side of things.
This commit is contained in:
@@ -2,35 +2,26 @@ package com.garbagemule.MobArena;
|
||||
|
||||
import org.bukkit.Server;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
class ServerVersionCheck {
|
||||
|
||||
private static final String[] EXACTS = {"1.13"};
|
||||
private static final String[] PREFIXES = {"1.13."};
|
||||
private static final String[] EXACTS = {"1.8", "1.9", "1.10", "1.11", "1.12"};
|
||||
private static final String[] PREFIXES = {"1.8.", "1.9.", "1.10.", "1.11.", "1.12."};
|
||||
|
||||
static void check(Server server) {
|
||||
String version = getMinecraftVersion(server);
|
||||
|
||||
for (String exact : EXACTS) {
|
||||
if (version.equals(exact)) {
|
||||
return;
|
||||
fail(version);
|
||||
}
|
||||
}
|
||||
for (String prefix : PREFIXES) {
|
||||
if (version.startsWith(prefix)) {
|
||||
return;
|
||||
fail(version);
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalStateException(new StringJoiner(" ")
|
||||
.add("Incompatible server version!")
|
||||
.add("This build only works on " + Arrays.toString(EXACTS) + ",")
|
||||
.add("but this server is running " + version + ".")
|
||||
.add("Perhaps you downloaded the wrong build?")
|
||||
.toString()
|
||||
);
|
||||
}
|
||||
|
||||
private static String getMinecraftVersion(Server server) {
|
||||
@@ -41,4 +32,13 @@ class ServerVersionCheck {
|
||||
return version.substring(start, end);
|
||||
}
|
||||
|
||||
private static void fail(String version) {
|
||||
throw new IllegalStateException(new StringJoiner(" ")
|
||||
.add("Incompatible server version!")
|
||||
.add("This build does not work on " + version + ".")
|
||||
.add("Perhaps you downloaded the wrong build?")
|
||||
.toString()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user