Don't worry if we can't determine the Java version

This commit is contained in:
Dan Mulloy 2017-03-18 19:29:16 -04:00
parent 9289825d87
commit aaf1af8e41
2 changed files with 8 additions and 4 deletions

View File

@ -63,10 +63,14 @@ public class Util {
/**
* Gets the currently running major Java version.
* @return The version
* @return The version or -1 if it could not be found
*/
public static int getJavaVersion() {
String version = Runtime.class.getPackage().getSpecificationVersion();
return (int) (Double.valueOf(version) * 10 % 10);
try {
String version = Runtime.class.getPackage().getSpecificationVersion();
return (int) (Double.parseDouble(version) * 10 % 10);
} catch (Throwable ex) {
return -1;
}
}
}

View File

@ -156,7 +156,7 @@ public class ProtocolLib extends JavaPlugin {
ProtocolLogger.init(this);
int java = Util.getJavaVersion();
if (java < 8 && !getConfig().getBoolean("ignoreJava", false)) {
if (java != -1 && java < 8 && !getConfig().getBoolean("ignoreJava", false)) {
logger.warning("Detected outdated Java version: Java " + java);
logger.warning("It is recommended that you update to Java 8 as soon as possible.");
logger.warning("Future versions of ProtocolLib many not support Java " + java + ".");