Refactor CraftBukkitImplementation utility

This commit is contained in:
Luck 2020-01-25 16:43:53 +00:00
parent 5fe7302965
commit 26de6cf86f
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B

View File

@ -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;
} }
} }