Warn on outdated Java version

This commit is contained in:
RednedEpic 2023-05-08 19:08:40 -05:00
parent 6da8d5e7be
commit a0b63abc6e
2 changed files with 33 additions and 0 deletions

View File

@ -540,6 +540,8 @@ public class GeyserImpl implements GeyserApi {
if (config.isNotifyOnNewBedrockUpdate()) {
VersionCheckUtils.checkForGeyserUpdate(this::getLogger);
}
VersionCheckUtils.checkForOutdatedJava(logger);
}
@Override

View File

@ -42,9 +42,12 @@ import javax.annotation.Nonnull;
import java.util.OptionalInt;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public final class VersionCheckUtils {
private static @Nonnull OptionalInt LATEST_BEDROCK_RELEASE = OptionalInt.empty();
private static final int SUPPORTED_JAVA_VERSION = 17;
public static void checkForOutdatedFloodgate(GeyserLogger logger) {
try {
@ -57,6 +60,34 @@ public final class VersionCheckUtils {
}
}
public static void checkForOutdatedJava(GeyserLogger logger) {
// Taken from Paper
String javaVersion = System.getProperty("java.version");
Matcher matcher = Pattern.compile("(?:1\\.)?(\\d+)").matcher(javaVersion);
if (!matcher.find()) {
logger.debug("Could not parse Java version string " + javaVersion);
return;
}
String version = matcher.group(1);
int majorVersion;
try {
majorVersion = Integer.parseInt(version);
} catch (NumberFormatException e) {
logger.debug("Could not format as an int: " + version);
return;
}
if (majorVersion < SUPPORTED_JAVA_VERSION) {
logger.warning("*********************************************");
logger.warning("");
logger.warning(GeyserLocale.getLocaleStringLog("geyser.bootstrap.unsupported_java.header"));
logger.warning(GeyserLocale.getLocaleStringLog("geyser.bootstrap.unsupported_java.message", SUPPORTED_JAVA_VERSION, javaVersion));
logger.warning("");
logger.warning("*********************************************");
}
}
public static void checkForGeyserUpdate(Supplier<GeyserCommandSource> recipient) {
CompletableFuture.runAsync(() -> {
try {