Skip to content

Commit

Permalink
Add Java 17 warning
Browse files Browse the repository at this point in the history
  • Loading branch information
SamB440 committed Jul 20, 2024
1 parent 4616c0a commit 4ebf752
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/ac/grim/grimac/manager/InitManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Initable>()
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/ac/grim/grimac/manager/init/start/JavaVersion.java
Original file line number Diff line number Diff line change
@@ -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.");
}
}
}

0 comments on commit 4ebf752

Please sign in to comment.