From 788d7b648dcc47b1b7f36e3d6b87ece5bdfe0568 Mon Sep 17 00:00:00 2001 From: RMJTromp Date: Tue, 18 Jun 2024 10:35:29 +0200 Subject: [PATCH] Reimplemented how server version is get to support the new paper-spigot updates. --- .../rmjtromp/chatemojis/utils/BukkitUtils.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/rmjtromp/chatemojis/utils/BukkitUtils.java b/src/main/java/com/rmjtromp/chatemojis/utils/BukkitUtils.java index 406b875..b55592f 100644 --- a/src/main/java/com/rmjtromp/chatemojis/utils/BukkitUtils.java +++ b/src/main/java/com/rmjtromp/chatemojis/utils/BukkitUtils.java @@ -33,8 +33,14 @@ public static Plugin getPlugin() { * Returns the server version for reflection use * @return Server Version */ + private static boolean hasVersionInPackageName = true; public static String getServerVersion() { - return Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]; + try { + return Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]; + } catch (ArrayIndexOutOfBoundsException e) { + hasVersionInPackageName = false; + return "v" + Bukkit.getBukkitVersion().replace(".", "_"); + } } /** @@ -81,7 +87,12 @@ public static List colorEncode(String...strings) { * @throws ClassNotFoundException Thrown if class could not be found */ public static Class getClass(@Pattern("^.+?\\.%s\\..+$") @NotNull String string) throws ClassNotFoundException { - return Class.forName(String.format(string, BukkitUtils.getServerVersion())); + String version = BukkitUtils.getServerVersion(); + + if(hasVersionInPackageName) + return Class.forName(String.format(string, version)); + + return Class.forName(string.replace(".%s", "")); } }