From 7630007833bc3fc58a24a4dd644d27ee3f07aad1 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Fri, 29 Jan 2016 23:41:26 -0500 Subject: [PATCH] Cut down on static calls to the main class --- .../main/java/com/comphenix/protocol/CommandProtocol.java | 2 +- .../main/java/com/comphenix/protocol/ProtocolConfig.java | 2 +- .../main/java/com/comphenix/protocol/ProtocolLibrary.java | 6 +++--- .../main/java/com/comphenix/protocol/async/AsyncMarker.java | 5 ++--- .../java/com/comphenix/protocol/compat/guava/Guava.java | 2 +- .../java/com/comphenix/protocol/compat/netty/Netty.java | 2 +- .../com/comphenix/protocol/injector/PluginVerifier.java | 3 +-- .../java/com/comphenix/protocol/updater/SpigotUpdater.java | 2 +- 8 files changed, 11 insertions(+), 13 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/CommandProtocol.java b/ProtocolLib/src/main/java/com/comphenix/protocol/CommandProtocol.java index d74016c7..a5352f1b 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/CommandProtocol.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/CommandProtocol.java @@ -256,7 +256,7 @@ class CommandProtocol extends CommandBase { sender.sendMessage("Data dump written to " + file.getAbsolutePath()); } catch (IOException ex) { - ProtocolLibrary.getStaticLogger().log(Level.SEVERE, "Failed to create dump:", ex); + ProtocolLibrary.log(Level.SEVERE, "Failed to create dump:", ex); sender.sendMessage(ChatColor.RED + "Failed to create dump! Check console!"); } finally { closer.close(); diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolConfig.java b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolConfig.java index 68663f76..999f3567 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolConfig.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolConfig.java @@ -170,7 +170,7 @@ public class ProtocolConfig { loadingSections = false; // Inform the user - ProtocolLibrary.log("Created default configuration."); + plugin.getLogger().info("Created default configuration."); } } diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java index 390285aa..c09a80f4 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java @@ -751,11 +751,11 @@ public class ProtocolLibrary extends JavaPlugin { log(Level.INFO, message, args); } - public static Logger getStaticLogger() { - return logger; + public static void log(Level level, String message, Throwable ex) { + logger.log(level, message, ex); } - public static void disableUpdates() { + public void disableUpdates() { UPDATES_DISABLED = true; } } diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncMarker.java b/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncMarker.java index e4aa2578..15e9ae88 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncMarker.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/async/AsyncMarker.java @@ -437,13 +437,12 @@ public class AsyncMarker implements Serializable, Comparable { return false; } } else { - ProtocolLibrary.log(Level.INFO, "Could not determine asynchronous state of packets."); - ProtocolLibrary.log(Level.INFO, "This can probably be ignored."); + ProtocolLibrary.log(Level.INFO, "Could not determine asynchronous state of packets (this can probably be ignored)"); alwaysSync = true; } } } - + if (alwaysSync) { return false; } else { diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/compat/guava/Guava.java b/ProtocolLib/src/main/java/com/comphenix/protocol/compat/guava/Guava.java index 6f94113a..fdacf25f 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/compat/guava/Guava.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/compat/guava/Guava.java @@ -40,7 +40,7 @@ public class Guava { Class clazz = Class.forName("com.comphenix.protocol.compat.guava.Guava10"); compat = (GuavaCompat) clazz.newInstance(); } catch (Throwable ex1) { - ProtocolLibrary.getStaticLogger().log(Level.SEVERE, "Failed to create Guava 10 compat:", ex1); + ProtocolLibrary.log(Level.SEVERE, "Failed to create Guava 10 compat:", ex1); } } } diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/compat/netty/Netty.java b/ProtocolLib/src/main/java/com/comphenix/protocol/compat/netty/Netty.java index f9ebf65c..32548234 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/compat/netty/Netty.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/compat/netty/Netty.java @@ -44,7 +44,7 @@ public class Netty { Class clazz = Class.forName("com.comphenix.protocol.compat.netty.shaded.ShadedNetty"); compat = (NettyCompat) clazz.newInstance(); } catch (Exception ex1) { - ProtocolLibrary.getStaticLogger().log(Level.SEVERE, "Failed to create legacy netty compat:", ex1); + ProtocolLibrary.log(Level.SEVERE, "Failed to create legacy netty compat:", ex1); } } } diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PluginVerifier.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PluginVerifier.java index fff08c37..e9a5b378 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PluginVerifier.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/PluginVerifier.java @@ -9,7 +9,6 @@ import java.util.logging.Level; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginLoadOrder; -import com.comphenix.protocol.ProtocolLibrary; import com.google.common.collect.Sets; /** @@ -82,7 +81,7 @@ class PluginVerifier { throw new IllegalArgumentException("dependency cannot have a load directives."); } catch (LinkageError e) { // They're probably using an ancient version of Bukkit - ProtocolLibrary.log(Level.WARNING, "Failed to determine loadBefore: " + e); + dependency.getLogger().log(Level.WARNING, "Failed to determine loadBefore: " + e); } this.dependency = dependency; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/updater/SpigotUpdater.java b/ProtocolLib/src/main/java/com/comphenix/protocol/updater/SpigotUpdater.java index 5c5f963e..252adafd 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/updater/SpigotUpdater.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/updater/SpigotUpdater.java @@ -76,7 +76,7 @@ public final class SpigotUpdater extends Updater { plugin.getLogger().log(Level.WARNING, "Failed to check for updates: " + ex); } - ProtocolLibrary.disableUpdates(); + plugin.disableUpdates(); } finally { // Invoke the listeners on the main thread for (Runnable listener : listeners) {