From b4f5f18283b0b8dae3415d3a64ea270c572dad7d Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Fri, 14 Oct 2016 19:28:17 -0400 Subject: [PATCH] Strongly recommend Java 8 If you must use Java 7, set 'ignoreJava: true' in the config. --- .../com/comphenix/protocol/utility/Util.java | 9 +++ .../com/comphenix/protocol/Application.java | 58 ------------------- .../com/comphenix/protocol/ProtocolLib.java | 31 +++------- 3 files changed, 18 insertions(+), 80 deletions(-) delete mode 100644 modules/ProtocolLib/src/main/java/com/comphenix/protocol/Application.java diff --git a/modules/API/src/main/java/com/comphenix/protocol/utility/Util.java b/modules/API/src/main/java/com/comphenix/protocol/utility/Util.java index f6ef046d..ed36fce1 100644 --- a/modules/API/src/main/java/com/comphenix/protocol/utility/Util.java +++ b/modules/API/src/main/java/com/comphenix/protocol/utility/Util.java @@ -60,4 +60,13 @@ public class Util { public static boolean isUsingSpigot() { return Bukkit.getServer().getVersion().contains("Spigot"); } + + /** + * Gets the currently running major Java version. + * @return The version + */ + public static int getJavaVersion() { + String version = Runtime.class.getPackage().getSpecificationVersion(); + return (int) (Double.valueOf(version) * 10 % 10); + } } diff --git a/modules/ProtocolLib/src/main/java/com/comphenix/protocol/Application.java b/modules/ProtocolLib/src/main/java/com/comphenix/protocol/Application.java deleted file mode 100644 index 249f2115..00000000 --- a/modules/ProtocolLib/src/main/java/com/comphenix/protocol/Application.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. - * Copyright (C) 2012 Kristian S. Stangeland - * - * 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 2 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, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - * 02111-1307 USA - */ - -package com.comphenix.protocol; - -import org.bukkit.Bukkit; - -/** - * Ignore this class. - * - * @author Kristian - */ -public class Application { - private static Thread mainThread; - private static boolean primaryMethod = true; - - public static void main(String[] args) { - // For now, though we might consider making a proper application - System.out.println("This is a Bukkit library. Place it in the plugin-folder and restart the server!"); - } - - /** - * Determine if we are running on the main thread. - * @return TRUE if we are, FALSE otherwise. - */ - public static boolean isPrimaryThread() { - if (primaryMethod) { - try { - return Bukkit.isPrimaryThread(); - } catch (LinkageError e) { - primaryMethod = false; - } - } - // Fallback method - return Thread.currentThread().equals(mainThread); - } - - /** - * Register the calling thread as the primary thread. - */ - static void registerPrimaryThread() { - mainThread = Thread.currentThread(); - } -} diff --git a/modules/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLib.java b/modules/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLib.java index 3264cc10..412736e7 100644 --- a/modules/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLib.java +++ b/modules/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLib.java @@ -52,6 +52,7 @@ import com.comphenix.protocol.updater.Updater.UpdateType; import com.comphenix.protocol.utility.ChatExtensions; import com.comphenix.protocol.utility.EnhancerFactory; import com.comphenix.protocol.utility.MinecraftVersion; +import com.comphenix.protocol.utility.Util; import com.google.common.base.Splitter; import com.google.common.collect.Iterables; import com.google.common.collect.Sets; @@ -149,10 +150,16 @@ public class ProtocolLib extends JavaPlugin { @Override public void onLoad() { // Logging - logger = getLoggerSafely(); + logger = getLogger(); ProtocolLogger.init(this); - Application.registerPrimaryThread(); + int java = Util.getJavaVersion(); + if (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 + "."); + logger.warning("Java 8 will allow for much faster reflection performance."); + } // Initialize enhancer factory EnhancerFactory.getInstance().setClassLoader(getClassLoader()); @@ -650,26 +657,6 @@ public class ProtocolLib extends JavaPlugin { reporter = new BasicErrorReporter(); } - // Get the Bukkit logger first, before we try to create our own - private Logger getLoggerSafely() { - Logger log = null; - - try { - log = getLogger(); - } catch (OutOfMemoryError e) { - throw e; - } catch (ThreadDeath e) { - throw e; - } catch (Throwable e) { - // Ignore - } - - // Use the default logger instead - if (log == null) - log = Logger.getLogger("Minecraft"); - return log; - } - /** * Retrieve the metrics instance used to measure users of this library. *