From 4ebf752522953da19f20f29b1511605ad425701b Mon Sep 17 00:00:00 2001 From: SamB440 Date: Sat, 20 Jul 2024 15:31:02 +0100 Subject: [PATCH] Add Java 17 warning --- .../ac/grim/grimac/manager/InitManager.java | 1 + .../manager/init/start/JavaVersion.java | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/main/java/ac/grim/grimac/manager/init/start/JavaVersion.java diff --git a/src/main/java/ac/grim/grimac/manager/InitManager.java b/src/main/java/ac/grim/grimac/manager/InitManager.java index 77de7c771a..49216c58da 100644 --- a/src/main/java/ac/grim/grimac/manager/InitManager.java +++ b/src/main/java/ac/grim/grimac/manager/InitManager.java @@ -32,6 +32,7 @@ public InitManager() { .put(DiscordManager.class, GrimAPI.INSTANCE.getDiscordManager()) .put(SpectateManager.class, GrimAPI.INSTANCE.getSpectateManager()) .put(GrimExternalAPI.class, GrimAPI.INSTANCE.getExternalAPI()) + .put(JavaVersion.class, new JavaVersion()) .build(); initializersOnStop = new ImmutableClassToInstanceMap.Builder() diff --git a/src/main/java/ac/grim/grimac/manager/init/start/JavaVersion.java b/src/main/java/ac/grim/grimac/manager/init/start/JavaVersion.java new file mode 100644 index 0000000000..b26afeac12 --- /dev/null +++ b/src/main/java/ac/grim/grimac/manager/init/start/JavaVersion.java @@ -0,0 +1,37 @@ +package ac.grim.grimac.manager.init.start; + +import ac.grim.grimac.manager.init.Initable; +import ac.grim.grimac.utils.anticheat.LogUtil; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class JavaVersion implements Initable { + + @Override + public void start() { + // Stolen from Via, stolen from Paper + String javaVersion = System.getProperty("java.version"); + Matcher matcher = Pattern.compile("(?:1\\.)?(\\d+)").matcher(javaVersion); + if (!matcher.find()) { + LogUtil.error("Failed to determine Java version; could not parse: " + javaVersion); + return; + } + + String versionString = matcher.group(1); + int version; + try { + version = Integer.parseInt(versionString); + } catch (NumberFormatException e) { + LogUtil.error("Failed to determine Java version; could not parse: " + versionString); + e.printStackTrace(); + return; + } + + if (version < 17) { + LogUtil.warn("You are running an outdated Java version, please update it to at least Java 17 (your version is " + javaVersion + ")."); + LogUtil.warn("GrimAC will no longer support this version of Java in a future release."); + LogUtil.warn("See https://github.com/GrimAnticheat/Grim/wiki/Updating-to-Java-17 for more information."); + } + } +}