mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-10 12:59:40 +01:00
Refactor CraftBukkitImplementation utility
This commit is contained in:
parent
5fe7302965
commit
26de6cf86f
@ -27,23 +27,24 @@ package me.lucko.luckperms.bukkit.util;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public final class CraftBukkitImplementation {
|
public final class CraftBukkitImplementation {
|
||||||
private CraftBukkitImplementation() {}
|
private CraftBukkitImplementation() {}
|
||||||
|
|
||||||
private static final String SERVER_PACKAGE_VERSION = getServerPackageVersion();
|
private static final String SERVER_PACKAGE_VERSION;
|
||||||
private static final boolean CHAT_COMPATIBLE = !SERVER_PACKAGE_VERSION.startsWith(".v1_7_");
|
private static final boolean CHAT_COMPATIBLE;
|
||||||
|
|
||||||
private static String getServerPackageVersion() {
|
static {
|
||||||
Class<?> server = Bukkit.getServer().getClass();
|
Class<?> server = Bukkit.getServer().getClass();
|
||||||
if (!server.getSimpleName().equals("CraftServer")) {
|
Matcher matcher = Pattern.compile("^org\\.bukkit\\.craftbukkit\\.(\\w+)\\.CraftServer$").matcher(server.getName());
|
||||||
return ".";
|
if (matcher.matches()) {
|
||||||
}
|
SERVER_PACKAGE_VERSION = '.' + matcher.group(1) + '.';
|
||||||
if (server.getName().equals("org.bukkit.craftbukkit.CraftServer")) {
|
CHAT_COMPATIBLE = !SERVER_PACKAGE_VERSION.startsWith(".v1_7_");
|
||||||
// Non versioned class
|
|
||||||
return ".";
|
|
||||||
} else {
|
} else {
|
||||||
String version = server.getName().substring("org.bukkit.craftbukkit".length());
|
SERVER_PACKAGE_VERSION = ".";
|
||||||
return version.substring(0, version.length() - "CraftServer".length());
|
CHAT_COMPATIBLE = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user