From a0b63abc6ef0e9840a8ab968d4b691d429efe139 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Mon, 8 May 2023 19:08:40 -0500 Subject: [PATCH] Warn on outdated Java version --- .../java/org/geysermc/geyser/GeyserImpl.java | 2 ++ .../geyser/util/VersionCheckUtils.java | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/core/src/main/java/org/geysermc/geyser/GeyserImpl.java b/core/src/main/java/org/geysermc/geyser/GeyserImpl.java index 45321163b..8204cfd3b 100644 --- a/core/src/main/java/org/geysermc/geyser/GeyserImpl.java +++ b/core/src/main/java/org/geysermc/geyser/GeyserImpl.java @@ -540,6 +540,8 @@ public class GeyserImpl implements GeyserApi { if (config.isNotifyOnNewBedrockUpdate()) { VersionCheckUtils.checkForGeyserUpdate(this::getLogger); } + + VersionCheckUtils.checkForOutdatedJava(logger); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/util/VersionCheckUtils.java b/core/src/main/java/org/geysermc/geyser/util/VersionCheckUtils.java index dc0edd37a..c0fd10232 100644 --- a/core/src/main/java/org/geysermc/geyser/util/VersionCheckUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/VersionCheckUtils.java @@ -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 recipient) { CompletableFuture.runAsync(() -> { try {