mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 14:46:45 +01:00
Add java version checker
This commit is contained in:
parent
ec683cdf88
commit
5d30e0854f
@ -156,6 +156,7 @@ import java.util.concurrent.Executors;
|
|||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static com.plotsquared.bukkit.util.JavaVersionCheck.checkJavaVersion;
|
||||||
import static com.plotsquared.core.util.PremiumVerification.getDownloadID;
|
import static com.plotsquared.core.util.PremiumVerification.getDownloadID;
|
||||||
import static com.plotsquared.core.util.PremiumVerification.getResourceID;
|
import static com.plotsquared.core.util.PremiumVerification.getResourceID;
|
||||||
import static com.plotsquared.core.util.PremiumVerification.getUserID;
|
import static com.plotsquared.core.util.PremiumVerification.getUserID;
|
||||||
@ -242,6 +243,9 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check whether the server runs on 11 or greater
|
||||||
|
checkJavaVersion();
|
||||||
|
|
||||||
// We create the injector after PlotSquared has been initialized, so that we have access
|
// We create the injector after PlotSquared has been initialized, so that we have access
|
||||||
// to generated instances and settings
|
// to generated instances and settings
|
||||||
this.injector = Guice
|
this.injector = Guice
|
||||||
|
@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* _____ _ _ _____ _
|
||||||
|
* | __ \| | | | / ____| | |
|
||||||
|
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||||
|
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||||
|
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||||
|
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||||
|
* | |
|
||||||
|
* |_|
|
||||||
|
* PlotSquared plot management system for Minecraft
|
||||||
|
* Copyright (C) 2020 IntellectualSites
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.plotsquared.bukkit.util;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class JavaVersionCheck {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger("P2/" + JavaVersionCheck.class.getSimpleName());
|
||||||
|
|
||||||
|
public JavaVersionCheck() {}
|
||||||
|
|
||||||
|
public static void checkJavaVersion() {
|
||||||
|
final String javaVersion = System.getProperty("java.version");
|
||||||
|
final int dotIndex = javaVersion.indexOf('.');
|
||||||
|
|
||||||
|
if (javaVersion.startsWith("1.")) {
|
||||||
|
JavaVersionCheck.notify(javaVersion, logger);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final int endIndex = dotIndex == -1 ? javaVersion.length() : dotIndex;
|
||||||
|
final String version = javaVersion.substring(0, endIndex);
|
||||||
|
|
||||||
|
final int javaVersionNumber;
|
||||||
|
try {
|
||||||
|
javaVersionNumber = Integer.parseInt(version);
|
||||||
|
} catch (final NumberFormatException e) {
|
||||||
|
logger.error("Failed to determine Java version. Could not parse {}", version, e);
|
||||||
|
JavaVersionCheck.notify(javaVersion, logger);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (javaVersionNumber < 11) {
|
||||||
|
JavaVersionCheck.notify(javaVersion, logger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void notify(final String version, final Logger logger) {
|
||||||
|
logger.error("************************************************************");
|
||||||
|
logger.error("* WARNING - YOU ARE RUNNING AN OUTDATED VERSION OF JAVA.");
|
||||||
|
logger.error("* PLOTSQUARED WILL STOP BEING COMPATIBLE WITH THIS VERSION OF");
|
||||||
|
logger.error("* JAVA WHEN MINECRAFT 1.17 IS RELEASED.");
|
||||||
|
logger.error("*");
|
||||||
|
logger.error("* Please update the version of Java to 11.");
|
||||||
|
logger.error("*");
|
||||||
|
logger.error("* Current Java version: " + version);
|
||||||
|
logger.error("************************************************************");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user