From 619548297df750fb859bccedc6815fe11f7e71b2 Mon Sep 17 00:00:00 2001 From: LabodiDavid Date: Thu, 12 Dec 2024 22:25:58 +0100 Subject: [PATCH] Added support for MC version up to 1.21.4 --- src/main/java/hu/ditservices/STPlugin.java | 4 +-- .../java/hu/ditservices/utils/Version.java | 35 +++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/main/java/hu/ditservices/STPlugin.java b/src/main/java/hu/ditservices/STPlugin.java index a780816..535e6f8 100644 --- a/src/main/java/hu/ditservices/STPlugin.java +++ b/src/main/java/hu/ditservices/STPlugin.java @@ -99,9 +99,9 @@ public final class STPlugin extends JavaPlugin implements CommandExecutor, Liste try { this.ServerStartTime = ManagementFactory.getRuntimeMXBean().getStartTime(); if (Version.ServerVersion.isCurrentLower(Version.ServerVersion.v1_12_R1) || - Version.ServerVersion.isCurrentHigher(Version.ServerVersion.v1_20_R2)) + Version.ServerVersion.isCurrentHigher(Version.ServerVersion.v1_21_4_R1)) { - throw new Exception("The server version is not supported! Update to a version between 1.12 - 1.20.2 to run this plugin."); + throw new Exception("The server version is not supported! Update to a version between 1.12 - 1.21.4 to run this plugin."); } if (this.reload()) { diff --git a/src/main/java/hu/ditservices/utils/Version.java b/src/main/java/hu/ditservices/utils/Version.java index 7dcd3b1..4da302e 100644 --- a/src/main/java/hu/ditservices/utils/Version.java +++ b/src/main/java/hu/ditservices/utils/Version.java @@ -28,7 +28,16 @@ public class Version { v1_19_R1, v1_19_R2, v1_20_R1, - v1_20_R2; + v1_20_R2, + v1_20_3_R1, + v1_20_4_R1, + v1_20_5_R1, + v1_20_6_R1, + v1_21_R1, + v1_21_1_R1, + v1_21_2_R1, + v1_21_3_R1, + v1_21_4_R1; private int value; @@ -59,11 +68,33 @@ public class Version { return current; } - public static String[] getArrayVersion() { + /*public static String[] getArrayVersion() { if (arrayVersion == null) { arrayVersion = org.bukkit.Bukkit.getServer().getClass().getPackage().getName().split("\\."); } + return arrayVersion; + }*/ + public static String[] getArrayVersion() { + if (arrayVersion == null) { + String packageName = org.bukkit.Bukkit.getServer().getClass().getPackage().getName(); + String[] splitPackageName = packageName.split("\\."); + + // Check if the splitPackageName length is more than 3 + if (splitPackageName.length > 3) { + arrayVersion = new String[] {splitPackageName[3]}; + } else { + // Handle the case for newer versions + String version = "UNKNOWN"; + try { + version = org.bukkit.Bukkit.getServer().getVersion().split("\\(MC: ")[1].split("\\)")[0]; + } catch (Exception e) { + e.printStackTrace(); + } + arrayVersion = new String[] {"v" + version.replace('.', '_') + "_R1"}; + } + } + return arrayVersion; }