mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 13:16:45 +01:00
Fix mcmmo picking wrong version on builds withou patch number (#4555)
* Fix server versioning * Switch to regex when getting server version * add comment * Poor beginner mistakes Co-authored-by: TheBusyBiscuit <TheBusyBiscuit@users.noreply.github.com> Co-authored-by: TheBusyBiscuit <TheBusyBiscuit@users.noreply.github.com>
This commit is contained in:
parent
de6ba4fb6a
commit
e816310da8
@ -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
|
// Gets two numbers separated by . and optional third number after next dot. Must end with - or _
|
||||||
//Grab all consecutive digits
|
Matcher versionMatch = Pattern.compile("(\\d+)\\.(\\d+)(?:\\.(\\d+))?[-_].*").matcher(platformVersionString);
|
||||||
major = getSubsequentDigits(splitVersion[0].toCharArray(), 0);
|
|
||||||
minor = getSubsequentDigits(splitVersion[1].toCharArray(), 0);
|
if (versionMatch.find()) {
|
||||||
//Not all versions of Minecraft have a patch digit
|
major = Integer.parseInt(versionMatch.group(1));
|
||||||
//If the first character isn't a digit it's not a patch number and its some crap we don't care about
|
minor = Integer.parseInt(versionMatch.group(2));
|
||||||
if(splitVersion.length > 2 && Character.isDigit(splitVersion[2].toCharArray()[0]))
|
|
||||||
patch = getSubsequentDigits(splitVersion[2].toCharArray(), 0);
|
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"))
|
||||||
|
Loading…
Reference in New Issue
Block a user