|
@@ -6,9 +6,9 @@ import org.bukkit.Bukkit;
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.annotations.Nullable;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
import java.util.Locale;
|
|
import java.util.Locale;
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
+import java.util.regex.Matcher;
|
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
@@ -47,18 +47,19 @@ public class PlatformManager {
|
|
private @NotNull MinecraftGameVersion determineGameVersion(String platformVersionString) {
|
|
private @NotNull MinecraftGameVersion determineGameVersion(String platformVersionString) {
|
|
int major = 0, minor = 0, patch = 0;
|
|
int major = 0, minor = 0, patch = 0;
|
|
|
|
|
|
- String[] splitVersion = platformVersionString.split("\\.", 3);
|
|
|
|
-
|
|
|
|
mcMMO.p.getLogger().info("Platform String: " + platformVersionString);
|
|
mcMMO.p.getLogger().info("Platform String: " + platformVersionString);
|
|
|
|
|
|
- //TODO: this is very hacky and probably isn't reliable
|
|
|
|
- //Grab all consecutive digits
|
|
|
|
- major = getSubsequentDigits(splitVersion[0].toCharArray(), 0);
|
|
|
|
- minor = getSubsequentDigits(splitVersion[1].toCharArray(), 0);
|
|
|
|
- //Not all versions of Minecraft have a patch digit
|
|
|
|
- //If the first character isn't a digit it's not a patch number and its some crap we don't care about
|
|
|
|
- if(splitVersion.length > 2 && Character.isDigit(splitVersion[2].toCharArray()[0]))
|
|
|
|
- patch = getSubsequentDigits(splitVersion[2].toCharArray(), 0);
|
|
|
|
|
|
+ // Gets two numbers separated by . and optional third number after next dot. Must end with - or _
|
|
|
|
+ Matcher versionMatch = Pattern.compile("(\\d+)\\.(\\d+)(?:\\.(\\d+))?[-_].*").matcher(platformVersionString);
|
|
|
|
+
|
|
|
|
+ if (versionMatch.find()) {
|
|
|
|
+ major = Integer.parseInt(versionMatch.group(1));
|
|
|
|
+ minor = Integer.parseInt(versionMatch.group(2));
|
|
|
|
+
|
|
|
|
+ if (versionMatch.group(3) != null) {
|
|
|
|
+ patch = Integer.parseInt(versionMatch.group(3));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
mcMMO.p.getLogger().info("Minecraft version determined to be - "
|
|
mcMMO.p.getLogger().info("Minecraft version determined to be - "
|
|
+ major + "."
|
|
+ major + "."
|
|
@@ -68,34 +69,6 @@ public class PlatformManager {
|
|
return new MinecraftGameVersion(major, minor, patch);
|
|
return new MinecraftGameVersion(major, minor, patch);
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Get all consecutive digits in a char array from position
|
|
|
|
- * @param charArray target char array
|
|
|
|
- * @param position starting position
|
|
|
|
- * @return all consecutive digits from position
|
|
|
|
- */
|
|
|
|
- private int getSubsequentDigits(char[] charArray, int position) {
|
|
|
|
- ArrayList<Character> digitArrayList = new ArrayList<>();
|
|
|
|
-
|
|
|
|
- do {
|
|
|
|
- if(Character.isDigit(charArray[position])) {
|
|
|
|
- digitArrayList.add(charArray[position]);
|
|
|
|
- position++;
|
|
|
|
- } else {
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- } while (position < charArray.length);
|
|
|
|
-
|
|
|
|
- //Convert List<Character> -> String
|
|
|
|
- String digits = digitArrayList
|
|
|
|
- .stream()
|
|
|
|
- .map(String::valueOf)
|
|
|
|
- .collect(Collectors.joining());
|
|
|
|
-
|
|
|
|
- //Copy value
|
|
|
|
- return Integer.parseInt(digits);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
//TODO: Rewrite this properly once we actually support a not-bukkit platform
|
|
//TODO: Rewrite this properly once we actually support a not-bukkit platform
|
|
private @NotNull ServerSoftwareType determinePlatformType() {
|
|
private @NotNull ServerSoftwareType determinePlatformType() {
|
|
if(Bukkit.getVersion().toLowerCase(Locale.ENGLISH).contains("paper"))
|
|
if(Bukkit.getVersion().toLowerCase(Locale.ENGLISH).contains("paper"))
|