mirror of
https://github.com/garbagemule/MobArena.git
synced 2024-11-23 02:55:46 +01:00
Add server version compatibility check.
Instead of the obscure error thrown from ArenaClass when the SHIELD enum value on Material isn't found, MobArena throws its own, more human-friendly error. Fixes #469
This commit is contained in:
parent
650e7bbd44
commit
5699fafeb0
@ -69,6 +69,8 @@ public class MobArena extends JavaPlugin
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
ServerVersionCheck.check(getServer());
|
||||
|
||||
// Initialize config-file
|
||||
configFile = new File(getDataFolder(), "config.yml");
|
||||
config = new YamlConfiguration();
|
||||
|
@ -0,0 +1,44 @@
|
||||
package com.garbagemule.MobArena;
|
||||
|
||||
import org.bukkit.Server;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
class ServerVersionCheck {
|
||||
|
||||
private static final String[] EXACTS = {"1.11", "1.12"};
|
||||
private static final String[] PREFIXES = {"1.11.", "1.12."};
|
||||
|
||||
static void check(Server server) {
|
||||
String version = getMinecraftVersion(server);
|
||||
|
||||
for (String exact : EXACTS) {
|
||||
if (version.equals(exact)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (String prefix : PREFIXES) {
|
||||
if (version.startsWith(prefix)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
// Same substring as the one bStats uses, so should be safe
|
||||
String version = server.getVersion();
|
||||
int start = version.indexOf("MC: ") + 4;
|
||||
int end = version.length() - 1;
|
||||
return version.substring(start, end);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user