Skip to content

Commit

Permalink
Reimplemented how server version is get to support the new paper-spig…
Browse files Browse the repository at this point in the history
…ot updates.
  • Loading branch information
RMJTromp committed Jun 18, 2024
1 parent f52ec47 commit 788d7b6
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main/java/com/rmjtromp/chatemojis/utils/BukkitUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(".", "_");
}
}

/**
Expand Down Expand Up @@ -81,7 +87,12 @@ public static List<String> 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", ""));
}

}
Expand Down

0 comments on commit 788d7b6

Please sign in to comment.