Skip to content

Commit

Permalink
add a method to get the craftbukkit package version
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Jul 17, 2024
1 parent 09a0817 commit e67ff4b
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public final class VersionUtils {
private static final int MAJOR_VERSION;
private static final int MINOR_VERSION;
private static final boolean IS_CRAFTBUKKIT_MAPPED;
private static final String CRAFTBUKKIT_PACKAGE_VERSION;

static {
Matcher versionMatcher = Pattern.compile("MC: \\d\\.(\\d+)(\\.(\\d+))?").matcher(Bukkit.getVersion());
Expand All @@ -26,6 +27,11 @@ public final class VersionUtils {

Matcher packageMatcher = Pattern.compile("v\\d+_\\d+_R\\d+").matcher(Bukkit.getServer().getClass().getPackage().getName());
IS_CRAFTBUKKIT_MAPPED = packageMatcher.find();
if (IS_CRAFTBUKKIT_MAPPED) {
CRAFTBUKKIT_PACKAGE_VERSION = packageMatcher.group();
} else {
CRAFTBUKKIT_PACKAGE_VERSION = "";
}
}

private VersionUtils() {
Expand Down Expand Up @@ -153,4 +159,13 @@ public static boolean isLowerThan(int majorVersion, int minorVersion) {
public static boolean isCraftBukkitMapped() {
return IS_CRAFTBUKKIT_MAPPED;
}

/**
* Get the CraftBukkit package version
*
* @return the CraftBukkit package version, or empty if {@link #isCraftBukkitMapped()} returns false
*/
public static String getCraftBukkitPackageVersion() {
return CRAFTBUKKIT_PACKAGE_VERSION;
}
}

0 comments on commit e67ff4b

Please sign in to comment.