From 3af1f45b4c43836551ef55f181d6166a8bc1bb96 Mon Sep 17 00:00:00 2001 From: N0tMyFaultOG Date: Tue, 8 Dec 2020 00:12:39 +0100 Subject: [PATCH] Add note about outdated java version --- .../fawe/bukkit/util/JavaVersionCheck.java | 53 +++++++++++++++++++ .../worldedit/bukkit/WorldEditPlugin.java | 4 ++ 2 files changed, 57 insertions(+) create mode 100644 worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/JavaVersionCheck.java diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/JavaVersionCheck.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/JavaVersionCheck.java new file mode 100644 index 000000000..b0fe317e2 --- /dev/null +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/JavaVersionCheck.java @@ -0,0 +1,53 @@ +package com.boydti.fawe.bukkit.util; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class JavaVersionCheck { + + public static final Logger logger = LoggerFactory.getLogger(JavaVersionCheck.class); + + private static int checkJavaVersion() { + String javaVersion = System.getProperty("java.version"); + final Matcher matcher = Pattern.compile("(?:1\\.)?(\\d+)").matcher(javaVersion); + if (!matcher.find()) { + logger.warn("Failed to determine Java version; Could not parse: {}", javaVersion); + return -1; + } + + final String version = matcher.group(1); + try { + return Integer.parseInt(version); + } catch (final NumberFormatException e) { + logger.warn("Failed to determine Java version; Could not parse {} from {}", version, javaVersion, e); + return -1; + } + } + + public static void checkJvm() { + if (checkJavaVersion() < 11) { + logger.warn("************************************************************"); + logger.warn("* WARNING - YOU ARE RUNNING AN OUTDATED VERSION OF JAVA."); + logger.warn("* FASTASYNCWORLDEDIT WILL STOP BEING COMPATIBLE WITH THIS VERSION OF"); + logger.warn("* JAVA WHEN MINECRAFT 1.17 IS RELEASED."); + logger.warn("*"); + logger.warn("* Please update the version of Java to 11. When Minecraft 1.17"); + logger.warn("* is released, support for versions of Java prior to 11 will"); + logger.warn("* be dropped."); + logger.warn("*"); + logger.warn("* Current Java version: {}", System.getProperty("java.version")); + logger.warn("************************************************************"); + } + if (checkJavaVersion() >= 15) { + logger.warn("************************************************************"); + logger.warn("* FastAsyncWorldEdit uses Nashorn for the craftscript engine."); + logger.warn("* Within Java 15, Nashorn has been removed from Java."); + logger.warn("* Until we add a suitable workaround, you should stick to Java 11"); + logger.warn("* to use all features of FastAsyncWorldEdit."); + logger.warn("************************************************************"); + } + } +} diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index 34f177580..f2d2e1347 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -84,6 +84,7 @@ import java.util.Locale; import java.util.Optional; import java.util.logging.Level; +import static com.boydti.fawe.bukkit.util.JavaVersionCheck.checkJvm; import static com.google.common.base.Preconditions.checkNotNull; import static com.sk89q.worldedit.internal.anvil.ChunkDeleter.DELCHUNKS_FILE_NAME; @@ -186,6 +187,9 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter // Setup metrics new Metrics(this, BSTATS_PLUGIN_ID); + + // Check whether the server runs on 11 or greater + checkJvm(); } private void setupPreWorldData() {