diff --git a/common/src/main/java/me/lojosho/hibiscuscommons/nms/MinecraftVersion.java b/common/src/main/java/me/lojosho/hibiscuscommons/nms/MinecraftVersion.java index 73d85c5..821380f 100644 --- a/common/src/main/java/me/lojosho/hibiscuscommons/nms/MinecraftVersion.java +++ b/common/src/main/java/me/lojosho/hibiscuscommons/nms/MinecraftVersion.java @@ -6,11 +6,14 @@ import org.jetbrains.annotations.Nullable; public enum MinecraftVersion { v1_20_4, v1_20_6, + v1_21, v1_21_1, + v1_21_2, v1_21_3, v1_21_4, v1_21_5, v1_21_6, + v1_21_7, ; public boolean isHigher(MinecraftVersion other) { diff --git a/common/src/main/java/me/lojosho/hibiscuscommons/nms/NMSHandlers.java b/common/src/main/java/me/lojosho/hibiscuscommons/nms/NMSHandlers.java index 81e1a0f..c2e397d 100644 --- a/common/src/main/java/me/lojosho/hibiscuscommons/nms/NMSHandlers.java +++ b/common/src/main/java/me/lojosho/hibiscuscommons/nms/NMSHandlers.java @@ -6,20 +6,21 @@ import org.bukkit.Bukkit; import java.lang.reflect.InvocationTargetException; import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; public class NMSHandlers { - private static final LinkedHashMap VERSION_MAP = new LinkedHashMap <>() {{ - put(MinecraftVersion.v1_20_4, "v1_20_R3"); - // 1.20.5 is not supported; was imminently bumped to 1.20.6 - put(MinecraftVersion.v1_20_6, "v1_20_R4"); - // 1.20 is not supported; was imminently bumped to 1.21.1 - put(MinecraftVersion.v1_21_1, "v1_21_R1"); - // 1.20.2 is not supported; was imminently bumped to 1.21.3 - put(MinecraftVersion.v1_21_3, "v1_21_R2"); - put(MinecraftVersion.v1_21_4, "v1_21_R3"); - put(MinecraftVersion.v1_21_5, "v1_21_R4"); - put(MinecraftVersion.v1_21_6, "v1_21_R5"); + private static final LinkedHashMap VERSION_MAP = new LinkedHashMap <>() {{ + put(MinecraftVersion.v1_20_6, new MinecraftVersionInformation("v1_20_R4", true)); + put(MinecraftVersion.v1_21, new MinecraftVersionInformation("v1_21_R1", false)); // 1.20 is not supported; was imminently bumped to 1.21.1 + put(MinecraftVersion.v1_21_1, new MinecraftVersionInformation("v1_21_R1", true)); + put(MinecraftVersion.v1_21_2, new MinecraftVersionInformation("v1_21_R2", false)); // 1.20.2 is not supported; was imminently bumped to 1.21.3 + put(MinecraftVersion.v1_21_3, new MinecraftVersionInformation("v1_21_R2", true)); + put(MinecraftVersion.v1_21_4, new MinecraftVersionInformation("v1_21_R3", true)); + put(MinecraftVersion.v1_21_5, new MinecraftVersionInformation("v1_21_R4", true)); + put(MinecraftVersion.v1_21_6, new MinecraftVersionInformation("v1_21_R5", false)); + put(MinecraftVersion.v1_21_7, new MinecraftVersionInformation("v1_21_R5", true)); }}; private static NMSHandler handler; @@ -40,7 +41,7 @@ public class NMSHandlers { final String bukkitVersion = Bukkit.getServer().getBukkitVersion(); String minecraftVersion = bukkitVersion.substring(0, bukkitVersion.indexOf('-')); MinecraftVersion enumVersion = MinecraftVersion.fromVersionString(minecraftVersion); - String packageVersion = VERSION_MAP.get(enumVersion); + MinecraftVersionInformation packageVersion = VERSION_MAP.get(enumVersion); if (packageVersion == null) { HibiscusCommonsPlugin.getInstance().getLogger().severe("An error occurred while trying to detect the version of the server."); @@ -50,23 +51,37 @@ public class NMSHandlers { HibiscusCommonsPlugin.getInstance().getLogger().severe("Detected Package Version: " + packageVersion); HibiscusCommonsPlugin.getInstance().getLogger().severe(" "); HibiscusCommonsPlugin.getInstance().getLogger().severe("Supported versions:"); - for (MinecraftVersion supportedVersion : VERSION_MAP.keySet()) { - HibiscusCommonsPlugin.getInstance().getLogger().severe(" - " + supportedVersion.toVersionString()); - } + sendSupportedVersions(); HibiscusCommonsPlugin.getInstance().getLogger().severe(" "); HibiscusCommonsPlugin.getInstance().getLogger().severe("Please update HibiscusCommons that supports this version."); throw new RuntimeException("Failed to detect the server version."); } - for (String selectedVersion : VERSION_MAP.values()) { - if (!selectedVersion.contains(packageVersion)) { + for (Map.Entry selectedVersion : VERSION_MAP.entrySet()) { + String internalReference = selectedVersion.getValue().internalReference(); + if (!internalReference.contains(packageVersion.internalReference())) { continue; } - //MessagesUtil.sendDebugMessages(packageVersion + " has been detected.", Level.INFO); - version = enumVersion; + + version = selectedVersion.getKey(); + + if (!selectedVersion.getValue().supported()) { + HibiscusCommonsPlugin.getInstance().getLogger().severe("Detected Deprecated Version!"); + HibiscusCommonsPlugin.getInstance().getLogger().severe(" "); + HibiscusCommonsPlugin.getInstance().getLogger().severe("Package Version: " + packageVersion.internalReference()); + HibiscusCommonsPlugin.getInstance().getLogger().severe("Is Supported: " + packageVersion.supported()); + HibiscusCommonsPlugin.getInstance().getLogger().severe(" "); + HibiscusCommonsPlugin.getInstance().getLogger().severe("This version has no explicit support for it. There maybe errors that are unfixable."); + HibiscusCommonsPlugin.getInstance().getLogger().severe("Consider moving to a version with explicit support. "); + HibiscusCommonsPlugin.getInstance().getLogger().severe(" "); + HibiscusCommonsPlugin.getInstance().getLogger().severe("Supported versions:"); + sendSupportedVersions(); + HibiscusCommonsPlugin.getInstance().getLogger().severe(" "); + } + try { - NMSUtils utilHandler = (NMSUtils) Class.forName("me.lojosho.hibiscuscommons.nms." + packageVersion + ".NMSUtils").getConstructor().newInstance(); - NMSPackets packetHandler = (NMSPackets) Class.forName("me.lojosho.hibiscuscommons.nms." + packageVersion + ".NMSPackets").getConstructor().newInstance(); + NMSUtils utilHandler = (NMSUtils) Class.forName("me.lojosho.hibiscuscommons.nms." + packageVersion.internalReference() + ".NMSUtils").getConstructor().newInstance(); + NMSPackets packetHandler = (NMSPackets) Class.forName("me.lojosho.hibiscuscommons.nms." + packageVersion.internalReference() + ".NMSPackets").getConstructor().newInstance(); handler = new NMSHandler(utilHandler, packetHandler); return; } catch (ClassNotFoundException | InvocationTargetException | InstantiationException | @@ -75,4 +90,13 @@ public class NMSHandlers { } } } + + private static void sendSupportedVersions() { + for (Map.Entry entry : VERSION_MAP.entrySet()) { + if (!entry.getValue().supported()) continue; + HibiscusCommonsPlugin.getInstance().getLogger().severe(" - " + entry.getKey().toVersionString()); + } + } + + private record MinecraftVersionInformation(String internalReference, boolean supported) {} } diff --git a/common/src/main/java/me/lojosho/hibiscuscommons/util/MessagesUtil.java b/common/src/main/java/me/lojosho/hibiscuscommons/util/MessagesUtil.java index 2d07acf..0cf0aa1 100644 --- a/common/src/main/java/me/lojosho/hibiscuscommons/util/MessagesUtil.java +++ b/common/src/main/java/me/lojosho/hibiscuscommons/util/MessagesUtil.java @@ -6,7 +6,7 @@ import java.util.logging.Level; public class MessagesUtil { - private static boolean debug = false; + private static boolean debug = true; public static void sendDebugMessages(String message) {