diff --git a/src/main/java/de/varoplugin/cfw/version/CrucibleVersionAdapter.java b/src/main/java/de/varoplugin/cfw/version/CrucibleVersionAdapter.java index 74766eb..c2b4697 100644 --- a/src/main/java/de/varoplugin/cfw/version/CrucibleVersionAdapter.java +++ b/src/main/java/de/varoplugin/cfw/version/CrucibleVersionAdapter.java @@ -39,7 +39,7 @@ protected void initServerProperties() throws ClassNotFoundException, NoSuchMetho @Override protected void initPlayer() throws NoSuchMethodException, SecurityException, NoSuchFieldException, ClassNotFoundException { - this.nmsPlayerClass = Class.forName("org.bukkit.craftbukkit." + VersionUtils.getNmsVersion() + ".entity.CraftPlayer").getMethod("getHandle").getReturnType(); + this.nmsPlayerClass = Class.forName(VersionUtils.getCraftBukkitPackage() + ".entity.CraftPlayer").getMethod("getHandle").getReturnType(); this.pingField = this.nmsPlayerClass.getField("field_71138_i"); this.connectionField = this.nmsPlayerClass.getField("field_71135_a"); this.sendPacketMethod = this.connectionField.getType().getMethod("func_147359_a", Class.forName("net.minecraft.network.Packet")); diff --git a/src/main/java/de/varoplugin/cfw/version/OneNineteenVersionAdapter.java b/src/main/java/de/varoplugin/cfw/version/OneNineteenVersionAdapter.java index c4d612f..0d7c03e 100644 --- a/src/main/java/de/varoplugin/cfw/version/OneNineteenVersionAdapter.java +++ b/src/main/java/de/varoplugin/cfw/version/OneNineteenVersionAdapter.java @@ -34,7 +34,7 @@ public class OneNineteenVersionAdapter extends OneSeventeenVersionAdapter { @Override public void forceClearWorlds() { try { - Field dedicatedServerField = Class.forName("org.bukkit.craftbukkit." + VersionUtils.getNmsVersion() + ".CraftServer").getDeclaredField("console"); + Field dedicatedServerField = Class.forName(VersionUtils.getCraftBukkitPackage() + ".CraftServer").getDeclaredField("console"); dedicatedServerField.setAccessible(true); Object dedicatedServer = dedicatedServerField.get(Bukkit.getServer()); Field worldServerField = dedicatedServer.getClass().getSuperclass().getDeclaredField(this.getWorldServerFieldName()); diff --git a/src/main/java/de/varoplugin/cfw/version/OneSevenVersionAdapter.java b/src/main/java/de/varoplugin/cfw/version/OneSevenVersionAdapter.java index fe9293e..161ef16 100644 --- a/src/main/java/de/varoplugin/cfw/version/OneSevenVersionAdapter.java +++ b/src/main/java/de/varoplugin/cfw/version/OneSevenVersionAdapter.java @@ -88,7 +88,7 @@ protected void initServerProperties() throws ClassNotFoundException, NoSuchMetho } protected void initEntity() throws NoSuchMethodException, SecurityException, ClassNotFoundException { - this.entityHandleMethod = Class.forName("org.bukkit.craftbukkit." + VersionUtils.getNmsVersion() + ".entity.CraftEntity").getMethod("getHandle"); + this.entityHandleMethod = Class.forName(VersionUtils.getCraftBukkitPackage() + ".entity.CraftEntity").getMethod("getHandle"); } protected void initPlayer() throws NoSuchMethodException, SecurityException, NoSuchFieldException, ClassNotFoundException { diff --git a/src/main/java/de/varoplugin/cfw/version/OneSixteenVersionAdapter.java b/src/main/java/de/varoplugin/cfw/version/OneSixteenVersionAdapter.java index face543..90ce680 100644 --- a/src/main/java/de/varoplugin/cfw/version/OneSixteenVersionAdapter.java +++ b/src/main/java/de/varoplugin/cfw/version/OneSixteenVersionAdapter.java @@ -34,7 +34,7 @@ public class OneSixteenVersionAdapter extends OneFourteenVersionAdapter { @Override public void forceClearWorlds() { try { - Field dedicatedServerField = Class.forName("org.bukkit.craftbukkit." + VersionUtils.getNmsVersion() + ".CraftServer").getDeclaredField("console"); + Field dedicatedServerField = Class.forName(VersionUtils.getCraftBukkitPackage() + ".CraftServer").getDeclaredField("console"); dedicatedServerField.setAccessible(true); Object dedicatedServer = dedicatedServerField.get(Bukkit.getServer()); Map worldServer = (Map) dedicatedServer.getClass().getField(this.getWorldServerFieldName()).get(dedicatedServer); diff --git a/src/main/java/de/varoplugin/cfw/version/OneTwelveVersionAdapter.java b/src/main/java/de/varoplugin/cfw/version/OneTwelveVersionAdapter.java index 310b810..c6e675b 100644 --- a/src/main/java/de/varoplugin/cfw/version/OneTwelveVersionAdapter.java +++ b/src/main/java/de/varoplugin/cfw/version/OneTwelveVersionAdapter.java @@ -40,7 +40,7 @@ class OneTwelveVersionAdapter extends OneNineVersionAdapter { @Override protected void initLocale() throws SecurityException, IllegalArgumentException { try { - this.localeMethod = Class.forName("org.bukkit.craftbukkit." + VersionUtils.getNmsVersion() + ".entity.CraftPlayer").getDeclaredMethod("getLocale"); + this.localeMethod = Class.forName(VersionUtils.getCraftBukkitPackage() + ".entity.CraftPlayer").getDeclaredMethod("getLocale"); } catch (NoSuchMethodException | SecurityException | ClassNotFoundException e) { e.printStackTrace(); } diff --git a/src/main/java/de/varoplugin/cfw/version/OneTwentyVersionAdapter.java b/src/main/java/de/varoplugin/cfw/version/OneTwentyVersionAdapter.java index d0e450e..32d028e 100644 --- a/src/main/java/de/varoplugin/cfw/version/OneTwentyVersionAdapter.java +++ b/src/main/java/de/varoplugin/cfw/version/OneTwentyVersionAdapter.java @@ -28,6 +28,11 @@ public class OneTwentyVersionAdapter extends OneNineteenVersionAdapter { + @Override + protected void initXp() { + // nop + } + @Override public void setXpCooldown(Player player, int cooldown) { player.setExpCooldown(cooldown); diff --git a/src/main/java/de/varoplugin/cfw/version/VersionUtils.java b/src/main/java/de/varoplugin/cfw/version/VersionUtils.java index 44768b7..96740ab 100644 --- a/src/main/java/de/varoplugin/cfw/version/VersionUtils.java +++ b/src/main/java/de/varoplugin/cfw/version/VersionUtils.java @@ -34,6 +34,7 @@ public class VersionUtils { private static final String FORGE_CLASS = "net.minecraftforge.common.MinecraftForge"; + private static final String craftBukkitPackage; private static final String nmsClass; private static final String nmsVersion; private static final boolean forgeSupport; @@ -50,18 +51,24 @@ public class VersionUtils { if (Bukkit.getServer() == null) { version = ServerVersion.UNSUPPORTED; serverSoftware = ServerSoftware.UNKNOWN; + craftBukkitPackage = null; nmsClass = null; nmsVersion = null; } else { - String base = "net.minecraft"; - nmsVersion = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; - if (nmsVersion.startsWith("v1")) { - // 1.7 - 1.16 - nmsClass = base + ".server." + nmsVersion; + craftBukkitPackage = Bukkit.getServer().getClass().getPackage().getName(); + String[] packageSplit = craftBukkitPackage.split("\\."); + if (packageSplit.length > 3) { + nmsVersion = packageSplit[3]; + if (nmsVersion.startsWith("v1")) { + // 1.7 - 1.16 + nmsClass = base + ".server." + nmsVersion; + } else + // Thermos (1.17+ does not use this string at all) + nmsClass = base + ".server"; } else { - // Thermos (1.17+ does not use this string at all) nmsClass = base + ".server"; + nmsVersion = Bukkit.getServer().getBukkitVersion().split("-")[0].replace('.', '_'); } version = ServerVersion.getVersion(nmsVersion); serverSoftware = ServerSoftware.getServerSoftware(); @@ -82,11 +89,15 @@ static boolean isClassPresent(String clazz) { } } + static String getCraftBukkitPackage() { + return craftBukkitPackage; + } + static String getNmsClass() { return nmsClass; } - public static String getNmsVersion() { + static String getNmsVersion() { return nmsVersion; }