From 27240cf370bda60da123c0add7db61e88ec86db6 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Tue, 14 Jun 2022 16:24:42 -0400 Subject: [PATCH 1/8] Add providers for paper component logging --- .../com/earth2me/essentials/Essentials.java | 66 +++++++++-------- .../earth2me/essentials/EssentialsLogger.java | 72 +++++++++++++++++++ .../net/ess3/provider/LoggerProvider.java | 21 ++++++ .../providers/BaseLoggerProvider.java | 24 +++++++ providers/PaperProvider/build.gradle | 4 +- .../providers/PaperLoggerProvider.java | 45 ++++++++++++ 6 files changed, 199 insertions(+), 33 deletions(-) create mode 100644 Essentials/src/main/java/com/earth2me/essentials/EssentialsLogger.java create mode 100644 providers/BaseProviders/src/main/java/net/ess3/provider/LoggerProvider.java create mode 100644 providers/BaseProviders/src/main/java/net/ess3/provider/providers/BaseLoggerProvider.java create mode 100644 providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperLoggerProvider.java diff --git a/Essentials/src/main/java/com/earth2me/essentials/Essentials.java b/Essentials/src/main/java/com/earth2me/essentials/Essentials.java index 9ab438975d4..f9451c616e8 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Essentials.java @@ -72,6 +72,7 @@ import net.ess3.provider.SpawnerItemProvider; import net.ess3.provider.SyncCommandsProvider; import net.ess3.provider.WorldInfoProvider; +import net.ess3.provider.providers.BaseLoggerProvider; import net.ess3.provider.providers.BasePotionDataProvider; import net.ess3.provider.providers.BlockMetaSpawnerItemProvider; import net.ess3.provider.providers.BukkitMaterialTagProvider; @@ -93,7 +94,6 @@ import net.ess3.provider.providers.PaperServerStateProvider; import net.essentialsx.api.v2.services.BalanceTop; import net.essentialsx.api.v2.services.mail.MailService; -import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.World; import org.bukkit.block.Block; @@ -204,6 +204,7 @@ public ISettings getSettings() { } public void setupForTesting(final Server server) throws IOException, InvalidDescriptionException { + EssentialsLogger.setLoggerProvider(new BaseLoggerProvider(LOGGER)); final File dataFolder = File.createTempFile("essentialstest", ""); if (!dataFolder.delete()) { throw new IOException(); @@ -216,8 +217,8 @@ public void setupForTesting(final Server server) throws IOException, InvalidDesc i18n.updateLocale("en"); Console.setInstance(this); - LOGGER.log(Level.INFO, tl("usingTempFolderForTesting")); - LOGGER.log(Level.INFO, dataFolder.toString()); + EssentialsLogger.log(Level.INFO, tl("usingTempFolderForTesting")); + EssentialsLogger.log(Level.INFO, dataFolder.toString()); settings = new Settings(this); mail = new MailServiceImpl(this); userMap = new UserMap(this); @@ -247,6 +248,9 @@ public void onEnable() { if (LOGGER != this.getLogger()) { LOGGER.setParent(this.getLogger()); } + + EssentialsLogger.setLoggerProvider(EssentialsLogger.getLoggerProvider(this)); + execTimer = new ExecuteTimer(); execTimer.start(); i18n = new I18n(this); @@ -257,30 +261,30 @@ public void onEnable() { switch (VersionUtil.getServerSupportStatus()) { case NMS_CLEANROOM: - getLogger().severe(tl("serverUnsupportedCleanroom")); + EssentialsLogger.severe(tl("serverUnsupportedCleanroom")); break; case DANGEROUS_FORK: - getLogger().severe(tl("serverUnsupportedDangerous")); + EssentialsLogger.severe(tl("serverUnsupportedDangerous")); break; case UNSTABLE: - getLogger().severe(tl("serverUnsupportedMods")); + EssentialsLogger.severe(tl("serverUnsupportedMods")); break; case OUTDATED: - getLogger().severe(tl("serverUnsupported")); + EssentialsLogger.severe(tl("serverUnsupported")); break; case LIMITED: - getLogger().info(tl("serverUnsupportedLimitedApi")); + EssentialsLogger.info(tl("serverUnsupportedLimitedApi")); break; } if (VersionUtil.getSupportStatusClass() != null) { - getLogger().info(tl("serverUnsupportedClass", VersionUtil.getSupportStatusClass())); + EssentialsLogger.info(tl("serverUnsupportedClass", VersionUtil.getSupportStatusClass())); } final PluginManager pm = getServer().getPluginManager(); for (final Plugin plugin : pm.getPlugins()) { if (plugin.getDescription().getName().startsWith("Essentials") && !plugin.getDescription().getVersion().equals(this.getDescription().getVersion()) && !plugin.getDescription().getName().equals("EssentialsAntiCheat")) { - getLogger().warning(tl("versionMismatch", plugin.getDescription().getName())); + EssentialsLogger.warning(tl("versionMismatch", plugin.getDescription().getName())); } } @@ -461,9 +465,9 @@ public void onEnable() { updateChecker = new UpdateChecker(this); runTaskAsynchronously(() -> { - getLogger().log(Level.INFO, tl("versionFetching")); + EssentialsLogger.log(Level.INFO, tl("versionFetching")); for (String str : updateChecker.getVersionMessages(false, true)) { - getLogger().log(getSettings().isUpdateCheckEnabled() ? Level.WARNING : Level.INFO, str); + EssentialsLogger.log(getSettings().isUpdateCheckEnabled() ? Level.WARNING : Level.INFO, str); } }); @@ -473,7 +477,7 @@ public void onEnable() { final String timeroutput = execTimer.end(); if (getSettings().isDebug()) { - LOGGER.log(Level.INFO, "Essentials load {0}", timeroutput); + EssentialsLogger.log(Level.INFO, "Essentials load " + timeroutput); } } catch (final NumberFormatException ex) { handleCrash(ex); @@ -493,7 +497,7 @@ private void registerListeners(final PluginManager pm) { HandlerList.unregisterAll(this); if (getSettings().isDebug()) { - LOGGER.log(Level.INFO, "Registering Listeners"); + EssentialsLogger.log(Level.INFO, "Registering Listeners"); } final EssentialsPluginListener pluginListener = new EssentialsPluginListener(this); @@ -537,7 +541,7 @@ private void registerListeners(final PluginManager pm) { public void onDisable() { final boolean stopping = getServerStateProvider().isStopping(); if (!stopping) { - LOGGER.log(Level.SEVERE, tl("serverReloading")); + EssentialsLogger.log(Level.SEVERE, tl("serverReloading")); } getBackup().setPendingShutdown(true); for (final User user : getOnlineUsers()) { @@ -557,7 +561,7 @@ public void onDisable() { } cleanupOpenInventories(); if (getBackup().getTaskLock() != null && !getBackup().getTaskLock().isDone()) { - LOGGER.log(Level.SEVERE, tl("backupInProgress")); + EssentialsLogger.log(Level.SEVERE, tl("backupInProgress")); getBackup().getTaskLock().join(); } if (i18n != null) { @@ -632,7 +636,7 @@ public List onTabCompleteEssentials(final CommandSender cSender, final C return completer.onTabComplete(cSender, command, commandLabel, args); } } catch (final Exception ex) { - Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex); + EssentialsLogger.log(Level.SEVERE, ex.getMessage(), ex); } } } @@ -662,7 +666,7 @@ public List onTabCompleteEssentials(final CommandSender cSender, final C cmd = loadCommand(commandPath, command.getName(), module, classLoader); } catch (final Exception ex) { sender.sendMessage(tl("commandNotLoaded", commandLabel)); - LOGGER.log(Level.SEVERE, tl("commandNotLoaded", commandLabel), ex); + EssentialsLogger.log(Level.SEVERE, tl("commandNotLoaded", commandLabel), ex); return Collections.emptyList(); } @@ -685,11 +689,11 @@ public List onTabCompleteEssentials(final CommandSender cSender, final C } catch (final Exception ex) { showError(sender, ex, commandLabel); // Tab completion shouldn't fail - LOGGER.log(Level.SEVERE, tl("commandFailed", commandLabel), ex); + EssentialsLogger.log(Level.SEVERE, tl("commandFailed", commandLabel), ex); return Collections.emptyList(); } } catch (final Throwable ex) { - LOGGER.log(Level.SEVERE, tl("commandFailed", commandLabel), ex); + EssentialsLogger.log(Level.SEVERE, tl("commandFailed", commandLabel), ex); return Collections.emptyList(); } } @@ -705,7 +709,7 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co // Allow plugins to override the command via onCommand if (!getSettings().isCommandOverridden(command.getName()) && (!commandLabel.startsWith("e") || commandLabel.equalsIgnoreCase(command.getName()))) { if (getSettings().isDebug()) { - LOGGER.log(Level.INFO, "Searching for alternative to: " + commandLabel); + EssentialsLogger.log(Level.INFO, "Searching for alternative to: " + commandLabel); } final Command pc = alternativeCommandsHandler.getAlternative(commandLabel); if (pc != null) { @@ -713,7 +717,7 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co try { pc.execute(cSender, commandLabel, args); } catch (final Exception ex) { - Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex); + EssentialsLogger.log(Level.SEVERE, ex.getMessage(), ex); cSender.sendMessage(tl("internalError")); } return true; @@ -733,10 +737,10 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co if (bSenderBlock != null) { if (getSettings().logCommandBlockCommands()) { - Bukkit.getLogger().log(Level.INFO, "CommandBlock at {0},{1},{2} issued server command: /{3} {4}", new Object[] {bSenderBlock.getX(), bSenderBlock.getY(), bSenderBlock.getZ(), commandLabel, EssentialsCommand.getFinalArg(args, 0)}); + EssentialsLogger.log(Level.INFO, "CommandBlock at " + bSenderBlock.getX() + "," + bSenderBlock.getY() + "," + bSenderBlock.getZ() + " issued server command: /" + commandLabel + " " + EssentialsCommand.getFinalArg(args, 0)); } } else if (user == null) { - Bukkit.getLogger().log(Level.INFO, "{0} issued server command: /{1} {2}", new Object[] {cSender.getName(), commandLabel, EssentialsCommand.getFinalArg(args, 0)}); + EssentialsLogger.log(Level.INFO, cSender.getName() + " issued server command: /" + commandLabel + " " + EssentialsCommand.getFinalArg(args, 0)); } final CommandSource sender = new CommandSource(cSender); @@ -769,13 +773,13 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co cmd = loadCommand(commandPath, command.getName(), module, classLoader); } catch (final Exception ex) { sender.sendMessage(tl("commandNotLoaded", commandLabel)); - LOGGER.log(Level.SEVERE, tl("commandNotLoaded", commandLabel), ex); + EssentialsLogger.log(Level.SEVERE, tl("commandNotLoaded", commandLabel), ex); return true; } // Check authorization if (user != null && !user.isAuthorized(cmd, permissionPrefix)) { - LOGGER.log(Level.INFO, tl("deniedAccessCommand", user.getName())); + EssentialsLogger.log(Level.INFO, tl("deniedAccessCommand", user.getName())); user.sendMessage(tl("noAccessCommand")); return true; } @@ -826,7 +830,7 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co return true; } } catch (final Throwable ex) { - LOGGER.log(Level.SEVERE, tl("commandFailed", commandLabel), ex); + EssentialsLogger.log(Level.SEVERE, tl("commandFailed", commandLabel), ex); return true; } } @@ -854,7 +858,7 @@ public void cleanupOpenInventories() { public void showError(final CommandSource sender, final Throwable exception, final String commandLabel) { sender.sendMessage(tl("errorWithMessage", exception.getMessage())); if (getSettings().isDebug()) { - LOGGER.log(Level.INFO, tl("errorCallingCommand", commandLabel), exception); + EssentialsLogger.log(Level.INFO, tl("errorCallingCommand", commandLabel), exception); } } @@ -1040,7 +1044,7 @@ public User getUser(final Player base) { } if (userMap == null) { - LOGGER.log(Level.WARNING, "Essentials userMap not initialized"); + EssentialsLogger.log(Level.WARNING, "Essentials userMap not initialized"); return null; } @@ -1048,7 +1052,7 @@ public User getUser(final Player base) { if (user == null) { if (getSettings().isDebug()) { - LOGGER.log(Level.INFO, "Constructing new userfile from base player {0}", base.getName()); + EssentialsLogger.log(Level.INFO, "Constructing new userfile from base player " + base.getName()); } user = new User(base, this); } else { @@ -1059,7 +1063,7 @@ public User getUser(final Player base) { private void handleCrash(final Throwable exception) { final PluginManager pm = getServer().getPluginManager(); - LOGGER.log(Level.SEVERE, exception.toString()); + EssentialsLogger.log(Level.SEVERE, exception.toString()); exception.printStackTrace(); pm.registerEvents(new Listener() { @EventHandler(priority = EventPriority.LOW) diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsLogger.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsLogger.java new file mode 100644 index 00000000000..c90a1531e05 --- /dev/null +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsLogger.java @@ -0,0 +1,72 @@ +package com.earth2me.essentials; + +import net.ess3.nms.refl.ReflUtil; +import net.ess3.provider.LoggerProvider; +import net.ess3.provider.providers.BaseLoggerProvider; +import net.ess3.provider.providers.PaperLoggerProvider; +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; + +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +public final class EssentialsLogger { + private static LoggerProvider loggerProvider; + private final static Map loggerProviders = new HashMap<>(); + + private EssentialsLogger() { + } + + public static LoggerProvider getLoggerProvider(final Plugin plugin) { + if (loggerProviders.containsKey(plugin.getName())) { + return loggerProviders.get(plugin.getName()); + } + + final LoggerProvider provider; + if (ReflUtil.getClassCached("io.papermc.paper.adventure.providers.ComponentLoggerProviderImpl") != null) { + provider = new PaperLoggerProvider(plugin); + } else { + provider = new BaseLoggerProvider(Logger.getLogger(plugin.getName())); + } + loggerProviders.put(plugin.getName(), provider); + return provider; + } + + public static LoggerProvider getLoggerProvider(final String pluginName) { + if (loggerProviders.containsKey(pluginName)) { + return loggerProviders.get(pluginName); + } + + final Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName); + if (plugin == null) { + throw new IllegalArgumentException("Plugin not found: " + pluginName); + } + return getLoggerProvider(plugin); + } + + public static void setLoggerProvider(LoggerProvider loggerProvider) { + EssentialsLogger.loggerProvider = loggerProvider; + } + + public static void log(Level level, String message, Throwable throwable) { + loggerProvider.log(level, message, throwable); + } + + public static void log(Level level, String message) { + log(level, message, null); + } + + public static void info(final String message) { + log(Level.INFO, message); + } + + public static void warning(final String message) { + log(Level.WARNING, message); + } + + public static void severe(final String message) { + log(Level.SEVERE, message); + } +} diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/LoggerProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/LoggerProvider.java new file mode 100644 index 00000000000..24e75fd4404 --- /dev/null +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/LoggerProvider.java @@ -0,0 +1,21 @@ +package net.ess3.provider; + +import java.util.logging.Level; + +public interface LoggerProvider { + void log(Level level, String message, Throwable throwable); + + void log(Level level, String message); + + default void warning(String message) { + log(Level.WARNING, message); + } + + default void info(String message) { + log(Level.INFO, message); + } + + default void severe(String message) { + log(Level.SEVERE, message); + } +} diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BaseLoggerProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BaseLoggerProvider.java new file mode 100644 index 00000000000..0c1af2e37af --- /dev/null +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BaseLoggerProvider.java @@ -0,0 +1,24 @@ +package net.ess3.provider.providers; + +import net.ess3.provider.LoggerProvider; + +import java.util.logging.Level; +import java.util.logging.Logger; + +public class BaseLoggerProvider implements LoggerProvider { + private final Logger logger; + + public BaseLoggerProvider(final Logger logger) { + this.logger = logger; + } + + @Override + public void log(Level level, String message, Throwable throwable) { + logger.log(level, message, throwable); + } + + @Override + public void log(Level level, String message) { + logger.log(level, message); + } +} diff --git a/providers/PaperProvider/build.gradle b/providers/PaperProvider/build.gradle index 729cc7b7ca8..1a4c356d3a3 100644 --- a/providers/PaperProvider/build.gradle +++ b/providers/PaperProvider/build.gradle @@ -10,8 +10,8 @@ dependencies { implementation(project(':providers:BaseProviders')) { exclude(module: 'spigot-api') } - compileOnly 'io.papermc.paper:paper-api:1.18.1-R0.1-SNAPSHOT' - compileOnly 'io.papermc.paper:paper-mojangapi:1.18.1-R0.1-SNAPSHOT' + compileOnly 'io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT' + compileOnly 'io.papermc.paper:paper-mojangapi:1.18.2-R0.1-SNAPSHOT' } essentials { diff --git a/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperLoggerProvider.java b/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperLoggerProvider.java new file mode 100644 index 00000000000..f94a73cc4a7 --- /dev/null +++ b/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperLoggerProvider.java @@ -0,0 +1,45 @@ +package net.ess3.provider.providers; + +import net.ess3.provider.LoggerProvider; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.logger.slf4j.ComponentLogger; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import org.bukkit.plugin.Plugin; + +import java.util.logging.Level; + +public class PaperLoggerProvider implements LoggerProvider { + private final ComponentLogger logger; + + public PaperLoggerProvider(final Plugin plugin) { + this.logger = plugin.getComponentLogger(); + } + + @Override + public void log(Level level, String message, Throwable throwable) { + final Component component = LegacyComponentSerializer.legacySection().deserialize(message); + if (level == Level.SEVERE) { + logger.error(component, throwable); + } else if (level == Level.WARNING) { + logger.warn(component, throwable); + } else if (level == Level.INFO) { + logger.info(component, throwable); + } else { + throw new IllegalArgumentException("Unknown level: " + level); + } + } + + @Override + public void log(Level level, String message) { + final Component component = LegacyComponentSerializer.legacySection().deserialize(message); + if (level == Level.SEVERE) { + logger.error(component); + } else if (level == Level.WARNING) { + logger.warn(component); + } else if (level == Level.INFO) { + logger.info(component); + } else { + throw new IllegalArgumentException("Unknown level: " + level); + } + } +} From ca150c51a1f4a68f4eed66f756758a32f10d8010 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Tue, 14 Jun 2022 16:25:51 -0400 Subject: [PATCH 2/8] Replace usages of java logger --- .../AlternativeCommandsHandler.java | 4 +- .../earth2me/essentials/AsyncTeleport.java | 2 +- .../java/com/earth2me/essentials/Backup.java | 12 +- .../essentials/EssentialsEntityListener.java | 4 +- .../essentials/EssentialsPlayerListener.java | 28 ++-- .../essentials/EssentialsPluginListener.java | 6 +- .../essentials/EssentialsServerListener.java | 8 +- .../earth2me/essentials/EssentialsTimer.java | 2 +- .../essentials/EssentialsUpgrade.java | 140 +++++++++--------- .../java/com/earth2me/essentials/I18n.java | 8 +- .../java/com/earth2me/essentials/Jails.java | 16 +- .../java/com/earth2me/essentials/Kit.java | 6 +- .../earth2me/essentials/MetaItemStack.java | 4 +- .../java/com/earth2me/essentials/Mob.java | 4 +- .../java/com/earth2me/essentials/MobData.java | 4 +- .../com/earth2me/essentials/Settings.java | 38 +++-- .../com/earth2me/essentials/Teleport.java | 2 +- .../java/com/earth2me/essentials/Trade.java | 31 ++-- .../java/com/earth2me/essentials/UUIDMap.java | 4 +- .../java/com/earth2me/essentials/User.java | 32 ++-- .../com/earth2me/essentials/UserData.java | 6 +- .../java/com/earth2me/essentials/UserMap.java | 24 +-- .../java/com/earth2me/essentials/Warps.java | 4 +- .../com/earth2me/essentials/api/Economy.java | 29 ++-- .../commands/Commandbalancetop.java | 3 +- .../essentials/commands/Commandcreatekit.java | 7 +- .../commands/Commandessentials.java | 13 +- .../essentials/commands/Commandkit.java | 3 +- .../essentials/commands/Commandsell.java | 3 +- .../essentials/commands/Commandtpaccept.java | 3 +- .../essentials/commands/Commandtpdeny.java | 3 +- .../commands/EssentialsCommand.java | 9 +- .../config/ConfigurationSaveTask.java | 5 +- .../config/EssentialsConfiguration.java | 29 ++-- .../config/EssentialsUserConfiguration.java | 5 +- .../essentials/economy/EconomyLayers.java | 3 +- .../economy/vault/VaultEconomyProvider.java | 9 +- .../essentials/items/AbstractItemDb.java | 5 +- .../essentials/items/CustomItemResolver.java | 3 +- .../earth2me/essentials/items/FlatItemDb.java | 7 +- .../essentials/items/LegacyItemDb.java | 5 +- .../essentials/perm/PermissionsHandler.java | 15 +- .../essentials/signs/EssentialsSign.java | 5 +- .../essentials/signs/SignBlockListener.java | 7 +- .../essentials/signs/SignPlayerListener.java | 3 +- .../essentials/textreader/BookInput.java | 3 +- .../essentials/textreader/HelpInput.java | 5 +- .../textreader/KeywordReplacer.java | 3 +- .../EssentialsAntiBuildListener.java | 5 +- .../antibuild/EssentialsConnect.java | 5 +- .../essentials/chat/EssentialsChat.java | 3 +- .../essentials/chat/EssentialsChatPlayer.java | 5 +- .../essentialsx/discord/DiscordSettings.java | 11 +- .../discord/EssentialsDiscord.java | 11 +- .../discord/JDADiscordService.java | 5 +- .../InteractionControllerImpl.java | 5 +- .../interactions/InteractionEventImpl.java | 5 +- .../discord/listeners/DiscordListener.java | 5 +- .../discord/util/ConsoleInjector.java | 4 +- .../essentials/geoip/EssentialsGeoIP.java | 10 +- .../geoip/EssentialsGeoIPPlayerListener.java | 5 +- .../essentials/protect/EssentialsConnect.java | 5 +- .../essentials/protect/EssentialsProtect.java | 11 +- .../essentials/spawn/EssentialsSpawn.java | 3 +- .../spawn/EssentialsSpawnPlayerListener.java | 5 +- 65 files changed, 339 insertions(+), 338 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/AlternativeCommandsHandler.java b/Essentials/src/main/java/com/earth2me/essentials/AlternativeCommandsHandler.java index b5d86018269..6f8815d22dd 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/AlternativeCommandsHandler.java +++ b/Essentials/src/main/java/com/earth2me/essentials/AlternativeCommandsHandler.java @@ -11,10 +11,8 @@ import java.util.Locale; import java.util.Map; import java.util.logging.Level; -import java.util.logging.Logger; public class AlternativeCommandsHandler { - private static final Logger LOGGER = Logger.getLogger("Essentials"); private final transient Map> altcommands = new HashMap<>(); private final transient Map disabledList = new HashMap<>(); private final transient IEssentials ess; @@ -95,7 +93,7 @@ public void executed(final String label, final Command pc) { if (pc instanceof PluginIdentifiableCommand) { final String altString = ((PluginIdentifiableCommand) pc).getPlugin().getName() + ":" + pc.getName(); if (ess.getSettings().isDebug()) { - LOGGER.log(Level.INFO, "Essentials: Alternative command " + label + " found, using " + altString); + EssentialsLogger.log(Level.INFO, "Essentials: Alternative command " + label + " found, using " + altString); } disabledList.put(label, altString); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/AsyncTeleport.java b/Essentials/src/main/java/com/earth2me/essentials/AsyncTeleport.java index 19ab4581815..2a3778e70f5 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/AsyncTeleport.java +++ b/Essentials/src/main/java/com/earth2me/essentials/AsyncTeleport.java @@ -401,7 +401,7 @@ void respawnNow(final IUser teleportee, final TeleportCause cause, final Complet nowAsync(teleportee, new LocationTarget(location), cause, future); } else { if (ess.getSettings().isDebug()) { - ess.getLogger().info("Could not find bed spawn, forcing respawn event."); + EssentialsLogger.info("Could not find bed spawn, forcing respawn event."); } final PlayerRespawnEvent pre = new PlayerRespawnEvent(player, player.getWorld().getSpawnLocation(), false); ess.getServer().getPluginManager().callEvent(pre); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Backup.java b/Essentials/src/main/java/com/earth2me/essentials/Backup.java index 101e7d25ec3..748d67353de 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Backup.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Backup.java @@ -10,12 +10,10 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; -import java.util.logging.Logger; import static com.earth2me.essentials.I18n.tl; public class Backup implements Runnable { - private static final Logger LOGGER = Logger.getLogger("Essentials"); private transient final Server server; private transient final IEssentials ess; private final AtomicBoolean pendingShutdown = new AtomicBoolean(false); @@ -81,7 +79,7 @@ public void run() { taskLock.complete(new Object()); return; } - LOGGER.log(Level.INFO, tl("backupStarted")); + EssentialsLogger.log(Level.INFO, tl("backupStarted")); final CommandSender cs = server.getConsoleSender(); server.dispatchCommand(cs, "save-all"); server.dispatchCommand(cs, "save-off"); @@ -99,17 +97,17 @@ public void run() { do { line = reader.readLine(); if (line != null) { - LOGGER.log(Level.INFO, line); + EssentialsLogger.log(Level.INFO, line); } } while (line != null); } } catch (final IOException ex) { - LOGGER.log(Level.SEVERE, null, ex); + EssentialsLogger.log(Level.SEVERE, null, ex); } }); child.waitFor(); } catch (final InterruptedException | IOException ex) { - LOGGER.log(Level.SEVERE, null, ex); + EssentialsLogger.log(Level.SEVERE, null, ex); } finally { class BackupEnableSaveTask implements Runnable { @Override @@ -120,7 +118,7 @@ public void run() { } active = false; taskLock.complete(new Object()); - LOGGER.log(Level.INFO, tl("backupFinished")); + EssentialsLogger.log(Level.INFO, tl("backupFinished")); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsEntityListener.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsEntityListener.java index c8040c660c6..3dee84eb011 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsEntityListener.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsEntityListener.java @@ -30,13 +30,11 @@ import java.util.List; import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Pattern; import static com.earth2me.essentials.I18n.tl; public class EssentialsEntityListener implements Listener { - private static final Logger LOGGER = Logger.getLogger("Essentials"); private static final transient Pattern powertoolPlayer = Pattern.compile("\\{player\\}"); private final IEssentials ess; @@ -110,7 +108,7 @@ class PowerToolInteractTask implements Runnable { @Override public void run() { attacker.getBase().chat("/" + command); - LOGGER.log(Level.INFO, String.format("[PT] %s issued server command: /%s", attacker.getName(), command)); + EssentialsLogger.log(Level.INFO, String.format("[PT] %s issued server command: /%s", attacker.getName(), command)); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java index 1a1de2a73e0..472f0586109 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java @@ -72,13 +72,11 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.function.Predicate; import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Pattern; import static com.earth2me.essentials.I18n.tl; public class EssentialsPlayerListener implements Listener, FakeAccessor { - private static final Logger LOGGER = Logger.getLogger("Essentials"); private final transient IEssentials ess; private final ConcurrentHashMap pendingMotdTasks = new ConcurrentHashMap<>(); @@ -166,7 +164,7 @@ public void onPlayerChat(final AsyncPlayerChatEvent event) { user.sendMessage(user.hasMuteReason() ? tl("voiceSilencedReasonTime", dateDiff, user.getMuteReason()) : tl("voiceSilencedTime", dateDiff)); } - LOGGER.info(tl("mutedUserSpeaks", user.getName(), event.getMessage())); + EssentialsLogger.info(tl("mutedUserSpeaks", user.getName(), event.getMessage())); } try { final Iterator it = event.getRecipients().iterator(); @@ -178,9 +176,9 @@ public void onPlayerChat(final AsyncPlayerChatEvent event) { } } catch (final UnsupportedOperationException ex) { if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.INFO, "Ignore could not block chat due to custom chat plugin event.", ex); + EssentialsLogger.log(Level.INFO, "Ignore could not block chat due to custom chat plugin event.", ex); } else { - ess.getLogger().info("Ignore could not block chat due to custom chat plugin event."); + EssentialsLogger.info("Ignore could not block chat due to custom chat plugin event."); } } @@ -198,7 +196,7 @@ public void onPlayerMove(final PlayerMoveEvent event) { event.getHandlers().unregister(this); if (ess.getSettings().isDebug()) { - LOGGER.log(Level.INFO, "Unregistering move listener"); + EssentialsLogger.log(Level.INFO, "Unregistering move listener"); } return; @@ -342,7 +340,7 @@ public void run() { if (toVanish != null && toVanish.isOnline()) { user.getBase().hidePlayer(toVanish); if (ess.getSettings().isDebug()) { - ess.getLogger().info("Hiding vanished player: " + p); + EssentialsLogger.info("Hiding vanished player: " + p); } } } @@ -428,12 +426,12 @@ public void run() { if (user.isSocialSpyEnabled() && !user.isAuthorized("essentials.socialspy")) { user.setSocialSpyEnabled(false); - ess.getLogger().log(Level.INFO, "Set socialspy to false for {0} because they had it enabled without permission.", user.getName()); + EssentialsLogger.log(Level.INFO, "Set socialspy to false for " + user.getName() + " because they had it enabled without permission."); } if (user.isGodModeEnabled() && !user.isAuthorized("essentials.god")) { user.setGodModeEnabled(false); - ess.getLogger().log(Level.INFO, "Set god mode to false for {0} because they had it enabled without permission.", user.getName()); + EssentialsLogger.log(Level.INFO, "Set god mode to false for " + user.getName() + " because they had it enabled without permission."); } user.setConfirmingClearCommand(null); @@ -460,9 +458,9 @@ public void run() { tempInput = new TextInput(user.getSource(), "motd", true, ess); } catch (final IOException ex) { if (ess.getSettings().isDebug()) { - LOGGER.log(Level.WARNING, ex.getMessage(), ex); + EssentialsLogger.log(Level.WARNING, ex.getMessage(), ex); } else { - LOGGER.log(Level.WARNING, ex.getMessage()); + EssentialsLogger.log(Level.WARNING, ex.getMessage()); } } } @@ -622,7 +620,7 @@ public void handlePlayerCommandPreprocess(final PlayerCommandPreprocessEvent eve } else { player.sendMessage(user.hasMuteReason() ? tl("voiceSilencedReasonTime", dateDiff, user.getMuteReason()) : tl("voiceSilencedTime", dateDiff)); } - LOGGER.info(tl("mutedUserSpeaks", player.getName(), event.getMessage())); + EssentialsLogger.info(tl("mutedUserSpeaks", player.getName(), event.getMessage())); return; } @@ -679,7 +677,7 @@ public void handlePlayerCommandPreprocess(final PlayerCommandPreprocessEvent eve if (cooldownEntry != null) { if (ess.getSettings().isDebug()) { - ess.getLogger().info("Applying " + cooldownEntry.getValue() + "ms cooldown on /" + fullCommand + " for" + user.getName() + "."); + EssentialsLogger.info("Applying " + cooldownEntry.getValue() + "ms cooldown on /" + fullCommand + " for" + user.getName() + "."); } final Date expiry = new Date(System.currentTimeMillis() + cooldownEntry.getValue()); user.addCommandCooldown(cooldownEntry.getKey(), expiry, ess.getSettings().isCommandCooldownPersistent(fullCommand)); @@ -810,7 +808,7 @@ public void run() { ess.scheduleSyncDelayedTask(new DelayedClickJumpTask()); } catch (final Exception ex) { if (ess.getSettings().isDebug()) { - LOGGER.log(Level.WARNING, ex.getMessage(), ex); + EssentialsLogger.log(Level.WARNING, ex.getMessage(), ex); } } } @@ -834,7 +832,7 @@ class PowerToolUseTask implements Runnable { @Override public void run() { user.getBase().chat("/" + command); - LOGGER.log(Level.INFO, String.format("[PT] %s issued server command: /%s", user.getName(), command)); + EssentialsLogger.log(Level.INFO, String.format("[PT] %s issued server command: /%s", user.getName(), command)); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsPluginListener.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsPluginListener.java index 38e1f9a1eb6..d28e8753ad2 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsPluginListener.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsPluginListener.java @@ -29,7 +29,7 @@ public void onPluginEnable(final PluginEnableEvent event) { if (EconomyLayers.isServerStarted()) { final EconomyLayer layer = EconomyLayers.onPluginEnable(event.getPlugin()); if (layer != null) { - ess.getLogger().log(Level.INFO, "Essentials found a compatible payment resolution method: " + layer.getName() + " (v" + layer.getPluginVersion() + ")!"); + EssentialsLogger.log(Level.INFO, "Essentials found a compatible payment resolution method: " + layer.getName() + " (v" + layer.getPluginVersion() + ")!"); } } } @@ -44,9 +44,9 @@ public void onPluginDisable(final PluginDisableEvent event) { if (EconomyLayers.onPluginDisable(event.getPlugin())) { final EconomyLayer layer = EconomyLayers.getSelectedLayer(); if (layer != null) { - ess.getLogger().log(Level.INFO, "Essentials found a new compatible payment resolution method: " + layer.getName() + " (v" + layer.getPluginVersion() + ")!"); + EssentialsLogger.log(Level.INFO, "Essentials found a new compatible payment resolution method: " + layer.getName() + " (v" + layer.getPluginVersion() + ")!"); } else { - ess.getLogger().log(Level.INFO, "Active payment resolution method has been disabled! Falling back to Essentials' default payment resolution system!"); + EssentialsLogger.log(Level.INFO, "Active payment resolution method has been disabled! Falling back to Essentials' default payment resolution system!"); } } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsServerListener.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsServerListener.java index 419f025dde0..4d40ee9122f 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsServerListener.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsServerListener.java @@ -37,13 +37,13 @@ public EssentialsServerListener(final IEssentials ess) { setSampleText = ReflUtil.getMethodCached(ServerListPingEvent.class, "setSampleText", List.class); getSampleText = ReflUtil.getMethodCached(ServerListPingEvent.class, "getSampleText"); if (setSampleText != null && getSampleText != null) { - ess.getLogger().info("ServerListPingEvent: Paper 1.12.2 setSampleText API"); + EssentialsLogger.info("ServerListPingEvent: Paper 1.12.2 setSampleText API"); isPaperSample = true; return; } } - ess.getLogger().info("ServerListPingEvent: Spigot iterator API"); + EssentialsLogger.info("ServerListPingEvent: Spigot iterator API"); isPaperSample = false; } @@ -56,7 +56,7 @@ public void onServerListPing(final ServerListPingEvent event) throws Exception { setSampleText.invoke(event, playerNames); } catch (final IllegalAccessException | InvocationTargetException | ClassCastException e) { if (!unsupportedLogged && shouldWarnSLPECaller(e)) { - ess.getLogger().log(Level.WARNING, "Unable to hide players from server list ping " + EssentialsLogger.log(Level.WARNING, "Unable to hide players from server list ping " + "using Paper 1.12 method!", e); unsupportedLogged = true; } @@ -80,7 +80,7 @@ public void onServerListPing(final ServerListPingEvent event) throws Exception { } } catch (final UnsupportedOperationException e) { if (!unsupportedLogged && shouldWarnSLPECaller(e)) { - ess.getLogger().log(Level.WARNING, "Could not hide vanished players while handling " + event.getClass().getName(), e); + EssentialsLogger.log(Level.WARNING, "Could not hide vanished players while handling " + event.getClass().getName(), e); unsupportedLogged = true; } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsTimer.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsTimer.java index fbc96e1d214..e009eaaada5 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsTimer.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsTimer.java @@ -63,7 +63,7 @@ public void run() { user.setLastOnlineActivity(currentTime); user.checkActivity(); } catch (final Exception e) { - ess.getLogger().log(Level.WARNING, "EssentialsTimer Error:", e); + EssentialsLogger.log(Level.WARNING, "EssentialsTimer Error:", e); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsUpgrade.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsUpgrade.java index 5511967cf5d..f254006c973 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsUpgrade.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsUpgrade.java @@ -47,14 +47,12 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; import static com.earth2me.essentials.I18n.tl; public class EssentialsUpgrade { - private final static Logger LOGGER = Logger.getLogger("Essentials"); private static final FileFilter YML_FILTER = pathname -> pathname.isFile() && pathname.getName().endsWith(".yml"); private static final String PATTERN_CONFIG_UUID_REGEX = "(?mi)^uuid:\\s*([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\\s*$"; private static final Pattern PATTERN_CONFIG_UUID = Pattern.compile(PATTERN_CONFIG_UUID_REGEX); @@ -73,7 +71,7 @@ public class EssentialsUpgrade { } public static void uuidFileConvert(final IEssentials ess, final Boolean ignoreUFCache) { - ess.getLogger().info("Starting Essentials UUID userdata conversion"); + EssentialsLogger.info("Starting Essentials UUID userdata conversion"); final File userdir = new File(ess.getDataFolder(), "userdata"); if (!userdir.exists()) { @@ -85,7 +83,7 @@ public static void uuidFileConvert(final IEssentials ess, final Boolean ignoreUF int countEssCache = 0; int countBukkit = 0; - ess.getLogger().info("Found " + userdir.list().length + " files to convert..."); + EssentialsLogger.info("Found " + userdir.list().length + " files to convert..."); for (final String string : userdir.list()) { if (!string.endsWith(".yml") || string.length() < 5) { @@ -96,7 +94,7 @@ public static void uuidFileConvert(final IEssentials ess, final Boolean ignoreUF if (showProgress == 0) { ess.getUserMap().getUUIDMap().forceWriteUUIDMap(); - ess.getLogger().info("Converted " + countFiles + "/" + userdir.list().length); + EssentialsLogger.info("Converted " + countFiles + "/" + userdir.list().length); } countFiles++; @@ -150,9 +148,9 @@ public static void uuidFileConvert(final IEssentials ess, final Boolean ignoreUF } ess.getUserMap().getUUIDMap().forceWriteUUIDMap(); - ess.getLogger().info("Converted " + countFiles + "/" + countFiles + ". Conversion complete."); - ess.getLogger().info("Converted via cache: " + countEssCache + " :: Converted via lookup: " + countBukkit + " :: Failed to convert: " + countFails); - ess.getLogger().info("To rerun the conversion type /essentials uuidconvert"); + EssentialsLogger.info("Converted " + countFiles + "/" + countFiles + ". Conversion complete."); + EssentialsLogger.info("Converted via cache: " + countEssCache + " :: Converted via lookup: " + countBukkit + " :: Failed to convert: " + countFails); + EssentialsLogger.info("To rerun the conversion type /essentials uuidconvert"); } public void convertMailList() { @@ -186,13 +184,13 @@ public void convertMailList() { config.blockingSave(); } } catch (RuntimeException ex) { - LOGGER.log(Level.INFO, "File: " + file); + EssentialsLogger.log(Level.INFO, "File: " + file); throw ex; } } doneFile.setProperty("updateUsersMailList", true); doneFile.save(); - LOGGER.info("Done converting mail list."); + EssentialsLogger.info("Done converting mail list."); } public void convertStupidCamelCaseUserdataKeys() { @@ -200,7 +198,7 @@ public void convertStupidCamelCaseUserdataKeys() { return; } - LOGGER.info("Attempting to migrate legacy userdata keys to Configurate"); + EssentialsLogger.info("Attempting to migrate legacy userdata keys to Configurate"); final File userdataFolder = new File(ess.getDataFolder(), "userdata"); if (!userdataFolder.exists() || !userdataFolder.isDirectory()) { @@ -241,13 +239,13 @@ public void convertStupidCamelCaseUserdataKeys() { } config.blockingSave(); } catch (final RuntimeException ex) { - LOGGER.log(Level.INFO, "File: " + file); + EssentialsLogger.log(Level.INFO, "File: " + file); throw ex; } } doneFile.setProperty("updateUsersStupidLegacyPathNames", true); doneFile.save(); - LOGGER.info("Done converting legacy userdata keys to Configurate."); + EssentialsLogger.info("Done converting legacy userdata keys to Configurate."); } /** @@ -290,31 +288,31 @@ public void purgeBrokenNpcAccounts() { } final File backupFolder = new File(ess.getDataFolder(), "userdata-npc-backup"); if (backupFolder.exists()) { - LOGGER.info("NPC backup folder already exists; skipping NPC purge."); - LOGGER.info("To finish purging broken NPC accounts, rename the \"plugins/Essentials/userdata-npc-backup\" folder and restart your server."); + EssentialsLogger.info("NPC backup folder already exists; skipping NPC purge."); + EssentialsLogger.info("To finish purging broken NPC accounts, rename the \"plugins/Essentials/userdata-npc-backup\" folder and restart your server."); return; } else if (!backupFolder.mkdir()) { - LOGGER.info("Skipping NPC purge due to error creating backup folder."); + EssentialsLogger.info("Skipping NPC purge due to error creating backup folder."); return; } - LOGGER.info("#===========================================================================#"); - LOGGER.info(" EssentialsX will now purge any NPC accounts which were incorrectly created."); - LOGGER.info(" Only NPC accounts with the default starting balance will be deleted. If"); - LOGGER.info(" they turn out to be valid NPC accounts, they will be re-created as needed."); - LOGGER.info(" Any files deleted here will be backed up to the "); - LOGGER.info(" \"plugins/Essentials/userdata-npc-backup\" folder. If you notice any files"); - LOGGER.info(" have been purged incorrectly, you should restore it from the backup and"); - LOGGER.info(" report it to us on GitHub:"); - LOGGER.info(" https://github.com/EssentialsX/Essentials/issues/new/choose"); - LOGGER.info(""); - LOGGER.info(" NOTE: This is a one-time process and will take several minutes if you have"); - LOGGER.info(" a lot of userdata files! If you interrupt this process, EssentialsX will"); - LOGGER.info(" skip the process until you rename or remove the backup folder."); - LOGGER.info("#===========================================================================#"); + EssentialsLogger.info("#===========================================================================#"); + EssentialsLogger.info(" EssentialsX will now purge any NPC accounts which were incorrectly created."); + EssentialsLogger.info(" Only NPC accounts with the default starting balance will be deleted. If"); + EssentialsLogger.info(" they turn out to be valid NPC accounts, they will be re-created as needed."); + EssentialsLogger.info(" Any files deleted here will be backed up to the "); + EssentialsLogger.info(" \"plugins/Essentials/userdata-npc-backup\" folder. If you notice any files"); + EssentialsLogger.info(" have been purged incorrectly, you should restore it from the backup and"); + EssentialsLogger.info(" report it to us on GitHub:"); + EssentialsLogger.info(" https://github.com/EssentialsX/Essentials/issues/new/choose"); + EssentialsLogger.info(""); + EssentialsLogger.info(" NOTE: This is a one-time process and will take several minutes if you have"); + EssentialsLogger.info(" a lot of userdata files! If you interrupt this process, EssentialsX will"); + EssentialsLogger.info(" skip the process until you rename or remove the backup folder."); + EssentialsLogger.info("#===========================================================================#"); final int totalUserFiles = userFiles.length; - LOGGER.info("Found ~" + totalUserFiles + " files under \"plugins/Essentials/userdata\"..."); + EssentialsLogger.info("Found ~" + totalUserFiles + " files under \"plugins/Essentials/userdata\"..."); final AtomicInteger movedAccounts = new AtomicInteger(0); final AtomicInteger totalAccounts = new AtomicInteger(0); @@ -324,7 +322,7 @@ public void purgeBrokenNpcAccounts() { final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); final ScheduledFuture feedbackTask = executor.scheduleWithFixedDelay( - () -> LOGGER.info("Scanned " + totalAccounts.get() + "/" + totalUserFiles + " accounts; moved " + movedAccounts.get() + " accounts"), + () -> EssentialsLogger.info("Scanned " + totalAccounts.get() + "/" + totalUserFiles + " accounts; moved " + movedAccounts.get() + " accounts"), 5, feedbackInterval, TimeUnit.SECONDS); for (final File file : userFiles) { @@ -358,10 +356,10 @@ public void purgeBrokenNpcAccounts() { Files.move(file, new File(backupFolder, file.getName())); movedAccounts.incrementAndGet(); } catch (IOException e) { - LOGGER.log(Level.SEVERE, "Error while moving NPC file", e); + EssentialsLogger.log(Level.SEVERE, "Error while moving NPC file", e); } } catch (final RuntimeException ex) { - LOGGER.log(Level.INFO, "File: " + file); + EssentialsLogger.log(Level.INFO, "File: " + file); feedbackTask.cancel(false); executor.shutdown(); throw ex; @@ -372,18 +370,18 @@ public void purgeBrokenNpcAccounts() { doneFile.setProperty("updatePurgeBrokenNpcAccounts", true); doneFile.save(); - LOGGER.info("#===========================================================================#"); - LOGGER.info(" EssentialsX has finished purging NPC accounts."); - LOGGER.info(""); - LOGGER.info(" Deleted accounts: " + movedAccounts); - LOGGER.info(" Total accounts processed: " + totalAccounts); - LOGGER.info(""); - LOGGER.info(" Purged accounts have been backed up to"); - LOGGER.info(" \"plugins/Essentials/userdata-npc-backup\", and can be restored from there"); - LOGGER.info(" if needed. Please report any files which have been incorrectly deleted"); - LOGGER.info(" to us on GitHub:"); - LOGGER.info(" https://github.com/EssentialsX/Essentials/issues/new/choose"); - LOGGER.info("#===========================================================================#"); + EssentialsLogger.info("#===========================================================================#"); + EssentialsLogger.info(" EssentialsX has finished purging NPC accounts."); + EssentialsLogger.info(""); + EssentialsLogger.info(" Deleted accounts: " + movedAccounts); + EssentialsLogger.info(" Total accounts processed: " + totalAccounts); + EssentialsLogger.info(""); + EssentialsLogger.info(" Purged accounts have been backed up to"); + EssentialsLogger.info(" \"plugins/Essentials/userdata-npc-backup\", and can be restored from there"); + EssentialsLogger.info(" if needed. Please report any files which have been incorrectly deleted"); + EssentialsLogger.info(" to us on GitHub:"); + EssentialsLogger.info(" https://github.com/EssentialsX/Essentials/issues/new/choose"); + EssentialsLogger.info("#===========================================================================#"); } public void convertIgnoreList() { @@ -392,7 +390,7 @@ public void convertIgnoreList() { return; } - LOGGER.info("Attempting to migrate ignore list to UUIDs"); + EssentialsLogger.info("Attempting to migrate ignore list to UUIDs"); final File userdataFolder = new File(ess.getDataFolder(), "userdata"); if (!userdataFolder.exists() || !userdataFolder.isDirectory()) { @@ -414,7 +412,7 @@ public void convertIgnoreList() { continue; } if (pattern.matcher(name.trim()).matches()) { - LOGGER.info("Detected already migrated ignore list!"); + EssentialsLogger.info("Detected already migrated ignore list!"); return; } final User user = ess.getOfflineUser(name); @@ -427,13 +425,13 @@ public void convertIgnoreList() { config.blockingSave(); } } catch (final RuntimeException ex) { - LOGGER.log(Level.INFO, "File: " + file); + EssentialsLogger.log(Level.INFO, "File: " + file); throw ex; } } doneFile.setProperty("updateUsersIgnoreListUUID", true); doneFile.save(); - LOGGER.info("Done converting ignore list."); + EssentialsLogger.info("Done converting ignore list."); } public void convertKits() { @@ -443,25 +441,25 @@ public void convertKits() { return; } - LOGGER.info("Attempting to convert old kits in config.yml to new kits.yml"); + EssentialsLogger.info("Attempting to convert old kits in config.yml to new kits.yml"); final CommentedConfigurationNode section = ess.getSettings().getKitSection(); if (section == null) { - LOGGER.info("No kits found to migrate."); + EssentialsLogger.info("No kits found to migrate."); return; } final Map legacyKits = ConfigurateUtil.getRawMap(section); for (final Map.Entry entry : legacyKits.entrySet()) { - LOGGER.info("Converting " + entry.getKey()); + EssentialsLogger.info("Converting " + entry.getKey()); config.setRaw("kits." + entry.getKey(), entry.getValue()); } config.save(); doneFile.setProperty("kitsyml", true); doneFile.save(); - LOGGER.info("Done converting kits."); + EssentialsLogger.info("Done converting kits."); } private void moveMotdRulesToFile(final String name) { @@ -494,7 +492,7 @@ private void moveMotdRulesToFile(final String name) { doneFile.setProperty("move" + name + "ToFile", true); doneFile.save(); } catch (final IOException e) { - LOGGER.log(Level.SEVERE, tl("upgradingFilesError"), e); + EssentialsLogger.log(Level.SEVERE, tl("upgradingFilesError"), e); } } @@ -572,7 +570,7 @@ private void updateUsersPowerToolsFormat() { config.blockingSave(); } } catch (final RuntimeException ex) { - LOGGER.log(Level.INFO, "File: " + file); + EssentialsLogger.log(Level.INFO, "File: " + file); throw ex; } } @@ -628,7 +626,7 @@ private void updateUsersHomesFormat() { } } catch (final RuntimeException ex) { - LOGGER.log(Level.INFO, "File: " + file); + EssentialsLogger.log(Level.INFO, "File: " + file); throw ex; } } @@ -657,15 +655,15 @@ private void sanitizeAllUserFilenames() { final File tmpFile = new File(listOfFile.getParentFile(), sanitizedFilename + ".tmp"); final File newFile = new File(listOfFile.getParentFile(), sanitizedFilename); if (!listOfFile.renameTo(tmpFile)) { - LOGGER.log(Level.WARNING, tl("userdataMoveError", filename, sanitizedFilename)); + EssentialsLogger.log(Level.WARNING, tl("userdataMoveError", filename, sanitizedFilename)); continue; } if (newFile.exists()) { - LOGGER.log(Level.WARNING, tl("duplicatedUserdata", filename, sanitizedFilename)); + EssentialsLogger.log(Level.WARNING, tl("duplicatedUserdata", filename, sanitizedFilename)); continue; } if (!tmpFile.renameTo(newFile)) { - LOGGER.log(Level.WARNING, tl("userdataMoveBackError", sanitizedFilename, sanitizedFilename)); + EssentialsLogger.log(Level.WARNING, tl("userdataMoveBackError", sanitizedFilename, sanitizedFilename)); } } doneFile.setProperty("sanitizeAllUserFilenames", true); @@ -830,8 +828,8 @@ private void uuidFileChange() { return; } - ess.getLogger().info("#### Starting Essentials UUID userdata conversion in a few seconds. ####"); - ess.getLogger().info("We recommend you take a backup of your server before upgrading from the old username system."); + EssentialsLogger.info("#### Starting Essentials UUID userdata conversion in a few seconds. ####"); + EssentialsLogger.info("We recommend you take a backup of your server before upgrading from the old username system."); try { Thread.sleep(15000); @@ -850,7 +848,7 @@ public void banFormatChange() { return; } - ess.getLogger().info("Starting Essentials ban format conversion"); + EssentialsLogger.info("Starting Essentials ban format conversion"); final File userdir = new File(ess.getDataFolder(), "userdata"); if (!userdir.exists()) { @@ -859,7 +857,7 @@ public void banFormatChange() { int countFiles = 0; - ess.getLogger().info("Found " + userdir.list().length + " files to convert..."); + EssentialsLogger.info("Found " + userdir.list().length + " files to convert..."); for (final String string : userdir.list()) { if (!string.endsWith(".yml") || string.length() < 5) { @@ -869,7 +867,7 @@ public void banFormatChange() { final int showProgress = countFiles % 250; if (showProgress == 0) { - ess.getLogger().info("Converted " + countFiles + "/" + userdir.list().length); + EssentialsLogger.info("Converted " + countFiles + "/" + userdir.list().length); } countFiles++; @@ -908,7 +906,7 @@ public void banFormatChange() { doneFile.setProperty("banFormatChange", true); doneFile.save(); - ess.getLogger().info("Ban format update complete."); + EssentialsLogger.info("Ban format update complete."); } private void updateBan(final String playerName, final String banReason, final Long banTimeout) { @@ -919,11 +917,11 @@ private void repairUserMap() { if (doneFile.getBoolean("userMapRepaired", false)) { return; } - ess.getLogger().info("Starting usermap repair"); + EssentialsLogger.info("Starting usermap repair"); final File userdataFolder = new File(ess.getDataFolder(), "userdata"); if (!userdataFolder.isDirectory()) { - ess.getLogger().warning("Missing userdata folder, aborting"); + EssentialsLogger.warning("Missing userdata folder, aborting"); return; } final File[] files = userdataFolder.listFiles(YML_FILTER); @@ -968,11 +966,11 @@ private void repairUserMap() { } if (index % 1000 == 0) { - ess.getLogger().info("Reading: " + format.format((100d * (double) index) / files.length) + EssentialsLogger.info("Reading: " + format.format((100d * (double) index) / files.length) + "%"); } } catch (final IOException e) { - ess.getLogger().log(Level.SEVERE, "Error while reading file: ", e); + EssentialsLogger.log(Level.SEVERE, "Error while reading file: ", e); return; } } @@ -982,7 +980,7 @@ private void repairUserMap() { doneFile.setProperty("userMapRepaired", true); doneFile.save(); - ess.getLogger().info("Completed usermap repair."); + EssentialsLogger.info("Completed usermap repair."); } public void beforeSettings() { diff --git a/Essentials/src/main/java/com/earth2me/essentials/I18n.java b/Essentials/src/main/java/com/earth2me/essentials/I18n.java index 9a2e1e4e7af..372e3809f07 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/I18n.java +++ b/Essentials/src/main/java/com/earth2me/essentials/I18n.java @@ -21,7 +21,6 @@ import java.util.PropertyResourceBundle; import java.util.ResourceBundle; import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Pattern; public class I18n implements net.ess3.api.II18n { @@ -89,7 +88,7 @@ private String translate(final String string) { } } catch (final MissingResourceException ex) { if (ess == null || ess.getSettings().isDebug()) { - Logger.getLogger("Essentials").log(Level.WARNING, String.format("Missing translation key \"%s\" in translation file %s", ex.getKey(), localeBundle.getLocale().toString()), ex); + EssentialsLogger.log(Level.WARNING, String.format("Missing translation key \"%s\" in translation file %s", ex.getKey(), localeBundle.getLocale().toString()), ex); } return defaultBundle.getString(string); } @@ -102,7 +101,7 @@ public String format(final String string, final Object... objects) { try { messageFormat = new MessageFormat(format); } catch (final IllegalArgumentException e) { - ess.getLogger().log(Level.SEVERE, "Invalid Translation key for '" + string + "': " + e.getMessage()); + EssentialsLogger.log(Level.SEVERE, "Invalid Translation key for '" + string + "': " + e.getMessage()); format = format.replaceAll("\\{(\\D*?)\\}", "\\[$1\\]"); messageFormat = new MessageFormat(format); } @@ -126,8 +125,7 @@ public void updateLocale(final String loc) { } ResourceBundle.clearCache(); messageFormatCache = new HashMap<>(); - Logger.getLogger("Essentials").log(Level.INFO, String.format("Using locale %s", currentLocale.toString())); - + EssentialsLogger.log(Level.INFO, "Using locale " + currentLocale.toString()); try { localeBundle = ResourceBundle.getBundle(MESSAGES, currentLocale, new UTF8PropertiesControl()); } catch (final MissingResourceException ex) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/Jails.java b/Essentials/src/main/java/com/earth2me/essentials/Jails.java index c40c9959eae..febede9a071 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Jails.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Jails.java @@ -34,12 +34,10 @@ import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.logging.Level; -import java.util.logging.Logger; import static com.earth2me.essentials.I18n.tl; public class Jails implements net.ess3.api.IJails { - private static final transient Logger LOGGER = Logger.getLogger("Essentials"); private static transient boolean enabled = false; private final IEssentials ess; private final EssentialsConfiguration config; @@ -76,7 +74,7 @@ private void registerListeners() { final JailListener blockListener = new JailListener(); pluginManager.registerEvents(blockListener, ess); if (ess.getSettings().isDebug()) { - LOGGER.log(Level.INFO, "Registering Jail listener"); + EssentialsLogger.log(Level.INFO, "Registering Jail listener"); } } @@ -268,9 +266,9 @@ public void onJailPlayerRespawn(final PlayerRespawnEvent event) { event.setRespawnLocation(getJail(user.getJail())); } catch (final Exception ex) { if (ess.getSettings().isDebug()) { - LOGGER.log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex); + EssentialsLogger.log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex); } else { - LOGGER.log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())); + EssentialsLogger.log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())); } } } @@ -286,9 +284,9 @@ public void onJailPlayerTeleport(final PlayerTeleportEvent event) { event.setTo(getJail(user.getJail())); } catch (final Exception ex) { if (ess.getSettings().isDebug()) { - LOGGER.log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex); + EssentialsLogger.log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex); } else { - LOGGER.log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())); + EssentialsLogger.log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())); } } user.sendMessage(tl("jailMessage")); @@ -306,9 +304,9 @@ public void onJailPlayerJoin(final PlayerJoinEvent event) { final CompletableFuture future = new CompletableFuture<>(); future.exceptionally(ex -> { if (ess.getSettings().isDebug()) { - LOGGER.log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex); + EssentialsLogger.log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex); } else { - LOGGER.log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())); + EssentialsLogger.log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())); } return false; }); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Kit.java b/Essentials/src/main/java/com/earth2me/essentials/Kit.java index e072fece091..f2cebb38db4 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Kit.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Kit.java @@ -147,7 +147,7 @@ public List getItems() throws Exception { } throw new Exception("Invalid item list"); } catch (final Exception e) { - ess.getLogger().log(Level.WARNING, "Error parsing kit " + kitName + ": " + e.getMessage()); + EssentialsLogger.log(Level.WARNING, "Error parsing kit " + kitName + ": " + e.getMessage()); throw new Exception(tl("kitError2"), e); } } @@ -192,7 +192,7 @@ public boolean expandItems(final User user, final List items) throws Exc if (kitItem.startsWith("@")) { if (ess.getSerializationProvider() == null) { - ess.getLogger().log(Level.WARNING, tl("kitError3", kitName, user.getName())); + EssentialsLogger.log(Level.WARNING, tl("kitError3", kitName, user.getName())); continue; } stack = ess.getSerializationProvider().deserializeItem(Base64Coder.decodeLines(kitItem.substring(1))); @@ -286,7 +286,7 @@ public boolean expandItems(final User user, final List items) throws Exc } } catch (final Exception e) { user.getBase().updateInventory(); - ess.getLogger().log(Level.WARNING, e.getMessage()); + EssentialsLogger.log(Level.WARNING, e.getMessage()); throw new Exception(tl("kitError2"), e); } return true; diff --git a/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java b/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java index d1edb3e028c..34f2998aff7 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java +++ b/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java @@ -138,7 +138,7 @@ public boolean canSpawn(final IEssentials ess) { return true; } catch (final Throwable npe) { if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.INFO, "Itemstack is invalid", npe); + EssentialsLogger.log(Level.INFO, "Itemstack is invalid", npe); } return false; } @@ -150,7 +150,7 @@ public void parseStringMeta(final CommandSource sender, final boolean allowUnsaf stack = ess.getServer().getUnsafe().modifyItemStack(stack, Joiner.on(' ').join(Arrays.asList(string).subList(fromArg, string.length))); } catch (final NullPointerException npe) { if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.INFO, "Itemstack is invalid", npe); + EssentialsLogger.log(Level.INFO, "Itemstack is invalid", npe); } } catch (final NoSuchMethodError nsme) { throw new Exception(tl("noMetaJson"), nsme); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Mob.java b/Essentials/src/main/java/com/earth2me/essentials/Mob.java index d48507d5d30..689eabe49c6 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Mob.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Mob.java @@ -13,7 +13,6 @@ import java.util.Map; import java.util.Set; import java.util.logging.Level; -import java.util.logging.Logger; import static com.earth2me.essentials.I18n.tl; @@ -107,7 +106,6 @@ public enum Mob { GLOW_SQUID("GlowSquid", Enemies.FRIENDLY, "GLOW_SQUID"), ; - public static final Logger logger = Logger.getLogger("Essentials"); private static final Map hashMap = new HashMap<>(); private static final Map bukkitMap = new HashMap<>(); @@ -166,7 +164,7 @@ public static Mob fromBukkitType(final EntityType type) { public Entity spawn(final World world, final Server server, final Location loc) throws MobException { final Entity entity = world.spawn(loc, this.bukkitType.getEntityClass()); if (entity == null) { - logger.log(Level.WARNING, tl("unableToSpawnMob")); + EssentialsLogger.log(Level.WARNING, tl("unableToSpawnMob")); throw new MobException(); } return entity; diff --git a/Essentials/src/main/java/com/earth2me/essentials/MobData.java b/Essentials/src/main/java/com/earth2me/essentials/MobData.java index ab8d1a60094..7ed68db781c 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/MobData.java +++ b/Essentials/src/main/java/com/earth2me/essentials/MobData.java @@ -35,7 +35,6 @@ import java.util.List; import java.util.Locale; import java.util.Random; -import java.util.logging.Logger; import java.util.stream.Collectors; import static com.earth2me.essentials.I18n.tl; @@ -199,7 +198,6 @@ public enum MobData { SCREAMING_GOAT("screaming", MobCompat.GOAT, Data.GOAT_SCREAMING, true), ; - public static final Logger logger = Logger.getLogger("Essentials"); final private String nickname; final private List suggestions; final private Object type; @@ -409,7 +407,7 @@ public void setData(final Entity spawned, final Player target, final String rawD } } } else { - logger.warning("Unknown mob data type: " + this.toString()); + EssentialsLogger.warning("Unknown mob data type: " + this.toString()); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/Settings.java b/Essentials/src/main/java/com/earth2me/essentials/Settings.java index d9aae83fbeb..1d465e6ecdc 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Settings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Settings.java @@ -40,14 +40,12 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Predicate; import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; import static com.earth2me.essentials.I18n.tl; public class Settings implements net.ess3.api.ISettings { - private static final Logger logger = Logger.getLogger("Essentials"); private static final BigDecimal DEFAULT_MAX_MONEY = new BigDecimal("10000000000000"); private static final BigDecimal DEFAULT_MIN_MONEY = new BigDecimal("-10000000000000"); private final transient EssentialsConfiguration config; @@ -387,7 +385,7 @@ private Map _getCommandCosts() { final String command = entry.getKey(); final CommentedConfigurationNode node = entry.getValue(); if (command.charAt(0) == '/') { - ess.getLogger().warning("Invalid command cost. '" + command + "' should not start with '/'."); + EssentialsLogger.warning("Invalid command cost. '" + command + "' should not start with '/'."); } try { if (ConfigurateUtil.isDouble(node)) { @@ -400,10 +398,10 @@ private Map _getCommandCosts() { final double cost = Double.parseDouble(costString.trim().replace("$", "").replace(getCurrencySymbol(), "").replaceAll("\\W", "")); newMap.put(command.toLowerCase(Locale.ENGLISH), BigDecimal.valueOf(cost)); } else { - ess.getLogger().warning("Invalid command cost for: " + command); + EssentialsLogger.warning("Invalid command cost for: " + command); } } catch (final Exception ex) { - ess.getLogger().warning("Invalid command cost for: " + command); + EssentialsLogger.warning("Invalid command cost for: " + command); } } return newMap; @@ -588,7 +586,7 @@ public String getChatFormat(final String group) { chatFormats.put(group, mFormat); } if (isDebug()) { - ess.getLogger().info(String.format("Found format '%s' for group '%s'", mFormat, group)); + EssentialsLogger.info(String.format("Found format '%s' for group '%s'", mFormat, group)); } return mFormat; } @@ -686,7 +684,7 @@ public void reloadConfig() { boolean mapModified = false; if (!disabledBukkitCommands.isEmpty()) { if (isDebug()) { - logger.log(Level.INFO, "Re-adding " + disabledBukkitCommands.size() + " disabled commands!"); + EssentialsLogger.log(Level.INFO, "Re-adding " + disabledBukkitCommands.size() + " disabled commands!"); } ess.getKnownCommandsProvider().getKnownCommands().putAll(disabledBukkitCommands); disabledBukkitCommands.clear(); @@ -698,12 +696,12 @@ public void reloadConfig() { final Command toDisable = ess.getPluginCommand(effectiveAlias); if (toDisable != null) { if (isDebug()) { - logger.log(Level.INFO, "Attempting removal of " + effectiveAlias); + EssentialsLogger.log(Level.INFO, "Attempting removal of " + effectiveAlias); } final Command removed = ess.getKnownCommandsProvider().getKnownCommands().remove(effectiveAlias); if (removed != null) { if (isDebug()) { - logger.log(Level.INFO, "Adding command " + effectiveAlias + " to disabled map!"); + EssentialsLogger.log(Level.INFO, "Adding command " + effectiveAlias + " to disabled map!"); } disabledBukkitCommands.put(effectiveAlias, removed); } @@ -720,7 +718,7 @@ public void reloadConfig() { if (mapModified) { if (isDebug()) { - logger.log(Level.INFO, "Syncing commands"); + EssentialsLogger.log(Level.INFO, "Syncing commands"); } if (reloadCount.get() < 2) { ess.scheduleSyncDelayedTask(() -> ess.getSyncCommandsProvider().syncCommands()); @@ -799,7 +797,7 @@ private List _getItemSpawnBlacklist() { //noinspection deprecation final IItemDb itemDb = ess.getItemDb(); if (itemDb == null || !itemDb.isReady()) { - logger.log(Level.FINE, "Skipping item spawn blacklist read; item DB not yet loaded."); + EssentialsLogger.log(Level.FINE, "Skipping item spawn blacklist read; item DB not yet loaded."); return epItemSpwn; } for (String itemName : config.getString("item-spawn-blacklist", "").split(",")) { @@ -811,7 +809,7 @@ private List _getItemSpawnBlacklist() { final ItemStack iStack = itemDb.get(itemName); epItemSpwn.add(iStack.getType()); } catch (final Exception ex) { - logger.log(Level.SEVERE, tl("unknownItemInList", itemName, "item-spawn-blacklist"), ex); + EssentialsLogger.log(Level.SEVERE, tl("unknownItemInList", itemName, "item-spawn-blacklist"), ex); } } return epItemSpwn; @@ -839,7 +837,7 @@ private List _getEnabledSigns() { try { newSigns.add(Signs.valueOf(signName).getSign()); } catch (final Exception ex) { - logger.log(Level.SEVERE, tl("unknownItemInList", signName, "enabledSigns")); + EssentialsLogger.log(Level.SEVERE, tl("unknownItemInList", signName, "enabledSigns")); continue; } signsEnabled = true; @@ -953,7 +951,7 @@ public List getProtectList(final String configName) { } if (mat == null) { - logger.log(Level.SEVERE, tl("unknownItemInList", itemName, configName)); + EssentialsLogger.log(Level.SEVERE, tl("unknownItemInList", itemName, configName)); } else { list.add(mat); } @@ -1575,7 +1573,7 @@ private Map _getCommandCooldowns() { try { pattern = Pattern.compile(cmdEntry.substring(1)); } catch (final PatternSyntaxException e) { - ess.getLogger().warning("Command cooldown error: " + e.getMessage()); + EssentialsLogger.warning("Command cooldown error: " + e.getMessage()); } } else { // Escape above Regex @@ -1597,12 +1595,12 @@ private Map _getCommandCooldowns() { } } if (!(value instanceof Number)) { - ess.getLogger().warning("Command cooldown error: '" + value + "' is not a valid cooldown"); + EssentialsLogger.warning("Command cooldown error: '" + value + "' is not a valid cooldown"); continue; } final double cooldown = ((Number) value).doubleValue(); if (cooldown < 1) { - ess.getLogger().warning("Command cooldown with very short " + cooldown + " cooldown."); + EssentialsLogger.warning("Command cooldown with very short " + cooldown + " cooldown."); } result.put(pattern, (long) cooldown * 1000); // convert to milliseconds @@ -1628,7 +1626,7 @@ public Entry getCommandCooldownEntry(final String label) { // Check if label matches current pattern (command-cooldown in config) final boolean matches = entry.getKey().matcher(label).matches(); if (isDebug()) { - ess.getLogger().info(String.format("Checking command '%s' against cooldown '%s': %s", label, entry.getKey(), matches)); + EssentialsLogger.info(String.format("Checking command '%s' against cooldown '%s': %s", label, entry.getKey(), matches)); } if (matches) { @@ -1695,7 +1693,7 @@ private List _getUnprotectedSign() { try { newSigns.add(Signs.valueOf(signName).getSign()); } catch (final Exception ex) { - logger.log(Level.SEVERE, tl("unknownItemInList", signName, "unprotected-sign-names")); + EssentialsLogger.log(Level.SEVERE, tl("unknownItemInList", signName, "unprotected-sign-names")); } } return newSigns; @@ -1880,7 +1878,7 @@ private Set> _getNickBlacklist() { try { blacklist.add(Pattern.compile(entry).asPredicate()); } catch (final PatternSyntaxException e) { - logger.warning("Invalid nickname blacklist regex: " + entry); + EssentialsLogger.warning("Invalid nickname blacklist regex: " + entry); } }); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Teleport.java b/Essentials/src/main/java/com/earth2me/essentials/Teleport.java index 6038b2e3578..30291b4bb54 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Teleport.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Teleport.java @@ -325,7 +325,7 @@ void respawnNow(final IUser teleportee, final TeleportCause cause) throws Except now(teleportee, new LocationTarget(bed), cause); } else { if (ess.getSettings().isDebug()) { - ess.getLogger().info("Could not find bed spawn, forcing respawn event."); + EssentialsLogger.info("Could not find bed spawn, forcing respawn event."); } final PlayerRespawnEvent pre = new PlayerRespawnEvent(player, player.getWorld().getSpawnLocation(), false); ess.getServer().getPluginManager().callEvent(pre); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Trade.java b/Essentials/src/main/java/com/earth2me/essentials/Trade.java index aa595a0bae3..c5d2bc24788 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Trade.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Trade.java @@ -22,7 +22,6 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.logging.Level; -import java.util.logging.Logger; import static com.earth2me.essentials.I18n.tl; @@ -80,7 +79,7 @@ public static void log(final String type, final String subtype, final String eve try { fw = new FileWriter(new File(ess.getDataFolder(), "trade.log"), true); } catch (final IOException ex) { - Logger.getLogger("Essentials").log(Level.SEVERE, null, ex); + EssentialsLogger.log(Level.SEVERE, null, ex); } } final StringBuilder sb = new StringBuilder(); @@ -159,7 +158,7 @@ public static void log(final String type, final String subtype, final String eve fw.write(sb.toString()); fw.flush(); } catch (final IOException ex) { - Logger.getLogger("Essentials").log(Level.SEVERE, null, ex); + EssentialsLogger.log(Level.SEVERE, null, ex); } } @@ -168,7 +167,7 @@ public static void closeLog() { try { fw.close(); } catch (final IOException ex) { - Logger.getLogger("Essentials").log(Level.SEVERE, null, ex); + EssentialsLogger.log(Level.SEVERE, null, ex); } fw = null; } @@ -190,7 +189,7 @@ public void isAffordableFor(final IUser user) throws ChargeException { public void isAffordableFor(final IUser user, final CompletableFuture future) { if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.INFO, "checking if " + user.getName() + " can afford charge."); + EssentialsLogger.log(Level.INFO, "checking if " + user.getName() + " can afford charge."); } if (getMoney() != null && getMoney().signum() > 0 && !user.canAfford(getMoney())) { @@ -221,7 +220,7 @@ public boolean pay(final IUser user) throws MaxMoneyException { public Map pay(final IUser user, final OverflowType type) throws MaxMoneyException { if (getMoney() != null && getMoney().signum() > 0) { if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.INFO, "paying user " + user.getName() + " via trade " + getMoney().toPlainString()); + EssentialsLogger.log(Level.INFO, "paying user " + user.getName() + " via trade " + getMoney().toPlainString()); } user.giveMoney(getMoney()); } @@ -233,7 +232,7 @@ public Map pay(final IUser user, final OverflowType type) th switch (type) { case ABORT: if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.INFO, "abort paying " + user.getName() + " itemstack " + getItemStack().toString() + " due to lack of inventory space "); + EssentialsLogger.log(Level.INFO, "abort paying " + user.getName() + " itemstack " + getItemStack().toString() + " due to lack of inventory space "); } return overFlow; @@ -244,7 +243,7 @@ public Map pay(final IUser user, final OverflowType type) th user.getBase().updateInventory(); if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.INFO, "paying " + user.getName() + " partial itemstack " + getItemStack().toString() + " with overflow " + returnStack.get(0).toString()); + EssentialsLogger.log(Level.INFO, "paying " + user.getName() + " partial itemstack " + getItemStack().toString() + " with overflow " + returnStack.get(0).toString()); } return returnStack; @@ -269,12 +268,12 @@ public Map pay(final IUser user, final OverflowType type) th } } if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.INFO, "paying " + user.getName() + " partial itemstack " + getItemStack().toString() + " and dropping overflow " + leftOver.get(0).toString()); + EssentialsLogger.log(Level.INFO, "paying " + user.getName() + " partial itemstack " + getItemStack().toString() + " and dropping overflow " + leftOver.get(0).toString()); } break; } } else if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.INFO, "paying " + user.getName() + " itemstack " + getItemStack().toString()); + EssentialsLogger.log(Level.INFO, "paying " + user.getName() + " itemstack " + getItemStack().toString()); } user.getBase().updateInventory(); } @@ -300,11 +299,11 @@ public void charge(final IUser user) throws ChargeException { public void charge(final IUser user, final CompletableFuture future) { if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.INFO, "attempting to charge user " + user.getName()); + EssentialsLogger.log(Level.INFO, "attempting to charge user " + user.getName()); } if (getMoney() != null) { if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.INFO, "charging user " + user.getName() + " money " + getMoney().toPlainString()); + EssentialsLogger.log(Level.INFO, "charging user " + user.getName() + " money " + getMoney().toPlainString()); } if (!user.canAfford(getMoney()) && getMoney().signum() > 0) { future.completeExceptionally(new ChargeException(tl("notEnoughMoney", NumberUtil.displayCurrency(getMoney(), ess)))); @@ -314,7 +313,7 @@ public void charge(final IUser user, final CompletableFuture future) { } if (getItemStack() != null) { if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.INFO, "charging user " + user.getName() + " itemstack " + getItemStack().toString()); + EssentialsLogger.log(Level.INFO, "charging user " + user.getName() + " itemstack " + getItemStack().toString()); } if (!user.getBase().getInventory().containsAtLeast(getItemStack(), getItemStack().getAmount())) { future.completeExceptionally(new ChargeException(tl("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase(Locale.ENGLISH).replace("_", " ")))); @@ -333,7 +332,7 @@ public void charge(final IUser user, final CompletableFuture future) { } if (getExperience() != null) { if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.INFO, "charging user " + user.getName() + " exp " + getExperience()); + EssentialsLogger.log(Level.INFO, "charging user " + user.getName() + " exp " + getExperience()); } final int experience = SetExpFix.getTotalExperience(user.getBase()); if (experience < getExperience() && getExperience() > 0) { @@ -343,7 +342,7 @@ public void charge(final IUser user, final CompletableFuture future) { SetExpFix.setTotalExperience(user.getBase(), experience - getExperience()); } if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.INFO, "charge user " + user.getName() + " completed"); + EssentialsLogger.log(Level.INFO, "charge user " + user.getName() + " completed"); } } @@ -380,7 +379,7 @@ public BigDecimal getCommandCost(final IUser user) { } if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.INFO, "calculated command (" + command + ") cost for " + user.getName() + " as " + cost); + EssentialsLogger.log(Level.INFO, "calculated command (" + command + ") cost for " + user.getName() + " as " + cost); } } if (cost.signum() != 0 && (user.isAuthorized("essentials.nocommandcost.all") || user.isAuthorized("essentials.nocommandcost." + command))) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/UUIDMap.java b/Essentials/src/main/java/com/earth2me/essentials/UUIDMap.java index be24d8f9983..403849c3116 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/UUIDMap.java +++ b/Essentials/src/main/java/com/earth2me/essentials/UUIDMap.java @@ -52,7 +52,7 @@ public void loadAllUsers(final ConcurrentSkipListMap names, final } if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.INFO, "Reading usermap from disk"); + EssentialsLogger.log(Level.INFO, "Reading usermap from disk"); } if (loading) { @@ -100,7 +100,7 @@ public void writeUUIDMap() { public void forceWriteUUIDMap() { if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.INFO, "Forcing usermap write to disk"); + EssentialsLogger.log(Level.INFO, "Forcing usermap write to disk"); } pendingWrite = true; writeTaskRunnable.run(); diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index 5b6327fc686..e397fd60ab7 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -48,13 +48,11 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; import java.util.logging.Level; -import java.util.logging.Logger; import static com.earth2me.essentials.I18n.tl; public class User extends UserData implements Comparable, IMessageRecipient, net.ess3.api.IUser { private static final Statistic PLAY_ONE_TICK = EnumUtil.getStatistic("PLAY_ONE_MINUTE", "PLAY_ONE_TICK"); - private static final Logger logger = Logger.getLogger("Essentials"); // User modules private final IMessageRecipient messageRecipient; @@ -129,7 +127,7 @@ public boolean isAuthorized(final IEssentialsCommand cmd, final String permissio public boolean isAuthorized(final String node) { final boolean result = isAuthorizedCheck(node); if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.INFO, "checking if " + base.getName() + " has " + node + " - " + result); + EssentialsLogger.log(Level.INFO, "checking if " + base.getName() + " has " + node + " - " + result); } return result; } @@ -138,7 +136,7 @@ public boolean isAuthorized(final String node) { public boolean isPermissionSet(final String node) { final boolean result = isPermSetCheck(node); if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.INFO, "checking if " + base.getName() + " has " + node + " (set-explicit) - " + result); + EssentialsLogger.log(Level.INFO, "checking if " + base.getName() + " has " + node + " (set-explicit) - " + result); } return result; } @@ -160,9 +158,9 @@ private boolean isAuthorizedCheck(final String node) { return ess.getPermissionsHandler().hasPermission(base, node); } catch (final Exception ex) { if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage(), ex); + EssentialsLogger.log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage(), ex); } else { - ess.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage()); + EssentialsLogger.log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage()); } return false; @@ -178,9 +176,9 @@ private boolean isPermSetCheck(final String node) { return ess.getPermissionsHandler().isPermissionSet(base, node); } catch (final Exception ex) { if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage(), ex); + EssentialsLogger.log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage(), ex); } else { - ess.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage()); + EssentialsLogger.log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage()); } return false; @@ -196,9 +194,9 @@ private TriState isAuthorizedExactCheck(final String node) { return ess.getPermissionsHandler().isPermissionSetExact(base, node); } catch (final Exception ex) { if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage(), ex); + EssentialsLogger.log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage(), ex); } else { - ess.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage()); + EssentialsLogger.log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage()); } return TriState.UNSET; @@ -281,7 +279,7 @@ public void takeMoney(final BigDecimal value, final CommandSource initiator, fin try { setMoney(getMoney().subtract(value), cause); } catch (final MaxMoneyException ex) { - ess.getLogger().log(Level.WARNING, "Invalid call to takeMoney, total balance can't be more than the max-money limit.", ex); + EssentialsLogger.log(Level.WARNING, "Invalid call to takeMoney, total balance can't be more than the max-money limit.", ex); } sendMessage(tl("takenFromAccount", NumberUtil.displayCurrency(value, ess))); if (initiator != null) { @@ -520,7 +518,7 @@ public void setDisplayNick() { this.getBase().setPlayerListName(name); } catch (final IllegalArgumentException e) { if (ess.getSettings().isDebug()) { - logger.log(Level.INFO, "Playerlist for " + name + " was not updated. Name clashed with another online player."); + EssentialsLogger.log(Level.INFO, "Playerlist for " + name + " was not updated. Name clashed with another online player."); } } } @@ -569,7 +567,7 @@ public BigDecimal getMoney() { final BigDecimal value = _getMoney(); final long elapsed = System.nanoTime() - start; if (elapsed > ess.getSettings().getEconomyLagWarning()) { - ess.getLogger().log(Level.INFO, "Lag Notice - Slow Economy Response - Request took over {0}ms!", elapsed / 1000000.0); + EssentialsLogger.log(Level.INFO, "Lag Notice - Slow Economy Response - Request took over " + elapsed / 1000000.0 + "ms!"); } return value; } @@ -582,7 +580,7 @@ public void setMoney(final BigDecimal value) throws MaxMoneyException { private BigDecimal _getMoney() { if (ess.getSettings().isEcoDisabled()) { if (ess.getSettings().isDebug()) { - ess.getLogger().info("Internal economy functions disabled, aborting balance check."); + EssentialsLogger.info("Internal economy functions disabled, aborting balance check."); } return BigDecimal.ZERO; } @@ -596,7 +594,7 @@ private BigDecimal _getMoney() { public void setMoney(final BigDecimal value, final UserBalanceUpdateEvent.Cause cause) throws MaxMoneyException { if (ess.getSettings().isEcoDisabled()) { if (ess.getSettings().isDebug()) { - ess.getLogger().info("Internal economy functions disabled, aborting balance change."); + EssentialsLogger.info("Internal economy functions disabled, aborting balance change."); } return; } @@ -871,7 +869,7 @@ public boolean isGodModeEnabledRaw() { public String getGroup() { final String result = ess.getPermissionsHandler().getGroup(base); if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.INFO, "looking up groupname of " + base.getName() + " - " + result); + EssentialsLogger.log(Level.INFO, "looking up groupname of " + base.getName() + " - " + result); } return result; } @@ -880,7 +878,7 @@ public String getGroup() { public boolean inGroup(final String group) { final boolean result = ess.getPermissionsHandler().inGroup(base, group); if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.INFO, "checking if " + base.getName() + " is in group " + group + " - " + result); + EssentialsLogger.log(Level.INFO, "checking if " + base.getName() + " is in group " + group + " - " + result); } return result; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/UserData.java b/Essentials/src/main/java/com/earth2me/essentials/UserData.java index 79126b5b3a1..6d32169cb34 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/UserData.java +++ b/Essentials/src/main/java/com/earth2me/essentials/UserData.java @@ -51,7 +51,7 @@ protected UserData(final Player base, final IEssentials ess) { try { filename = base.getUniqueId().toString(); } catch (final Throwable ex) { - ess.getLogger().warning("Falling back to old username system for " + base.getName()); + EssentialsLogger.warning("Falling back to old username system for " + base.getName()); filename = base.getName(); } @@ -85,14 +85,14 @@ public final void reloadConfig() { try { holder = config.getRootNode().get(UserConfigHolder.class); } catch (SerializationException e) { - ess.getLogger().log(Level.SEVERE, "Error while reading user config: " + e.getMessage(), e); + EssentialsLogger.log(Level.SEVERE, "Error while reading user config: " + e.getMessage(), e); throw new RuntimeException(e); } config.setSaveHook(() -> { try { config.getRootNode().set(UserConfigHolder.class, holder); } catch (SerializationException e) { - ess.getLogger().log(Level.SEVERE, "Error while saving user config: " + e.getMessage(), e); + EssentialsLogger.log(Level.SEVERE, "Error while saving user config: " + e.getMessage(), e); throw new RuntimeException(e); } }); diff --git a/Essentials/src/main/java/com/earth2me/essentials/UserMap.java b/Essentials/src/main/java/com/earth2me/essentials/UserMap.java index 35f5eefe614..12b9bbd6e98 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/UserMap.java +++ b/Essentials/src/main/java/com/earth2me/essentials/UserMap.java @@ -95,7 +95,7 @@ public User getUser(final String name) { final String sanitizedName = StringUtil.safeString(name); try { if (ess.getSettings().isDebug()) { - ess.getLogger().warning("Looking up username " + name + " (" + sanitizedName + ") ..."); + EssentialsLogger.warning("Looking up username " + name + " (" + sanitizedName + ") ..."); } if (names.containsKey(sanitizedName)) { @@ -104,12 +104,12 @@ public User getUser(final String name) { } if (ess.getSettings().isDebug()) { - ess.getLogger().warning(name + "(" + sanitizedName + ") has no known usermap entry"); + EssentialsLogger.warning(name + "(" + sanitizedName + ") has no known usermap entry"); } final File userFile = getUserFileFromString(sanitizedName); if (userFile.exists()) { - ess.getLogger().info("Importing user " + name + " to usermap."); + EssentialsLogger.info("Importing user " + name + " to usermap."); final User user = new User(new OfflinePlayer(sanitizedName, ess.getServer()), ess); trackUUID(user.getBase().getUniqueId(), user.getName(), true); return user; @@ -117,7 +117,7 @@ public User getUser(final String name) { return null; } catch (final UncheckedExecutionException ex) { if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.WARNING, ex, () -> String.format("Exception while getting user for %s (%s)", name, sanitizedName)); + EssentialsLogger.log(Level.WARNING, "Exception while getting user for " + name + " (" + sanitizedName + ")", ex); } return null; } @@ -132,7 +132,7 @@ public User getUser(final UUID uuid) { } } catch (final ExecutionException | UncheckedExecutionException ex) { if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.WARNING, ex, () -> "Exception while getting user for " + uuid); + EssentialsLogger.log(Level.WARNING, "Exception while getting user for " + uuid, ex); } return null; } @@ -148,11 +148,11 @@ public void trackUUID(final UUID uuid, final String name, final boolean replace) uuidMap.writeUUIDMap(); } else if (!isUUIDMatch(uuid, keyName)) { if (replace) { - ess.getLogger().info("Found new UUID for " + name + ". Replacing " + names.get(keyName).toString() + " with " + uuid.toString()); + EssentialsLogger.info("Found new UUID for " + name + ". Replacing " + names.get(keyName).toString() + " with " + uuid.toString()); names.put(keyName, uuid); uuidMap.writeUUIDMap(); } else { - ess.getLogger().log(Level.INFO, MessageFormat.format(WARN_UUID_NOT_REPLACE, uuid.toString(), name, names.get(keyName).toString()), new RuntimeException()); + EssentialsLogger.log(Level.INFO, MessageFormat.format(WARN_UUID_NOT_REPLACE, uuid.toString(), name, names.get(keyName).toString()), new RuntimeException()); } } } @@ -193,7 +193,7 @@ public User load(final org.bukkit.OfflinePlayer player) throws UserDoesNotExistE if (player instanceof Player) { if (ess.getSettings().isDebug()) { - ess.getLogger().info("Loading online OfflinePlayer into user map..."); + EssentialsLogger.info("Loading online OfflinePlayer into user map..."); } final User user = new User((Player) player, ess); trackUUID(player.getUniqueId(), player.getName(), true); @@ -202,7 +202,7 @@ public User load(final org.bukkit.OfflinePlayer player) throws UserDoesNotExistE final File userFile = getUserFileFromID(player.getUniqueId()); if (ess.getSettings().isDebug()) { - ess.getLogger().info("Loading OfflinePlayer into user map. Has data: " + userFile.exists() + " for " + player); + EssentialsLogger.info("Loading OfflinePlayer into user map. Has data: " + userFile.exists() + " for " + player); } final OfflinePlayer essPlayer = new OfflinePlayer(player.getUniqueId(), ess.getServer()); @@ -211,7 +211,7 @@ public User load(final org.bukkit.OfflinePlayer player) throws UserDoesNotExistE essPlayer.setName(user.getLastAccountName()); } else { if (ess.getSettings().isDebug()) { - ess.getLogger().info("OfflinePlayer usermap load saving user data for " + player); + EssentialsLogger.info("OfflinePlayer usermap load saving user data for " + player); } // this code makes me sad @@ -242,7 +242,7 @@ public void invalidateAll() { public void removeUser(final String name) { if (names == null) { - ess.getLogger().warning("Name collection is null, cannot remove user."); + EssentialsLogger.warning("Name collection is null, cannot remove user."); return; } final UUID uuid = names.get(name); @@ -308,7 +308,7 @@ public File getUserFileFromString(final String name) { public User getUserFromBukkit(String name) { name = StringUtil.safeString(name); if (ess.getSettings().isDebug()) { - ess.getLogger().warning("Using potentially blocking Bukkit UUID lookup for: " + name); + EssentialsLogger.warning("Using potentially blocking Bukkit UUID lookup for: " + name); } // Don't attempt to look up entirely invalid usernames if (name == null || !validUserPattern.matcher(name).matches()) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/Warps.java b/Essentials/src/main/java/com/earth2me/essentials/Warps.java index 6c34493b383..4086e815996 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Warps.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Warps.java @@ -16,12 +16,10 @@ import java.util.Map; import java.util.UUID; import java.util.logging.Level; -import java.util.logging.Logger; import static com.earth2me.essentials.I18n.tl; public class Warps implements IConf, net.ess3.api.IWarps { - private static final Logger logger = Logger.getLogger("Essentials"); private final Map warpPoints = new HashMap<>(); private final File warpsFolder; @@ -135,7 +133,7 @@ public final void reloadConfig() { warpPoints.put(new StringIgnoreCase(name), conf); } } catch (final Exception ex) { - logger.log(Level.WARNING, tl("loadWarpError", filename), ex); + EssentialsLogger.log(Level.WARNING, tl("loadWarpError", filename), ex); } } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/api/Economy.java b/Essentials/src/main/java/com/earth2me/essentials/api/Economy.java index dd7ae19f71c..103e5f9d598 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/api/Economy.java +++ b/Essentials/src/main/java/com/earth2me/essentials/api/Economy.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.api; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; import com.earth2me.essentials.config.EssentialsUserConfiguration; @@ -17,14 +18,12 @@ import java.text.MessageFormat; import java.util.UUID; import java.util.logging.Level; -import java.util.logging.Logger; /** * You should use Vault instead of directly using this class. */ public class Economy { public static final MathContext MATH_CONTEXT = MathContext.DECIMAL128; - private static final Logger LOGGER = Logger.getLogger("Essentials"); private static IEssentials ess; private static final String WARN_CALL_BEFORE_LOAD = "Essentials API is called before Essentials is loaded."; @@ -54,8 +53,8 @@ private static void createNPCFile(String name) { final UUID npcUUID = UUID.nameUUIDFromBytes(("NPC:" + name).getBytes(Charsets.UTF_8)); final File npcFile = new File(folder, npcUUID + ".yml"); if (npcFile.exists()) { - LOGGER.log(Level.SEVERE, MessageFormat.format(WARN_NPC_RECREATE_1, name, npcUUID.toString()), new RuntimeException()); - LOGGER.log(Level.SEVERE, WARN_NPC_RECREATE_2); + EssentialsLogger.log(Level.SEVERE, MessageFormat.format(WARN_NPC_RECREATE_1, name, npcUUID.toString()), new RuntimeException()); + EssentialsLogger.log(Level.SEVERE, WARN_NPC_RECREATE_2); } final EssentialsUserConfiguration npcConfig = new EssentialsUserConfiguration(name, npcUUID, npcFile); npcConfig.load(); @@ -90,7 +89,7 @@ private static User getUserByName(final String name) { if (player != null) { user = ess.getUser(player.getUniqueId()); if (user != null) { - LOGGER.log(Level.INFO, MessageFormat.format(WARN_PLAYER_UUID_NO_NAME, name, player.getUniqueId().toString()), new RuntimeException()); + EssentialsLogger.log(Level.INFO, MessageFormat.format(WARN_PLAYER_UUID_NO_NAME, name, player.getUniqueId().toString()), new RuntimeException()); } } } @@ -190,7 +189,7 @@ public static void setMoney(final String name, final double balance) throws User try { setMoney(name, BigDecimal.valueOf(balance)); } catch (final ArithmeticException e) { - LOGGER.log(Level.WARNING, "Failed to set balance of " + name + " to " + balance + ": " + e.getMessage(), e); + EssentialsLogger.log(Level.WARNING, "Failed to set balance of " + name + " to " + balance + ": " + e.getMessage(), e); } } @@ -268,7 +267,7 @@ public static void add(final String name, final double amount) throws UserDoesNo try { add(name, BigDecimal.valueOf(amount)); } catch (final ArithmeticException e) { - LOGGER.log(Level.WARNING, "Failed to add " + amount + " to balance of " + name + ": " + e.getMessage(), e); + EssentialsLogger.log(Level.WARNING, "Failed to add " + amount + " to balance of " + name + ": " + e.getMessage(), e); } } @@ -340,7 +339,7 @@ public static void subtract(final String name, final double amount) throws UserD try { substract(name, BigDecimal.valueOf(amount)); } catch (final ArithmeticException e) { - LOGGER.log(Level.WARNING, "Failed to subtract " + amount + " of balance of " + name + ": " + e.getMessage(), e); + EssentialsLogger.log(Level.WARNING, "Failed to subtract " + amount + " of balance of " + name + ": " + e.getMessage(), e); } } @@ -410,7 +409,7 @@ public static void divide(final String name, final double amount) throws UserDoe try { divide(name, BigDecimal.valueOf(amount)); } catch (final ArithmeticException e) { - LOGGER.log(Level.WARNING, "Failed to divide balance of " + name + " by " + amount + ": " + e.getMessage(), e); + EssentialsLogger.log(Level.WARNING, "Failed to divide balance of " + name + " by " + amount + ": " + e.getMessage(), e); } } @@ -482,7 +481,7 @@ public static void multiply(final String name, final double amount) throws UserD try { multiply(name, BigDecimal.valueOf(amount)); } catch (final ArithmeticException e) { - LOGGER.log(Level.WARNING, "Failed to multiply balance of " + name + " by " + amount + ": " + e.getMessage(), e); + EssentialsLogger.log(Level.WARNING, "Failed to multiply balance of " + name + " by " + amount + ": " + e.getMessage(), e); } } @@ -603,7 +602,7 @@ public static boolean hasEnough(final String name, final double amount) throws U try { return hasEnough(name, BigDecimal.valueOf(amount)); } catch (final ArithmeticException e) { - LOGGER.log(Level.WARNING, "Failed to compare balance of " + name + " with " + amount + ": " + e.getMessage(), e); + EssentialsLogger.log(Level.WARNING, "Failed to compare balance of " + name + " with " + amount + ": " + e.getMessage(), e); return false; } } @@ -664,7 +663,7 @@ public static boolean hasMore(final String name, final double amount) throws Use try { return hasMore(name, BigDecimal.valueOf(amount)); } catch (final ArithmeticException e) { - LOGGER.log(Level.WARNING, "Failed to compare balance of " + name + " with " + amount + ": " + e.getMessage(), e); + EssentialsLogger.log(Level.WARNING, "Failed to compare balance of " + name + " with " + amount + ": " + e.getMessage(), e); return false; } } @@ -726,7 +725,7 @@ public static boolean hasLess(final String name, final double amount) throws Use try { return hasLess(name, BigDecimal.valueOf(amount)); } catch (final ArithmeticException e) { - LOGGER.log(Level.WARNING, "Failed to compare balance of " + name + " with " + amount + ": " + e.getMessage(), e); + EssentialsLogger.log(Level.WARNING, "Failed to compare balance of " + name + " with " + amount + ": " + e.getMessage(), e); return false; } } @@ -833,7 +832,7 @@ public static String format(final double amount) { try { return format(BigDecimal.valueOf(amount)); } catch (final NumberFormatException e) { - LOGGER.log(Level.WARNING, "Failed to display " + amount + ": " + e.getMessage(), e); + EssentialsLogger.log(Level.WARNING, "Failed to display " + amount + ": " + e.getMessage(), e); return "NaN"; } } @@ -900,7 +899,7 @@ public static boolean createNPC(final String name) { createNPCFile(name); return true; } - LOGGER.log(Level.WARNING, MessageFormat.format(WARN_EXISTING_NPC_CREATE, name, user.getConfigUUID()), new RuntimeException()); + EssentialsLogger.log(Level.WARNING, MessageFormat.format(WARN_EXISTING_NPC_CREATE, name, user.getConfigUUID()), new RuntimeException()); return false; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java index 0aa0ce63986..d1a00697cbc 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.CommandSource; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.textreader.SimpleTextInput; import com.earth2me.essentials.textreader.TextPager; import com.earth2me.essentials.utils.NumberUtil; @@ -91,7 +92,7 @@ private class Viewer implements Runnable { public void run() { if (ess.getSettings().isEcoDisabled()) { if (ess.getSettings().isDebug()) { - ess.getLogger().info("Internal economy functions disabled, aborting baltop."); + EssentialsLogger.info("Internal economy functions disabled, aborting baltop."); } return; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcreatekit.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcreatekit.java index 81d4519b5db..9719d00071e 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcreatekit.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcreatekit.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.CommandSource; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.DateUtil; import com.earth2me.essentials.utils.PasteUtil; @@ -91,18 +92,18 @@ private void uploadPaste(final CommandSource sender, final String kitName, final sender.sendMessage(tl("createKitSuccess", kitName, delayFormat, result.getPasteUrl())); sender.sendMessage(separator); if (ess.getSettings().isDebug()) { - ess.getLogger().info(sender.getSender().getName() + " created a kit: " + result.getPasteUrl()); + EssentialsLogger.info(sender.getSender().getName() + " created a kit: " + result.getPasteUrl()); } } }); future.exceptionally(throwable -> { sender.sendMessage(tl("createKitFailed", kitName)); - ess.getLogger().log(Level.SEVERE, "Error creating kit: ", throwable); + EssentialsLogger.log(Level.SEVERE, "Error creating kit: ", throwable); return null; }); } catch (Exception e) { sender.sendMessage(tl("createKitFailed", kitName)); - ess.getLogger().log(Level.SEVERE, "Error creating kit: ", e); + EssentialsLogger.log(Level.SEVERE, "Error creating kit: ", e); } }); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandessentials.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandessentials.java index 9dd3fdd6087..d340a6360ee 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandessentials.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandessentials.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.CommandSource; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.EssentialsUpgrade; import com.earth2me.essentials.User; import com.earth2me.essentials.UserMap; @@ -363,8 +364,8 @@ private void runDump(Server server, CommandSource sender, String commandLabel, S sender.sendMessage(tl("dumpUrl", dumpUrl)); sender.sendMessage(tl("dumpDeleteKey", result.getDeletionKey())); if (sender.isPlayer()) { - ess.getLogger().info(tl("dumpConsoleUrl", dumpUrl)); - ess.getLogger().info(tl("dumpDeleteKey", result.getDeletionKey())); + EssentialsLogger.info(tl("dumpConsoleUrl", dumpUrl)); + EssentialsLogger.info(tl("dumpDeleteKey", result.getDeletionKey())); } } files.clear(); @@ -412,7 +413,7 @@ private void runNya(final Server server, final CommandSource sender, final Strin private void runMoo(final Server server, final CommandSource sender, final String command, final String[] args) { if (args.length == 2 && args[1].equals("moo")) { for (final String s : CONSOLE_MOO) { - logger.info(s); + EssentialsLogger.info(s); } for (final Player player : ess.getOnlinePlayers()) { player.sendMessage(PLAYER_MOO); @@ -476,7 +477,7 @@ private void runCleanup(final Server server, final CommandSource sender, final S } if (ess.getSettings().isDebug()) { - ess.getLogger().info("Deleting user: " + user.getName() + " Money: " + moneyCount + " Homes: " + homeCount + " Last seen: " + DateUtil.formatDateDiff(lastLog)); + EssentialsLogger.info("Deleting user: " + user.getName() + " Money: " + moneyCount + " Homes: " + homeCount + " Last seen: " + DateUtil.formatDateDiff(lastLog)); } user.reset(); @@ -510,7 +511,7 @@ private void runHomes(final Server server, final CommandSource sender, final Str user.delHome(homeName); } } catch (Exception e) { - ess.getLogger().info("Unable to delete home " + homeName + " for " + user.getName()); + EssentialsLogger.info("Unable to delete home " + homeName + " for " + user.getName()); } } } @@ -536,7 +537,7 @@ private void runHomes(final Server server, final CommandSource sender, final Str user.delHome(homeName); } } catch (Exception e) { - ess.getLogger().info("Unable to delete home " + homeName + " for " + user.getName()); + EssentialsLogger.info("Unable to delete home " + homeName + " for " + user.getName()); } } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandkit.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandkit.java index 28fc58911ac..44f2f3d748c 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandkit.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandkit.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.CommandSource; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.Kit; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.StringUtil; @@ -87,7 +88,7 @@ private void giveKits(final User userTo, final User userFrom, final String kitNa } catch (final NoChargeException ex) { if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.INFO, "Soft kit error, abort spawning " + kit.getName(), ex); + EssentialsLogger.log(Level.INFO, "Soft kit error, abort spawning " + kit.getName(), ex); } } catch (final Exception ex) { ess.showError(userFrom.getSource(), ex, "\\ kit: " + kit.getName()); diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsell.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsell.java index 1a153c03982..5f016e69f93 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsell.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsell.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.NumberUtil; @@ -117,7 +118,7 @@ private BigDecimal sellItem(final User user, final ItemStack is, final String[] Trade.log("Command", "Sell", "Item", user.getName(), new Trade(ris, ess), user.getName(), new Trade(result, ess), user.getLocation(), user.getMoney(), ess); user.giveMoney(result, null, UserBalanceUpdateEvent.Cause.COMMAND_SELL); user.sendMessage(tl("itemSold", NumberUtil.displayCurrency(result, ess), amount, is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(worth, ess))); - logger.log(Level.INFO, tl("itemSoldConsole", user.getName(), is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(result, ess), amount, NumberUtil.displayCurrency(worth, ess), user.getDisplayName())); + EssentialsLogger.log(Level.INFO, tl("itemSoldConsole", user.getName(), is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(result, ess), amount, NumberUtil.displayCurrency(worth, ess), user.getDisplayName())); return result; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java index cabdeb8cae9..d93591da884 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.AsyncTeleport; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.IUser; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; @@ -99,7 +100,7 @@ private void handleTeleport(final User user, final IUser.TpaRequest request, Str Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { if (ess.getSettings().isDebug()) { - logger.info("TPA accept cancelled by API for " + user.getName() + " (requested by " + requester.getName() + ")"); + EssentialsLogger.info("TPA accept cancelled by API for " + user.getName() + " (requested by " + requester.getName() + ")"); } return; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java index b5c10de5109..e4391f8f518 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.IUser; import com.earth2me.essentials.User; import net.essentialsx.api.v2.events.TeleportRequestResponseEvent; @@ -84,7 +85,7 @@ private boolean sendEvent(User user, User player, IUser.TpaRequest request) { Bukkit.getPluginManager().callEvent(event); final boolean cancelled = event.isCancelled(); if (cancelled && ess.getSettings().isDebug()) { - logger.info("TPA deny cancelled by API for " + user.getName() + " (requested by " + player.getName() + ")"); + EssentialsLogger.info("TPA deny cancelled by API for " + user.getName() + " (requested by " + player.getName() + ")"); } return event.isCancelled(); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/EssentialsCommand.java b/Essentials/src/main/java/com/earth2me/essentials/commands/EssentialsCommand.java index 7fcfdea88b4..c7230c80e41 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/EssentialsCommand.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/EssentialsCommand.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.CommandSource; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.IEssentialsModule; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; @@ -26,14 +27,12 @@ import java.util.MissingResourceException; import java.util.concurrent.CompletableFuture; import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; import static com.earth2me.essentials.I18n.tl; public abstract class EssentialsCommand implements IEssentialsCommand { - protected static final Logger logger = Logger.getLogger("Essentials"); /** * Common time durations (in seconds), for use in tab completion. */ @@ -316,7 +315,7 @@ protected final List tabCompleteCommand(final CommandSource sender, fina final int numArgs = args.length - index - 1; if (ess.getSettings().isDebug()) { - ess.getLogger().info(numArgs + " " + index + " " + Arrays.toString(args)); + EssentialsLogger.info(numArgs + " " + index + " " + Arrays.toString(args)); } String[] effectiveArgs = new String[numArgs]; System.arraycopy(args, index, effectiveArgs, 0, numArgs); @@ -324,7 +323,7 @@ protected final List tabCompleteCommand(final CommandSource sender, fina effectiveArgs = new String[] {""}; } if (ess.getSettings().isDebug()) { - ess.getLogger().info(command + " -- " + Arrays.toString(effectiveArgs)); + EssentialsLogger.info(command + " -- " + Arrays.toString(effectiveArgs)); } return command.tabComplete(sender.getSender(), label, effectiveArgs); @@ -334,7 +333,7 @@ protected final List tabCompleteCommand(final CommandSource sender, fina public void showError(final CommandSender sender, final Throwable throwable, final String commandLabel) { sender.sendMessage(tl("errorWithMessage", throwable.getMessage())); if (ess.getSettings().isDebug()) { - logger.log(Level.INFO, tl("errorCallingCommand", commandLabel), throwable); + EssentialsLogger.log(Level.INFO, tl("errorCallingCommand", commandLabel), throwable); throwable.printStackTrace(); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/config/ConfigurationSaveTask.java b/Essentials/src/main/java/com/earth2me/essentials/config/ConfigurationSaveTask.java index 6c9ebc51ca7..a73ba7822d4 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/config/ConfigurationSaveTask.java +++ b/Essentials/src/main/java/com/earth2me/essentials/config/ConfigurationSaveTask.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.config; +import com.earth2me.essentials.EssentialsLogger; import org.spongepowered.configurate.CommentedConfigurationNode; import org.spongepowered.configurate.ConfigurateException; import org.spongepowered.configurate.yaml.YamlConfigurationLoader; @@ -7,8 +8,6 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; -import static com.earth2me.essentials.config.EssentialsConfiguration.LOGGER; - public class ConfigurationSaveTask implements Runnable { private final YamlConfigurationLoader loader; private final CommentedConfigurationNode node; @@ -32,7 +31,7 @@ public void run() { try { loader.save(node); } catch (ConfigurateException e) { - LOGGER.log(Level.SEVERE, e.getMessage(), e); + EssentialsLogger.log(Level.SEVERE, e.getMessage(), e); } finally { pendingWrites.decrementAndGet(); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsConfiguration.java b/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsConfiguration.java index 1e9988a5378..d57ea1edf35 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsConfiguration.java +++ b/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsConfiguration.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.config; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.config.annotations.DeleteIfIncomplete; import com.earth2me.essentials.config.annotations.DeleteOnEmpty; import com.earth2me.essentials.config.entities.CommandCooldown; @@ -44,12 +45,10 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; -import java.util.logging.Logger; import static com.earth2me.essentials.I18n.tl; public class EssentialsConfiguration { - protected static final Logger LOGGER = Logger.getLogger("Essentials"); private static final ExecutorService EXECUTOR_SERVICE = Executors.newSingleThreadExecutor(); private static final ObjectMapper.Factory MAPPER_FACTORY = ObjectMapper.factoryBuilder() .addProcessor(DeleteOnEmpty.class, (data, value) -> new DeleteOnEmptyProcessor()) @@ -133,7 +132,7 @@ public Map getLocationSectionMap(final String path) { try { result.put(entry.getKey().toLowerCase(Locale.ENGLISH), jailNode.get(LazyLocation.class)); } catch (SerializationException e) { - LOGGER.log(Level.WARNING, "Error serializing key " + entry.getKey(), e); + EssentialsLogger.log(Level.WARNING, "Error serializing key " + entry.getKey(), e); } } return result; @@ -147,7 +146,7 @@ public void setExplicitList(final String path, final List list, final Typ try { toSplitRoot(path, configurationNode).set(type, list); } catch (SerializationException e) { - LOGGER.log(Level.SEVERE, e.getMessage(), e); + EssentialsLogger.log(Level.SEVERE, e.getMessage(), e); } } @@ -163,7 +162,7 @@ public List getList(final String path, Class type) { } return list; } catch (SerializationException e) { - LOGGER.log(Level.SEVERE, e.getMessage(), e); + EssentialsLogger.log(Level.SEVERE, e.getMessage(), e); return new ArrayList<>(); } } @@ -301,7 +300,7 @@ public void removeProperty(String path) { try { node.set(null); } catch (SerializationException e) { - LOGGER.log(Level.SEVERE, e.getMessage(), e); + EssentialsLogger.log(Level.SEVERE, e.getMessage(), e); } } } @@ -310,7 +309,7 @@ private void setInternal(final String path, final Object value) { try { toSplitRoot(path, configurationNode).set(value); } catch (SerializationException e) { - LOGGER.log(Level.SEVERE, e.getMessage(), e); + EssentialsLogger.log(Level.SEVERE, e.getMessage(), e); } } @@ -336,13 +335,13 @@ public CommentedConfigurationNode toSplitRoot(String path, final CommentedConfig public synchronized void load() { if (pendingWrites.get() != 0) { - LOGGER.log(Level.INFO, "Parsing config file {0} has been aborted due to {1} current pending write(s).", new Object[]{configFile, pendingWrites.get()}); + EssentialsLogger.log(Level.INFO, "Parsing config file " + configFile + " has been aborted due to " + pendingWrites.get() + " current pending write(s)."); return; } if (configFile.getParentFile() != null && !configFile.getParentFile().exists()) { if (!configFile.getParentFile().mkdirs()) { - LOGGER.log(Level.SEVERE, tl("failedToCreateConfig", configFile.toString())); + EssentialsLogger.log(Level.SEVERE, tl("failedToCreateConfig", configFile.toString())); return; } } @@ -354,10 +353,10 @@ public synchronized void load() { convertAltFile(); } else if (templateName != null) { try (final InputStream is = resourceClass.getResourceAsStream(templateName)) { - LOGGER.log(Level.INFO, tl("creatingConfigFromTemplate", configFile.toString())); + EssentialsLogger.log(Level.INFO, tl("creatingConfigFromTemplate", configFile.toString())); Files.copy(is, configFile.toPath()); } catch (IOException e) { - LOGGER.log(Level.SEVERE, tl("failedToWriteConfig", configFile.toString()), e); + EssentialsLogger.log(Level.SEVERE, tl("failedToWriteConfig", configFile.toString()), e); } } } @@ -367,12 +366,12 @@ public synchronized void load() { } catch (final ParsingException e) { final File broken = new File(configFile.getAbsolutePath() + ".broken." + System.currentTimeMillis()); if (configFile.renameTo(broken)) { - LOGGER.log(Level.SEVERE, "The file " + configFile.toString() + " is broken, it has been renamed to " + broken.toString(), e.getCause()); + EssentialsLogger.log(Level.SEVERE, "The file " + configFile.toString() + " is broken, it has been renamed to " + broken.toString(), e.getCause()); return; } - LOGGER.log(Level.SEVERE, "The file " + configFile.toString() + " is broken. A backup file has failed to be created", e.getCause()); + EssentialsLogger.log(Level.SEVERE, "The file " + configFile.toString() + " is broken. A backup file has failed to be created", e.getCause()); } catch (final ConfigurateException e) { - LOGGER.log(Level.SEVERE, e.getMessage(), e); + EssentialsLogger.log(Level.SEVERE, e.getMessage(), e); } finally { // Something is wrong! We need a node! I hope the backup worked! if (configurationNode == null) { @@ -435,7 +434,7 @@ public synchronized void blockingSave() { try { delaySave().get(); } catch (final InterruptedException | ExecutionException e) { - LOGGER.log(Level.SEVERE, e.getMessage(), e); + EssentialsLogger.log(Level.SEVERE, e.getMessage(), e); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsUserConfiguration.java b/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsUserConfiguration.java index 798b4da3720..45190bc299e 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsUserConfiguration.java +++ b/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsUserConfiguration.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.config; +import com.earth2me.essentials.EssentialsLogger; import com.google.common.base.Charsets; import com.google.common.io.Files; @@ -43,7 +44,7 @@ public void convertLegacyFile() { //noinspection UnstableApiUsage Files.move(file, new File(configFile.getParentFile(), uuid + ".yml")); } catch (final IOException ex) { - LOGGER.log(Level.WARNING, "Failed to migrate user: " + username, ex); + EssentialsLogger.log(Level.WARNING, "Failed to migrate user: " + username, ex); } setProperty("last-account-name", username); @@ -68,7 +69,7 @@ public void convertAltFile() { //noinspection UnstableApiUsage Files.move(getAltFile(), new File(configFile.getParentFile(), uuid + ".yml")); } catch (final IOException ex) { - LOGGER.log(Level.WARNING, "Failed to migrate user: " + username, ex); + EssentialsLogger.log(Level.WARNING, "Failed to migrate user: " + username, ex); } } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/economy/EconomyLayers.java b/Essentials/src/main/java/com/earth2me/essentials/economy/EconomyLayers.java index a4184e5588a..17f1704fa73 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/economy/EconomyLayers.java +++ b/Essentials/src/main/java/com/earth2me/essentials/economy/EconomyLayers.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.economy; import com.earth2me.essentials.Essentials; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.economy.layers.VaultLayer; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; @@ -40,7 +41,7 @@ public static void onEnable(final Essentials ess) { } final EconomyLayer layer = onPluginEnable(plugin); if (layer != null) { - ess.getLogger().log(Level.INFO, "Essentials found a compatible payment resolution method: " + layer.getName() + " (v" + layer.getPluginVersion() + ")!"); + EssentialsLogger.log(Level.INFO, "Essentials found a compatible payment resolution method: " + layer.getName() + " (v" + layer.getPluginVersion() + ")!"); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/economy/vault/VaultEconomyProvider.java b/Essentials/src/main/java/com/earth2me/essentials/economy/vault/VaultEconomyProvider.java index 4ba9e66ca16..92676c7fc10 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/economy/vault/VaultEconomyProvider.java +++ b/Essentials/src/main/java/com/earth2me/essentials/economy/vault/VaultEconomyProvider.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.economy.vault; import com.earth2me.essentials.Essentials; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.api.NoLoanPermittedException; import com.earth2me.essentials.api.UserDoesNotExistException; import com.earth2me.essentials.config.EssentialsUserConfiguration; @@ -19,7 +20,6 @@ import java.util.List; import java.util.UUID; import java.util.logging.Level; -import java.util.logging.Logger; /** * A goddamn Vault adapter, what more do you want? @@ -29,7 +29,6 @@ * {@link com.earth2me.essentials.User}. */ public class VaultEconomyProvider implements Economy { - private static final Logger LOGGER = Logger.getLogger("Essentials"); private static final String WARN_NPC_RECREATE_1 = "Account creation was requested for NPC user {0}, but an account file with UUID {1} already exists."; private static final String WARN_NPC_RECREATE_2 = "Essentials will create a new account as requested by the other plugin, but this is almost certainly a bug and should be reported."; @@ -301,8 +300,8 @@ public boolean createPlayerAccount(OfflinePlayer player) { } final File npcFile = new File(folder, player.getUniqueId() + ".yml"); if (npcFile.exists()) { - LOGGER.log(Level.SEVERE, MessageFormat.format(WARN_NPC_RECREATE_1, player.getName(), player.getUniqueId().toString()), new RuntimeException()); - LOGGER.log(Level.SEVERE, WARN_NPC_RECREATE_2); + EssentialsLogger.log(Level.SEVERE, MessageFormat.format(WARN_NPC_RECREATE_1, player.getName(), player.getUniqueId().toString()), new RuntimeException()); + EssentialsLogger.log(Level.SEVERE, WARN_NPC_RECREATE_2); } final EssentialsUserConfiguration npcConfig = new EssentialsUserConfiguration(player.getName(), player.getUniqueId(), npcFile); npcConfig.load(); @@ -317,7 +316,7 @@ public boolean createPlayerAccount(OfflinePlayer player) { // Loading a v4 UUID that we somehow didn't track, mark it as a normal player and hope for the best, vault sucks :/ try { if (ess.getSettings().isDebug()) { - LOGGER.info("Vault requested a player account creation for a v4 UUID: " + player); + EssentialsLogger.info("Vault requested a player account creation for a v4 UUID: " + player); } ess.getUserMap().load(player); return true; diff --git a/Essentials/src/main/java/com/earth2me/essentials/items/AbstractItemDb.java b/Essentials/src/main/java/com/earth2me/essentials/items/AbstractItemDb.java index 4feb311c180..735fd499f7a 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/items/AbstractItemDb.java +++ b/Essentials/src/main/java/com/earth2me/essentials/items/AbstractItemDb.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.items; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.IConf; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.FormatUtil; @@ -105,7 +106,7 @@ public ItemStack get(final String id) throws Exception { ItemStack tryResolverDeserialize(final String id) { for (final PluginKey key : resolverMap.keySet()) { if (ess.getSettings().isDebug()) { - ess.getLogger().info(String.format("Trying to deserialize item '%s' with resolver '%s'...", id, key)); + EssentialsLogger.info(String.format("Trying to deserialize item '%s' with resolver '%s'...", id, key)); } final Function resolver = resolverMap.get(key); @@ -122,7 +123,7 @@ ItemStack tryResolverDeserialize(final String id) { String tryResolverSerialize(final ItemStack stack) { for (final PluginKey key : resolverMap.keySet()) { if (ess.getSettings().isDebug()) { - ess.getLogger().info(String.format("Trying to serialize '%s' with resolver '%s'...", stack.toString(), key)); + EssentialsLogger.info(String.format("Trying to serialize '%s' with resolver '%s'...", stack.toString(), key)); } final ItemResolver resolver = resolverMap.get(key); diff --git a/Essentials/src/main/java/com/earth2me/essentials/items/CustomItemResolver.java b/Essentials/src/main/java/com/earth2me/essentials/items/CustomItemResolver.java index 3e575427674..115c03be1aa 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/items/CustomItemResolver.java +++ b/Essentials/src/main/java/com/earth2me/essentials/items/CustomItemResolver.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.items; import com.earth2me.essentials.Essentials; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.IConf; import com.earth2me.essentials.config.ConfigurateUtil; import com.earth2me.essentials.config.EssentialsConfiguration; @@ -61,7 +62,7 @@ public void reloadConfig() { final Map section = ConfigurateUtil.getRawMap(config.getSection("aliases")); if (section.isEmpty()) { - ess.getLogger().warning("No aliases found in custom_items.yml."); + EssentialsLogger.warning("No aliases found in custom_items.yml."); return; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/items/FlatItemDb.java b/Essentials/src/main/java/com/earth2me/essentials/items/FlatItemDb.java index feba4deade5..8a95214f5c4 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/items/FlatItemDb.java +++ b/Essentials/src/main/java/com/earth2me/essentials/items/FlatItemDb.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.items; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.ManagedFile; import com.earth2me.essentials.utils.EnumUtil; import com.earth2me.essentials.utils.MaterialUtil; @@ -23,13 +24,11 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.logging.Logger; import java.util.stream.Collectors; import static com.earth2me.essentials.I18n.tl; public class FlatItemDb extends AbstractItemDb { - protected static final Logger LOGGER = Logger.getLogger("Essentials"); private static final Gson gson = new Gson(); // Maps primary name to ItemData @@ -54,7 +53,7 @@ public void reloadConfig() { } this.rebuild(); - LOGGER.info(String.format("Loaded %s items from items.json.", listNames().size())); + EssentialsLogger.info(String.format("Loaded %s items from items.json.", listNames().size())); } private void rebuild() { @@ -100,7 +99,7 @@ private void loadJSON(final String source) { if (valid) { allAliases.add(key); } else { - LOGGER.warning(String.format("Failed to add item: \"%s\": %s", key, element.toString())); + EssentialsLogger.warning(String.format("Failed to add item: \"%s\": %s", key, element.toString())); } } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/items/LegacyItemDb.java b/Essentials/src/main/java/com/earth2me/essentials/items/LegacyItemDb.java index e0de483b3ba..17eb05c191a 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/items/LegacyItemDb.java +++ b/Essentials/src/main/java/com/earth2me/essentials/items/LegacyItemDb.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.items; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.ManagedFile; import com.earth2me.essentials.utils.EnumUtil; import com.earth2me.essentials.utils.NumberUtil; @@ -17,14 +18,12 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; import static com.earth2me.essentials.I18n.tl; public class LegacyItemDb extends AbstractItemDb { - protected static final Logger LOGGER = Logger.getLogger("Essentials"); private final transient Map items = new HashMap<>(); private final transient Map> names = new HashMap<>(); private final transient Map primaryName = new HashMap<>(); @@ -119,7 +118,7 @@ public void reloadConfig() { nameList.sort(LengthCompare.INSTANCE); } - LOGGER.info(String.format("Loaded %s items from items.csv.", listNames().size())); + EssentialsLogger.info(String.format("Loaded %s items from items.csv.", listNames().size())); ready = true; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/perm/PermissionsHandler.java b/Essentials/src/main/java/com/earth2me/essentials/perm/PermissionsHandler.java index 722c55a9a05..1a78ee701cf 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/perm/PermissionsHandler.java +++ b/Essentials/src/main/java/com/earth2me/essentials/perm/PermissionsHandler.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.perm; import com.earth2me.essentials.Essentials; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.User; import com.earth2me.essentials.perm.impl.AbstractVaultHandler; import com.earth2me.essentials.perm.impl.ConfigPermissionsHandler; @@ -169,18 +170,18 @@ public void checkPermissions() { if (handler instanceof AbstractVaultHandler) { String enabledPermsPlugin = ((AbstractVaultHandler) handler).getEnabledPermsPlugin(); if (enabledPermsPlugin == null) enabledPermsPlugin = "generic"; - ess.getLogger().info("Using Vault based permissions (" + enabledPermsPlugin + ")"); + EssentialsLogger.info("Using Vault based permissions (" + enabledPermsPlugin + ")"); } else if (handler.getClass() == SuperpermsHandler.class) { if (handler.tryProvider(ess)) { - ess.getLogger().warning("Detected supported permissions plugin " + + EssentialsLogger.warning("Detected supported permissions plugin " + ((SuperpermsHandler) handler).getEnabledPermsPlugin() + " without Vault installed."); - ess.getLogger().warning("Features such as chat prefixes/suffixes and group-related functionality will not " + + EssentialsLogger.warning("Features such as chat prefixes/suffixes and group-related functionality will not " + "work until you install Vault."); } - ess.getLogger().info("Using superperms-based permissions."); + EssentialsLogger.info("Using superperms-based permissions."); } else if (handler.getClass() == ConfigPermissionsHandler.class) { - ess.getLogger().info("Using config file enhanced permissions."); - ess.getLogger().info("Permissions listed in as player-commands will be given to all users."); + EssentialsLogger.info("Using config file enhanced permissions."); + EssentialsLogger.info("Permissions listed in as player-commands will be given to all users."); } } @@ -195,7 +196,7 @@ public String getName() { private void checkPermLag(final long start, final String summary) { final long elapsed = System.nanoTime() - start; if (elapsed > ess.getSettings().getPermissionsLagWarning()) { - ess.getLogger().log(Level.WARNING, String.format("Permissions lag notice with (%s). Response took %fms. Summary: %s", getName(), elapsed / 1000000.0, summary)); + EssentialsLogger.log(Level.WARNING, String.format("Permissions lag notice with (%s). Response took %fms. Summary: %s", getName(), elapsed / 1000000.0, summary)); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/signs/EssentialsSign.java b/Essentials/src/main/java/com/earth2me/essentials/signs/EssentialsSign.java index cb0aaaf96b2..6c0892a74e3 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/signs/EssentialsSign.java +++ b/Essentials/src/main/java/com/earth2me/essentials/signs/EssentialsSign.java @@ -2,6 +2,7 @@ import com.earth2me.essentials.ChargeException; import com.earth2me.essentials.CommandSource; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.MetaItemStack; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; @@ -107,7 +108,7 @@ protected final boolean onSignCreate(final SignChangeEvent event, final IEssenti ess.getServer().getPluginManager().callEvent(signEvent); if (signEvent.isCancelled()) { if (ess.getSettings().isDebug()) { - ess.getLogger().info("SignCreateEvent cancelled for sign " + signEvent.getEssentialsSign().getName()); + EssentialsLogger.info("SignCreateEvent cancelled for sign " + signEvent.getEssentialsSign().getName()); } return false; } @@ -129,7 +130,7 @@ protected final boolean onSignCreate(final SignChangeEvent event, final IEssenti public String getSuccessName(final IEssentials ess) { final String successName = getSuccessName(); if (successName == null) { - ess.getLogger().severe("signFormatSuccess message must use the {0} argument."); + EssentialsLogger.severe("signFormatSuccess message must use the {0} argument."); } return successName; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/signs/SignBlockListener.java b/Essentials/src/main/java/com/earth2me/essentials/signs/SignBlockListener.java index eba8079a7a9..c11fa5d21ed 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/signs/SignBlockListener.java +++ b/Essentials/src/main/java/com/earth2me/essentials/signs/SignBlockListener.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.signs; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.I18n; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.FormatUtil; @@ -23,10 +24,8 @@ import org.bukkit.event.block.SignChangeEvent; import java.util.logging.Level; -import java.util.logging.Logger; public class SignBlockListener implements Listener { - private static final Logger LOGGER = Logger.getLogger("Essentials"); private final transient IEssentials ess; public SignBlockListener(final IEssentials ess) { @@ -52,7 +51,7 @@ public boolean protectSignsAndBlocks(final Block block, final Player player) thr // prevent any signs be broken by destroying the block they are attached to if (EssentialsSign.checkIfBlockBreaksSigns(block)) { if (ess.getSettings().isDebug()) { - LOGGER.log(Level.INFO, "Prevented that a block was broken next to a sign."); + EssentialsLogger.log(Level.INFO, "Prevented that a block was broken next to a sign."); } return true; } @@ -70,7 +69,7 @@ public boolean protectSignsAndBlocks(final Block block, final Player player) thr for (final EssentialsSign sign : ess.getSettings().enabledSigns()) { if (sign.areHeavyEventRequired() && sign.getBlocks().contains(block.getType()) && !sign.onBlockBreak(block, player, ess)) { - LOGGER.log(Level.INFO, "A block was protected by a sign."); + EssentialsLogger.log(Level.INFO, "A block was protected by a sign."); return true; } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/signs/SignPlayerListener.java b/Essentials/src/main/java/com/earth2me/essentials/signs/SignPlayerListener.java index ff2638c7d3f..2c5eccea7ff 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/signs/SignPlayerListener.java +++ b/Essentials/src/main/java/com/earth2me/essentials/signs/SignPlayerListener.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.signs; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.utils.MaterialUtil; import net.ess3.api.IEssentials; import org.bukkit.Material; @@ -40,7 +41,7 @@ public void onSignPlayerInteract(final PlayerInteractEvent event) { targetBlock = ess.getUser(event.getPlayer()).getTargetBlock(5); } catch (final IllegalStateException ex) { if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.WARNING, ex.getMessage(), ex); + EssentialsLogger.log(Level.WARNING, ex.getMessage(), ex); } } block = targetBlock; diff --git a/Essentials/src/main/java/com/earth2me/essentials/textreader/BookInput.java b/Essentials/src/main/java/com/earth2me/essentials/textreader/BookInput.java index 1826f77f4c1..ad1b04e0424 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/textreader/BookInput.java +++ b/Essentials/src/main/java/com/earth2me/essentials/textreader/BookInput.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.textreader; +import com.earth2me.essentials.EssentialsLogger; import net.ess3.api.IEssentials; import java.io.BufferedReader; @@ -44,7 +45,7 @@ public BookInput(final String filename, final boolean createFile, final IEssenti length = input.read(buffer); } } - ess.getLogger().info("File " + filename + ".txt does not exist. Creating one for you."); + EssentialsLogger.info("File " + filename + ".txt does not exist. Creating one for you."); } } if (!file.exists()) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/textreader/HelpInput.java b/Essentials/src/main/java/com/earth2me/essentials/textreader/HelpInput.java index dd3442c80b9..12041e9b5e9 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/textreader/HelpInput.java +++ b/Essentials/src/main/java/com/earth2me/essentials/textreader/HelpInput.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.textreader; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.User; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; @@ -15,12 +16,10 @@ import java.util.Locale; import java.util.Map; import java.util.logging.Level; -import java.util.logging.Logger; import static com.earth2me.essentials.I18n.tl; public class HelpInput implements IText { - private static final Logger logger = Logger.getLogger("Essentials"); private final transient List lines = new ArrayList<>(); private final transient List chapters = new ArrayList<>(); private final transient Map bookmarks = new HashMap<>(); @@ -121,7 +120,7 @@ public HelpInput(final User user, final String match, final IEssentials ess) { } catch (final NullPointerException ignored) { } catch (final Exception ex) { if (!reported) { - logger.log(Level.WARNING, tl("commandHelpFailedForPlugin", pluginNameLow), ex); + EssentialsLogger.log(Level.WARNING, tl("commandHelpFailedForPlugin", pluginNameLow), ex); } reported = true; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/textreader/KeywordReplacer.java b/Essentials/src/main/java/com/earth2me/essentials/textreader/KeywordReplacer.java index 3bc099e0812..f7160087af1 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/textreader/KeywordReplacer.java +++ b/Essentials/src/main/java/com/earth2me/essentials/textreader/KeywordReplacer.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.textreader; import com.earth2me.essentials.CommandSource; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.ExecuteTimer; import com.earth2me.essentials.PlayerList; import com.earth2me.essentials.User; @@ -154,7 +155,7 @@ private void replaceKeywords(final CommandSource sender) { execTimer.mark("Text Replace"); final String timeroutput = execTimer.end(); if (ess.getSettings().isDebug()) { - ess.getLogger().log(Level.INFO, "Keyword Replacer " + timeroutput); + EssentialsLogger.log(Level.INFO, "Keyword Replacer " + timeroutput); } } diff --git a/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java b/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java index 07f47153a27..e11072ab7d2 100644 --- a/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java +++ b/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java @@ -1,8 +1,10 @@ package com.earth2me.essentials.antibuild; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.VersionUtil; import net.ess3.api.IEssentials; +import net.ess3.provider.LoggerProvider; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.ArmorStand; @@ -33,12 +35,11 @@ import org.bukkit.inventory.ItemStack; import java.util.logging.Level; -import java.util.logging.Logger; import static com.earth2me.essentials.I18n.tl; public class EssentialsAntiBuildListener implements Listener { - private static final Logger logger = Logger.getLogger("EssentialsAntiBuild"); + private final static LoggerProvider logger = EssentialsLogger.getLoggerProvider("EssentialsAntiBuild"); final private transient IAntiBuild prot; final private transient IEssentials ess; diff --git a/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsConnect.java b/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsConnect.java index c6fa26c41b9..10c9825eebc 100644 --- a/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsConnect.java +++ b/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsConnect.java @@ -1,19 +1,20 @@ package com.earth2me.essentials.antibuild; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.IConf; import com.earth2me.essentials.User; import net.ess3.api.IEssentials; +import net.ess3.provider.LoggerProvider; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; import java.util.logging.Level; -import java.util.logging.Logger; import static com.earth2me.essentials.I18n.tl; class EssentialsConnect { - private static final Logger logger = Logger.getLogger("EssentialsAntiBuild"); + private final static LoggerProvider logger = EssentialsLogger.getLoggerProvider("EssentialsAntiBuild"); private final transient IEssentials ess; private final transient IAntiBuild protect; diff --git a/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChat.java b/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChat.java index 374f407499a..8e5a9790c66 100644 --- a/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChat.java +++ b/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChat.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.chat; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.metrics.MetricsWrapper; import net.ess3.api.IEssentials; import org.bukkit.command.Command; @@ -24,7 +25,7 @@ public void onEnable() { final PluginManager pluginManager = getServer().getPluginManager(); ess = (IEssentials) pluginManager.getPlugin("Essentials"); if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) { - getLogger().log(Level.WARNING, tl("versionMismatchAll")); + EssentialsLogger.getLoggerProvider("EssentialsChat").log(Level.WARNING, tl("versionMismatchAll")); } if (!ess.isEnabled()) { this.setEnabled(false); diff --git a/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayer.java b/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayer.java index 32988091a01..80e35e9528b 100644 --- a/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayer.java +++ b/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayer.java @@ -1,18 +1,19 @@ package com.earth2me.essentials.chat; import com.earth2me.essentials.ChargeException; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; import net.ess3.api.IEssentials; +import net.ess3.provider.LoggerProvider; import org.bukkit.Server; import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerChatEvent; import java.util.Map; -import java.util.logging.Logger; public abstract class EssentialsChatPlayer implements Listener { - static final Logger logger = Logger.getLogger("EssentialsChat"); + static final LoggerProvider logger = EssentialsLogger.getLoggerProvider("EssentialsChat"); final transient IEssentials ess; final transient Server server; private final transient Map chatStorage; diff --git a/EssentialsDiscord/src/main/java/net/essentialsx/discord/DiscordSettings.java b/EssentialsDiscord/src/main/java/net/essentialsx/discord/DiscordSettings.java index 81a91907dc4..9c321eb68b9 100644 --- a/EssentialsDiscord/src/main/java/net/essentialsx/discord/DiscordSettings.java +++ b/EssentialsDiscord/src/main/java/net/essentialsx/discord/DiscordSettings.java @@ -20,6 +20,7 @@ import java.util.regex.PatternSyntaxException; import static com.earth2me.essentials.I18n.tl; +import static net.essentialsx.discord.EssentialsDiscord.LOGGER; public class DiscordSettings implements IConf { private final EssentialsConfiguration config; @@ -359,7 +360,7 @@ private MessageFormat generateMessageFormat(String content, String defaultStr, b @Override public void reloadConfig() { if (plugin.isInvalidStartup()) { - plugin.getLogger().warning(tl("discordReloadInvalid")); + LOGGER.warning(tl("discordReloadInvalid")); return; } @@ -405,7 +406,7 @@ public void reloadConfig() { try { filters.add(Pattern.compile(chatFilterString)); } catch (PatternSyntaxException e) { - plugin.getLogger().log(java.util.logging.Level.WARNING, "Invalid pattern for \"chat.discord-filter\": " + e.getMessage()); + LOGGER.log(java.util.logging.Level.WARNING, "Invalid pattern for \"chat.discord-filter\": " + e.getMessage()); } } } @@ -419,7 +420,7 @@ public void reloadConfig() { discordFilter = Collections.emptyList(); } } catch (PatternSyntaxException e) { - plugin.getLogger().log(java.util.logging.Level.WARNING, "Invalid pattern for \"chat.discord-filter\": " + e.getMessage()); + LOGGER.log(java.util.logging.Level.WARNING, "Invalid pattern for \"chat.discord-filter\": " + e.getMessage()); discordFilter = Collections.emptyList(); } } @@ -433,7 +434,7 @@ public void reloadConfig() { try { filters.add(Pattern.compile(filterString)); } catch (PatternSyntaxException e) { - plugin.getLogger().log(java.util.logging.Level.WARNING, "Invalid pattern for \"console.log-level\": " + e.getMessage()); + LOGGER.log(java.util.logging.Level.WARNING, "Invalid pattern for \"console.log-level\": " + e.getMessage()); } } } @@ -447,7 +448,7 @@ public void reloadConfig() { consoleFilter = Collections.emptyList(); } } catch (PatternSyntaxException e) { - plugin.getLogger().log(java.util.logging.Level.WARNING, "Invalid pattern for \"console.log-level\": " + e.getMessage()); + LOGGER.log(java.util.logging.Level.WARNING, "Invalid pattern for \"console.log-level\": " + e.getMessage()); consoleFilter = Collections.emptyList(); } } diff --git a/EssentialsDiscord/src/main/java/net/essentialsx/discord/EssentialsDiscord.java b/EssentialsDiscord/src/main/java/net/essentialsx/discord/EssentialsDiscord.java index fcc24e099ca..4e7e49d11bb 100644 --- a/EssentialsDiscord/src/main/java/net/essentialsx/discord/EssentialsDiscord.java +++ b/EssentialsDiscord/src/main/java/net/essentialsx/discord/EssentialsDiscord.java @@ -1,8 +1,10 @@ package net.essentialsx.discord; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.IEssentialsModule; import com.earth2me.essentials.metrics.MetricsWrapper; +import net.ess3.provider.LoggerProvider; import net.essentialsx.discord.interactions.InteractionControllerImpl; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -12,12 +14,11 @@ import java.util.List; import java.util.logging.Level; -import java.util.logging.Logger; import static com.earth2me.essentials.I18n.tl; public class EssentialsDiscord extends JavaPlugin implements IEssentialsModule { - private final static Logger logger = Logger.getLogger("EssentialsDiscord"); + protected final static LoggerProvider LOGGER = EssentialsLogger.getLoggerProvider("EssentialsDiscord"); private transient IEssentials ess; private transient MetricsWrapper metrics = null; @@ -33,13 +34,13 @@ public void onEnable() { return; } if (!getDescription().getVersion().equals(ess.getDescription().getVersion())) { - getLogger().log(Level.WARNING, tl("versionMismatchAll")); + LOGGER.log(Level.WARNING, tl("versionMismatchAll")); } // JDK-8274349 - Mitigation for a regression in Java 17 on 1 core systems which was fixed in 17.0.2 final String[] javaVersion = System.getProperty("java.version").split("\\."); if (Runtime.getRuntime().availableProcessors() <= 1 && javaVersion[0].startsWith("17") && (javaVersion.length < 2 || (javaVersion[1].equals("0") && javaVersion[2].startsWith("1")))) { - logger.log(Level.INFO, "Essentials is mitigating JDK-8274349"); + LOGGER.log(Level.INFO, "Essentials is mitigating JDK-8274349"); System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "1"); } @@ -58,7 +59,7 @@ public void onEnable() { jda.startup(); ess.scheduleSyncDelayedTask(() -> ((InteractionControllerImpl) jda.getInteractionController()).processBatchRegistration()); } catch (Exception e) { - logger.log(Level.SEVERE, tl("discordErrorLogin", e.getMessage())); + LOGGER.log(Level.SEVERE, tl("discordErrorLogin", e.getMessage())); if (ess.getSettings().isDebug()) { e.printStackTrace(); } diff --git a/EssentialsDiscord/src/main/java/net/essentialsx/discord/JDADiscordService.java b/EssentialsDiscord/src/main/java/net/essentialsx/discord/JDADiscordService.java index 5a0dfe87d57..dc5b001f04e 100644 --- a/EssentialsDiscord/src/main/java/net/essentialsx/discord/JDADiscordService.java +++ b/EssentialsDiscord/src/main/java/net/essentialsx/discord/JDADiscordService.java @@ -4,6 +4,7 @@ import club.minnced.discord.webhook.WebhookClientBuilder; import club.minnced.discord.webhook.send.WebhookMessage; import club.minnced.discord.webhook.send.WebhookMessageBuilder; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.IEssentialsModule; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.FormatUtil; @@ -21,6 +22,7 @@ import net.dv8tion.jda.api.utils.cache.CacheFlag; import net.ess3.nms.refl.providers.AchievementListenerProvider; import net.ess3.nms.refl.providers.AdvancementListenerProvider; +import net.ess3.provider.LoggerProvider; import net.ess3.provider.providers.PaperAdvancementListenerProvider; import net.essentialsx.api.v2.events.discord.DiscordMessageEvent; import net.essentialsx.api.v2.services.discord.DiscordService; @@ -54,14 +56,13 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; import static com.earth2me.essentials.I18n.tl; public class JDADiscordService implements DiscordService, IEssentialsModule { - private final static Logger logger = Logger.getLogger("EssentialsDiscord"); + private final static LoggerProvider logger = EssentialsLogger.getLoggerProvider("EssentialsDiscord"); private final EssentialsDiscord plugin; private final Unsafe unsafe = this::getJda; diff --git a/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionControllerImpl.java b/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionControllerImpl.java index c5c9150bc31..42ba5fade1f 100644 --- a/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionControllerImpl.java +++ b/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionControllerImpl.java @@ -1,5 +1,6 @@ package net.essentialsx.discord.interactions; +import com.earth2me.essentials.EssentialsLogger; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.exceptions.ErrorResponseException; import net.dv8tion.jda.api.hooks.ListenerAdapter; @@ -7,6 +8,7 @@ import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.requests.ErrorResponse; +import net.ess3.provider.LoggerProvider; import net.essentialsx.api.v2.services.discord.InteractionCommand; import net.essentialsx.api.v2.services.discord.InteractionCommandArgument; import net.essentialsx.api.v2.services.discord.InteractionController; @@ -22,12 +24,11 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; -import java.util.logging.Logger; import static com.earth2me.essentials.I18n.tl; public class InteractionControllerImpl extends ListenerAdapter implements InteractionController { - private final static Logger logger = Logger.getLogger("EssentialsDiscord"); + private final static LoggerProvider logger = EssentialsLogger.getLoggerProvider("EssentialsDiscord"); private final JDADiscordService jda; diff --git a/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionEventImpl.java b/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionEventImpl.java index 37c6dfd405a..e9e0e425886 100644 --- a/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionEventImpl.java +++ b/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionEventImpl.java @@ -1,11 +1,13 @@ package net.essentialsx.discord.interactions; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.utils.FormatUtil; import com.google.common.base.Joiner; import net.dv8tion.jda.api.MessageBuilder; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.interactions.commands.OptionMapping; +import net.ess3.provider.LoggerProvider; import net.essentialsx.api.v2.services.discord.InteractionChannel; import net.essentialsx.api.v2.services.discord.InteractionEvent; import net.essentialsx.api.v2.services.discord.InteractionMember; @@ -14,13 +16,12 @@ import java.util.ArrayList; import java.util.List; import java.util.logging.Level; -import java.util.logging.Logger; /** * A class which provides information about what triggered an interaction event. */ public class InteractionEventImpl implements InteractionEvent { - private final static Logger logger = Logger.getLogger("EssentialsDiscord"); + private final static LoggerProvider logger = EssentialsLogger.getLoggerProvider("EssentialsDiscord"); private final SlashCommandEvent event; private final InteractionMember member; private final List replyBuffer = new ArrayList<>(); diff --git a/EssentialsDiscord/src/main/java/net/essentialsx/discord/listeners/DiscordListener.java b/EssentialsDiscord/src/main/java/net/essentialsx/discord/listeners/DiscordListener.java index 616888c66ed..de07fea8e98 100644 --- a/EssentialsDiscord/src/main/java/net/essentialsx/discord/listeners/DiscordListener.java +++ b/EssentialsDiscord/src/main/java/net/essentialsx/discord/listeners/DiscordListener.java @@ -1,5 +1,6 @@ package net.essentialsx.discord.listeners; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.utils.FormatUtil; import com.vdurmont.emoji.EmojiParser; import net.dv8tion.jda.api.entities.Member; @@ -8,6 +9,7 @@ import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.ess3.api.IUser; +import net.ess3.provider.LoggerProvider; import net.essentialsx.api.v2.events.discord.DiscordRelayEvent; import net.essentialsx.discord.JDADiscordService; import net.essentialsx.discord.interactions.InteractionChannelImpl; @@ -21,11 +23,10 @@ import java.util.Collections; import java.util.List; import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Pattern; public class DiscordListener extends ListenerAdapter { - private final static Logger logger = Logger.getLogger("EssentialsDiscord"); + private final static LoggerProvider logger = EssentialsLogger.getLoggerProvider("EssentialsDiscord"); private final JDADiscordService plugin; diff --git a/EssentialsDiscord/src/main/java/net/essentialsx/discord/util/ConsoleInjector.java b/EssentialsDiscord/src/main/java/net/essentialsx/discord/util/ConsoleInjector.java index e6ce349c8b3..611a57d5ed2 100644 --- a/EssentialsDiscord/src/main/java/net/essentialsx/discord/util/ConsoleInjector.java +++ b/EssentialsDiscord/src/main/java/net/essentialsx/discord/util/ConsoleInjector.java @@ -1,9 +1,11 @@ package net.essentialsx.discord.util; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.utils.FormatUtil; import com.google.common.base.Splitter; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.utils.TimeFormat; +import net.ess3.provider.LoggerProvider; import net.essentialsx.discord.JDADiscordService; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.core.LogEvent; @@ -21,7 +23,7 @@ @Plugin(name = "EssentialsX-ConsoleInjector", category = "Core", elementType = "appender", printObject = true) public class ConsoleInjector extends AbstractAppender { - private final static java.util.logging.Logger logger = java.util.logging.Logger.getLogger("EssentialsDiscord"); + private final static LoggerProvider logger = EssentialsLogger.getLoggerProvider("EssentialsDiscord"); private final JDADiscordService jda; private final BlockingQueue messageQueue = new LinkedBlockingQueue<>(); diff --git a/EssentialsGeoIP/src/main/java/com/earth2me/essentials/geoip/EssentialsGeoIP.java b/EssentialsGeoIP/src/main/java/com/earth2me/essentials/geoip/EssentialsGeoIP.java index 8cf58ebb1ed..b09e0539b18 100644 --- a/EssentialsGeoIP/src/main/java/com/earth2me/essentials/geoip/EssentialsGeoIP.java +++ b/EssentialsGeoIP/src/main/java/com/earth2me/essentials/geoip/EssentialsGeoIP.java @@ -1,16 +1,18 @@ package com.earth2me.essentials.geoip; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.metrics.MetricsWrapper; import net.ess3.api.IEssentials; +import net.ess3.provider.LoggerProvider; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import java.util.logging.Level; -import java.util.logging.Logger; import static com.earth2me.essentials.I18n.tl; public class EssentialsGeoIP extends JavaPlugin { + private final static LoggerProvider logger = EssentialsLogger.getLoggerProvider("EssentialsGeoIP"); private transient MetricsWrapper metrics = null; @@ -19,19 +21,17 @@ public void onEnable() { final PluginManager pm = getServer().getPluginManager(); final IEssentials ess = (IEssentials) pm.getPlugin("Essentials"); if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) { - getLogger().log(Level.WARNING, tl("versionMismatchAll")); + logger.log(Level.WARNING, tl("versionMismatchAll")); } if (!ess.isEnabled()) { this.setEnabled(false); return; } - Logger.getLogger(com.fasterxml.jackson.databind.ext.Java7Support.class.getName()).setLevel(Level.SEVERE); - final EssentialsGeoIPPlayerListener playerListener = new EssentialsGeoIPPlayerListener(getDataFolder(), ess); pm.registerEvents(playerListener, this); - getLogger().log(Level.INFO, "This product includes GeoLite2 data created by MaxMind, available from http://www.maxmind.com/."); + logger.log(Level.INFO, "This product includes GeoLite2 data created by MaxMind, available from http://www.maxmind.com/."); if (metrics == null) { metrics = new MetricsWrapper(this, 3815, false); diff --git a/EssentialsGeoIP/src/main/java/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java b/EssentialsGeoIP/src/main/java/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java index 9bdbc30bdc5..140fa6b5250 100644 --- a/EssentialsGeoIP/src/main/java/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java +++ b/EssentialsGeoIP/src/main/java/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.geoip; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.IConf; import com.earth2me.essentials.User; import com.earth2me.essentials.config.EssentialsConfiguration; @@ -11,6 +12,7 @@ import com.maxmind.geoip2.model.CityResponse; import com.maxmind.geoip2.model.CountryResponse; import net.ess3.api.IEssentials; +import net.ess3.provider.LoggerProvider; import net.essentialsx.api.v2.events.AsyncUserDataLoadEvent; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -31,13 +33,12 @@ import java.util.Arrays; import java.util.Date; import java.util.logging.Level; -import java.util.logging.Logger; import java.util.zip.GZIPInputStream; import static com.earth2me.essentials.I18n.tl; public class EssentialsGeoIPPlayerListener implements Listener, IConf { - private static final Logger logger = Logger.getLogger("EssentialsGeoIP"); + private static final LoggerProvider logger = EssentialsLogger.getLoggerProvider("EssentialsGeoIP"); private final File dataFolder; private final EssentialsConfiguration config; private final transient IEssentials ess; diff --git a/EssentialsProtect/src/main/java/com/earth2me/essentials/protect/EssentialsConnect.java b/EssentialsProtect/src/main/java/com/earth2me/essentials/protect/EssentialsConnect.java index 42bb5a0b4f8..4d0657818c9 100644 --- a/EssentialsProtect/src/main/java/com/earth2me/essentials/protect/EssentialsConnect.java +++ b/EssentialsProtect/src/main/java/com/earth2me/essentials/protect/EssentialsConnect.java @@ -1,16 +1,17 @@ package com.earth2me.essentials.protect; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.IConf; import net.ess3.api.IEssentials; +import net.ess3.provider.LoggerProvider; import org.bukkit.plugin.Plugin; import java.util.logging.Level; -import java.util.logging.Logger; import static com.earth2me.essentials.I18n.tl; class EssentialsConnect { - private static final Logger logger = Logger.getLogger("EssentialsProtect"); + private static final LoggerProvider logger = EssentialsLogger.getLoggerProvider("EssentialsProtect"); private final IEssentials ess; private final IProtect protect; diff --git a/EssentialsProtect/src/main/java/com/earth2me/essentials/protect/EssentialsProtect.java b/EssentialsProtect/src/main/java/com/earth2me/essentials/protect/EssentialsProtect.java index ff673dde2e3..afff2f84392 100644 --- a/EssentialsProtect/src/main/java/com/earth2me/essentials/protect/EssentialsProtect.java +++ b/EssentialsProtect/src/main/java/com/earth2me/essentials/protect/EssentialsProtect.java @@ -1,7 +1,9 @@ package com.earth2me.essentials.protect; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.metrics.MetricsWrapper; import com.earth2me.essentials.utils.VersionUtil; +import net.ess3.provider.LoggerProvider; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; @@ -15,6 +17,7 @@ import java.util.logging.Level; public class EssentialsProtect extends JavaPlugin implements IProtect { + private final static LoggerProvider LOGGER = EssentialsLogger.getLoggerProvider("EssentialsProtect"); private final Map settingsBoolean = new EnumMap<>(ProtectConfig.class); private final Map settingsString = new EnumMap<>(ProtectConfig.class); private final Map> settingsList = new EnumMap<>(ProtectConfig.class); @@ -39,7 +42,7 @@ public void onEnable() { } private void initialize(final PluginManager pm, final Plugin essPlugin) { - getLogger().log(Level.INFO, "Continuing to enable Protect."); + LOGGER.log(Level.INFO, "Continuing to enable Protect."); ess = new EssentialsConnect(essPlugin, this); final EssentialsProtectBlockListener blockListener = new EssentialsProtectBlockListener(this); @@ -72,14 +75,14 @@ private void enableEmergencyMode(final PluginManager pm) { for (final Player player : getServer().getOnlinePlayers()) { player.sendMessage("Essentials Protect is in emergency mode. Check your log for errors."); } - getLogger().log(Level.SEVERE, "Essentials not installed or failed to load. Essentials Protect is in emergency mode now."); + LOGGER.log(Level.SEVERE, "Essentials not installed or failed to load. Essentials Protect is in emergency mode now."); } void disableEmergencyMode() { final PluginManager pm = this.getServer().getPluginManager(); final Plugin essPlugin = pm.getPlugin("Essentials"); if (essPlugin == null || !essPlugin.isEnabled()) { - getLogger().log(Level.SEVERE, "Tried to disable emergency mode, but Essentials still isn't enabled!"); + LOGGER.log(Level.SEVERE, "Tried to disable emergency mode, but Essentials still isn't enabled!"); return; } @@ -88,7 +91,7 @@ void disableEmergencyMode() { for (final Player player : getServer().getOnlinePlayers()) { player.sendMessage("Essentials Protect is no longer in emergency mode."); } - getLogger().log(Level.SEVERE, "Essentials was loaded late! Essentials Protect is no longer in emergency mode."); + LOGGER.log(Level.SEVERE, "Essentials was loaded late! Essentials Protect is no longer in emergency mode."); initialize(pm, essPlugin); } diff --git a/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawn.java b/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawn.java index a23a28b1bcc..6cad7aba7b5 100644 --- a/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawn.java +++ b/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawn.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.spawn; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.metrics.MetricsWrapper; import net.ess3.api.IEssentials; import org.bukkit.Location; @@ -25,7 +26,7 @@ public void onEnable() { final PluginManager pluginManager = getServer().getPluginManager(); ess = (IEssentials) pluginManager.getPlugin("Essentials"); if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) { - getLogger().log(Level.WARNING, tl("versionMismatchAll")); + EssentialsLogger.getLoggerProvider("EssentialsSpawn").log(Level.WARNING, tl("versionMismatchAll")); } if (!ess.isEnabled()) { this.setEnabled(false); diff --git a/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java b/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java index e72522a856e..3ac4260f02b 100644 --- a/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java +++ b/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.spawn; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.Kit; import com.earth2me.essentials.OfflinePlayer; import com.earth2me.essentials.User; @@ -8,6 +9,7 @@ import com.earth2me.essentials.textreader.SimpleTextPager; import com.earth2me.essentials.utils.VersionUtil; import net.ess3.api.IEssentials; +import net.ess3.provider.LoggerProvider; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.Listener; @@ -19,12 +21,11 @@ import java.util.Locale; import java.util.concurrent.CompletableFuture; import java.util.logging.Level; -import java.util.logging.Logger; import static com.earth2me.essentials.I18n.tl; class EssentialsSpawnPlayerListener implements Listener { - private static final Logger logger = Logger.getLogger("EssentialsSpawn"); + private static final LoggerProvider logger = EssentialsLogger.getLoggerProvider("EssentialsSpawn"); private final transient IEssentials ess; private final transient SpawnStorage spawns; From 13c2e8b10c51b59b15f0ca3c9bb8445ca1d68c65 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Tue, 14 Jun 2022 16:29:39 -0400 Subject: [PATCH 3/8] Add fine level --- .../java/net/ess3/provider/providers/PaperLoggerProvider.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperLoggerProvider.java b/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperLoggerProvider.java index f94a73cc4a7..d32e8d89aab 100644 --- a/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperLoggerProvider.java +++ b/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperLoggerProvider.java @@ -24,6 +24,8 @@ public void log(Level level, String message, Throwable throwable) { logger.warn(component, throwable); } else if (level == Level.INFO) { logger.info(component, throwable); + } else if (level == Level.FINE) { + logger.trace(component, throwable); } else { throw new IllegalArgumentException("Unknown level: " + level); } From a5a23bf953bae7e90760a06fd4bb7ce5dc356c4b Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Tue, 14 Jun 2022 16:36:36 -0400 Subject: [PATCH 4/8] Fix EssentialsDiscord and EssentialsProtect startup --- .../main/java/net/essentialsx/discord/EssentialsDiscord.java | 4 +++- .../com/earth2me/essentials/protect/EssentialsProtect.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/EssentialsDiscord/src/main/java/net/essentialsx/discord/EssentialsDiscord.java b/EssentialsDiscord/src/main/java/net/essentialsx/discord/EssentialsDiscord.java index 4e7e49d11bb..8c6474a598a 100644 --- a/EssentialsDiscord/src/main/java/net/essentialsx/discord/EssentialsDiscord.java +++ b/EssentialsDiscord/src/main/java/net/essentialsx/discord/EssentialsDiscord.java @@ -18,7 +18,7 @@ import static com.earth2me.essentials.I18n.tl; public class EssentialsDiscord extends JavaPlugin implements IEssentialsModule { - protected final static LoggerProvider LOGGER = EssentialsLogger.getLoggerProvider("EssentialsDiscord"); + protected static LoggerProvider LOGGER; private transient IEssentials ess; private transient MetricsWrapper metrics = null; @@ -33,6 +33,8 @@ public void onEnable() { setEnabled(false); return; } + LOGGER = EssentialsLogger.getLoggerProvider("EssentialsDiscord"); + if (!getDescription().getVersion().equals(ess.getDescription().getVersion())) { LOGGER.log(Level.WARNING, tl("versionMismatchAll")); } diff --git a/EssentialsProtect/src/main/java/com/earth2me/essentials/protect/EssentialsProtect.java b/EssentialsProtect/src/main/java/com/earth2me/essentials/protect/EssentialsProtect.java index afff2f84392..ee8e51385ac 100644 --- a/EssentialsProtect/src/main/java/com/earth2me/essentials/protect/EssentialsProtect.java +++ b/EssentialsProtect/src/main/java/com/earth2me/essentials/protect/EssentialsProtect.java @@ -17,7 +17,7 @@ import java.util.logging.Level; public class EssentialsProtect extends JavaPlugin implements IProtect { - private final static LoggerProvider LOGGER = EssentialsLogger.getLoggerProvider("EssentialsProtect"); + private static LoggerProvider LOGGER; private final Map settingsBoolean = new EnumMap<>(ProtectConfig.class); private final Map settingsString = new EnumMap<>(ProtectConfig.class); private final Map> settingsList = new EnumMap<>(ProtectConfig.class); @@ -27,6 +27,8 @@ public class EssentialsProtect extends JavaPlugin implements IProtect { @Override public void onEnable() { + LOGGER = EssentialsLogger.getLoggerProvider("EssentialsProtect"); + final PluginManager pm = this.getServer().getPluginManager(); final Plugin essPlugin = pm.getPlugin("Essentials"); if (essPlugin == null || !essPlugin.isEnabled()) { From 90a31cc970f6e62e16858d4b8c3c2515b69883b9 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Wed, 15 Jun 2022 13:11:38 -0400 Subject: [PATCH 5/8] The means to an end --- .../AlternativeCommandsHandler.java | 2 +- .../earth2me/essentials/AsyncTeleport.java | 2 +- .../java/com/earth2me/essentials/Backup.java | 10 +- .../com/earth2me/essentials/Essentials.java | 71 ++++----- .../essentials/EssentialsEntityListener.java | 2 +- .../earth2me/essentials/EssentialsLogger.java | 25 +--- .../essentials/EssentialsPlayerListener.java | 26 ++-- .../essentials/EssentialsPluginListener.java | 6 +- .../essentials/EssentialsServerListener.java | 8 +- .../earth2me/essentials/EssentialsTimer.java | 2 +- .../essentials/EssentialsUpgrade.java | 138 +++++++++--------- .../java/com/earth2me/essentials/I18n.java | 6 +- .../java/com/earth2me/essentials/Jails.java | 14 +- .../java/com/earth2me/essentials/Kit.java | 6 +- .../earth2me/essentials/MetaItemStack.java | 4 +- .../java/com/earth2me/essentials/Mob.java | 2 +- .../java/com/earth2me/essentials/MobData.java | 2 +- .../com/earth2me/essentials/Settings.java | 36 ++--- .../com/earth2me/essentials/Teleport.java | 2 +- .../java/com/earth2me/essentials/Trade.java | 30 ++-- .../java/com/earth2me/essentials/UUIDMap.java | 4 +- .../java/com/earth2me/essentials/User.java | 30 ++-- .../com/earth2me/essentials/UserData.java | 6 +- .../java/com/earth2me/essentials/UserMap.java | 24 +-- .../java/com/earth2me/essentials/Warps.java | 2 +- .../com/earth2me/essentials/api/Economy.java | 26 ++-- .../commands/Commandbalancetop.java | 2 +- .../essentials/commands/Commandcreatekit.java | 6 +- .../commands/Commandessentials.java | 12 +- .../essentials/commands/Commandkit.java | 2 +- .../essentials/commands/Commandsell.java | 2 +- .../essentials/commands/Commandtpaccept.java | 2 +- .../essentials/commands/Commandtpdeny.java | 2 +- .../commands/EssentialsCommand.java | 6 +- .../config/ConfigurationSaveTask.java | 2 +- .../config/EssentialsConfiguration.java | 26 ++-- .../config/EssentialsUserConfiguration.java | 4 +- .../essentials/economy/EconomyLayers.java | 2 +- .../economy/vault/VaultEconomyProvider.java | 6 +- .../essentials/items/AbstractItemDb.java | 4 +- .../essentials/items/CustomItemResolver.java | 2 +- .../earth2me/essentials/items/FlatItemDb.java | 4 +- .../essentials/items/LegacyItemDb.java | 2 +- .../essentials/perm/PermissionsHandler.java | 14 +- .../essentials/signs/EssentialsSign.java | 4 +- .../essentials/signs/SignBlockListener.java | 4 +- .../essentials/signs/SignPlayerListener.java | 2 +- .../essentials/textreader/BookInput.java | 2 +- .../essentials/textreader/HelpInput.java | 2 +- .../textreader/KeywordReplacer.java | 2 +- .../net/ess3/provider/LoggerProvider.java | 36 +++-- .../providers/BaseLoggerProvider.java | 7 +- .../providers/PaperLoggerProvider.java | 9 +- 53 files changed, 330 insertions(+), 324 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/AlternativeCommandsHandler.java b/Essentials/src/main/java/com/earth2me/essentials/AlternativeCommandsHandler.java index 6f8815d22dd..d6e25969e7a 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/AlternativeCommandsHandler.java +++ b/Essentials/src/main/java/com/earth2me/essentials/AlternativeCommandsHandler.java @@ -93,7 +93,7 @@ public void executed(final String label, final Command pc) { if (pc instanceof PluginIdentifiableCommand) { final String altString = ((PluginIdentifiableCommand) pc).getPlugin().getName() + ":" + pc.getName(); if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "Essentials: Alternative command " + label + " found, using " + altString); + EssentialsLogger.getLogger().log(Level.INFO, "Essentials: Alternative command " + label + " found, using " + altString); } disabledList.put(label, altString); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/AsyncTeleport.java b/Essentials/src/main/java/com/earth2me/essentials/AsyncTeleport.java index 2a3778e70f5..1712cf60cfd 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/AsyncTeleport.java +++ b/Essentials/src/main/java/com/earth2me/essentials/AsyncTeleport.java @@ -401,7 +401,7 @@ void respawnNow(final IUser teleportee, final TeleportCause cause, final Complet nowAsync(teleportee, new LocationTarget(location), cause, future); } else { if (ess.getSettings().isDebug()) { - EssentialsLogger.info("Could not find bed spawn, forcing respawn event."); + EssentialsLogger.getLogger().info("Could not find bed spawn, forcing respawn event."); } final PlayerRespawnEvent pre = new PlayerRespawnEvent(player, player.getWorld().getSpawnLocation(), false); ess.getServer().getPluginManager().callEvent(pre); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Backup.java b/Essentials/src/main/java/com/earth2me/essentials/Backup.java index 748d67353de..fba47c344f9 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Backup.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Backup.java @@ -79,7 +79,7 @@ public void run() { taskLock.complete(new Object()); return; } - EssentialsLogger.log(Level.INFO, tl("backupStarted")); + EssentialsLogger.getLogger().log(Level.INFO, tl("backupStarted")); final CommandSender cs = server.getConsoleSender(); server.dispatchCommand(cs, "save-all"); server.dispatchCommand(cs, "save-off"); @@ -97,17 +97,17 @@ public void run() { do { line = reader.readLine(); if (line != null) { - EssentialsLogger.log(Level.INFO, line); + EssentialsLogger.getLogger().log(Level.INFO, line); } } while (line != null); } } catch (final IOException ex) { - EssentialsLogger.log(Level.SEVERE, null, ex); + EssentialsLogger.getLogger().log(Level.SEVERE, null, ex); } }); child.waitFor(); } catch (final InterruptedException | IOException ex) { - EssentialsLogger.log(Level.SEVERE, null, ex); + EssentialsLogger.getLogger().log(Level.SEVERE, null, ex); } finally { class BackupEnableSaveTask implements Runnable { @Override @@ -118,7 +118,7 @@ public void run() { } active = false; taskLock.complete(new Object()); - EssentialsLogger.log(Level.INFO, tl("backupFinished")); + EssentialsLogger.getLogger().log(Level.INFO, tl("backupFinished")); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/Essentials.java b/Essentials/src/main/java/com/earth2me/essentials/Essentials.java index f9451c616e8..48e8cd9c738 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Essentials.java @@ -141,7 +141,8 @@ import static com.earth2me.essentials.I18n.tl; public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials { - private static final Logger LOGGER = Logger.getLogger("Essentials"); + private static Logger LOGGER; + private static final Logger BUKKIT_LOGGER = Logger.getLogger("Essentials"); private final transient TNTExplodeListener tntListener = new TNTExplodeListener(this); private final transient Set vanishedPlayers = new LinkedHashSet<>(); private transient ISettings settings; @@ -204,7 +205,7 @@ public ISettings getSettings() { } public void setupForTesting(final Server server) throws IOException, InvalidDescriptionException { - EssentialsLogger.setLoggerProvider(new BaseLoggerProvider(LOGGER)); + LOGGER = EssentialsLogger.setLoggerProvider(new BaseLoggerProvider(BUKKIT_LOGGER)); final File dataFolder = File.createTempFile("essentialstest", ""); if (!dataFolder.delete()) { throw new IOException(); @@ -217,8 +218,8 @@ public void setupForTesting(final Server server) throws IOException, InvalidDesc i18n.updateLocale("en"); Console.setInstance(this); - EssentialsLogger.log(Level.INFO, tl("usingTempFolderForTesting")); - EssentialsLogger.log(Level.INFO, dataFolder.toString()); + EssentialsLogger.getLogger().log(Level.INFO, tl("usingTempFolderForTesting")); + EssentialsLogger.getLogger().log(Level.INFO, dataFolder.toString()); settings = new Settings(this); mail = new MailServiceImpl(this); userMap = new UserMap(this); @@ -245,11 +246,11 @@ public void onLoad() { @Override public void onEnable() { try { - if (LOGGER != this.getLogger()) { - LOGGER.setParent(this.getLogger()); + if (BUKKIT_LOGGER != this.getLogger()) { + BUKKIT_LOGGER.setParent(this.getLogger()); } - EssentialsLogger.setLoggerProvider(EssentialsLogger.getLoggerProvider(this)); + LOGGER = EssentialsLogger.setLoggerProvider(EssentialsLogger.getLoggerProvider(this)); execTimer = new ExecuteTimer(); execTimer.start(); @@ -261,30 +262,30 @@ public void onEnable() { switch (VersionUtil.getServerSupportStatus()) { case NMS_CLEANROOM: - EssentialsLogger.severe(tl("serverUnsupportedCleanroom")); + EssentialsLogger.getLogger().severe(tl("serverUnsupportedCleanroom")); break; case DANGEROUS_FORK: - EssentialsLogger.severe(tl("serverUnsupportedDangerous")); + EssentialsLogger.getLogger().severe(tl("serverUnsupportedDangerous")); break; case UNSTABLE: - EssentialsLogger.severe(tl("serverUnsupportedMods")); + EssentialsLogger.getLogger().severe(tl("serverUnsupportedMods")); break; case OUTDATED: - EssentialsLogger.severe(tl("serverUnsupported")); + EssentialsLogger.getLogger().severe(tl("serverUnsupported")); break; case LIMITED: - EssentialsLogger.info(tl("serverUnsupportedLimitedApi")); + EssentialsLogger.getLogger().info(tl("serverUnsupportedLimitedApi")); break; } if (VersionUtil.getSupportStatusClass() != null) { - EssentialsLogger.info(tl("serverUnsupportedClass", VersionUtil.getSupportStatusClass())); + EssentialsLogger.getLogger().info(tl("serverUnsupportedClass", VersionUtil.getSupportStatusClass())); } final PluginManager pm = getServer().getPluginManager(); for (final Plugin plugin : pm.getPlugins()) { if (plugin.getDescription().getName().startsWith("Essentials") && !plugin.getDescription().getVersion().equals(this.getDescription().getVersion()) && !plugin.getDescription().getName().equals("EssentialsAntiCheat")) { - EssentialsLogger.warning(tl("versionMismatch", plugin.getDescription().getName())); + EssentialsLogger.getLogger().warning(tl("versionMismatch", plugin.getDescription().getName())); } } @@ -465,9 +466,9 @@ public void onEnable() { updateChecker = new UpdateChecker(this); runTaskAsynchronously(() -> { - EssentialsLogger.log(Level.INFO, tl("versionFetching")); + EssentialsLogger.getLogger().log(Level.INFO, tl("versionFetching")); for (String str : updateChecker.getVersionMessages(false, true)) { - EssentialsLogger.log(getSettings().isUpdateCheckEnabled() ? Level.WARNING : Level.INFO, str); + EssentialsLogger.getLogger().log(getSettings().isUpdateCheckEnabled() ? Level.WARNING : Level.INFO, str); } }); @@ -477,7 +478,7 @@ public void onEnable() { final String timeroutput = execTimer.end(); if (getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "Essentials load " + timeroutput); + EssentialsLogger.getLogger().log(Level.INFO, "Essentials load " + timeroutput); } } catch (final NumberFormatException ex) { handleCrash(ex); @@ -497,7 +498,7 @@ private void registerListeners(final PluginManager pm) { HandlerList.unregisterAll(this); if (getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "Registering Listeners"); + EssentialsLogger.getLogger().log(Level.INFO, "Registering Listeners"); } final EssentialsPluginListener pluginListener = new EssentialsPluginListener(this); @@ -541,7 +542,7 @@ private void registerListeners(final PluginManager pm) { public void onDisable() { final boolean stopping = getServerStateProvider().isStopping(); if (!stopping) { - EssentialsLogger.log(Level.SEVERE, tl("serverReloading")); + EssentialsLogger.getLogger().log(Level.SEVERE, tl("serverReloading")); } getBackup().setPendingShutdown(true); for (final User user : getOnlineUsers()) { @@ -561,7 +562,7 @@ public void onDisable() { } cleanupOpenInventories(); if (getBackup().getTaskLock() != null && !getBackup().getTaskLock().isDone()) { - EssentialsLogger.log(Level.SEVERE, tl("backupInProgress")); + EssentialsLogger.getLogger().log(Level.SEVERE, tl("backupInProgress")); getBackup().getTaskLock().join(); } if (i18n != null) { @@ -636,7 +637,7 @@ public List onTabCompleteEssentials(final CommandSender cSender, final C return completer.onTabComplete(cSender, command, commandLabel, args); } } catch (final Exception ex) { - EssentialsLogger.log(Level.SEVERE, ex.getMessage(), ex); + EssentialsLogger.getLogger().log(Level.SEVERE, ex.getMessage(), ex); } } } @@ -666,7 +667,7 @@ public List onTabCompleteEssentials(final CommandSender cSender, final C cmd = loadCommand(commandPath, command.getName(), module, classLoader); } catch (final Exception ex) { sender.sendMessage(tl("commandNotLoaded", commandLabel)); - EssentialsLogger.log(Level.SEVERE, tl("commandNotLoaded", commandLabel), ex); + EssentialsLogger.getLogger().log(Level.SEVERE, tl("commandNotLoaded", commandLabel), ex); return Collections.emptyList(); } @@ -689,11 +690,11 @@ public List onTabCompleteEssentials(final CommandSender cSender, final C } catch (final Exception ex) { showError(sender, ex, commandLabel); // Tab completion shouldn't fail - EssentialsLogger.log(Level.SEVERE, tl("commandFailed", commandLabel), ex); + EssentialsLogger.getLogger().log(Level.SEVERE, tl("commandFailed", commandLabel), ex); return Collections.emptyList(); } } catch (final Throwable ex) { - EssentialsLogger.log(Level.SEVERE, tl("commandFailed", commandLabel), ex); + EssentialsLogger.getLogger().log(Level.SEVERE, tl("commandFailed", commandLabel), ex); return Collections.emptyList(); } } @@ -709,7 +710,7 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co // Allow plugins to override the command via onCommand if (!getSettings().isCommandOverridden(command.getName()) && (!commandLabel.startsWith("e") || commandLabel.equalsIgnoreCase(command.getName()))) { if (getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "Searching for alternative to: " + commandLabel); + EssentialsLogger.getLogger().log(Level.INFO, "Searching for alternative to: " + commandLabel); } final Command pc = alternativeCommandsHandler.getAlternative(commandLabel); if (pc != null) { @@ -717,7 +718,7 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co try { pc.execute(cSender, commandLabel, args); } catch (final Exception ex) { - EssentialsLogger.log(Level.SEVERE, ex.getMessage(), ex); + EssentialsLogger.getLogger().log(Level.SEVERE, ex.getMessage(), ex); cSender.sendMessage(tl("internalError")); } return true; @@ -737,10 +738,10 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co if (bSenderBlock != null) { if (getSettings().logCommandBlockCommands()) { - EssentialsLogger.log(Level.INFO, "CommandBlock at " + bSenderBlock.getX() + "," + bSenderBlock.getY() + "," + bSenderBlock.getZ() + " issued server command: /" + commandLabel + " " + EssentialsCommand.getFinalArg(args, 0)); + EssentialsLogger.getLogger().log(Level.INFO, "CommandBlock at " + bSenderBlock.getX() + "," + bSenderBlock.getY() + "," + bSenderBlock.getZ() + " issued server command: /" + commandLabel + " " + EssentialsCommand.getFinalArg(args, 0)); } } else if (user == null) { - EssentialsLogger.log(Level.INFO, cSender.getName() + " issued server command: /" + commandLabel + " " + EssentialsCommand.getFinalArg(args, 0)); + EssentialsLogger.getLogger().log(Level.INFO, cSender.getName() + " issued server command: /" + commandLabel + " " + EssentialsCommand.getFinalArg(args, 0)); } final CommandSource sender = new CommandSource(cSender); @@ -773,13 +774,13 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co cmd = loadCommand(commandPath, command.getName(), module, classLoader); } catch (final Exception ex) { sender.sendMessage(tl("commandNotLoaded", commandLabel)); - EssentialsLogger.log(Level.SEVERE, tl("commandNotLoaded", commandLabel), ex); + EssentialsLogger.getLogger().log(Level.SEVERE, tl("commandNotLoaded", commandLabel), ex); return true; } // Check authorization if (user != null && !user.isAuthorized(cmd, permissionPrefix)) { - EssentialsLogger.log(Level.INFO, tl("deniedAccessCommand", user.getName())); + EssentialsLogger.getLogger().log(Level.INFO, tl("deniedAccessCommand", user.getName())); user.sendMessage(tl("noAccessCommand")); return true; } @@ -830,7 +831,7 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co return true; } } catch (final Throwable ex) { - EssentialsLogger.log(Level.SEVERE, tl("commandFailed", commandLabel), ex); + EssentialsLogger.getLogger().log(Level.SEVERE, tl("commandFailed", commandLabel), ex); return true; } } @@ -858,7 +859,7 @@ public void cleanupOpenInventories() { public void showError(final CommandSource sender, final Throwable exception, final String commandLabel) { sender.sendMessage(tl("errorWithMessage", exception.getMessage())); if (getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, tl("errorCallingCommand", commandLabel), exception); + EssentialsLogger.getLogger().log(Level.INFO, tl("errorCallingCommand", commandLabel), exception); } } @@ -1044,7 +1045,7 @@ public User getUser(final Player base) { } if (userMap == null) { - EssentialsLogger.log(Level.WARNING, "Essentials userMap not initialized"); + EssentialsLogger.getLogger().log(Level.WARNING, "Essentials userMap not initialized"); return null; } @@ -1052,7 +1053,7 @@ public User getUser(final Player base) { if (user == null) { if (getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "Constructing new userfile from base player " + base.getName()); + EssentialsLogger.getLogger().log(Level.INFO, "Constructing new userfile from base player " + base.getName()); } user = new User(base, this); } else { @@ -1063,7 +1064,7 @@ public User getUser(final Player base) { private void handleCrash(final Throwable exception) { final PluginManager pm = getServer().getPluginManager(); - EssentialsLogger.log(Level.SEVERE, exception.toString()); + EssentialsLogger.getLogger().log(Level.SEVERE, exception.toString()); exception.printStackTrace(); pm.registerEvents(new Listener() { @EventHandler(priority = EventPriority.LOW) diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsEntityListener.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsEntityListener.java index 3dee84eb011..8a8ffd0a23a 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsEntityListener.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsEntityListener.java @@ -108,7 +108,7 @@ class PowerToolInteractTask implements Runnable { @Override public void run() { attacker.getBase().chat("/" + command); - EssentialsLogger.log(Level.INFO, String.format("[PT] %s issued server command: /%s", attacker.getName(), command)); + EssentialsLogger.getLogger().log(Level.INFO, String.format("[PT] %s issued server command: /%s", attacker.getName(), command)); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsLogger.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsLogger.java index c90a1531e05..9086153515f 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsLogger.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsLogger.java @@ -9,7 +9,6 @@ import java.util.HashMap; import java.util.Map; -import java.util.logging.Level; import java.util.logging.Logger; public final class EssentialsLogger { @@ -46,27 +45,11 @@ public static LoggerProvider getLoggerProvider(final String pluginName) { return getLoggerProvider(plugin); } - public static void setLoggerProvider(LoggerProvider loggerProvider) { - EssentialsLogger.loggerProvider = loggerProvider; + public static Logger setLoggerProvider(LoggerProvider loggerProvider) { + return EssentialsLogger.loggerProvider = loggerProvider; } - public static void log(Level level, String message, Throwable throwable) { - loggerProvider.log(level, message, throwable); - } - - public static void log(Level level, String message) { - log(level, message, null); - } - - public static void info(final String message) { - log(Level.INFO, message); - } - - public static void warning(final String message) { - log(Level.WARNING, message); - } - - public static void severe(final String message) { - log(Level.SEVERE, message); + public static LoggerProvider getLogger() { + return loggerProvider; } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java index 472f0586109..a59e2f77683 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java @@ -164,7 +164,7 @@ public void onPlayerChat(final AsyncPlayerChatEvent event) { user.sendMessage(user.hasMuteReason() ? tl("voiceSilencedReasonTime", dateDiff, user.getMuteReason()) : tl("voiceSilencedTime", dateDiff)); } - EssentialsLogger.info(tl("mutedUserSpeaks", user.getName(), event.getMessage())); + EssentialsLogger.getLogger().info(tl("mutedUserSpeaks", user.getName(), event.getMessage())); } try { final Iterator it = event.getRecipients().iterator(); @@ -176,9 +176,9 @@ public void onPlayerChat(final AsyncPlayerChatEvent event) { } } catch (final UnsupportedOperationException ex) { if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "Ignore could not block chat due to custom chat plugin event.", ex); + EssentialsLogger.getLogger().log(Level.INFO, "Ignore could not block chat due to custom chat plugin event.", ex); } else { - EssentialsLogger.info("Ignore could not block chat due to custom chat plugin event."); + EssentialsLogger.getLogger().info("Ignore could not block chat due to custom chat plugin event."); } } @@ -196,7 +196,7 @@ public void onPlayerMove(final PlayerMoveEvent event) { event.getHandlers().unregister(this); if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "Unregistering move listener"); + EssentialsLogger.getLogger().log(Level.INFO, "Unregistering move listener"); } return; @@ -340,7 +340,7 @@ public void run() { if (toVanish != null && toVanish.isOnline()) { user.getBase().hidePlayer(toVanish); if (ess.getSettings().isDebug()) { - EssentialsLogger.info("Hiding vanished player: " + p); + EssentialsLogger.getLogger().info("Hiding vanished player: " + p); } } } @@ -426,12 +426,12 @@ public void run() { if (user.isSocialSpyEnabled() && !user.isAuthorized("essentials.socialspy")) { user.setSocialSpyEnabled(false); - EssentialsLogger.log(Level.INFO, "Set socialspy to false for " + user.getName() + " because they had it enabled without permission."); + EssentialsLogger.getLogger().log(Level.INFO, "Set socialspy to false for " + user.getName() + " because they had it enabled without permission."); } if (user.isGodModeEnabled() && !user.isAuthorized("essentials.god")) { user.setGodModeEnabled(false); - EssentialsLogger.log(Level.INFO, "Set god mode to false for " + user.getName() + " because they had it enabled without permission."); + EssentialsLogger.getLogger().log(Level.INFO, "Set god mode to false for " + user.getName() + " because they had it enabled without permission."); } user.setConfirmingClearCommand(null); @@ -458,9 +458,9 @@ public void run() { tempInput = new TextInput(user.getSource(), "motd", true, ess); } catch (final IOException ex) { if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.WARNING, ex.getMessage(), ex); + EssentialsLogger.getLogger().log(Level.WARNING, ex.getMessage(), ex); } else { - EssentialsLogger.log(Level.WARNING, ex.getMessage()); + EssentialsLogger.getLogger().log(Level.WARNING, ex.getMessage()); } } } @@ -620,7 +620,7 @@ public void handlePlayerCommandPreprocess(final PlayerCommandPreprocessEvent eve } else { player.sendMessage(user.hasMuteReason() ? tl("voiceSilencedReasonTime", dateDiff, user.getMuteReason()) : tl("voiceSilencedTime", dateDiff)); } - EssentialsLogger.info(tl("mutedUserSpeaks", player.getName(), event.getMessage())); + EssentialsLogger.getLogger().info(tl("mutedUserSpeaks", player.getName(), event.getMessage())); return; } @@ -677,7 +677,7 @@ public void handlePlayerCommandPreprocess(final PlayerCommandPreprocessEvent eve if (cooldownEntry != null) { if (ess.getSettings().isDebug()) { - EssentialsLogger.info("Applying " + cooldownEntry.getValue() + "ms cooldown on /" + fullCommand + " for" + user.getName() + "."); + EssentialsLogger.getLogger().info("Applying " + cooldownEntry.getValue() + "ms cooldown on /" + fullCommand + " for" + user.getName() + "."); } final Date expiry = new Date(System.currentTimeMillis() + cooldownEntry.getValue()); user.addCommandCooldown(cooldownEntry.getKey(), expiry, ess.getSettings().isCommandCooldownPersistent(fullCommand)); @@ -808,7 +808,7 @@ public void run() { ess.scheduleSyncDelayedTask(new DelayedClickJumpTask()); } catch (final Exception ex) { if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.WARNING, ex.getMessage(), ex); + EssentialsLogger.getLogger().log(Level.WARNING, ex.getMessage(), ex); } } } @@ -832,7 +832,7 @@ class PowerToolUseTask implements Runnable { @Override public void run() { user.getBase().chat("/" + command); - EssentialsLogger.log(Level.INFO, String.format("[PT] %s issued server command: /%s", user.getName(), command)); + EssentialsLogger.getLogger().log(Level.INFO, String.format("[PT] %s issued server command: /%s", user.getName(), command)); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsPluginListener.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsPluginListener.java index d28e8753ad2..cd20b5e5abc 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsPluginListener.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsPluginListener.java @@ -29,7 +29,7 @@ public void onPluginEnable(final PluginEnableEvent event) { if (EconomyLayers.isServerStarted()) { final EconomyLayer layer = EconomyLayers.onPluginEnable(event.getPlugin()); if (layer != null) { - EssentialsLogger.log(Level.INFO, "Essentials found a compatible payment resolution method: " + layer.getName() + " (v" + layer.getPluginVersion() + ")!"); + EssentialsLogger.getLogger().log(Level.INFO, "Essentials found a compatible payment resolution method: " + layer.getName() + " (v" + layer.getPluginVersion() + ")!"); } } } @@ -44,9 +44,9 @@ public void onPluginDisable(final PluginDisableEvent event) { if (EconomyLayers.onPluginDisable(event.getPlugin())) { final EconomyLayer layer = EconomyLayers.getSelectedLayer(); if (layer != null) { - EssentialsLogger.log(Level.INFO, "Essentials found a new compatible payment resolution method: " + layer.getName() + " (v" + layer.getPluginVersion() + ")!"); + EssentialsLogger.getLogger().log(Level.INFO, "Essentials found a new compatible payment resolution method: " + layer.getName() + " (v" + layer.getPluginVersion() + ")!"); } else { - EssentialsLogger.log(Level.INFO, "Active payment resolution method has been disabled! Falling back to Essentials' default payment resolution system!"); + EssentialsLogger.getLogger().log(Level.INFO, "Active payment resolution method has been disabled! Falling back to Essentials' default payment resolution system!"); } } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsServerListener.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsServerListener.java index 4d40ee9122f..f474dbdd660 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsServerListener.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsServerListener.java @@ -37,13 +37,13 @@ public EssentialsServerListener(final IEssentials ess) { setSampleText = ReflUtil.getMethodCached(ServerListPingEvent.class, "setSampleText", List.class); getSampleText = ReflUtil.getMethodCached(ServerListPingEvent.class, "getSampleText"); if (setSampleText != null && getSampleText != null) { - EssentialsLogger.info("ServerListPingEvent: Paper 1.12.2 setSampleText API"); + EssentialsLogger.getLogger().info("ServerListPingEvent: Paper 1.12.2 setSampleText API"); isPaperSample = true; return; } } - EssentialsLogger.info("ServerListPingEvent: Spigot iterator API"); + EssentialsLogger.getLogger().info("ServerListPingEvent: Spigot iterator API"); isPaperSample = false; } @@ -56,7 +56,7 @@ public void onServerListPing(final ServerListPingEvent event) throws Exception { setSampleText.invoke(event, playerNames); } catch (final IllegalAccessException | InvocationTargetException | ClassCastException e) { if (!unsupportedLogged && shouldWarnSLPECaller(e)) { - EssentialsLogger.log(Level.WARNING, "Unable to hide players from server list ping " + EssentialsLogger.getLogger().log(Level.WARNING, "Unable to hide players from server list ping " + "using Paper 1.12 method!", e); unsupportedLogged = true; } @@ -80,7 +80,7 @@ public void onServerListPing(final ServerListPingEvent event) throws Exception { } } catch (final UnsupportedOperationException e) { if (!unsupportedLogged && shouldWarnSLPECaller(e)) { - EssentialsLogger.log(Level.WARNING, "Could not hide vanished players while handling " + event.getClass().getName(), e); + EssentialsLogger.getLogger().log(Level.WARNING, "Could not hide vanished players while handling " + event.getClass().getName(), e); unsupportedLogged = true; } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsTimer.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsTimer.java index e009eaaada5..8eded0a49f2 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsTimer.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsTimer.java @@ -63,7 +63,7 @@ public void run() { user.setLastOnlineActivity(currentTime); user.checkActivity(); } catch (final Exception e) { - EssentialsLogger.log(Level.WARNING, "EssentialsTimer Error:", e); + EssentialsLogger.getLogger().log(Level.WARNING, "EssentialsTimer Error:", e); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsUpgrade.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsUpgrade.java index f254006c973..54ee76f206e 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsUpgrade.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsUpgrade.java @@ -71,7 +71,7 @@ public class EssentialsUpgrade { } public static void uuidFileConvert(final IEssentials ess, final Boolean ignoreUFCache) { - EssentialsLogger.info("Starting Essentials UUID userdata conversion"); + EssentialsLogger.getLogger().info("Starting Essentials UUID userdata conversion"); final File userdir = new File(ess.getDataFolder(), "userdata"); if (!userdir.exists()) { @@ -83,7 +83,7 @@ public static void uuidFileConvert(final IEssentials ess, final Boolean ignoreUF int countEssCache = 0; int countBukkit = 0; - EssentialsLogger.info("Found " + userdir.list().length + " files to convert..."); + EssentialsLogger.getLogger().info("Found " + userdir.list().length + " files to convert..."); for (final String string : userdir.list()) { if (!string.endsWith(".yml") || string.length() < 5) { @@ -94,7 +94,7 @@ public static void uuidFileConvert(final IEssentials ess, final Boolean ignoreUF if (showProgress == 0) { ess.getUserMap().getUUIDMap().forceWriteUUIDMap(); - EssentialsLogger.info("Converted " + countFiles + "/" + userdir.list().length); + EssentialsLogger.getLogger().info("Converted " + countFiles + "/" + userdir.list().length); } countFiles++; @@ -148,9 +148,9 @@ public static void uuidFileConvert(final IEssentials ess, final Boolean ignoreUF } ess.getUserMap().getUUIDMap().forceWriteUUIDMap(); - EssentialsLogger.info("Converted " + countFiles + "/" + countFiles + ". Conversion complete."); - EssentialsLogger.info("Converted via cache: " + countEssCache + " :: Converted via lookup: " + countBukkit + " :: Failed to convert: " + countFails); - EssentialsLogger.info("To rerun the conversion type /essentials uuidconvert"); + EssentialsLogger.getLogger().info("Converted " + countFiles + "/" + countFiles + ". Conversion complete."); + EssentialsLogger.getLogger().info("Converted via cache: " + countEssCache + " :: Converted via lookup: " + countBukkit + " :: Failed to convert: " + countFails); + EssentialsLogger.getLogger().info("To rerun the conversion type /essentials uuidconvert"); } public void convertMailList() { @@ -184,13 +184,13 @@ public void convertMailList() { config.blockingSave(); } } catch (RuntimeException ex) { - EssentialsLogger.log(Level.INFO, "File: " + file); + EssentialsLogger.getLogger().log(Level.INFO, "File: " + file); throw ex; } } doneFile.setProperty("updateUsersMailList", true); doneFile.save(); - EssentialsLogger.info("Done converting mail list."); + EssentialsLogger.getLogger().info("Done converting mail list."); } public void convertStupidCamelCaseUserdataKeys() { @@ -198,7 +198,7 @@ public void convertStupidCamelCaseUserdataKeys() { return; } - EssentialsLogger.info("Attempting to migrate legacy userdata keys to Configurate"); + EssentialsLogger.getLogger().info("Attempting to migrate legacy userdata keys to Configurate"); final File userdataFolder = new File(ess.getDataFolder(), "userdata"); if (!userdataFolder.exists() || !userdataFolder.isDirectory()) { @@ -239,13 +239,13 @@ public void convertStupidCamelCaseUserdataKeys() { } config.blockingSave(); } catch (final RuntimeException ex) { - EssentialsLogger.log(Level.INFO, "File: " + file); + EssentialsLogger.getLogger().log(Level.INFO, "File: " + file); throw ex; } } doneFile.setProperty("updateUsersStupidLegacyPathNames", true); doneFile.save(); - EssentialsLogger.info("Done converting legacy userdata keys to Configurate."); + EssentialsLogger.getLogger().info("Done converting legacy userdata keys to Configurate."); } /** @@ -288,31 +288,31 @@ public void purgeBrokenNpcAccounts() { } final File backupFolder = new File(ess.getDataFolder(), "userdata-npc-backup"); if (backupFolder.exists()) { - EssentialsLogger.info("NPC backup folder already exists; skipping NPC purge."); - EssentialsLogger.info("To finish purging broken NPC accounts, rename the \"plugins/Essentials/userdata-npc-backup\" folder and restart your server."); + EssentialsLogger.getLogger().info("NPC backup folder already exists; skipping NPC purge."); + EssentialsLogger.getLogger().info("To finish purging broken NPC accounts, rename the \"plugins/Essentials/userdata-npc-backup\" folder and restart your server."); return; } else if (!backupFolder.mkdir()) { - EssentialsLogger.info("Skipping NPC purge due to error creating backup folder."); + EssentialsLogger.getLogger().info("Skipping NPC purge due to error creating backup folder."); return; } - EssentialsLogger.info("#===========================================================================#"); - EssentialsLogger.info(" EssentialsX will now purge any NPC accounts which were incorrectly created."); - EssentialsLogger.info(" Only NPC accounts with the default starting balance will be deleted. If"); - EssentialsLogger.info(" they turn out to be valid NPC accounts, they will be re-created as needed."); - EssentialsLogger.info(" Any files deleted here will be backed up to the "); - EssentialsLogger.info(" \"plugins/Essentials/userdata-npc-backup\" folder. If you notice any files"); - EssentialsLogger.info(" have been purged incorrectly, you should restore it from the backup and"); - EssentialsLogger.info(" report it to us on GitHub:"); - EssentialsLogger.info(" https://github.com/EssentialsX/Essentials/issues/new/choose"); - EssentialsLogger.info(""); - EssentialsLogger.info(" NOTE: This is a one-time process and will take several minutes if you have"); - EssentialsLogger.info(" a lot of userdata files! If you interrupt this process, EssentialsX will"); - EssentialsLogger.info(" skip the process until you rename or remove the backup folder."); - EssentialsLogger.info("#===========================================================================#"); + EssentialsLogger.getLogger().info("#===========================================================================#"); + EssentialsLogger.getLogger().info(" EssentialsX will now purge any NPC accounts which were incorrectly created."); + EssentialsLogger.getLogger().info(" Only NPC accounts with the default starting balance will be deleted. If"); + EssentialsLogger.getLogger().info(" they turn out to be valid NPC accounts, they will be re-created as needed."); + EssentialsLogger.getLogger().info(" Any files deleted here will be backed up to the "); + EssentialsLogger.getLogger().info(" \"plugins/Essentials/userdata-npc-backup\" folder. If you notice any files"); + EssentialsLogger.getLogger().info(" have been purged incorrectly, you should restore it from the backup and"); + EssentialsLogger.getLogger().info(" report it to us on GitHub:"); + EssentialsLogger.getLogger().info(" https://github.com/EssentialsX/Essentials/issues/new/choose"); + EssentialsLogger.getLogger().info(""); + EssentialsLogger.getLogger().info(" NOTE: This is a one-time process and will take several minutes if you have"); + EssentialsLogger.getLogger().info(" a lot of userdata files! If you interrupt this process, EssentialsX will"); + EssentialsLogger.getLogger().info(" skip the process until you rename or remove the backup folder."); + EssentialsLogger.getLogger().info("#===========================================================================#"); final int totalUserFiles = userFiles.length; - EssentialsLogger.info("Found ~" + totalUserFiles + " files under \"plugins/Essentials/userdata\"..."); + EssentialsLogger.getLogger().info("Found ~" + totalUserFiles + " files under \"plugins/Essentials/userdata\"..."); final AtomicInteger movedAccounts = new AtomicInteger(0); final AtomicInteger totalAccounts = new AtomicInteger(0); @@ -322,7 +322,7 @@ public void purgeBrokenNpcAccounts() { final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); final ScheduledFuture feedbackTask = executor.scheduleWithFixedDelay( - () -> EssentialsLogger.info("Scanned " + totalAccounts.get() + "/" + totalUserFiles + " accounts; moved " + movedAccounts.get() + " accounts"), + () -> EssentialsLogger.getLogger().info("Scanned " + totalAccounts.get() + "/" + totalUserFiles + " accounts; moved " + movedAccounts.get() + " accounts"), 5, feedbackInterval, TimeUnit.SECONDS); for (final File file : userFiles) { @@ -356,10 +356,10 @@ public void purgeBrokenNpcAccounts() { Files.move(file, new File(backupFolder, file.getName())); movedAccounts.incrementAndGet(); } catch (IOException e) { - EssentialsLogger.log(Level.SEVERE, "Error while moving NPC file", e); + EssentialsLogger.getLogger().log(Level.SEVERE, "Error while moving NPC file", e); } } catch (final RuntimeException ex) { - EssentialsLogger.log(Level.INFO, "File: " + file); + EssentialsLogger.getLogger().log(Level.INFO, "File: " + file); feedbackTask.cancel(false); executor.shutdown(); throw ex; @@ -370,18 +370,18 @@ public void purgeBrokenNpcAccounts() { doneFile.setProperty("updatePurgeBrokenNpcAccounts", true); doneFile.save(); - EssentialsLogger.info("#===========================================================================#"); - EssentialsLogger.info(" EssentialsX has finished purging NPC accounts."); - EssentialsLogger.info(""); - EssentialsLogger.info(" Deleted accounts: " + movedAccounts); - EssentialsLogger.info(" Total accounts processed: " + totalAccounts); - EssentialsLogger.info(""); - EssentialsLogger.info(" Purged accounts have been backed up to"); - EssentialsLogger.info(" \"plugins/Essentials/userdata-npc-backup\", and can be restored from there"); - EssentialsLogger.info(" if needed. Please report any files which have been incorrectly deleted"); - EssentialsLogger.info(" to us on GitHub:"); - EssentialsLogger.info(" https://github.com/EssentialsX/Essentials/issues/new/choose"); - EssentialsLogger.info("#===========================================================================#"); + EssentialsLogger.getLogger().info("#===========================================================================#"); + EssentialsLogger.getLogger().info(" EssentialsX has finished purging NPC accounts."); + EssentialsLogger.getLogger().info(""); + EssentialsLogger.getLogger().info(" Deleted accounts: " + movedAccounts); + EssentialsLogger.getLogger().info(" Total accounts processed: " + totalAccounts); + EssentialsLogger.getLogger().info(""); + EssentialsLogger.getLogger().info(" Purged accounts have been backed up to"); + EssentialsLogger.getLogger().info(" \"plugins/Essentials/userdata-npc-backup\", and can be restored from there"); + EssentialsLogger.getLogger().info(" if needed. Please report any files which have been incorrectly deleted"); + EssentialsLogger.getLogger().info(" to us on GitHub:"); + EssentialsLogger.getLogger().info(" https://github.com/EssentialsX/Essentials/issues/new/choose"); + EssentialsLogger.getLogger().info("#===========================================================================#"); } public void convertIgnoreList() { @@ -390,7 +390,7 @@ public void convertIgnoreList() { return; } - EssentialsLogger.info("Attempting to migrate ignore list to UUIDs"); + EssentialsLogger.getLogger().info("Attempting to migrate ignore list to UUIDs"); final File userdataFolder = new File(ess.getDataFolder(), "userdata"); if (!userdataFolder.exists() || !userdataFolder.isDirectory()) { @@ -412,7 +412,7 @@ public void convertIgnoreList() { continue; } if (pattern.matcher(name.trim()).matches()) { - EssentialsLogger.info("Detected already migrated ignore list!"); + EssentialsLogger.getLogger().info("Detected already migrated ignore list!"); return; } final User user = ess.getOfflineUser(name); @@ -425,13 +425,13 @@ public void convertIgnoreList() { config.blockingSave(); } } catch (final RuntimeException ex) { - EssentialsLogger.log(Level.INFO, "File: " + file); + EssentialsLogger.getLogger().log(Level.INFO, "File: " + file); throw ex; } } doneFile.setProperty("updateUsersIgnoreListUUID", true); doneFile.save(); - EssentialsLogger.info("Done converting ignore list."); + EssentialsLogger.getLogger().info("Done converting ignore list."); } public void convertKits() { @@ -441,25 +441,25 @@ public void convertKits() { return; } - EssentialsLogger.info("Attempting to convert old kits in config.yml to new kits.yml"); + EssentialsLogger.getLogger().info("Attempting to convert old kits in config.yml to new kits.yml"); final CommentedConfigurationNode section = ess.getSettings().getKitSection(); if (section == null) { - EssentialsLogger.info("No kits found to migrate."); + EssentialsLogger.getLogger().info("No kits found to migrate."); return; } final Map legacyKits = ConfigurateUtil.getRawMap(section); for (final Map.Entry entry : legacyKits.entrySet()) { - EssentialsLogger.info("Converting " + entry.getKey()); + EssentialsLogger.getLogger().info("Converting " + entry.getKey()); config.setRaw("kits." + entry.getKey(), entry.getValue()); } config.save(); doneFile.setProperty("kitsyml", true); doneFile.save(); - EssentialsLogger.info("Done converting kits."); + EssentialsLogger.getLogger().info("Done converting kits."); } private void moveMotdRulesToFile(final String name) { @@ -492,7 +492,7 @@ private void moveMotdRulesToFile(final String name) { doneFile.setProperty("move" + name + "ToFile", true); doneFile.save(); } catch (final IOException e) { - EssentialsLogger.log(Level.SEVERE, tl("upgradingFilesError"), e); + EssentialsLogger.getLogger().log(Level.SEVERE, tl("upgradingFilesError"), e); } } @@ -570,7 +570,7 @@ private void updateUsersPowerToolsFormat() { config.blockingSave(); } } catch (final RuntimeException ex) { - EssentialsLogger.log(Level.INFO, "File: " + file); + EssentialsLogger.getLogger().log(Level.INFO, "File: " + file); throw ex; } } @@ -626,7 +626,7 @@ private void updateUsersHomesFormat() { } } catch (final RuntimeException ex) { - EssentialsLogger.log(Level.INFO, "File: " + file); + EssentialsLogger.getLogger().log(Level.INFO, "File: " + file); throw ex; } } @@ -655,15 +655,15 @@ private void sanitizeAllUserFilenames() { final File tmpFile = new File(listOfFile.getParentFile(), sanitizedFilename + ".tmp"); final File newFile = new File(listOfFile.getParentFile(), sanitizedFilename); if (!listOfFile.renameTo(tmpFile)) { - EssentialsLogger.log(Level.WARNING, tl("userdataMoveError", filename, sanitizedFilename)); + EssentialsLogger.getLogger().log(Level.WARNING, tl("userdataMoveError", filename, sanitizedFilename)); continue; } if (newFile.exists()) { - EssentialsLogger.log(Level.WARNING, tl("duplicatedUserdata", filename, sanitizedFilename)); + EssentialsLogger.getLogger().log(Level.WARNING, tl("duplicatedUserdata", filename, sanitizedFilename)); continue; } if (!tmpFile.renameTo(newFile)) { - EssentialsLogger.log(Level.WARNING, tl("userdataMoveBackError", sanitizedFilename, sanitizedFilename)); + EssentialsLogger.getLogger().log(Level.WARNING, tl("userdataMoveBackError", sanitizedFilename, sanitizedFilename)); } } doneFile.setProperty("sanitizeAllUserFilenames", true); @@ -828,8 +828,8 @@ private void uuidFileChange() { return; } - EssentialsLogger.info("#### Starting Essentials UUID userdata conversion in a few seconds. ####"); - EssentialsLogger.info("We recommend you take a backup of your server before upgrading from the old username system."); + EssentialsLogger.getLogger().info("#### Starting Essentials UUID userdata conversion in a few seconds. ####"); + EssentialsLogger.getLogger().info("We recommend you take a backup of your server before upgrading from the old username system."); try { Thread.sleep(15000); @@ -848,7 +848,7 @@ public void banFormatChange() { return; } - EssentialsLogger.info("Starting Essentials ban format conversion"); + EssentialsLogger.getLogger().info("Starting Essentials ban format conversion"); final File userdir = new File(ess.getDataFolder(), "userdata"); if (!userdir.exists()) { @@ -857,7 +857,7 @@ public void banFormatChange() { int countFiles = 0; - EssentialsLogger.info("Found " + userdir.list().length + " files to convert..."); + EssentialsLogger.getLogger().info("Found " + userdir.list().length + " files to convert..."); for (final String string : userdir.list()) { if (!string.endsWith(".yml") || string.length() < 5) { @@ -867,7 +867,7 @@ public void banFormatChange() { final int showProgress = countFiles % 250; if (showProgress == 0) { - EssentialsLogger.info("Converted " + countFiles + "/" + userdir.list().length); + EssentialsLogger.getLogger().info("Converted " + countFiles + "/" + userdir.list().length); } countFiles++; @@ -906,7 +906,7 @@ public void banFormatChange() { doneFile.setProperty("banFormatChange", true); doneFile.save(); - EssentialsLogger.info("Ban format update complete."); + EssentialsLogger.getLogger().info("Ban format update complete."); } private void updateBan(final String playerName, final String banReason, final Long banTimeout) { @@ -917,11 +917,11 @@ private void repairUserMap() { if (doneFile.getBoolean("userMapRepaired", false)) { return; } - EssentialsLogger.info("Starting usermap repair"); + EssentialsLogger.getLogger().info("Starting usermap repair"); final File userdataFolder = new File(ess.getDataFolder(), "userdata"); if (!userdataFolder.isDirectory()) { - EssentialsLogger.warning("Missing userdata folder, aborting"); + EssentialsLogger.getLogger().warning("Missing userdata folder, aborting"); return; } final File[] files = userdataFolder.listFiles(YML_FILTER); @@ -966,11 +966,11 @@ private void repairUserMap() { } if (index % 1000 == 0) { - EssentialsLogger.info("Reading: " + format.format((100d * (double) index) / files.length) + EssentialsLogger.getLogger().info("Reading: " + format.format((100d * (double) index) / files.length) + "%"); } } catch (final IOException e) { - EssentialsLogger.log(Level.SEVERE, "Error while reading file: ", e); + EssentialsLogger.getLogger().log(Level.SEVERE, "Error while reading file: ", e); return; } } @@ -980,7 +980,7 @@ private void repairUserMap() { doneFile.setProperty("userMapRepaired", true); doneFile.save(); - EssentialsLogger.info("Completed usermap repair."); + EssentialsLogger.getLogger().info("Completed usermap repair."); } public void beforeSettings() { diff --git a/Essentials/src/main/java/com/earth2me/essentials/I18n.java b/Essentials/src/main/java/com/earth2me/essentials/I18n.java index 372e3809f07..ece2a90bca8 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/I18n.java +++ b/Essentials/src/main/java/com/earth2me/essentials/I18n.java @@ -88,7 +88,7 @@ private String translate(final String string) { } } catch (final MissingResourceException ex) { if (ess == null || ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.WARNING, String.format("Missing translation key \"%s\" in translation file %s", ex.getKey(), localeBundle.getLocale().toString()), ex); + EssentialsLogger.getLogger().log(Level.WARNING, String.format("Missing translation key \"%s\" in translation file %s", ex.getKey(), localeBundle.getLocale().toString()), ex); } return defaultBundle.getString(string); } @@ -101,7 +101,7 @@ public String format(final String string, final Object... objects) { try { messageFormat = new MessageFormat(format); } catch (final IllegalArgumentException e) { - EssentialsLogger.log(Level.SEVERE, "Invalid Translation key for '" + string + "': " + e.getMessage()); + EssentialsLogger.getLogger().log(Level.SEVERE, "Invalid Translation key for '" + string + "': " + e.getMessage()); format = format.replaceAll("\\{(\\D*?)\\}", "\\[$1\\]"); messageFormat = new MessageFormat(format); } @@ -125,7 +125,7 @@ public void updateLocale(final String loc) { } ResourceBundle.clearCache(); messageFormatCache = new HashMap<>(); - EssentialsLogger.log(Level.INFO, "Using locale " + currentLocale.toString()); + EssentialsLogger.getLogger().log(Level.INFO, "Using locale " + currentLocale.toString()); try { localeBundle = ResourceBundle.getBundle(MESSAGES, currentLocale, new UTF8PropertiesControl()); } catch (final MissingResourceException ex) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/Jails.java b/Essentials/src/main/java/com/earth2me/essentials/Jails.java index febede9a071..b974dc1fa13 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Jails.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Jails.java @@ -74,7 +74,7 @@ private void registerListeners() { final JailListener blockListener = new JailListener(); pluginManager.registerEvents(blockListener, ess); if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "Registering Jail listener"); + EssentialsLogger.getLogger().log(Level.INFO, "Registering Jail listener"); } } @@ -266,9 +266,9 @@ public void onJailPlayerRespawn(final PlayerRespawnEvent event) { event.setRespawnLocation(getJail(user.getJail())); } catch (final Exception ex) { if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex); + EssentialsLogger.getLogger().log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex); } else { - EssentialsLogger.log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())); + EssentialsLogger.getLogger().log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())); } } } @@ -284,9 +284,9 @@ public void onJailPlayerTeleport(final PlayerTeleportEvent event) { event.setTo(getJail(user.getJail())); } catch (final Exception ex) { if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex); + EssentialsLogger.getLogger().log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex); } else { - EssentialsLogger.log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())); + EssentialsLogger.getLogger().log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())); } } user.sendMessage(tl("jailMessage")); @@ -304,9 +304,9 @@ public void onJailPlayerJoin(final PlayerJoinEvent event) { final CompletableFuture future = new CompletableFuture<>(); future.exceptionally(ex -> { if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex); + EssentialsLogger.getLogger().log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex); } else { - EssentialsLogger.log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())); + EssentialsLogger.getLogger().log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())); } return false; }); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Kit.java b/Essentials/src/main/java/com/earth2me/essentials/Kit.java index f2cebb38db4..5ddfd76478a 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Kit.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Kit.java @@ -147,7 +147,7 @@ public List getItems() throws Exception { } throw new Exception("Invalid item list"); } catch (final Exception e) { - EssentialsLogger.log(Level.WARNING, "Error parsing kit " + kitName + ": " + e.getMessage()); + EssentialsLogger.getLogger().log(Level.WARNING, "Error parsing kit " + kitName + ": " + e.getMessage()); throw new Exception(tl("kitError2"), e); } } @@ -192,7 +192,7 @@ public boolean expandItems(final User user, final List items) throws Exc if (kitItem.startsWith("@")) { if (ess.getSerializationProvider() == null) { - EssentialsLogger.log(Level.WARNING, tl("kitError3", kitName, user.getName())); + EssentialsLogger.getLogger().log(Level.WARNING, tl("kitError3", kitName, user.getName())); continue; } stack = ess.getSerializationProvider().deserializeItem(Base64Coder.decodeLines(kitItem.substring(1))); @@ -286,7 +286,7 @@ public boolean expandItems(final User user, final List items) throws Exc } } catch (final Exception e) { user.getBase().updateInventory(); - EssentialsLogger.log(Level.WARNING, e.getMessage()); + EssentialsLogger.getLogger().log(Level.WARNING, e.getMessage()); throw new Exception(tl("kitError2"), e); } return true; diff --git a/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java b/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java index 34f2998aff7..a222a15f64d 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java +++ b/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java @@ -138,7 +138,7 @@ public boolean canSpawn(final IEssentials ess) { return true; } catch (final Throwable npe) { if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "Itemstack is invalid", npe); + EssentialsLogger.getLogger().log(Level.INFO, "Itemstack is invalid", npe); } return false; } @@ -150,7 +150,7 @@ public void parseStringMeta(final CommandSource sender, final boolean allowUnsaf stack = ess.getServer().getUnsafe().modifyItemStack(stack, Joiner.on(' ').join(Arrays.asList(string).subList(fromArg, string.length))); } catch (final NullPointerException npe) { if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "Itemstack is invalid", npe); + EssentialsLogger.getLogger().log(Level.INFO, "Itemstack is invalid", npe); } } catch (final NoSuchMethodError nsme) { throw new Exception(tl("noMetaJson"), nsme); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Mob.java b/Essentials/src/main/java/com/earth2me/essentials/Mob.java index 689eabe49c6..7f4650b3d1e 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Mob.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Mob.java @@ -164,7 +164,7 @@ public static Mob fromBukkitType(final EntityType type) { public Entity spawn(final World world, final Server server, final Location loc) throws MobException { final Entity entity = world.spawn(loc, this.bukkitType.getEntityClass()); if (entity == null) { - EssentialsLogger.log(Level.WARNING, tl("unableToSpawnMob")); + EssentialsLogger.getLogger().log(Level.WARNING, tl("unableToSpawnMob")); throw new MobException(); } return entity; diff --git a/Essentials/src/main/java/com/earth2me/essentials/MobData.java b/Essentials/src/main/java/com/earth2me/essentials/MobData.java index 7ed68db781c..10c35197b8d 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/MobData.java +++ b/Essentials/src/main/java/com/earth2me/essentials/MobData.java @@ -407,7 +407,7 @@ public void setData(final Entity spawned, final Player target, final String rawD } } } else { - EssentialsLogger.warning("Unknown mob data type: " + this.toString()); + EssentialsLogger.getLogger().warning("Unknown mob data type: " + this.toString()); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/Settings.java b/Essentials/src/main/java/com/earth2me/essentials/Settings.java index 1d465e6ecdc..1400878e839 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Settings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Settings.java @@ -385,7 +385,7 @@ private Map _getCommandCosts() { final String command = entry.getKey(); final CommentedConfigurationNode node = entry.getValue(); if (command.charAt(0) == '/') { - EssentialsLogger.warning("Invalid command cost. '" + command + "' should not start with '/'."); + EssentialsLogger.getLogger().warning("Invalid command cost. '" + command + "' should not start with '/'."); } try { if (ConfigurateUtil.isDouble(node)) { @@ -398,10 +398,10 @@ private Map _getCommandCosts() { final double cost = Double.parseDouble(costString.trim().replace("$", "").replace(getCurrencySymbol(), "").replaceAll("\\W", "")); newMap.put(command.toLowerCase(Locale.ENGLISH), BigDecimal.valueOf(cost)); } else { - EssentialsLogger.warning("Invalid command cost for: " + command); + EssentialsLogger.getLogger().warning("Invalid command cost for: " + command); } } catch (final Exception ex) { - EssentialsLogger.warning("Invalid command cost for: " + command); + EssentialsLogger.getLogger().warning("Invalid command cost for: " + command); } } return newMap; @@ -586,7 +586,7 @@ public String getChatFormat(final String group) { chatFormats.put(group, mFormat); } if (isDebug()) { - EssentialsLogger.info(String.format("Found format '%s' for group '%s'", mFormat, group)); + EssentialsLogger.getLogger().info(String.format("Found format '%s' for group '%s'", mFormat, group)); } return mFormat; } @@ -684,7 +684,7 @@ public void reloadConfig() { boolean mapModified = false; if (!disabledBukkitCommands.isEmpty()) { if (isDebug()) { - EssentialsLogger.log(Level.INFO, "Re-adding " + disabledBukkitCommands.size() + " disabled commands!"); + EssentialsLogger.getLogger().log(Level.INFO, "Re-adding " + disabledBukkitCommands.size() + " disabled commands!"); } ess.getKnownCommandsProvider().getKnownCommands().putAll(disabledBukkitCommands); disabledBukkitCommands.clear(); @@ -696,12 +696,12 @@ public void reloadConfig() { final Command toDisable = ess.getPluginCommand(effectiveAlias); if (toDisable != null) { if (isDebug()) { - EssentialsLogger.log(Level.INFO, "Attempting removal of " + effectiveAlias); + EssentialsLogger.getLogger().log(Level.INFO, "Attempting removal of " + effectiveAlias); } final Command removed = ess.getKnownCommandsProvider().getKnownCommands().remove(effectiveAlias); if (removed != null) { if (isDebug()) { - EssentialsLogger.log(Level.INFO, "Adding command " + effectiveAlias + " to disabled map!"); + EssentialsLogger.getLogger().log(Level.INFO, "Adding command " + effectiveAlias + " to disabled map!"); } disabledBukkitCommands.put(effectiveAlias, removed); } @@ -718,7 +718,7 @@ public void reloadConfig() { if (mapModified) { if (isDebug()) { - EssentialsLogger.log(Level.INFO, "Syncing commands"); + EssentialsLogger.getLogger().log(Level.INFO, "Syncing commands"); } if (reloadCount.get() < 2) { ess.scheduleSyncDelayedTask(() -> ess.getSyncCommandsProvider().syncCommands()); @@ -797,7 +797,7 @@ private List _getItemSpawnBlacklist() { //noinspection deprecation final IItemDb itemDb = ess.getItemDb(); if (itemDb == null || !itemDb.isReady()) { - EssentialsLogger.log(Level.FINE, "Skipping item spawn blacklist read; item DB not yet loaded."); + EssentialsLogger.getLogger().log(Level.FINE, "Skipping item spawn blacklist read; item DB not yet loaded."); return epItemSpwn; } for (String itemName : config.getString("item-spawn-blacklist", "").split(",")) { @@ -809,7 +809,7 @@ private List _getItemSpawnBlacklist() { final ItemStack iStack = itemDb.get(itemName); epItemSpwn.add(iStack.getType()); } catch (final Exception ex) { - EssentialsLogger.log(Level.SEVERE, tl("unknownItemInList", itemName, "item-spawn-blacklist"), ex); + EssentialsLogger.getLogger().log(Level.SEVERE, tl("unknownItemInList", itemName, "item-spawn-blacklist"), ex); } } return epItemSpwn; @@ -837,7 +837,7 @@ private List _getEnabledSigns() { try { newSigns.add(Signs.valueOf(signName).getSign()); } catch (final Exception ex) { - EssentialsLogger.log(Level.SEVERE, tl("unknownItemInList", signName, "enabledSigns")); + EssentialsLogger.getLogger().log(Level.SEVERE, tl("unknownItemInList", signName, "enabledSigns")); continue; } signsEnabled = true; @@ -951,7 +951,7 @@ public List getProtectList(final String configName) { } if (mat == null) { - EssentialsLogger.log(Level.SEVERE, tl("unknownItemInList", itemName, configName)); + EssentialsLogger.getLogger().log(Level.SEVERE, tl("unknownItemInList", itemName, configName)); } else { list.add(mat); } @@ -1573,7 +1573,7 @@ private Map _getCommandCooldowns() { try { pattern = Pattern.compile(cmdEntry.substring(1)); } catch (final PatternSyntaxException e) { - EssentialsLogger.warning("Command cooldown error: " + e.getMessage()); + EssentialsLogger.getLogger().warning("Command cooldown error: " + e.getMessage()); } } else { // Escape above Regex @@ -1595,12 +1595,12 @@ private Map _getCommandCooldowns() { } } if (!(value instanceof Number)) { - EssentialsLogger.warning("Command cooldown error: '" + value + "' is not a valid cooldown"); + EssentialsLogger.getLogger().warning("Command cooldown error: '" + value + "' is not a valid cooldown"); continue; } final double cooldown = ((Number) value).doubleValue(); if (cooldown < 1) { - EssentialsLogger.warning("Command cooldown with very short " + cooldown + " cooldown."); + EssentialsLogger.getLogger().warning("Command cooldown with very short " + cooldown + " cooldown."); } result.put(pattern, (long) cooldown * 1000); // convert to milliseconds @@ -1626,7 +1626,7 @@ public Entry getCommandCooldownEntry(final String label) { // Check if label matches current pattern (command-cooldown in config) final boolean matches = entry.getKey().matcher(label).matches(); if (isDebug()) { - EssentialsLogger.info(String.format("Checking command '%s' against cooldown '%s': %s", label, entry.getKey(), matches)); + EssentialsLogger.getLogger().info(String.format("Checking command '%s' against cooldown '%s': %s", label, entry.getKey(), matches)); } if (matches) { @@ -1693,7 +1693,7 @@ private List _getUnprotectedSign() { try { newSigns.add(Signs.valueOf(signName).getSign()); } catch (final Exception ex) { - EssentialsLogger.log(Level.SEVERE, tl("unknownItemInList", signName, "unprotected-sign-names")); + EssentialsLogger.getLogger().log(Level.SEVERE, tl("unknownItemInList", signName, "unprotected-sign-names")); } } return newSigns; @@ -1878,7 +1878,7 @@ private Set> _getNickBlacklist() { try { blacklist.add(Pattern.compile(entry).asPredicate()); } catch (final PatternSyntaxException e) { - EssentialsLogger.warning("Invalid nickname blacklist regex: " + entry); + EssentialsLogger.getLogger().warning("Invalid nickname blacklist regex: " + entry); } }); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Teleport.java b/Essentials/src/main/java/com/earth2me/essentials/Teleport.java index 30291b4bb54..91e481aa357 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Teleport.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Teleport.java @@ -325,7 +325,7 @@ void respawnNow(final IUser teleportee, final TeleportCause cause) throws Except now(teleportee, new LocationTarget(bed), cause); } else { if (ess.getSettings().isDebug()) { - EssentialsLogger.info("Could not find bed spawn, forcing respawn event."); + EssentialsLogger.getLogger().info("Could not find bed spawn, forcing respawn event."); } final PlayerRespawnEvent pre = new PlayerRespawnEvent(player, player.getWorld().getSpawnLocation(), false); ess.getServer().getPluginManager().callEvent(pre); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Trade.java b/Essentials/src/main/java/com/earth2me/essentials/Trade.java index c5d2bc24788..58c03af6df9 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Trade.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Trade.java @@ -79,7 +79,7 @@ public static void log(final String type, final String subtype, final String eve try { fw = new FileWriter(new File(ess.getDataFolder(), "trade.log"), true); } catch (final IOException ex) { - EssentialsLogger.log(Level.SEVERE, null, ex); + EssentialsLogger.getLogger().log(Level.SEVERE, null, ex); } } final StringBuilder sb = new StringBuilder(); @@ -158,7 +158,7 @@ public static void log(final String type, final String subtype, final String eve fw.write(sb.toString()); fw.flush(); } catch (final IOException ex) { - EssentialsLogger.log(Level.SEVERE, null, ex); + EssentialsLogger.getLogger().log(Level.SEVERE, null, ex); } } @@ -167,7 +167,7 @@ public static void closeLog() { try { fw.close(); } catch (final IOException ex) { - EssentialsLogger.log(Level.SEVERE, null, ex); + EssentialsLogger.getLogger().log(Level.SEVERE, null, ex); } fw = null; } @@ -189,7 +189,7 @@ public void isAffordableFor(final IUser user) throws ChargeException { public void isAffordableFor(final IUser user, final CompletableFuture future) { if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "checking if " + user.getName() + " can afford charge."); + EssentialsLogger.getLogger().log(Level.INFO, "checking if " + user.getName() + " can afford charge."); } if (getMoney() != null && getMoney().signum() > 0 && !user.canAfford(getMoney())) { @@ -220,7 +220,7 @@ public boolean pay(final IUser user) throws MaxMoneyException { public Map pay(final IUser user, final OverflowType type) throws MaxMoneyException { if (getMoney() != null && getMoney().signum() > 0) { if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "paying user " + user.getName() + " via trade " + getMoney().toPlainString()); + EssentialsLogger.getLogger().log(Level.INFO, "paying user " + user.getName() + " via trade " + getMoney().toPlainString()); } user.giveMoney(getMoney()); } @@ -232,7 +232,7 @@ public Map pay(final IUser user, final OverflowType type) th switch (type) { case ABORT: if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "abort paying " + user.getName() + " itemstack " + getItemStack().toString() + " due to lack of inventory space "); + EssentialsLogger.getLogger().log(Level.INFO, "abort paying " + user.getName() + " itemstack " + getItemStack().toString() + " due to lack of inventory space "); } return overFlow; @@ -243,7 +243,7 @@ public Map pay(final IUser user, final OverflowType type) th user.getBase().updateInventory(); if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "paying " + user.getName() + " partial itemstack " + getItemStack().toString() + " with overflow " + returnStack.get(0).toString()); + EssentialsLogger.getLogger().log(Level.INFO, "paying " + user.getName() + " partial itemstack " + getItemStack().toString() + " with overflow " + returnStack.get(0).toString()); } return returnStack; @@ -268,12 +268,12 @@ public Map pay(final IUser user, final OverflowType type) th } } if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "paying " + user.getName() + " partial itemstack " + getItemStack().toString() + " and dropping overflow " + leftOver.get(0).toString()); + EssentialsLogger.getLogger().log(Level.INFO, "paying " + user.getName() + " partial itemstack " + getItemStack().toString() + " and dropping overflow " + leftOver.get(0).toString()); } break; } } else if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "paying " + user.getName() + " itemstack " + getItemStack().toString()); + EssentialsLogger.getLogger().log(Level.INFO, "paying " + user.getName() + " itemstack " + getItemStack().toString()); } user.getBase().updateInventory(); } @@ -299,11 +299,11 @@ public void charge(final IUser user) throws ChargeException { public void charge(final IUser user, final CompletableFuture future) { if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "attempting to charge user " + user.getName()); + EssentialsLogger.getLogger().log(Level.INFO, "attempting to charge user " + user.getName()); } if (getMoney() != null) { if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "charging user " + user.getName() + " money " + getMoney().toPlainString()); + EssentialsLogger.getLogger().log(Level.INFO, "charging user " + user.getName() + " money " + getMoney().toPlainString()); } if (!user.canAfford(getMoney()) && getMoney().signum() > 0) { future.completeExceptionally(new ChargeException(tl("notEnoughMoney", NumberUtil.displayCurrency(getMoney(), ess)))); @@ -313,7 +313,7 @@ public void charge(final IUser user, final CompletableFuture future) { } if (getItemStack() != null) { if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "charging user " + user.getName() + " itemstack " + getItemStack().toString()); + EssentialsLogger.getLogger().log(Level.INFO, "charging user " + user.getName() + " itemstack " + getItemStack().toString()); } if (!user.getBase().getInventory().containsAtLeast(getItemStack(), getItemStack().getAmount())) { future.completeExceptionally(new ChargeException(tl("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase(Locale.ENGLISH).replace("_", " ")))); @@ -332,7 +332,7 @@ public void charge(final IUser user, final CompletableFuture future) { } if (getExperience() != null) { if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "charging user " + user.getName() + " exp " + getExperience()); + EssentialsLogger.getLogger().log(Level.INFO, "charging user " + user.getName() + " exp " + getExperience()); } final int experience = SetExpFix.getTotalExperience(user.getBase()); if (experience < getExperience() && getExperience() > 0) { @@ -342,7 +342,7 @@ public void charge(final IUser user, final CompletableFuture future) { SetExpFix.setTotalExperience(user.getBase(), experience - getExperience()); } if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "charge user " + user.getName() + " completed"); + EssentialsLogger.getLogger().log(Level.INFO, "charge user " + user.getName() + " completed"); } } @@ -379,7 +379,7 @@ public BigDecimal getCommandCost(final IUser user) { } if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "calculated command (" + command + ") cost for " + user.getName() + " as " + cost); + EssentialsLogger.getLogger().log(Level.INFO, "calculated command (" + command + ") cost for " + user.getName() + " as " + cost); } } if (cost.signum() != 0 && (user.isAuthorized("essentials.nocommandcost.all") || user.isAuthorized("essentials.nocommandcost." + command))) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/UUIDMap.java b/Essentials/src/main/java/com/earth2me/essentials/UUIDMap.java index 403849c3116..347b93dfa47 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/UUIDMap.java +++ b/Essentials/src/main/java/com/earth2me/essentials/UUIDMap.java @@ -52,7 +52,7 @@ public void loadAllUsers(final ConcurrentSkipListMap names, final } if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "Reading usermap from disk"); + EssentialsLogger.getLogger().log(Level.INFO, "Reading usermap from disk"); } if (loading) { @@ -100,7 +100,7 @@ public void writeUUIDMap() { public void forceWriteUUIDMap() { if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "Forcing usermap write to disk"); + EssentialsLogger.getLogger().log(Level.INFO, "Forcing usermap write to disk"); } pendingWrite = true; writeTaskRunnable.run(); diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index e397fd60ab7..bbdf2a67b96 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -127,7 +127,7 @@ public boolean isAuthorized(final IEssentialsCommand cmd, final String permissio public boolean isAuthorized(final String node) { final boolean result = isAuthorizedCheck(node); if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "checking if " + base.getName() + " has " + node + " - " + result); + EssentialsLogger.getLogger().log(Level.INFO, "checking if " + base.getName() + " has " + node + " - " + result); } return result; } @@ -136,7 +136,7 @@ public boolean isAuthorized(final String node) { public boolean isPermissionSet(final String node) { final boolean result = isPermSetCheck(node); if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "checking if " + base.getName() + " has " + node + " (set-explicit) - " + result); + EssentialsLogger.getLogger().log(Level.INFO, "checking if " + base.getName() + " has " + node + " (set-explicit) - " + result); } return result; } @@ -158,9 +158,9 @@ private boolean isAuthorizedCheck(final String node) { return ess.getPermissionsHandler().hasPermission(base, node); } catch (final Exception ex) { if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage(), ex); + EssentialsLogger.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage(), ex); } else { - EssentialsLogger.log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage()); + EssentialsLogger.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage()); } return false; @@ -176,9 +176,9 @@ private boolean isPermSetCheck(final String node) { return ess.getPermissionsHandler().isPermissionSet(base, node); } catch (final Exception ex) { if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage(), ex); + EssentialsLogger.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage(), ex); } else { - EssentialsLogger.log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage()); + EssentialsLogger.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage()); } return false; @@ -194,9 +194,9 @@ private TriState isAuthorizedExactCheck(final String node) { return ess.getPermissionsHandler().isPermissionSetExact(base, node); } catch (final Exception ex) { if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage(), ex); + EssentialsLogger.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage(), ex); } else { - EssentialsLogger.log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage()); + EssentialsLogger.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage()); } return TriState.UNSET; @@ -279,7 +279,7 @@ public void takeMoney(final BigDecimal value, final CommandSource initiator, fin try { setMoney(getMoney().subtract(value), cause); } catch (final MaxMoneyException ex) { - EssentialsLogger.log(Level.WARNING, "Invalid call to takeMoney, total balance can't be more than the max-money limit.", ex); + EssentialsLogger.getLogger().log(Level.WARNING, "Invalid call to takeMoney, total balance can't be more than the max-money limit.", ex); } sendMessage(tl("takenFromAccount", NumberUtil.displayCurrency(value, ess))); if (initiator != null) { @@ -518,7 +518,7 @@ public void setDisplayNick() { this.getBase().setPlayerListName(name); } catch (final IllegalArgumentException e) { if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "Playerlist for " + name + " was not updated. Name clashed with another online player."); + EssentialsLogger.getLogger().log(Level.INFO, "Playerlist for " + name + " was not updated. Name clashed with another online player."); } } } @@ -567,7 +567,7 @@ public BigDecimal getMoney() { final BigDecimal value = _getMoney(); final long elapsed = System.nanoTime() - start; if (elapsed > ess.getSettings().getEconomyLagWarning()) { - EssentialsLogger.log(Level.INFO, "Lag Notice - Slow Economy Response - Request took over " + elapsed / 1000000.0 + "ms!"); + EssentialsLogger.getLogger().log(Level.INFO, "Lag Notice - Slow Economy Response - Request took over " + elapsed / 1000000.0 + "ms!"); } return value; } @@ -580,7 +580,7 @@ public void setMoney(final BigDecimal value) throws MaxMoneyException { private BigDecimal _getMoney() { if (ess.getSettings().isEcoDisabled()) { if (ess.getSettings().isDebug()) { - EssentialsLogger.info("Internal economy functions disabled, aborting balance check."); + EssentialsLogger.getLogger().info("Internal economy functions disabled, aborting balance check."); } return BigDecimal.ZERO; } @@ -594,7 +594,7 @@ private BigDecimal _getMoney() { public void setMoney(final BigDecimal value, final UserBalanceUpdateEvent.Cause cause) throws MaxMoneyException { if (ess.getSettings().isEcoDisabled()) { if (ess.getSettings().isDebug()) { - EssentialsLogger.info("Internal economy functions disabled, aborting balance change."); + EssentialsLogger.getLogger().info("Internal economy functions disabled, aborting balance change."); } return; } @@ -869,7 +869,7 @@ public boolean isGodModeEnabledRaw() { public String getGroup() { final String result = ess.getPermissionsHandler().getGroup(base); if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "looking up groupname of " + base.getName() + " - " + result); + EssentialsLogger.getLogger().log(Level.INFO, "looking up groupname of " + base.getName() + " - " + result); } return result; } @@ -878,7 +878,7 @@ public String getGroup() { public boolean inGroup(final String group) { final boolean result = ess.getPermissionsHandler().inGroup(base, group); if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "checking if " + base.getName() + " is in group " + group + " - " + result); + EssentialsLogger.getLogger().log(Level.INFO, "checking if " + base.getName() + " is in group " + group + " - " + result); } return result; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/UserData.java b/Essentials/src/main/java/com/earth2me/essentials/UserData.java index 6d32169cb34..1e3bca83948 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/UserData.java +++ b/Essentials/src/main/java/com/earth2me/essentials/UserData.java @@ -51,7 +51,7 @@ protected UserData(final Player base, final IEssentials ess) { try { filename = base.getUniqueId().toString(); } catch (final Throwable ex) { - EssentialsLogger.warning("Falling back to old username system for " + base.getName()); + EssentialsLogger.getLogger().warning("Falling back to old username system for " + base.getName()); filename = base.getName(); } @@ -85,14 +85,14 @@ public final void reloadConfig() { try { holder = config.getRootNode().get(UserConfigHolder.class); } catch (SerializationException e) { - EssentialsLogger.log(Level.SEVERE, "Error while reading user config: " + e.getMessage(), e); + EssentialsLogger.getLogger().log(Level.SEVERE, "Error while reading user config: " + e.getMessage(), e); throw new RuntimeException(e); } config.setSaveHook(() -> { try { config.getRootNode().set(UserConfigHolder.class, holder); } catch (SerializationException e) { - EssentialsLogger.log(Level.SEVERE, "Error while saving user config: " + e.getMessage(), e); + EssentialsLogger.getLogger().log(Level.SEVERE, "Error while saving user config: " + e.getMessage(), e); throw new RuntimeException(e); } }); diff --git a/Essentials/src/main/java/com/earth2me/essentials/UserMap.java b/Essentials/src/main/java/com/earth2me/essentials/UserMap.java index 12b9bbd6e98..40cc732b3d6 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/UserMap.java +++ b/Essentials/src/main/java/com/earth2me/essentials/UserMap.java @@ -95,7 +95,7 @@ public User getUser(final String name) { final String sanitizedName = StringUtil.safeString(name); try { if (ess.getSettings().isDebug()) { - EssentialsLogger.warning("Looking up username " + name + " (" + sanitizedName + ") ..."); + EssentialsLogger.getLogger().warning("Looking up username " + name + " (" + sanitizedName + ") ..."); } if (names.containsKey(sanitizedName)) { @@ -104,12 +104,12 @@ public User getUser(final String name) { } if (ess.getSettings().isDebug()) { - EssentialsLogger.warning(name + "(" + sanitizedName + ") has no known usermap entry"); + EssentialsLogger.getLogger().warning(name + "(" + sanitizedName + ") has no known usermap entry"); } final File userFile = getUserFileFromString(sanitizedName); if (userFile.exists()) { - EssentialsLogger.info("Importing user " + name + " to usermap."); + EssentialsLogger.getLogger().info("Importing user " + name + " to usermap."); final User user = new User(new OfflinePlayer(sanitizedName, ess.getServer()), ess); trackUUID(user.getBase().getUniqueId(), user.getName(), true); return user; @@ -117,7 +117,7 @@ public User getUser(final String name) { return null; } catch (final UncheckedExecutionException ex) { if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.WARNING, "Exception while getting user for " + name + " (" + sanitizedName + ")", ex); + EssentialsLogger.getLogger().log(Level.WARNING, "Exception while getting user for " + name + " (" + sanitizedName + ")", ex); } return null; } @@ -132,7 +132,7 @@ public User getUser(final UUID uuid) { } } catch (final ExecutionException | UncheckedExecutionException ex) { if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.WARNING, "Exception while getting user for " + uuid, ex); + EssentialsLogger.getLogger().log(Level.WARNING, "Exception while getting user for " + uuid, ex); } return null; } @@ -148,11 +148,11 @@ public void trackUUID(final UUID uuid, final String name, final boolean replace) uuidMap.writeUUIDMap(); } else if (!isUUIDMatch(uuid, keyName)) { if (replace) { - EssentialsLogger.info("Found new UUID for " + name + ". Replacing " + names.get(keyName).toString() + " with " + uuid.toString()); + EssentialsLogger.getLogger().info("Found new UUID for " + name + ". Replacing " + names.get(keyName).toString() + " with " + uuid.toString()); names.put(keyName, uuid); uuidMap.writeUUIDMap(); } else { - EssentialsLogger.log(Level.INFO, MessageFormat.format(WARN_UUID_NOT_REPLACE, uuid.toString(), name, names.get(keyName).toString()), new RuntimeException()); + EssentialsLogger.getLogger().log(Level.INFO, MessageFormat.format(WARN_UUID_NOT_REPLACE, uuid.toString(), name, names.get(keyName).toString()), new RuntimeException()); } } } @@ -193,7 +193,7 @@ public User load(final org.bukkit.OfflinePlayer player) throws UserDoesNotExistE if (player instanceof Player) { if (ess.getSettings().isDebug()) { - EssentialsLogger.info("Loading online OfflinePlayer into user map..."); + EssentialsLogger.getLogger().info("Loading online OfflinePlayer into user map..."); } final User user = new User((Player) player, ess); trackUUID(player.getUniqueId(), player.getName(), true); @@ -202,7 +202,7 @@ public User load(final org.bukkit.OfflinePlayer player) throws UserDoesNotExistE final File userFile = getUserFileFromID(player.getUniqueId()); if (ess.getSettings().isDebug()) { - EssentialsLogger.info("Loading OfflinePlayer into user map. Has data: " + userFile.exists() + " for " + player); + EssentialsLogger.getLogger().info("Loading OfflinePlayer into user map. Has data: " + userFile.exists() + " for " + player); } final OfflinePlayer essPlayer = new OfflinePlayer(player.getUniqueId(), ess.getServer()); @@ -211,7 +211,7 @@ public User load(final org.bukkit.OfflinePlayer player) throws UserDoesNotExistE essPlayer.setName(user.getLastAccountName()); } else { if (ess.getSettings().isDebug()) { - EssentialsLogger.info("OfflinePlayer usermap load saving user data for " + player); + EssentialsLogger.getLogger().info("OfflinePlayer usermap load saving user data for " + player); } // this code makes me sad @@ -242,7 +242,7 @@ public void invalidateAll() { public void removeUser(final String name) { if (names == null) { - EssentialsLogger.warning("Name collection is null, cannot remove user."); + EssentialsLogger.getLogger().warning("Name collection is null, cannot remove user."); return; } final UUID uuid = names.get(name); @@ -308,7 +308,7 @@ public File getUserFileFromString(final String name) { public User getUserFromBukkit(String name) { name = StringUtil.safeString(name); if (ess.getSettings().isDebug()) { - EssentialsLogger.warning("Using potentially blocking Bukkit UUID lookup for: " + name); + EssentialsLogger.getLogger().warning("Using potentially blocking Bukkit UUID lookup for: " + name); } // Don't attempt to look up entirely invalid usernames if (name == null || !validUserPattern.matcher(name).matches()) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/Warps.java b/Essentials/src/main/java/com/earth2me/essentials/Warps.java index 4086e815996..7938397cbd6 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Warps.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Warps.java @@ -133,7 +133,7 @@ public final void reloadConfig() { warpPoints.put(new StringIgnoreCase(name), conf); } } catch (final Exception ex) { - EssentialsLogger.log(Level.WARNING, tl("loadWarpError", filename), ex); + EssentialsLogger.getLogger().log(Level.WARNING, tl("loadWarpError", filename), ex); } } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/api/Economy.java b/Essentials/src/main/java/com/earth2me/essentials/api/Economy.java index 103e5f9d598..af3cebaf052 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/api/Economy.java +++ b/Essentials/src/main/java/com/earth2me/essentials/api/Economy.java @@ -53,8 +53,8 @@ private static void createNPCFile(String name) { final UUID npcUUID = UUID.nameUUIDFromBytes(("NPC:" + name).getBytes(Charsets.UTF_8)); final File npcFile = new File(folder, npcUUID + ".yml"); if (npcFile.exists()) { - EssentialsLogger.log(Level.SEVERE, MessageFormat.format(WARN_NPC_RECREATE_1, name, npcUUID.toString()), new RuntimeException()); - EssentialsLogger.log(Level.SEVERE, WARN_NPC_RECREATE_2); + EssentialsLogger.getLogger().log(Level.SEVERE, MessageFormat.format(WARN_NPC_RECREATE_1, name, npcUUID.toString()), new RuntimeException()); + EssentialsLogger.getLogger().log(Level.SEVERE, WARN_NPC_RECREATE_2); } final EssentialsUserConfiguration npcConfig = new EssentialsUserConfiguration(name, npcUUID, npcFile); npcConfig.load(); @@ -89,7 +89,7 @@ private static User getUserByName(final String name) { if (player != null) { user = ess.getUser(player.getUniqueId()); if (user != null) { - EssentialsLogger.log(Level.INFO, MessageFormat.format(WARN_PLAYER_UUID_NO_NAME, name, player.getUniqueId().toString()), new RuntimeException()); + EssentialsLogger.getLogger().log(Level.INFO, MessageFormat.format(WARN_PLAYER_UUID_NO_NAME, name, player.getUniqueId().toString()), new RuntimeException()); } } } @@ -189,7 +189,7 @@ public static void setMoney(final String name, final double balance) throws User try { setMoney(name, BigDecimal.valueOf(balance)); } catch (final ArithmeticException e) { - EssentialsLogger.log(Level.WARNING, "Failed to set balance of " + name + " to " + balance + ": " + e.getMessage(), e); + EssentialsLogger.getLogger().log(Level.WARNING, "Failed to set balance of " + name + " to " + balance + ": " + e.getMessage(), e); } } @@ -267,7 +267,7 @@ public static void add(final String name, final double amount) throws UserDoesNo try { add(name, BigDecimal.valueOf(amount)); } catch (final ArithmeticException e) { - EssentialsLogger.log(Level.WARNING, "Failed to add " + amount + " to balance of " + name + ": " + e.getMessage(), e); + EssentialsLogger.getLogger().log(Level.WARNING, "Failed to add " + amount + " to balance of " + name + ": " + e.getMessage(), e); } } @@ -339,7 +339,7 @@ public static void subtract(final String name, final double amount) throws UserD try { substract(name, BigDecimal.valueOf(amount)); } catch (final ArithmeticException e) { - EssentialsLogger.log(Level.WARNING, "Failed to subtract " + amount + " of balance of " + name + ": " + e.getMessage(), e); + EssentialsLogger.getLogger().log(Level.WARNING, "Failed to subtract " + amount + " of balance of " + name + ": " + e.getMessage(), e); } } @@ -409,7 +409,7 @@ public static void divide(final String name, final double amount) throws UserDoe try { divide(name, BigDecimal.valueOf(amount)); } catch (final ArithmeticException e) { - EssentialsLogger.log(Level.WARNING, "Failed to divide balance of " + name + " by " + amount + ": " + e.getMessage(), e); + EssentialsLogger.getLogger().log(Level.WARNING, "Failed to divide balance of " + name + " by " + amount + ": " + e.getMessage(), e); } } @@ -481,7 +481,7 @@ public static void multiply(final String name, final double amount) throws UserD try { multiply(name, BigDecimal.valueOf(amount)); } catch (final ArithmeticException e) { - EssentialsLogger.log(Level.WARNING, "Failed to multiply balance of " + name + " by " + amount + ": " + e.getMessage(), e); + EssentialsLogger.getLogger().log(Level.WARNING, "Failed to multiply balance of " + name + " by " + amount + ": " + e.getMessage(), e); } } @@ -602,7 +602,7 @@ public static boolean hasEnough(final String name, final double amount) throws U try { return hasEnough(name, BigDecimal.valueOf(amount)); } catch (final ArithmeticException e) { - EssentialsLogger.log(Level.WARNING, "Failed to compare balance of " + name + " with " + amount + ": " + e.getMessage(), e); + EssentialsLogger.getLogger().log(Level.WARNING, "Failed to compare balance of " + name + " with " + amount + ": " + e.getMessage(), e); return false; } } @@ -663,7 +663,7 @@ public static boolean hasMore(final String name, final double amount) throws Use try { return hasMore(name, BigDecimal.valueOf(amount)); } catch (final ArithmeticException e) { - EssentialsLogger.log(Level.WARNING, "Failed to compare balance of " + name + " with " + amount + ": " + e.getMessage(), e); + EssentialsLogger.getLogger().log(Level.WARNING, "Failed to compare balance of " + name + " with " + amount + ": " + e.getMessage(), e); return false; } } @@ -725,7 +725,7 @@ public static boolean hasLess(final String name, final double amount) throws Use try { return hasLess(name, BigDecimal.valueOf(amount)); } catch (final ArithmeticException e) { - EssentialsLogger.log(Level.WARNING, "Failed to compare balance of " + name + " with " + amount + ": " + e.getMessage(), e); + EssentialsLogger.getLogger().log(Level.WARNING, "Failed to compare balance of " + name + " with " + amount + ": " + e.getMessage(), e); return false; } } @@ -832,7 +832,7 @@ public static String format(final double amount) { try { return format(BigDecimal.valueOf(amount)); } catch (final NumberFormatException e) { - EssentialsLogger.log(Level.WARNING, "Failed to display " + amount + ": " + e.getMessage(), e); + EssentialsLogger.getLogger().log(Level.WARNING, "Failed to display " + amount + ": " + e.getMessage(), e); return "NaN"; } } @@ -899,7 +899,7 @@ public static boolean createNPC(final String name) { createNPCFile(name); return true; } - EssentialsLogger.log(Level.WARNING, MessageFormat.format(WARN_EXISTING_NPC_CREATE, name, user.getConfigUUID()), new RuntimeException()); + EssentialsLogger.getLogger().log(Level.WARNING, MessageFormat.format(WARN_EXISTING_NPC_CREATE, name, user.getConfigUUID()), new RuntimeException()); return false; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java index d1a00697cbc..a89597b6944 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java @@ -92,7 +92,7 @@ private class Viewer implements Runnable { public void run() { if (ess.getSettings().isEcoDisabled()) { if (ess.getSettings().isDebug()) { - EssentialsLogger.info("Internal economy functions disabled, aborting baltop."); + EssentialsLogger.getLogger().info("Internal economy functions disabled, aborting baltop."); } return; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcreatekit.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcreatekit.java index 9719d00071e..3d989eeaf44 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcreatekit.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcreatekit.java @@ -92,18 +92,18 @@ private void uploadPaste(final CommandSource sender, final String kitName, final sender.sendMessage(tl("createKitSuccess", kitName, delayFormat, result.getPasteUrl())); sender.sendMessage(separator); if (ess.getSettings().isDebug()) { - EssentialsLogger.info(sender.getSender().getName() + " created a kit: " + result.getPasteUrl()); + EssentialsLogger.getLogger().info(sender.getSender().getName() + " created a kit: " + result.getPasteUrl()); } } }); future.exceptionally(throwable -> { sender.sendMessage(tl("createKitFailed", kitName)); - EssentialsLogger.log(Level.SEVERE, "Error creating kit: ", throwable); + EssentialsLogger.getLogger().log(Level.SEVERE, "Error creating kit: ", throwable); return null; }); } catch (Exception e) { sender.sendMessage(tl("createKitFailed", kitName)); - EssentialsLogger.log(Level.SEVERE, "Error creating kit: ", e); + EssentialsLogger.getLogger().log(Level.SEVERE, "Error creating kit: ", e); } }); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandessentials.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandessentials.java index d340a6360ee..680b5b0964c 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandessentials.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandessentials.java @@ -364,8 +364,8 @@ private void runDump(Server server, CommandSource sender, String commandLabel, S sender.sendMessage(tl("dumpUrl", dumpUrl)); sender.sendMessage(tl("dumpDeleteKey", result.getDeletionKey())); if (sender.isPlayer()) { - EssentialsLogger.info(tl("dumpConsoleUrl", dumpUrl)); - EssentialsLogger.info(tl("dumpDeleteKey", result.getDeletionKey())); + EssentialsLogger.getLogger().info(tl("dumpConsoleUrl", dumpUrl)); + EssentialsLogger.getLogger().info(tl("dumpDeleteKey", result.getDeletionKey())); } } files.clear(); @@ -413,7 +413,7 @@ private void runNya(final Server server, final CommandSource sender, final Strin private void runMoo(final Server server, final CommandSource sender, final String command, final String[] args) { if (args.length == 2 && args[1].equals("moo")) { for (final String s : CONSOLE_MOO) { - EssentialsLogger.info(s); + EssentialsLogger.getLogger().info(s); } for (final Player player : ess.getOnlinePlayers()) { player.sendMessage(PLAYER_MOO); @@ -477,7 +477,7 @@ private void runCleanup(final Server server, final CommandSource sender, final S } if (ess.getSettings().isDebug()) { - EssentialsLogger.info("Deleting user: " + user.getName() + " Money: " + moneyCount + " Homes: " + homeCount + " Last seen: " + DateUtil.formatDateDiff(lastLog)); + EssentialsLogger.getLogger().info("Deleting user: " + user.getName() + " Money: " + moneyCount + " Homes: " + homeCount + " Last seen: " + DateUtil.formatDateDiff(lastLog)); } user.reset(); @@ -511,7 +511,7 @@ private void runHomes(final Server server, final CommandSource sender, final Str user.delHome(homeName); } } catch (Exception e) { - EssentialsLogger.info("Unable to delete home " + homeName + " for " + user.getName()); + EssentialsLogger.getLogger().info("Unable to delete home " + homeName + " for " + user.getName()); } } } @@ -537,7 +537,7 @@ private void runHomes(final Server server, final CommandSource sender, final Str user.delHome(homeName); } } catch (Exception e) { - EssentialsLogger.info("Unable to delete home " + homeName + " for " + user.getName()); + EssentialsLogger.getLogger().info("Unable to delete home " + homeName + " for " + user.getName()); } } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandkit.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandkit.java index 44f2f3d748c..c2ef4c968df 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandkit.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandkit.java @@ -88,7 +88,7 @@ private void giveKits(final User userTo, final User userFrom, final String kitNa } catch (final NoChargeException ex) { if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "Soft kit error, abort spawning " + kit.getName(), ex); + EssentialsLogger.getLogger().log(Level.INFO, "Soft kit error, abort spawning " + kit.getName(), ex); } } catch (final Exception ex) { ess.showError(userFrom.getSource(), ex, "\\ kit: " + kit.getName()); diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsell.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsell.java index 5f016e69f93..a9876bab48f 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsell.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsell.java @@ -118,7 +118,7 @@ private BigDecimal sellItem(final User user, final ItemStack is, final String[] Trade.log("Command", "Sell", "Item", user.getName(), new Trade(ris, ess), user.getName(), new Trade(result, ess), user.getLocation(), user.getMoney(), ess); user.giveMoney(result, null, UserBalanceUpdateEvent.Cause.COMMAND_SELL); user.sendMessage(tl("itemSold", NumberUtil.displayCurrency(result, ess), amount, is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(worth, ess))); - EssentialsLogger.log(Level.INFO, tl("itemSoldConsole", user.getName(), is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(result, ess), amount, NumberUtil.displayCurrency(worth, ess), user.getDisplayName())); + EssentialsLogger.getLogger().log(Level.INFO, tl("itemSoldConsole", user.getName(), is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(result, ess), amount, NumberUtil.displayCurrency(worth, ess), user.getDisplayName())); return result; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java index d93591da884..528d4961104 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java @@ -100,7 +100,7 @@ private void handleTeleport(final User user, final IUser.TpaRequest request, Str Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { if (ess.getSettings().isDebug()) { - EssentialsLogger.info("TPA accept cancelled by API for " + user.getName() + " (requested by " + requester.getName() + ")"); + EssentialsLogger.getLogger().info("TPA accept cancelled by API for " + user.getName() + " (requested by " + requester.getName() + ")"); } return; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java index e4391f8f518..9653fc1bd7e 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java @@ -85,7 +85,7 @@ private boolean sendEvent(User user, User player, IUser.TpaRequest request) { Bukkit.getPluginManager().callEvent(event); final boolean cancelled = event.isCancelled(); if (cancelled && ess.getSettings().isDebug()) { - EssentialsLogger.info("TPA deny cancelled by API for " + user.getName() + " (requested by " + player.getName() + ")"); + EssentialsLogger.getLogger().info("TPA deny cancelled by API for " + user.getName() + " (requested by " + player.getName() + ")"); } return event.isCancelled(); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/EssentialsCommand.java b/Essentials/src/main/java/com/earth2me/essentials/commands/EssentialsCommand.java index c7230c80e41..42c6aef20a5 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/EssentialsCommand.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/EssentialsCommand.java @@ -315,7 +315,7 @@ protected final List tabCompleteCommand(final CommandSource sender, fina final int numArgs = args.length - index - 1; if (ess.getSettings().isDebug()) { - EssentialsLogger.info(numArgs + " " + index + " " + Arrays.toString(args)); + EssentialsLogger.getLogger().info(numArgs + " " + index + " " + Arrays.toString(args)); } String[] effectiveArgs = new String[numArgs]; System.arraycopy(args, index, effectiveArgs, 0, numArgs); @@ -323,7 +323,7 @@ protected final List tabCompleteCommand(final CommandSource sender, fina effectiveArgs = new String[] {""}; } if (ess.getSettings().isDebug()) { - EssentialsLogger.info(command + " -- " + Arrays.toString(effectiveArgs)); + EssentialsLogger.getLogger().info(command + " -- " + Arrays.toString(effectiveArgs)); } return command.tabComplete(sender.getSender(), label, effectiveArgs); @@ -333,7 +333,7 @@ protected final List tabCompleteCommand(final CommandSource sender, fina public void showError(final CommandSender sender, final Throwable throwable, final String commandLabel) { sender.sendMessage(tl("errorWithMessage", throwable.getMessage())); if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, tl("errorCallingCommand", commandLabel), throwable); + EssentialsLogger.getLogger().log(Level.INFO, tl("errorCallingCommand", commandLabel), throwable); throwable.printStackTrace(); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/config/ConfigurationSaveTask.java b/Essentials/src/main/java/com/earth2me/essentials/config/ConfigurationSaveTask.java index a73ba7822d4..083e88869ec 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/config/ConfigurationSaveTask.java +++ b/Essentials/src/main/java/com/earth2me/essentials/config/ConfigurationSaveTask.java @@ -31,7 +31,7 @@ public void run() { try { loader.save(node); } catch (ConfigurateException e) { - EssentialsLogger.log(Level.SEVERE, e.getMessage(), e); + EssentialsLogger.getLogger().log(Level.SEVERE, e.getMessage(), e); } finally { pendingWrites.decrementAndGet(); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsConfiguration.java b/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsConfiguration.java index d57ea1edf35..c6a0af7c88f 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsConfiguration.java +++ b/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsConfiguration.java @@ -132,7 +132,7 @@ public Map getLocationSectionMap(final String path) { try { result.put(entry.getKey().toLowerCase(Locale.ENGLISH), jailNode.get(LazyLocation.class)); } catch (SerializationException e) { - EssentialsLogger.log(Level.WARNING, "Error serializing key " + entry.getKey(), e); + EssentialsLogger.getLogger().log(Level.WARNING, "Error serializing key " + entry.getKey(), e); } } return result; @@ -146,7 +146,7 @@ public void setExplicitList(final String path, final List list, final Typ try { toSplitRoot(path, configurationNode).set(type, list); } catch (SerializationException e) { - EssentialsLogger.log(Level.SEVERE, e.getMessage(), e); + EssentialsLogger.getLogger().log(Level.SEVERE, e.getMessage(), e); } } @@ -162,7 +162,7 @@ public List getList(final String path, Class type) { } return list; } catch (SerializationException e) { - EssentialsLogger.log(Level.SEVERE, e.getMessage(), e); + EssentialsLogger.getLogger().log(Level.SEVERE, e.getMessage(), e); return new ArrayList<>(); } } @@ -300,7 +300,7 @@ public void removeProperty(String path) { try { node.set(null); } catch (SerializationException e) { - EssentialsLogger.log(Level.SEVERE, e.getMessage(), e); + EssentialsLogger.getLogger().log(Level.SEVERE, e.getMessage(), e); } } } @@ -309,7 +309,7 @@ private void setInternal(final String path, final Object value) { try { toSplitRoot(path, configurationNode).set(value); } catch (SerializationException e) { - EssentialsLogger.log(Level.SEVERE, e.getMessage(), e); + EssentialsLogger.getLogger().log(Level.SEVERE, e.getMessage(), e); } } @@ -335,13 +335,13 @@ public CommentedConfigurationNode toSplitRoot(String path, final CommentedConfig public synchronized void load() { if (pendingWrites.get() != 0) { - EssentialsLogger.log(Level.INFO, "Parsing config file " + configFile + " has been aborted due to " + pendingWrites.get() + " current pending write(s)."); + EssentialsLogger.getLogger().log(Level.INFO, "Parsing config file " + configFile + " has been aborted due to " + pendingWrites.get() + " current pending write(s)."); return; } if (configFile.getParentFile() != null && !configFile.getParentFile().exists()) { if (!configFile.getParentFile().mkdirs()) { - EssentialsLogger.log(Level.SEVERE, tl("failedToCreateConfig", configFile.toString())); + EssentialsLogger.getLogger().log(Level.SEVERE, tl("failedToCreateConfig", configFile.toString())); return; } } @@ -353,10 +353,10 @@ public synchronized void load() { convertAltFile(); } else if (templateName != null) { try (final InputStream is = resourceClass.getResourceAsStream(templateName)) { - EssentialsLogger.log(Level.INFO, tl("creatingConfigFromTemplate", configFile.toString())); + EssentialsLogger.getLogger().log(Level.INFO, tl("creatingConfigFromTemplate", configFile.toString())); Files.copy(is, configFile.toPath()); } catch (IOException e) { - EssentialsLogger.log(Level.SEVERE, tl("failedToWriteConfig", configFile.toString()), e); + EssentialsLogger.getLogger().log(Level.SEVERE, tl("failedToWriteConfig", configFile.toString()), e); } } } @@ -366,12 +366,12 @@ public synchronized void load() { } catch (final ParsingException e) { final File broken = new File(configFile.getAbsolutePath() + ".broken." + System.currentTimeMillis()); if (configFile.renameTo(broken)) { - EssentialsLogger.log(Level.SEVERE, "The file " + configFile.toString() + " is broken, it has been renamed to " + broken.toString(), e.getCause()); + EssentialsLogger.getLogger().log(Level.SEVERE, "The file " + configFile.toString() + " is broken, it has been renamed to " + broken.toString(), e.getCause()); return; } - EssentialsLogger.log(Level.SEVERE, "The file " + configFile.toString() + " is broken. A backup file has failed to be created", e.getCause()); + EssentialsLogger.getLogger().log(Level.SEVERE, "The file " + configFile.toString() + " is broken. A backup file has failed to be created", e.getCause()); } catch (final ConfigurateException e) { - EssentialsLogger.log(Level.SEVERE, e.getMessage(), e); + EssentialsLogger.getLogger().log(Level.SEVERE, e.getMessage(), e); } finally { // Something is wrong! We need a node! I hope the backup worked! if (configurationNode == null) { @@ -434,7 +434,7 @@ public synchronized void blockingSave() { try { delaySave().get(); } catch (final InterruptedException | ExecutionException e) { - EssentialsLogger.log(Level.SEVERE, e.getMessage(), e); + EssentialsLogger.getLogger().log(Level.SEVERE, e.getMessage(), e); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsUserConfiguration.java b/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsUserConfiguration.java index 45190bc299e..462ff667b54 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsUserConfiguration.java +++ b/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsUserConfiguration.java @@ -44,7 +44,7 @@ public void convertLegacyFile() { //noinspection UnstableApiUsage Files.move(file, new File(configFile.getParentFile(), uuid + ".yml")); } catch (final IOException ex) { - EssentialsLogger.log(Level.WARNING, "Failed to migrate user: " + username, ex); + EssentialsLogger.getLogger().log(Level.WARNING, "Failed to migrate user: " + username, ex); } setProperty("last-account-name", username); @@ -69,7 +69,7 @@ public void convertAltFile() { //noinspection UnstableApiUsage Files.move(getAltFile(), new File(configFile.getParentFile(), uuid + ".yml")); } catch (final IOException ex) { - EssentialsLogger.log(Level.WARNING, "Failed to migrate user: " + username, ex); + EssentialsLogger.getLogger().log(Level.WARNING, "Failed to migrate user: " + username, ex); } } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/economy/EconomyLayers.java b/Essentials/src/main/java/com/earth2me/essentials/economy/EconomyLayers.java index 17f1704fa73..c6ed3022497 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/economy/EconomyLayers.java +++ b/Essentials/src/main/java/com/earth2me/essentials/economy/EconomyLayers.java @@ -41,7 +41,7 @@ public static void onEnable(final Essentials ess) { } final EconomyLayer layer = onPluginEnable(plugin); if (layer != null) { - EssentialsLogger.log(Level.INFO, "Essentials found a compatible payment resolution method: " + layer.getName() + " (v" + layer.getPluginVersion() + ")!"); + EssentialsLogger.getLogger().log(Level.INFO, "Essentials found a compatible payment resolution method: " + layer.getName() + " (v" + layer.getPluginVersion() + ")!"); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/economy/vault/VaultEconomyProvider.java b/Essentials/src/main/java/com/earth2me/essentials/economy/vault/VaultEconomyProvider.java index 92676c7fc10..254b263d375 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/economy/vault/VaultEconomyProvider.java +++ b/Essentials/src/main/java/com/earth2me/essentials/economy/vault/VaultEconomyProvider.java @@ -300,8 +300,8 @@ public boolean createPlayerAccount(OfflinePlayer player) { } final File npcFile = new File(folder, player.getUniqueId() + ".yml"); if (npcFile.exists()) { - EssentialsLogger.log(Level.SEVERE, MessageFormat.format(WARN_NPC_RECREATE_1, player.getName(), player.getUniqueId().toString()), new RuntimeException()); - EssentialsLogger.log(Level.SEVERE, WARN_NPC_RECREATE_2); + EssentialsLogger.getLogger().log(Level.SEVERE, MessageFormat.format(WARN_NPC_RECREATE_1, player.getName(), player.getUniqueId().toString()), new RuntimeException()); + EssentialsLogger.getLogger().log(Level.SEVERE, WARN_NPC_RECREATE_2); } final EssentialsUserConfiguration npcConfig = new EssentialsUserConfiguration(player.getName(), player.getUniqueId(), npcFile); npcConfig.load(); @@ -316,7 +316,7 @@ public boolean createPlayerAccount(OfflinePlayer player) { // Loading a v4 UUID that we somehow didn't track, mark it as a normal player and hope for the best, vault sucks :/ try { if (ess.getSettings().isDebug()) { - EssentialsLogger.info("Vault requested a player account creation for a v4 UUID: " + player); + EssentialsLogger.getLogger().info("Vault requested a player account creation for a v4 UUID: " + player); } ess.getUserMap().load(player); return true; diff --git a/Essentials/src/main/java/com/earth2me/essentials/items/AbstractItemDb.java b/Essentials/src/main/java/com/earth2me/essentials/items/AbstractItemDb.java index 735fd499f7a..9a4424c6f16 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/items/AbstractItemDb.java +++ b/Essentials/src/main/java/com/earth2me/essentials/items/AbstractItemDb.java @@ -106,7 +106,7 @@ public ItemStack get(final String id) throws Exception { ItemStack tryResolverDeserialize(final String id) { for (final PluginKey key : resolverMap.keySet()) { if (ess.getSettings().isDebug()) { - EssentialsLogger.info(String.format("Trying to deserialize item '%s' with resolver '%s'...", id, key)); + EssentialsLogger.getLogger().info(String.format("Trying to deserialize item '%s' with resolver '%s'...", id, key)); } final Function resolver = resolverMap.get(key); @@ -123,7 +123,7 @@ ItemStack tryResolverDeserialize(final String id) { String tryResolverSerialize(final ItemStack stack) { for (final PluginKey key : resolverMap.keySet()) { if (ess.getSettings().isDebug()) { - EssentialsLogger.info(String.format("Trying to serialize '%s' with resolver '%s'...", stack.toString(), key)); + EssentialsLogger.getLogger().info(String.format("Trying to serialize '%s' with resolver '%s'...", stack.toString(), key)); } final ItemResolver resolver = resolverMap.get(key); diff --git a/Essentials/src/main/java/com/earth2me/essentials/items/CustomItemResolver.java b/Essentials/src/main/java/com/earth2me/essentials/items/CustomItemResolver.java index 115c03be1aa..8a7032b8e91 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/items/CustomItemResolver.java +++ b/Essentials/src/main/java/com/earth2me/essentials/items/CustomItemResolver.java @@ -62,7 +62,7 @@ public void reloadConfig() { final Map section = ConfigurateUtil.getRawMap(config.getSection("aliases")); if (section.isEmpty()) { - EssentialsLogger.warning("No aliases found in custom_items.yml."); + EssentialsLogger.getLogger().warning("No aliases found in custom_items.yml."); return; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/items/FlatItemDb.java b/Essentials/src/main/java/com/earth2me/essentials/items/FlatItemDb.java index 8a95214f5c4..4ac1edd2f71 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/items/FlatItemDb.java +++ b/Essentials/src/main/java/com/earth2me/essentials/items/FlatItemDb.java @@ -53,7 +53,7 @@ public void reloadConfig() { } this.rebuild(); - EssentialsLogger.info(String.format("Loaded %s items from items.json.", listNames().size())); + EssentialsLogger.getLogger().info(String.format("Loaded %s items from items.json.", listNames().size())); } private void rebuild() { @@ -99,7 +99,7 @@ private void loadJSON(final String source) { if (valid) { allAliases.add(key); } else { - EssentialsLogger.warning(String.format("Failed to add item: \"%s\": %s", key, element.toString())); + EssentialsLogger.getLogger().warning(String.format("Failed to add item: \"%s\": %s", key, element.toString())); } } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/items/LegacyItemDb.java b/Essentials/src/main/java/com/earth2me/essentials/items/LegacyItemDb.java index 17eb05c191a..716ed2ad116 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/items/LegacyItemDb.java +++ b/Essentials/src/main/java/com/earth2me/essentials/items/LegacyItemDb.java @@ -118,7 +118,7 @@ public void reloadConfig() { nameList.sort(LengthCompare.INSTANCE); } - EssentialsLogger.info(String.format("Loaded %s items from items.csv.", listNames().size())); + EssentialsLogger.getLogger().info(String.format("Loaded %s items from items.csv.", listNames().size())); ready = true; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/perm/PermissionsHandler.java b/Essentials/src/main/java/com/earth2me/essentials/perm/PermissionsHandler.java index 1a78ee701cf..0805282e1b7 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/perm/PermissionsHandler.java +++ b/Essentials/src/main/java/com/earth2me/essentials/perm/PermissionsHandler.java @@ -170,18 +170,18 @@ public void checkPermissions() { if (handler instanceof AbstractVaultHandler) { String enabledPermsPlugin = ((AbstractVaultHandler) handler).getEnabledPermsPlugin(); if (enabledPermsPlugin == null) enabledPermsPlugin = "generic"; - EssentialsLogger.info("Using Vault based permissions (" + enabledPermsPlugin + ")"); + EssentialsLogger.getLogger().info("Using Vault based permissions (" + enabledPermsPlugin + ")"); } else if (handler.getClass() == SuperpermsHandler.class) { if (handler.tryProvider(ess)) { - EssentialsLogger.warning("Detected supported permissions plugin " + + EssentialsLogger.getLogger().warning("Detected supported permissions plugin " + ((SuperpermsHandler) handler).getEnabledPermsPlugin() + " without Vault installed."); - EssentialsLogger.warning("Features such as chat prefixes/suffixes and group-related functionality will not " + + EssentialsLogger.getLogger().warning("Features such as chat prefixes/suffixes and group-related functionality will not " + "work until you install Vault."); } - EssentialsLogger.info("Using superperms-based permissions."); + EssentialsLogger.getLogger().info("Using superperms-based permissions."); } else if (handler.getClass() == ConfigPermissionsHandler.class) { - EssentialsLogger.info("Using config file enhanced permissions."); - EssentialsLogger.info("Permissions listed in as player-commands will be given to all users."); + EssentialsLogger.getLogger().info("Using config file enhanced permissions."); + EssentialsLogger.getLogger().info("Permissions listed in as player-commands will be given to all users."); } } @@ -196,7 +196,7 @@ public String getName() { private void checkPermLag(final long start, final String summary) { final long elapsed = System.nanoTime() - start; if (elapsed > ess.getSettings().getPermissionsLagWarning()) { - EssentialsLogger.log(Level.WARNING, String.format("Permissions lag notice with (%s). Response took %fms. Summary: %s", getName(), elapsed / 1000000.0, summary)); + EssentialsLogger.getLogger().log(Level.WARNING, String.format("Permissions lag notice with (%s). Response took %fms. Summary: %s", getName(), elapsed / 1000000.0, summary)); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/signs/EssentialsSign.java b/Essentials/src/main/java/com/earth2me/essentials/signs/EssentialsSign.java index 6c0892a74e3..70f276f451a 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/signs/EssentialsSign.java +++ b/Essentials/src/main/java/com/earth2me/essentials/signs/EssentialsSign.java @@ -108,7 +108,7 @@ protected final boolean onSignCreate(final SignChangeEvent event, final IEssenti ess.getServer().getPluginManager().callEvent(signEvent); if (signEvent.isCancelled()) { if (ess.getSettings().isDebug()) { - EssentialsLogger.info("SignCreateEvent cancelled for sign " + signEvent.getEssentialsSign().getName()); + EssentialsLogger.getLogger().info("SignCreateEvent cancelled for sign " + signEvent.getEssentialsSign().getName()); } return false; } @@ -130,7 +130,7 @@ protected final boolean onSignCreate(final SignChangeEvent event, final IEssenti public String getSuccessName(final IEssentials ess) { final String successName = getSuccessName(); if (successName == null) { - EssentialsLogger.severe("signFormatSuccess message must use the {0} argument."); + EssentialsLogger.getLogger().severe("signFormatSuccess message must use the {0} argument."); } return successName; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/signs/SignBlockListener.java b/Essentials/src/main/java/com/earth2me/essentials/signs/SignBlockListener.java index c11fa5d21ed..c87a49d5222 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/signs/SignBlockListener.java +++ b/Essentials/src/main/java/com/earth2me/essentials/signs/SignBlockListener.java @@ -51,7 +51,7 @@ public boolean protectSignsAndBlocks(final Block block, final Player player) thr // prevent any signs be broken by destroying the block they are attached to if (EssentialsSign.checkIfBlockBreaksSigns(block)) { if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "Prevented that a block was broken next to a sign."); + EssentialsLogger.getLogger().log(Level.INFO, "Prevented that a block was broken next to a sign."); } return true; } @@ -69,7 +69,7 @@ public boolean protectSignsAndBlocks(final Block block, final Player player) thr for (final EssentialsSign sign : ess.getSettings().enabledSigns()) { if (sign.areHeavyEventRequired() && sign.getBlocks().contains(block.getType()) && !sign.onBlockBreak(block, player, ess)) { - EssentialsLogger.log(Level.INFO, "A block was protected by a sign."); + EssentialsLogger.getLogger().log(Level.INFO, "A block was protected by a sign."); return true; } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/signs/SignPlayerListener.java b/Essentials/src/main/java/com/earth2me/essentials/signs/SignPlayerListener.java index 2c5eccea7ff..c19419e7e73 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/signs/SignPlayerListener.java +++ b/Essentials/src/main/java/com/earth2me/essentials/signs/SignPlayerListener.java @@ -41,7 +41,7 @@ public void onSignPlayerInteract(final PlayerInteractEvent event) { targetBlock = ess.getUser(event.getPlayer()).getTargetBlock(5); } catch (final IllegalStateException ex) { if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.WARNING, ex.getMessage(), ex); + EssentialsLogger.getLogger().log(Level.WARNING, ex.getMessage(), ex); } } block = targetBlock; diff --git a/Essentials/src/main/java/com/earth2me/essentials/textreader/BookInput.java b/Essentials/src/main/java/com/earth2me/essentials/textreader/BookInput.java index ad1b04e0424..cd3fcb8a821 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/textreader/BookInput.java +++ b/Essentials/src/main/java/com/earth2me/essentials/textreader/BookInput.java @@ -45,7 +45,7 @@ public BookInput(final String filename, final boolean createFile, final IEssenti length = input.read(buffer); } } - EssentialsLogger.info("File " + filename + ".txt does not exist. Creating one for you."); + EssentialsLogger.getLogger().info("File " + filename + ".txt does not exist. Creating one for you."); } } if (!file.exists()) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/textreader/HelpInput.java b/Essentials/src/main/java/com/earth2me/essentials/textreader/HelpInput.java index 12041e9b5e9..d6a4f13419d 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/textreader/HelpInput.java +++ b/Essentials/src/main/java/com/earth2me/essentials/textreader/HelpInput.java @@ -120,7 +120,7 @@ public HelpInput(final User user, final String match, final IEssentials ess) { } catch (final NullPointerException ignored) { } catch (final Exception ex) { if (!reported) { - EssentialsLogger.log(Level.WARNING, tl("commandHelpFailedForPlugin", pluginNameLow), ex); + EssentialsLogger.getLogger().log(Level.WARNING, tl("commandHelpFailedForPlugin", pluginNameLow), ex); } reported = true; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/textreader/KeywordReplacer.java b/Essentials/src/main/java/com/earth2me/essentials/textreader/KeywordReplacer.java index f7160087af1..70f28f09f97 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/textreader/KeywordReplacer.java +++ b/Essentials/src/main/java/com/earth2me/essentials/textreader/KeywordReplacer.java @@ -155,7 +155,7 @@ private void replaceKeywords(final CommandSource sender) { execTimer.mark("Text Replace"); final String timeroutput = execTimer.end(); if (ess.getSettings().isDebug()) { - EssentialsLogger.log(Level.INFO, "Keyword Replacer " + timeroutput); + EssentialsLogger.getLogger().log(Level.INFO, "Keyword Replacer " + timeroutput); } } diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/LoggerProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/LoggerProvider.java index 24e75fd4404..aaba0c8b822 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/LoggerProvider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/LoggerProvider.java @@ -1,21 +1,39 @@ package net.ess3.provider; import java.util.logging.Level; +import java.util.logging.Logger; -public interface LoggerProvider { - void log(Level level, String message, Throwable throwable); +public abstract class LoggerProvider extends Logger { + public LoggerProvider(final String name) { + super(name, null); + } + + protected abstract void doTheLog(Level level, String message, Throwable throwable); + + protected abstract void doTheLog(Level level, String message); - void log(Level level, String message); + @Override + public void log(Level level, String msg) { + doTheLog(level, msg); + } + + @Override + public void log(Level level, String msg, Throwable thrown) { + doTheLog(level, msg, thrown); + } - default void warning(String message) { - log(Level.WARNING, message); + @Override + public void warning(String message) { + doTheLog(Level.WARNING, message); } - default void info(String message) { - log(Level.INFO, message); + @Override + public void info(String message) { + doTheLog(Level.INFO, message); } - default void severe(String message) { - log(Level.SEVERE, message); + @Override + public void severe(String message) { + doTheLog(Level.SEVERE, message); } } diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BaseLoggerProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BaseLoggerProvider.java index 0c1af2e37af..e65a3eba331 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BaseLoggerProvider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BaseLoggerProvider.java @@ -5,20 +5,21 @@ import java.util.logging.Level; import java.util.logging.Logger; -public class BaseLoggerProvider implements LoggerProvider { +public class BaseLoggerProvider extends LoggerProvider { private final Logger logger; public BaseLoggerProvider(final Logger logger) { + super(logger.getName()); this.logger = logger; } @Override - public void log(Level level, String message, Throwable throwable) { + protected void doTheLog(Level level, String message, Throwable throwable) { logger.log(level, message, throwable); } @Override - public void log(Level level, String message) { + protected void doTheLog(Level level, String message) { logger.log(level, message); } } diff --git a/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperLoggerProvider.java b/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperLoggerProvider.java index d32e8d89aab..6fd7b31d123 100644 --- a/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperLoggerProvider.java +++ b/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperLoggerProvider.java @@ -8,15 +8,16 @@ import java.util.logging.Level; -public class PaperLoggerProvider implements LoggerProvider { +public class PaperLoggerProvider extends LoggerProvider { private final ComponentLogger logger; public PaperLoggerProvider(final Plugin plugin) { + super(plugin.getComponentLogger().getName()); this.logger = plugin.getComponentLogger(); } @Override - public void log(Level level, String message, Throwable throwable) { + protected void doTheLog(Level level, String message, Throwable throwable) { final Component component = LegacyComponentSerializer.legacySection().deserialize(message); if (level == Level.SEVERE) { logger.error(component, throwable); @@ -32,7 +33,7 @@ public void log(Level level, String message, Throwable throwable) { } @Override - public void log(Level level, String message) { + protected void doTheLog(Level level, String message) { final Component component = LegacyComponentSerializer.legacySection().deserialize(message); if (level == Level.SEVERE) { logger.error(component); @@ -40,6 +41,8 @@ public void log(Level level, String message) { logger.warn(component); } else if (level == Level.INFO) { logger.info(component); + } else if (level == Level.FINE) { + logger.trace(component); } else { throw new IllegalArgumentException("Unknown level: " + level); } From daba60b3fe83fe3d81a355791a5f448cd7f1dd63 Mon Sep 17 00:00:00 2001 From: MD <1917406+mdcfe@users.noreply.github.com> Date: Mon, 27 Jun 2022 18:18:55 +0100 Subject: [PATCH 6/8] Use logger accessors from plugin class --- .../AlternativeCommandsHandler.java | 2 +- .../earth2me/essentials/AsyncTeleport.java | 2 +- .../java/com/earth2me/essentials/Backup.java | 10 +- .../com/earth2me/essentials/Essentials.java | 89 ++++++----- .../essentials/EssentialsEntityListener.java | 2 +- .../earth2me/essentials/EssentialsLogger.java | 9 -- .../essentials/EssentialsPlayerListener.java | 26 ++-- .../essentials/EssentialsPluginListener.java | 6 +- .../essentials/EssentialsServerListener.java | 8 +- .../earth2me/essentials/EssentialsTimer.java | 2 +- .../essentials/EssentialsUpgrade.java | 144 +++++++++--------- .../java/com/earth2me/essentials/I18n.java | 6 +- .../java/com/earth2me/essentials/Jails.java | 14 +- .../java/com/earth2me/essentials/Kit.java | 6 +- .../com/earth2me/essentials/ManagedFile.java | 9 +- .../earth2me/essentials/MetaItemStack.java | 4 +- .../java/com/earth2me/essentials/Mob.java | 2 +- .../java/com/earth2me/essentials/MobData.java | 2 +- .../com/earth2me/essentials/Settings.java | 36 ++--- .../com/earth2me/essentials/Teleport.java | 2 +- .../java/com/earth2me/essentials/Trade.java | 30 ++-- .../java/com/earth2me/essentials/UUIDMap.java | 11 +- .../java/com/earth2me/essentials/User.java | 30 ++-- .../com/earth2me/essentials/UserData.java | 6 +- .../java/com/earth2me/essentials/UserMap.java | 24 +-- .../java/com/earth2me/essentials/Warps.java | 2 +- .../com/earth2me/essentials/api/Economy.java | 27 ++-- .../commands/Commandbalancetop.java | 3 +- .../essentials/commands/Commandcreatekit.java | 7 +- .../commands/Commandessentials.java | 13 +- .../essentials/commands/Commandgc.java | 4 +- .../essentials/commands/Commandkit.java | 3 +- .../essentials/commands/Commandsell.java | 3 +- .../essentials/commands/Commandtpaccept.java | 3 +- .../essentials/commands/Commandtpdeny.java | 3 +- .../commands/EssentialsCommand.java | 7 +- .../config/ConfigurationSaveTask.java | 4 +- .../config/EssentialsConfiguration.java | 28 ++-- .../config/EssentialsUserConfiguration.java | 6 +- .../essentials/economy/EconomyLayers.java | 3 +- .../economy/vault/VaultEconomyProvider.java | 7 +- .../essentials/items/AbstractItemDb.java | 5 +- .../essentials/items/CustomItemResolver.java | 3 +- .../earth2me/essentials/items/FlatItemDb.java | 7 +- .../essentials/items/LegacyItemDb.java | 3 +- .../essentials/perm/PermissionsHandler.java | 15 +- .../essentials/signs/EssentialsSign.java | 5 +- .../essentials/signs/SignBlockListener.java | 5 +- .../essentials/signs/SignPlayerListener.java | 3 +- .../essentials/textreader/BookInput.java | 3 +- .../essentials/textreader/HelpInput.java | 3 +- .../textreader/KeywordReplacer.java | 3 +- .../antibuild/EssentialsAntiBuild.java | 12 ++ .../EssentialsAntiBuildListener.java | 9 +- .../antibuild/EssentialsConnect.java | 7 +- .../essentials/chat/EssentialsChat.java | 19 ++- .../essentials/chat/EssentialsChatPlayer.java | 7 +- .../EssentialsChatPlayerListenerHighest.java | 4 +- .../EssentialsChatPlayerListenerLowest.java | 4 +- .../EssentialsChatPlayerListenerNormal.java | 6 +- .../essentialsx/discord/DiscordSettings.java | 11 +- .../discord/EssentialsDiscord.java | 30 +++- .../discord/JDADiscordService.java | 5 +- .../InteractionControllerImpl.java | 7 +- .../interactions/InteractionEventImpl.java | 6 +- .../discord/listeners/DiscordListener.java | 6 +- .../discord/util/ConsoleInjector.java | 5 +- .../essentials/geoip/EssentialsGeoIP.java | 21 ++- .../geoip/EssentialsGeoIPPlayerListener.java | 27 ++-- .../essentials/protect/EssentialsConnect.java | 5 +- .../essentials/protect/EssentialsProtect.java | 23 ++- .../essentials/spawn/EssentialsSpawn.java | 22 ++- .../spawn/EssentialsSpawnPlayerListener.java | 5 +- .../essentials/xmpp/EssentialsXMPP.java | 21 +++ .../earth2me/essentials/xmpp/XMPPManager.java | 2 +- 75 files changed, 495 insertions(+), 429 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/AlternativeCommandsHandler.java b/Essentials/src/main/java/com/earth2me/essentials/AlternativeCommandsHandler.java index d6e25969e7a..322cebb4d9f 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/AlternativeCommandsHandler.java +++ b/Essentials/src/main/java/com/earth2me/essentials/AlternativeCommandsHandler.java @@ -93,7 +93,7 @@ public void executed(final String label, final Command pc) { if (pc instanceof PluginIdentifiableCommand) { final String altString = ((PluginIdentifiableCommand) pc).getPlugin().getName() + ":" + pc.getName(); if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "Essentials: Alternative command " + label + " found, using " + altString); + ess.getLogger().log(Level.INFO, "Essentials: Alternative command " + label + " found, using " + altString); } disabledList.put(label, altString); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/AsyncTeleport.java b/Essentials/src/main/java/com/earth2me/essentials/AsyncTeleport.java index 1712cf60cfd..19ab4581815 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/AsyncTeleport.java +++ b/Essentials/src/main/java/com/earth2me/essentials/AsyncTeleport.java @@ -401,7 +401,7 @@ void respawnNow(final IUser teleportee, final TeleportCause cause, final Complet nowAsync(teleportee, new LocationTarget(location), cause, future); } else { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().info("Could not find bed spawn, forcing respawn event."); + ess.getLogger().info("Could not find bed spawn, forcing respawn event."); } final PlayerRespawnEvent pre = new PlayerRespawnEvent(player, player.getWorld().getSpawnLocation(), false); ess.getServer().getPluginManager().callEvent(pre); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Backup.java b/Essentials/src/main/java/com/earth2me/essentials/Backup.java index fba47c344f9..c4ddc2f490f 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Backup.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Backup.java @@ -79,7 +79,7 @@ public void run() { taskLock.complete(new Object()); return; } - EssentialsLogger.getLogger().log(Level.INFO, tl("backupStarted")); + ess.getLogger().log(Level.INFO, tl("backupStarted")); final CommandSender cs = server.getConsoleSender(); server.dispatchCommand(cs, "save-all"); server.dispatchCommand(cs, "save-off"); @@ -97,17 +97,17 @@ public void run() { do { line = reader.readLine(); if (line != null) { - EssentialsLogger.getLogger().log(Level.INFO, line); + ess.getLogger().log(Level.INFO, line); } } while (line != null); } } catch (final IOException ex) { - EssentialsLogger.getLogger().log(Level.SEVERE, null, ex); + ess.getLogger().log(Level.SEVERE, null, ex); } }); child.waitFor(); } catch (final InterruptedException | IOException ex) { - EssentialsLogger.getLogger().log(Level.SEVERE, null, ex); + ess.getLogger().log(Level.SEVERE, null, ex); } finally { class BackupEnableSaveTask implements Runnable { @Override @@ -118,7 +118,7 @@ public void run() { } active = false; taskLock.complete(new Object()); - EssentialsLogger.getLogger().log(Level.INFO, tl("backupFinished")); + ess.getLogger().log(Level.INFO, tl("backupFinished")); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/Essentials.java b/Essentials/src/main/java/com/earth2me/essentials/Essentials.java index 48e8cd9c738..8ed17dc6184 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Essentials.java @@ -141,8 +141,8 @@ import static com.earth2me.essentials.I18n.tl; public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials { - private static Logger LOGGER; private static final Logger BUKKIT_LOGGER = Logger.getLogger("Essentials"); + private static Logger LOGGER = null; private final transient TNTExplodeListener tntListener = new TNTExplodeListener(this); private final transient Set vanishedPlayers = new LinkedHashSet<>(); private transient ISettings settings; @@ -205,7 +205,7 @@ public ISettings getSettings() { } public void setupForTesting(final Server server) throws IOException, InvalidDescriptionException { - LOGGER = EssentialsLogger.setLoggerProvider(new BaseLoggerProvider(BUKKIT_LOGGER)); + LOGGER = new BaseLoggerProvider(BUKKIT_LOGGER); final File dataFolder = File.createTempFile("essentialstest", ""); if (!dataFolder.delete()) { throw new IOException(); @@ -218,8 +218,8 @@ public void setupForTesting(final Server server) throws IOException, InvalidDesc i18n.updateLocale("en"); Console.setInstance(this); - EssentialsLogger.getLogger().log(Level.INFO, tl("usingTempFolderForTesting")); - EssentialsLogger.getLogger().log(Level.INFO, dataFolder.toString()); + LOGGER.log(Level.INFO, tl("usingTempFolderForTesting")); + LOGGER.log(Level.INFO, dataFolder.toString()); settings = new Settings(this); mail = new MailServiceImpl(this); userMap = new UserMap(this); @@ -246,11 +246,10 @@ public void onLoad() { @Override public void onEnable() { try { - if (BUKKIT_LOGGER != this.getLogger()) { - BUKKIT_LOGGER.setParent(this.getLogger()); + if (BUKKIT_LOGGER != super.getLogger()) { + BUKKIT_LOGGER.setParent(super.getLogger()); } - - LOGGER = EssentialsLogger.setLoggerProvider(EssentialsLogger.getLoggerProvider(this)); + LOGGER = EssentialsLogger.getLoggerProvider(this); execTimer = new ExecuteTimer(); execTimer.start(); @@ -262,30 +261,30 @@ public void onEnable() { switch (VersionUtil.getServerSupportStatus()) { case NMS_CLEANROOM: - EssentialsLogger.getLogger().severe(tl("serverUnsupportedCleanroom")); + getLogger().severe(tl("serverUnsupportedCleanroom")); break; case DANGEROUS_FORK: - EssentialsLogger.getLogger().severe(tl("serverUnsupportedDangerous")); + getLogger().severe(tl("serverUnsupportedDangerous")); break; case UNSTABLE: - EssentialsLogger.getLogger().severe(tl("serverUnsupportedMods")); + getLogger().severe(tl("serverUnsupportedMods")); break; case OUTDATED: - EssentialsLogger.getLogger().severe(tl("serverUnsupported")); + getLogger().severe(tl("serverUnsupported")); break; case LIMITED: - EssentialsLogger.getLogger().info(tl("serverUnsupportedLimitedApi")); + getLogger().info(tl("serverUnsupportedLimitedApi")); break; } if (VersionUtil.getSupportStatusClass() != null) { - EssentialsLogger.getLogger().info(tl("serverUnsupportedClass", VersionUtil.getSupportStatusClass())); + getLogger().info(tl("serverUnsupportedClass", VersionUtil.getSupportStatusClass())); } final PluginManager pm = getServer().getPluginManager(); for (final Plugin plugin : pm.getPlugins()) { if (plugin.getDescription().getName().startsWith("Essentials") && !plugin.getDescription().getVersion().equals(this.getDescription().getVersion()) && !plugin.getDescription().getName().equals("EssentialsAntiCheat")) { - EssentialsLogger.getLogger().warning(tl("versionMismatch", plugin.getDescription().getName())); + getLogger().warning(tl("versionMismatch", plugin.getDescription().getName())); } } @@ -466,9 +465,9 @@ public void onEnable() { updateChecker = new UpdateChecker(this); runTaskAsynchronously(() -> { - EssentialsLogger.getLogger().log(Level.INFO, tl("versionFetching")); + getLogger().log(Level.INFO, tl("versionFetching")); for (String str : updateChecker.getVersionMessages(false, true)) { - EssentialsLogger.getLogger().log(getSettings().isUpdateCheckEnabled() ? Level.WARNING : Level.INFO, str); + getLogger().log(getSettings().isUpdateCheckEnabled() ? Level.WARNING : Level.INFO, str); } }); @@ -478,7 +477,7 @@ public void onEnable() { final String timeroutput = execTimer.end(); if (getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "Essentials load " + timeroutput); + LOGGER.log(Level.INFO, "Essentials load {0}", timeroutput); } } catch (final NumberFormatException ex) { handleCrash(ex); @@ -489,6 +488,24 @@ public void onEnable() { getBackup().setPendingShutdown(false); } + @Override + public Logger getLogger() { + if (LOGGER != null) { + return LOGGER; + } + + return super.getLogger(); + } + + // Returns our provider logger if available + public static Logger getWrappedLogger() { + if (LOGGER != null) { + return LOGGER; + } + + return BUKKIT_LOGGER; + } + @Override public void saveConfig() { // We don't use any of the bukkit config writing, as this breaks our config file formatting. @@ -498,7 +515,7 @@ private void registerListeners(final PluginManager pm) { HandlerList.unregisterAll(this); if (getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "Registering Listeners"); + LOGGER.log(Level.INFO, "Registering Listeners"); } final EssentialsPluginListener pluginListener = new EssentialsPluginListener(this); @@ -542,7 +559,7 @@ private void registerListeners(final PluginManager pm) { public void onDisable() { final boolean stopping = getServerStateProvider().isStopping(); if (!stopping) { - EssentialsLogger.getLogger().log(Level.SEVERE, tl("serverReloading")); + LOGGER.log(Level.SEVERE, tl("serverReloading")); } getBackup().setPendingShutdown(true); for (final User user : getOnlineUsers()) { @@ -562,7 +579,7 @@ public void onDisable() { } cleanupOpenInventories(); if (getBackup().getTaskLock() != null && !getBackup().getTaskLock().isDone()) { - EssentialsLogger.getLogger().log(Level.SEVERE, tl("backupInProgress")); + LOGGER.log(Level.SEVERE, tl("backupInProgress")); getBackup().getTaskLock().join(); } if (i18n != null) { @@ -637,7 +654,7 @@ public List onTabCompleteEssentials(final CommandSender cSender, final C return completer.onTabComplete(cSender, command, commandLabel, args); } } catch (final Exception ex) { - EssentialsLogger.getLogger().log(Level.SEVERE, ex.getMessage(), ex); + LOGGER.log(Level.SEVERE, ex.getMessage(), ex); } } } @@ -667,7 +684,7 @@ public List onTabCompleteEssentials(final CommandSender cSender, final C cmd = loadCommand(commandPath, command.getName(), module, classLoader); } catch (final Exception ex) { sender.sendMessage(tl("commandNotLoaded", commandLabel)); - EssentialsLogger.getLogger().log(Level.SEVERE, tl("commandNotLoaded", commandLabel), ex); + LOGGER.log(Level.SEVERE, tl("commandNotLoaded", commandLabel), ex); return Collections.emptyList(); } @@ -690,11 +707,11 @@ public List onTabCompleteEssentials(final CommandSender cSender, final C } catch (final Exception ex) { showError(sender, ex, commandLabel); // Tab completion shouldn't fail - EssentialsLogger.getLogger().log(Level.SEVERE, tl("commandFailed", commandLabel), ex); + LOGGER.log(Level.SEVERE, tl("commandFailed", commandLabel), ex); return Collections.emptyList(); } } catch (final Throwable ex) { - EssentialsLogger.getLogger().log(Level.SEVERE, tl("commandFailed", commandLabel), ex); + LOGGER.log(Level.SEVERE, tl("commandFailed", commandLabel), ex); return Collections.emptyList(); } } @@ -710,7 +727,7 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co // Allow plugins to override the command via onCommand if (!getSettings().isCommandOverridden(command.getName()) && (!commandLabel.startsWith("e") || commandLabel.equalsIgnoreCase(command.getName()))) { if (getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "Searching for alternative to: " + commandLabel); + LOGGER.log(Level.INFO, "Searching for alternative to: " + commandLabel); } final Command pc = alternativeCommandsHandler.getAlternative(commandLabel); if (pc != null) { @@ -718,7 +735,7 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co try { pc.execute(cSender, commandLabel, args); } catch (final Exception ex) { - EssentialsLogger.getLogger().log(Level.SEVERE, ex.getMessage(), ex); + LOGGER.log(Level.SEVERE, ex.getMessage(), ex); cSender.sendMessage(tl("internalError")); } return true; @@ -738,10 +755,10 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co if (bSenderBlock != null) { if (getSettings().logCommandBlockCommands()) { - EssentialsLogger.getLogger().log(Level.INFO, "CommandBlock at " + bSenderBlock.getX() + "," + bSenderBlock.getY() + "," + bSenderBlock.getZ() + " issued server command: /" + commandLabel + " " + EssentialsCommand.getFinalArg(args, 0)); + LOGGER.log(Level.INFO, "CommandBlock at {0},{1},{2} issued server command: /{3} {4}", new Object[] {bSenderBlock.getX(), bSenderBlock.getY(), bSenderBlock.getZ(), commandLabel, EssentialsCommand.getFinalArg(args, 0)}); } } else if (user == null) { - EssentialsLogger.getLogger().log(Level.INFO, cSender.getName() + " issued server command: /" + commandLabel + " " + EssentialsCommand.getFinalArg(args, 0)); + LOGGER.log(Level.INFO, "{0} issued server command: /{1} {2}", new Object[] {cSender.getName(), commandLabel, EssentialsCommand.getFinalArg(args, 0)}); } final CommandSource sender = new CommandSource(cSender); @@ -774,13 +791,13 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co cmd = loadCommand(commandPath, command.getName(), module, classLoader); } catch (final Exception ex) { sender.sendMessage(tl("commandNotLoaded", commandLabel)); - EssentialsLogger.getLogger().log(Level.SEVERE, tl("commandNotLoaded", commandLabel), ex); + LOGGER.log(Level.SEVERE, tl("commandNotLoaded", commandLabel), ex); return true; } // Check authorization if (user != null && !user.isAuthorized(cmd, permissionPrefix)) { - EssentialsLogger.getLogger().log(Level.INFO, tl("deniedAccessCommand", user.getName())); + LOGGER.log(Level.INFO, tl("deniedAccessCommand", user.getName())); user.sendMessage(tl("noAccessCommand")); return true; } @@ -831,7 +848,7 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co return true; } } catch (final Throwable ex) { - EssentialsLogger.getLogger().log(Level.SEVERE, tl("commandFailed", commandLabel), ex); + LOGGER.log(Level.SEVERE, tl("commandFailed", commandLabel), ex); return true; } } @@ -859,7 +876,7 @@ public void cleanupOpenInventories() { public void showError(final CommandSource sender, final Throwable exception, final String commandLabel) { sender.sendMessage(tl("errorWithMessage", exception.getMessage())); if (getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, tl("errorCallingCommand", commandLabel), exception); + LOGGER.log(Level.INFO, tl("errorCallingCommand", commandLabel), exception); } } @@ -1045,7 +1062,7 @@ public User getUser(final Player base) { } if (userMap == null) { - EssentialsLogger.getLogger().log(Level.WARNING, "Essentials userMap not initialized"); + LOGGER.log(Level.WARNING, "Essentials userMap not initialized"); return null; } @@ -1053,7 +1070,7 @@ public User getUser(final Player base) { if (user == null) { if (getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "Constructing new userfile from base player " + base.getName()); + LOGGER.log(Level.INFO, "Constructing new userfile from base player {0}", base.getName()); } user = new User(base, this); } else { @@ -1064,7 +1081,7 @@ public User getUser(final Player base) { private void handleCrash(final Throwable exception) { final PluginManager pm = getServer().getPluginManager(); - EssentialsLogger.getLogger().log(Level.SEVERE, exception.toString()); + LOGGER.log(Level.SEVERE, exception.toString()); exception.printStackTrace(); pm.registerEvents(new Listener() { @EventHandler(priority = EventPriority.LOW) diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsEntityListener.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsEntityListener.java index 8a8ffd0a23a..ba305ec0b93 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsEntityListener.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsEntityListener.java @@ -108,7 +108,7 @@ class PowerToolInteractTask implements Runnable { @Override public void run() { attacker.getBase().chat("/" + command); - EssentialsLogger.getLogger().log(Level.INFO, String.format("[PT] %s issued server command: /%s", attacker.getName(), command)); + ess.getLogger().log(Level.INFO, String.format("[PT] %s issued server command: /%s", attacker.getName(), command)); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsLogger.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsLogger.java index 9086153515f..5190bb66e67 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsLogger.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsLogger.java @@ -12,7 +12,6 @@ import java.util.logging.Logger; public final class EssentialsLogger { - private static LoggerProvider loggerProvider; private final static Map loggerProviders = new HashMap<>(); private EssentialsLogger() { @@ -44,12 +43,4 @@ public static LoggerProvider getLoggerProvider(final String pluginName) { } return getLoggerProvider(plugin); } - - public static Logger setLoggerProvider(LoggerProvider loggerProvider) { - return EssentialsLogger.loggerProvider = loggerProvider; - } - - public static LoggerProvider getLogger() { - return loggerProvider; - } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java index 95c7757459e..8e444c6c76d 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java @@ -164,7 +164,7 @@ public void onPlayerChat(final AsyncPlayerChatEvent event) { user.sendMessage(user.hasMuteReason() ? tl("voiceSilencedReasonTime", dateDiff, user.getMuteReason()) : tl("voiceSilencedTime", dateDiff)); } - EssentialsLogger.getLogger().info(tl("mutedUserSpeaks", user.getName(), event.getMessage())); + ess.getLogger().info(tl("mutedUserSpeaks", user.getName(), event.getMessage())); } try { final Iterator it = event.getRecipients().iterator(); @@ -176,9 +176,9 @@ public void onPlayerChat(final AsyncPlayerChatEvent event) { } } catch (final UnsupportedOperationException ex) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "Ignore could not block chat due to custom chat plugin event.", ex); + ess.getLogger().log(Level.INFO, "Ignore could not block chat due to custom chat plugin event.", ex); } else { - EssentialsLogger.getLogger().info("Ignore could not block chat due to custom chat plugin event."); + ess.getLogger().info("Ignore could not block chat due to custom chat plugin event."); } } @@ -196,7 +196,7 @@ public void onPlayerMove(final PlayerMoveEvent event) { event.getHandlers().unregister(this); if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "Unregistering move listener"); + ess.getLogger().log(Level.INFO, "Unregistering move listener"); } return; @@ -344,7 +344,7 @@ public void run() { if (toVanish != null && toVanish.isOnline()) { user.getBase().hidePlayer(toVanish); if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().info("Hiding vanished player: " + p); + ess.getLogger().info("Hiding vanished player: " + p); } } } @@ -430,12 +430,12 @@ public void run() { if (user.isSocialSpyEnabled() && !user.isAuthorized("essentials.socialspy")) { user.setSocialSpyEnabled(false); - EssentialsLogger.getLogger().log(Level.INFO, "Set socialspy to false for " + user.getName() + " because they had it enabled without permission."); + ess.getLogger().log(Level.INFO, "Set socialspy to false for {0} because they had it enabled without permission.", user.getName()); } if (user.isGodModeEnabled() && !user.isAuthorized("essentials.god")) { user.setGodModeEnabled(false); - EssentialsLogger.getLogger().log(Level.INFO, "Set god mode to false for " + user.getName() + " because they had it enabled without permission."); + ess.getLogger().log(Level.INFO, "Set god mode to false for {0} because they had it enabled without permission.", user.getName()); } user.setConfirmingClearCommand(null); @@ -462,9 +462,9 @@ public void run() { tempInput = new TextInput(user.getSource(), "motd", true, ess); } catch (final IOException ex) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.WARNING, ex.getMessage(), ex); + ess.getLogger().log(Level.WARNING, ex.getMessage(), ex); } else { - EssentialsLogger.getLogger().log(Level.WARNING, ex.getMessage()); + ess.getLogger().log(Level.WARNING, ex.getMessage()); } } } @@ -624,7 +624,7 @@ public void handlePlayerCommandPreprocess(final PlayerCommandPreprocessEvent eve } else { player.sendMessage(user.hasMuteReason() ? tl("voiceSilencedReasonTime", dateDiff, user.getMuteReason()) : tl("voiceSilencedTime", dateDiff)); } - EssentialsLogger.getLogger().info(tl("mutedUserSpeaks", player.getName(), event.getMessage())); + ess.getLogger().info(tl("mutedUserSpeaks", player.getName(), event.getMessage())); return; } @@ -681,7 +681,7 @@ public void handlePlayerCommandPreprocess(final PlayerCommandPreprocessEvent eve if (cooldownEntry != null) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().info("Applying " + cooldownEntry.getValue() + "ms cooldown on /" + fullCommand + " for" + user.getName() + "."); + ess.getLogger().info("Applying " + cooldownEntry.getValue() + "ms cooldown on /" + fullCommand + " for" + user.getName() + "."); } final Date expiry = new Date(System.currentTimeMillis() + cooldownEntry.getValue()); user.addCommandCooldown(cooldownEntry.getKey(), expiry, ess.getSettings().isCommandCooldownPersistent(fullCommand)); @@ -812,7 +812,7 @@ public void run() { ess.scheduleSyncDelayedTask(new DelayedClickJumpTask()); } catch (final Exception ex) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.WARNING, ex.getMessage(), ex); + ess.getLogger().log(Level.WARNING, ex.getMessage(), ex); } } } @@ -836,7 +836,7 @@ class PowerToolUseTask implements Runnable { @Override public void run() { user.getBase().chat("/" + command); - EssentialsLogger.getLogger().log(Level.INFO, String.format("[PT] %s issued server command: /%s", user.getName(), command)); + ess.getLogger().log(Level.INFO, String.format("[PT] %s issued server command: /%s", user.getName(), command)); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsPluginListener.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsPluginListener.java index cd20b5e5abc..38e1f9a1eb6 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsPluginListener.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsPluginListener.java @@ -29,7 +29,7 @@ public void onPluginEnable(final PluginEnableEvent event) { if (EconomyLayers.isServerStarted()) { final EconomyLayer layer = EconomyLayers.onPluginEnable(event.getPlugin()); if (layer != null) { - EssentialsLogger.getLogger().log(Level.INFO, "Essentials found a compatible payment resolution method: " + layer.getName() + " (v" + layer.getPluginVersion() + ")!"); + ess.getLogger().log(Level.INFO, "Essentials found a compatible payment resolution method: " + layer.getName() + " (v" + layer.getPluginVersion() + ")!"); } } } @@ -44,9 +44,9 @@ public void onPluginDisable(final PluginDisableEvent event) { if (EconomyLayers.onPluginDisable(event.getPlugin())) { final EconomyLayer layer = EconomyLayers.getSelectedLayer(); if (layer != null) { - EssentialsLogger.getLogger().log(Level.INFO, "Essentials found a new compatible payment resolution method: " + layer.getName() + " (v" + layer.getPluginVersion() + ")!"); + ess.getLogger().log(Level.INFO, "Essentials found a new compatible payment resolution method: " + layer.getName() + " (v" + layer.getPluginVersion() + ")!"); } else { - EssentialsLogger.getLogger().log(Level.INFO, "Active payment resolution method has been disabled! Falling back to Essentials' default payment resolution system!"); + ess.getLogger().log(Level.INFO, "Active payment resolution method has been disabled! Falling back to Essentials' default payment resolution system!"); } } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsServerListener.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsServerListener.java index f474dbdd660..419f025dde0 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsServerListener.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsServerListener.java @@ -37,13 +37,13 @@ public EssentialsServerListener(final IEssentials ess) { setSampleText = ReflUtil.getMethodCached(ServerListPingEvent.class, "setSampleText", List.class); getSampleText = ReflUtil.getMethodCached(ServerListPingEvent.class, "getSampleText"); if (setSampleText != null && getSampleText != null) { - EssentialsLogger.getLogger().info("ServerListPingEvent: Paper 1.12.2 setSampleText API"); + ess.getLogger().info("ServerListPingEvent: Paper 1.12.2 setSampleText API"); isPaperSample = true; return; } } - EssentialsLogger.getLogger().info("ServerListPingEvent: Spigot iterator API"); + ess.getLogger().info("ServerListPingEvent: Spigot iterator API"); isPaperSample = false; } @@ -56,7 +56,7 @@ public void onServerListPing(final ServerListPingEvent event) throws Exception { setSampleText.invoke(event, playerNames); } catch (final IllegalAccessException | InvocationTargetException | ClassCastException e) { if (!unsupportedLogged && shouldWarnSLPECaller(e)) { - EssentialsLogger.getLogger().log(Level.WARNING, "Unable to hide players from server list ping " + ess.getLogger().log(Level.WARNING, "Unable to hide players from server list ping " + "using Paper 1.12 method!", e); unsupportedLogged = true; } @@ -80,7 +80,7 @@ public void onServerListPing(final ServerListPingEvent event) throws Exception { } } catch (final UnsupportedOperationException e) { if (!unsupportedLogged && shouldWarnSLPECaller(e)) { - EssentialsLogger.getLogger().log(Level.WARNING, "Could not hide vanished players while handling " + event.getClass().getName(), e); + ess.getLogger().log(Level.WARNING, "Could not hide vanished players while handling " + event.getClass().getName(), e); unsupportedLogged = true; } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsTimer.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsTimer.java index 8eded0a49f2..fbc96e1d214 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsTimer.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsTimer.java @@ -63,7 +63,7 @@ public void run() { user.setLastOnlineActivity(currentTime); user.checkActivity(); } catch (final Exception e) { - EssentialsLogger.getLogger().log(Level.WARNING, "EssentialsTimer Error:", e); + ess.getLogger().log(Level.WARNING, "EssentialsTimer Error:", e); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsUpgrade.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsUpgrade.java index 54ee76f206e..8e4ec15e46b 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsUpgrade.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsUpgrade.java @@ -71,7 +71,7 @@ public class EssentialsUpgrade { } public static void uuidFileConvert(final IEssentials ess, final Boolean ignoreUFCache) { - EssentialsLogger.getLogger().info("Starting Essentials UUID userdata conversion"); + ess.getLogger().info("Starting Essentials UUID userdata conversion"); final File userdir = new File(ess.getDataFolder(), "userdata"); if (!userdir.exists()) { @@ -83,7 +83,7 @@ public static void uuidFileConvert(final IEssentials ess, final Boolean ignoreUF int countEssCache = 0; int countBukkit = 0; - EssentialsLogger.getLogger().info("Found " + userdir.list().length + " files to convert..."); + ess.getLogger().info("Found " + userdir.list().length + " files to convert..."); for (final String string : userdir.list()) { if (!string.endsWith(".yml") || string.length() < 5) { @@ -94,7 +94,7 @@ public static void uuidFileConvert(final IEssentials ess, final Boolean ignoreUF if (showProgress == 0) { ess.getUserMap().getUUIDMap().forceWriteUUIDMap(); - EssentialsLogger.getLogger().info("Converted " + countFiles + "/" + userdir.list().length); + ess.getLogger().info("Converted " + countFiles + "/" + userdir.list().length); } countFiles++; @@ -148,9 +148,9 @@ public static void uuidFileConvert(final IEssentials ess, final Boolean ignoreUF } ess.getUserMap().getUUIDMap().forceWriteUUIDMap(); - EssentialsLogger.getLogger().info("Converted " + countFiles + "/" + countFiles + ". Conversion complete."); - EssentialsLogger.getLogger().info("Converted via cache: " + countEssCache + " :: Converted via lookup: " + countBukkit + " :: Failed to convert: " + countFails); - EssentialsLogger.getLogger().info("To rerun the conversion type /essentials uuidconvert"); + ess.getLogger().info("Converted " + countFiles + "/" + countFiles + ". Conversion complete."); + ess.getLogger().info("Converted via cache: " + countEssCache + " :: Converted via lookup: " + countBukkit + " :: Failed to convert: " + countFails); + ess.getLogger().info("To rerun the conversion type /essentials uuidconvert"); } public void convertMailList() { @@ -184,13 +184,13 @@ public void convertMailList() { config.blockingSave(); } } catch (RuntimeException ex) { - EssentialsLogger.getLogger().log(Level.INFO, "File: " + file); + ess.getLogger().log(Level.INFO, "File: " + file); throw ex; } } doneFile.setProperty("updateUsersMailList", true); doneFile.save(); - EssentialsLogger.getLogger().info("Done converting mail list."); + ess.getLogger().info("Done converting mail list."); } public void convertStupidCamelCaseUserdataKeys() { @@ -198,7 +198,7 @@ public void convertStupidCamelCaseUserdataKeys() { return; } - EssentialsLogger.getLogger().info("Attempting to migrate legacy userdata keys to Configurate"); + ess.getLogger().info("Attempting to migrate legacy userdata keys to Configurate"); final File userdataFolder = new File(ess.getDataFolder(), "userdata"); if (!userdataFolder.exists() || !userdataFolder.isDirectory()) { @@ -239,13 +239,13 @@ public void convertStupidCamelCaseUserdataKeys() { } config.blockingSave(); } catch (final RuntimeException ex) { - EssentialsLogger.getLogger().log(Level.INFO, "File: " + file); + ess.getLogger().log(Level.INFO, "File: " + file); throw ex; } } doneFile.setProperty("updateUsersStupidLegacyPathNames", true); doneFile.save(); - EssentialsLogger.getLogger().info("Done converting legacy userdata keys to Configurate."); + ess.getLogger().info("Done converting legacy userdata keys to Configurate."); } /** @@ -288,31 +288,31 @@ public void purgeBrokenNpcAccounts() { } final File backupFolder = new File(ess.getDataFolder(), "userdata-npc-backup"); if (backupFolder.exists()) { - EssentialsLogger.getLogger().info("NPC backup folder already exists; skipping NPC purge."); - EssentialsLogger.getLogger().info("To finish purging broken NPC accounts, rename the \"plugins/Essentials/userdata-npc-backup\" folder and restart your server."); + ess.getLogger().info("NPC backup folder already exists; skipping NPC purge."); + ess.getLogger().info("To finish purging broken NPC accounts, rename the \"plugins/Essentials/userdata-npc-backup\" folder and restart your server."); return; } else if (!backupFolder.mkdir()) { - EssentialsLogger.getLogger().info("Skipping NPC purge due to error creating backup folder."); + ess.getLogger().info("Skipping NPC purge due to error creating backup folder."); return; } - EssentialsLogger.getLogger().info("#===========================================================================#"); - EssentialsLogger.getLogger().info(" EssentialsX will now purge any NPC accounts which were incorrectly created."); - EssentialsLogger.getLogger().info(" Only NPC accounts with the default starting balance will be deleted. If"); - EssentialsLogger.getLogger().info(" they turn out to be valid NPC accounts, they will be re-created as needed."); - EssentialsLogger.getLogger().info(" Any files deleted here will be backed up to the "); - EssentialsLogger.getLogger().info(" \"plugins/Essentials/userdata-npc-backup\" folder. If you notice any files"); - EssentialsLogger.getLogger().info(" have been purged incorrectly, you should restore it from the backup and"); - EssentialsLogger.getLogger().info(" report it to us on GitHub:"); - EssentialsLogger.getLogger().info(" https://github.com/EssentialsX/Essentials/issues/new/choose"); - EssentialsLogger.getLogger().info(""); - EssentialsLogger.getLogger().info(" NOTE: This is a one-time process and will take several minutes if you have"); - EssentialsLogger.getLogger().info(" a lot of userdata files! If you interrupt this process, EssentialsX will"); - EssentialsLogger.getLogger().info(" skip the process until you rename or remove the backup folder."); - EssentialsLogger.getLogger().info("#===========================================================================#"); + ess.getLogger().info("#===========================================================================#"); + ess.getLogger().info(" EssentialsX will now purge any NPC accounts which were incorrectly created."); + ess.getLogger().info(" Only NPC accounts with the default starting balance will be deleted. If"); + ess.getLogger().info(" they turn out to be valid NPC accounts, they will be re-created as needed."); + ess.getLogger().info(" Any files deleted here will be backed up to the "); + ess.getLogger().info(" \"plugins/Essentials/userdata-npc-backup\" folder. If you notice any files"); + ess.getLogger().info(" have been purged incorrectly, you should restore it from the backup and"); + ess.getLogger().info(" report it to us on GitHub:"); + ess.getLogger().info(" https://github.com/EssentialsX/Essentials/issues/new/choose"); + ess.getLogger().info(""); + ess.getLogger().info(" NOTE: This is a one-time process and will take several minutes if you have"); + ess.getLogger().info(" a lot of userdata files! If you interrupt this process, EssentialsX will"); + ess.getLogger().info(" skip the process until you rename or remove the backup folder."); + ess.getLogger().info("#===========================================================================#"); final int totalUserFiles = userFiles.length; - EssentialsLogger.getLogger().info("Found ~" + totalUserFiles + " files under \"plugins/Essentials/userdata\"..."); + ess.getLogger().info("Found ~" + totalUserFiles + " files under \"plugins/Essentials/userdata\"..."); final AtomicInteger movedAccounts = new AtomicInteger(0); final AtomicInteger totalAccounts = new AtomicInteger(0); @@ -322,7 +322,7 @@ public void purgeBrokenNpcAccounts() { final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); final ScheduledFuture feedbackTask = executor.scheduleWithFixedDelay( - () -> EssentialsLogger.getLogger().info("Scanned " + totalAccounts.get() + "/" + totalUserFiles + " accounts; moved " + movedAccounts.get() + " accounts"), + () -> ess.getLogger().info("Scanned " + totalAccounts.get() + "/" + totalUserFiles + " accounts; moved " + movedAccounts.get() + " accounts"), 5, feedbackInterval, TimeUnit.SECONDS); for (final File file : userFiles) { @@ -356,10 +356,10 @@ public void purgeBrokenNpcAccounts() { Files.move(file, new File(backupFolder, file.getName())); movedAccounts.incrementAndGet(); } catch (IOException e) { - EssentialsLogger.getLogger().log(Level.SEVERE, "Error while moving NPC file", e); + ess.getLogger().log(Level.SEVERE, "Error while moving NPC file", e); } } catch (final RuntimeException ex) { - EssentialsLogger.getLogger().log(Level.INFO, "File: " + file); + ess.getLogger().log(Level.INFO, "File: " + file); feedbackTask.cancel(false); executor.shutdown(); throw ex; @@ -370,18 +370,18 @@ public void purgeBrokenNpcAccounts() { doneFile.setProperty("updatePurgeBrokenNpcAccounts", true); doneFile.save(); - EssentialsLogger.getLogger().info("#===========================================================================#"); - EssentialsLogger.getLogger().info(" EssentialsX has finished purging NPC accounts."); - EssentialsLogger.getLogger().info(""); - EssentialsLogger.getLogger().info(" Deleted accounts: " + movedAccounts); - EssentialsLogger.getLogger().info(" Total accounts processed: " + totalAccounts); - EssentialsLogger.getLogger().info(""); - EssentialsLogger.getLogger().info(" Purged accounts have been backed up to"); - EssentialsLogger.getLogger().info(" \"plugins/Essentials/userdata-npc-backup\", and can be restored from there"); - EssentialsLogger.getLogger().info(" if needed. Please report any files which have been incorrectly deleted"); - EssentialsLogger.getLogger().info(" to us on GitHub:"); - EssentialsLogger.getLogger().info(" https://github.com/EssentialsX/Essentials/issues/new/choose"); - EssentialsLogger.getLogger().info("#===========================================================================#"); + ess.getLogger().info("#===========================================================================#"); + ess.getLogger().info(" EssentialsX has finished purging NPC accounts."); + ess.getLogger().info(""); + ess.getLogger().info(" Deleted accounts: " + movedAccounts); + ess.getLogger().info(" Total accounts processed: " + totalAccounts); + ess.getLogger().info(""); + ess.getLogger().info(" Purged accounts have been backed up to"); + ess.getLogger().info(" \"plugins/Essentials/userdata-npc-backup\", and can be restored from there"); + ess.getLogger().info(" if needed. Please report any files which have been incorrectly deleted"); + ess.getLogger().info(" to us on GitHub:"); + ess.getLogger().info(" https://github.com/EssentialsX/Essentials/issues/new/choose"); + ess.getLogger().info("#===========================================================================#"); } public void convertIgnoreList() { @@ -390,7 +390,7 @@ public void convertIgnoreList() { return; } - EssentialsLogger.getLogger().info("Attempting to migrate ignore list to UUIDs"); + ess.getLogger().info("Attempting to migrate ignore list to UUIDs"); final File userdataFolder = new File(ess.getDataFolder(), "userdata"); if (!userdataFolder.exists() || !userdataFolder.isDirectory()) { @@ -412,7 +412,7 @@ public void convertIgnoreList() { continue; } if (pattern.matcher(name.trim()).matches()) { - EssentialsLogger.getLogger().info("Detected already migrated ignore list!"); + ess.getLogger().info("Detected already migrated ignore list!"); return; } final User user = ess.getOfflineUser(name); @@ -425,13 +425,13 @@ public void convertIgnoreList() { config.blockingSave(); } } catch (final RuntimeException ex) { - EssentialsLogger.getLogger().log(Level.INFO, "File: " + file); + ess.getLogger().log(Level.INFO, "File: " + file); throw ex; } } doneFile.setProperty("updateUsersIgnoreListUUID", true); doneFile.save(); - EssentialsLogger.getLogger().info("Done converting ignore list."); + ess.getLogger().info("Done converting ignore list."); } public void convertKits() { @@ -441,25 +441,25 @@ public void convertKits() { return; } - EssentialsLogger.getLogger().info("Attempting to convert old kits in config.yml to new kits.yml"); + ess.getLogger().info("Attempting to convert old kits in config.yml to new kits.yml"); final CommentedConfigurationNode section = ess.getSettings().getKitSection(); if (section == null) { - EssentialsLogger.getLogger().info("No kits found to migrate."); + ess.getLogger().info("No kits found to migrate."); return; } final Map legacyKits = ConfigurateUtil.getRawMap(section); for (final Map.Entry entry : legacyKits.entrySet()) { - EssentialsLogger.getLogger().info("Converting " + entry.getKey()); + ess.getLogger().info("Converting " + entry.getKey()); config.setRaw("kits." + entry.getKey(), entry.getValue()); } config.save(); doneFile.setProperty("kitsyml", true); doneFile.save(); - EssentialsLogger.getLogger().info("Done converting kits."); + ess.getLogger().info("Done converting kits."); } private void moveMotdRulesToFile(final String name) { @@ -492,7 +492,7 @@ private void moveMotdRulesToFile(final String name) { doneFile.setProperty("move" + name + "ToFile", true); doneFile.save(); } catch (final IOException e) { - EssentialsLogger.getLogger().log(Level.SEVERE, tl("upgradingFilesError"), e); + ess.getLogger().log(Level.SEVERE, tl("upgradingFilesError"), e); } } @@ -570,7 +570,7 @@ private void updateUsersPowerToolsFormat() { config.blockingSave(); } } catch (final RuntimeException ex) { - EssentialsLogger.getLogger().log(Level.INFO, "File: " + file); + ess.getLogger().log(Level.INFO, "File: " + file); throw ex; } } @@ -626,7 +626,7 @@ private void updateUsersHomesFormat() { } } catch (final RuntimeException ex) { - EssentialsLogger.getLogger().log(Level.INFO, "File: " + file); + ess.getLogger().log(Level.INFO, "File: " + file); throw ex; } } @@ -655,15 +655,15 @@ private void sanitizeAllUserFilenames() { final File tmpFile = new File(listOfFile.getParentFile(), sanitizedFilename + ".tmp"); final File newFile = new File(listOfFile.getParentFile(), sanitizedFilename); if (!listOfFile.renameTo(tmpFile)) { - EssentialsLogger.getLogger().log(Level.WARNING, tl("userdataMoveError", filename, sanitizedFilename)); + ess.getLogger().log(Level.WARNING, tl("userdataMoveError", filename, sanitizedFilename)); continue; } if (newFile.exists()) { - EssentialsLogger.getLogger().log(Level.WARNING, tl("duplicatedUserdata", filename, sanitizedFilename)); + ess.getLogger().log(Level.WARNING, tl("duplicatedUserdata", filename, sanitizedFilename)); continue; } if (!tmpFile.renameTo(newFile)) { - EssentialsLogger.getLogger().log(Level.WARNING, tl("userdataMoveBackError", sanitizedFilename, sanitizedFilename)); + ess.getLogger().log(Level.WARNING, tl("userdataMoveBackError", sanitizedFilename, sanitizedFilename)); } } doneFile.setProperty("sanitizeAllUserFilenames", true); @@ -720,7 +720,7 @@ private void deleteOldItemsCsv() { doneFile.setProperty("deleteOldItemsCsv", true); doneFile.save(); } catch (final IOException ex) { - Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex); + Essentials.getWrappedLogger().log(Level.SEVERE, ex.getMessage(), ex); } } } @@ -746,7 +746,7 @@ private void updateSpawnsToNewSpawnsConfig() { config.blockingSave(); } } catch (final Exception ex) { - Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex); + Essentials.getWrappedLogger().log(Level.SEVERE, ex.getMessage(), ex); } } doneFile.setProperty("updateSpawnsToNewSpawnsConfig", true); @@ -774,7 +774,7 @@ private void updateJailsToNewJailsConfig() { config.blockingSave(); } } catch (final Exception ex) { - Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex); + Essentials.getWrappedLogger().log(Level.SEVERE, ex.getMessage(), ex); } } doneFile.setProperty("updateJailsToNewJailsConfig", true); @@ -828,8 +828,8 @@ private void uuidFileChange() { return; } - EssentialsLogger.getLogger().info("#### Starting Essentials UUID userdata conversion in a few seconds. ####"); - EssentialsLogger.getLogger().info("We recommend you take a backup of your server before upgrading from the old username system."); + ess.getLogger().info("#### Starting Essentials UUID userdata conversion in a few seconds. ####"); + ess.getLogger().info("We recommend you take a backup of your server before upgrading from the old username system."); try { Thread.sleep(15000); @@ -848,7 +848,7 @@ public void banFormatChange() { return; } - EssentialsLogger.getLogger().info("Starting Essentials ban format conversion"); + ess.getLogger().info("Starting Essentials ban format conversion"); final File userdir = new File(ess.getDataFolder(), "userdata"); if (!userdir.exists()) { @@ -857,7 +857,7 @@ public void banFormatChange() { int countFiles = 0; - EssentialsLogger.getLogger().info("Found " + userdir.list().length + " files to convert..."); + ess.getLogger().info("Found " + userdir.list().length + " files to convert..."); for (final String string : userdir.list()) { if (!string.endsWith(".yml") || string.length() < 5) { @@ -867,7 +867,7 @@ public void banFormatChange() { final int showProgress = countFiles % 250; if (showProgress == 0) { - EssentialsLogger.getLogger().info("Converted " + countFiles + "/" + userdir.list().length); + ess.getLogger().info("Converted " + countFiles + "/" + userdir.list().length); } countFiles++; @@ -906,7 +906,7 @@ public void banFormatChange() { doneFile.setProperty("banFormatChange", true); doneFile.save(); - EssentialsLogger.getLogger().info("Ban format update complete."); + ess.getLogger().info("Ban format update complete."); } private void updateBan(final String playerName, final String banReason, final Long banTimeout) { @@ -917,11 +917,11 @@ private void repairUserMap() { if (doneFile.getBoolean("userMapRepaired", false)) { return; } - EssentialsLogger.getLogger().info("Starting usermap repair"); + ess.getLogger().info("Starting usermap repair"); final File userdataFolder = new File(ess.getDataFolder(), "userdata"); if (!userdataFolder.isDirectory()) { - EssentialsLogger.getLogger().warning("Missing userdata folder, aborting"); + ess.getLogger().warning("Missing userdata folder, aborting"); return; } final File[] files = userdataFolder.listFiles(YML_FILTER); @@ -966,11 +966,11 @@ private void repairUserMap() { } if (index % 1000 == 0) { - EssentialsLogger.getLogger().info("Reading: " + format.format((100d * (double) index) / files.length) + ess.getLogger().info("Reading: " + format.format((100d * (double) index) / files.length) + "%"); } } catch (final IOException e) { - EssentialsLogger.getLogger().log(Level.SEVERE, "Error while reading file: ", e); + ess.getLogger().log(Level.SEVERE, "Error while reading file: ", e); return; } } @@ -980,7 +980,7 @@ private void repairUserMap() { doneFile.setProperty("userMapRepaired", true); doneFile.save(); - EssentialsLogger.getLogger().info("Completed usermap repair."); + ess.getLogger().info("Completed usermap repair."); } public void beforeSettings() { diff --git a/Essentials/src/main/java/com/earth2me/essentials/I18n.java b/Essentials/src/main/java/com/earth2me/essentials/I18n.java index ece2a90bca8..582a14fbe34 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/I18n.java +++ b/Essentials/src/main/java/com/earth2me/essentials/I18n.java @@ -88,7 +88,6 @@ private String translate(final String string) { } } catch (final MissingResourceException ex) { if (ess == null || ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.WARNING, String.format("Missing translation key \"%s\" in translation file %s", ex.getKey(), localeBundle.getLocale().toString()), ex); } return defaultBundle.getString(string); } @@ -101,7 +100,7 @@ public String format(final String string, final Object... objects) { try { messageFormat = new MessageFormat(format); } catch (final IllegalArgumentException e) { - EssentialsLogger.getLogger().log(Level.SEVERE, "Invalid Translation key for '" + string + "': " + e.getMessage()); + ess.getLogger().log(Level.SEVERE, "Invalid Translation key for '" + string + "': " + e.getMessage()); format = format.replaceAll("\\{(\\D*?)\\}", "\\[$1\\]"); messageFormat = new MessageFormat(format); } @@ -125,7 +124,8 @@ public void updateLocale(final String loc) { } ResourceBundle.clearCache(); messageFormatCache = new HashMap<>(); - EssentialsLogger.getLogger().log(Level.INFO, "Using locale " + currentLocale.toString()); + Essentials.getWrappedLogger().log(Level.INFO, String.format("Using locale %s", currentLocale.toString())); + try { localeBundle = ResourceBundle.getBundle(MESSAGES, currentLocale, new UTF8PropertiesControl()); } catch (final MissingResourceException ex) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/Jails.java b/Essentials/src/main/java/com/earth2me/essentials/Jails.java index b974dc1fa13..2cbf2c91c7e 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Jails.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Jails.java @@ -74,7 +74,7 @@ private void registerListeners() { final JailListener blockListener = new JailListener(); pluginManager.registerEvents(blockListener, ess); if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "Registering Jail listener"); + ess.getLogger().log(Level.INFO, "Registering Jail listener"); } } @@ -266,9 +266,9 @@ public void onJailPlayerRespawn(final PlayerRespawnEvent event) { event.setRespawnLocation(getJail(user.getJail())); } catch (final Exception ex) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex); + ess.getLogger().log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex); } else { - EssentialsLogger.getLogger().log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())); + ess.getLogger().log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())); } } } @@ -284,9 +284,9 @@ public void onJailPlayerTeleport(final PlayerTeleportEvent event) { event.setTo(getJail(user.getJail())); } catch (final Exception ex) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex); + ess.getLogger().log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex); } else { - EssentialsLogger.getLogger().log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())); + ess.getLogger().log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())); } } user.sendMessage(tl("jailMessage")); @@ -304,9 +304,9 @@ public void onJailPlayerJoin(final PlayerJoinEvent event) { final CompletableFuture future = new CompletableFuture<>(); future.exceptionally(ex -> { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex); + ess.getLogger().log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex); } else { - EssentialsLogger.getLogger().log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())); + ess.getLogger().log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())); } return false; }); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Kit.java b/Essentials/src/main/java/com/earth2me/essentials/Kit.java index 5ddfd76478a..e072fece091 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Kit.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Kit.java @@ -147,7 +147,7 @@ public List getItems() throws Exception { } throw new Exception("Invalid item list"); } catch (final Exception e) { - EssentialsLogger.getLogger().log(Level.WARNING, "Error parsing kit " + kitName + ": " + e.getMessage()); + ess.getLogger().log(Level.WARNING, "Error parsing kit " + kitName + ": " + e.getMessage()); throw new Exception(tl("kitError2"), e); } } @@ -192,7 +192,7 @@ public boolean expandItems(final User user, final List items) throws Exc if (kitItem.startsWith("@")) { if (ess.getSerializationProvider() == null) { - EssentialsLogger.getLogger().log(Level.WARNING, tl("kitError3", kitName, user.getName())); + ess.getLogger().log(Level.WARNING, tl("kitError3", kitName, user.getName())); continue; } stack = ess.getSerializationProvider().deserializeItem(Base64Coder.decodeLines(kitItem.substring(1))); @@ -286,7 +286,7 @@ public boolean expandItems(final User user, final List items) throws Exc } } catch (final Exception e) { user.getBase().updateInventory(); - EssentialsLogger.getLogger().log(Level.WARNING, e.getMessage()); + ess.getLogger().log(Level.WARNING, e.getMessage()); throw new Exception(tl("kitError2"), e); } return true; diff --git a/Essentials/src/main/java/com/earth2me/essentials/ManagedFile.java b/Essentials/src/main/java/com/earth2me/essentials/ManagedFile.java index 3d1fda60b70..b529445b6d6 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/ManagedFile.java +++ b/Essentials/src/main/java/com/earth2me/essentials/ManagedFile.java @@ -1,7 +1,6 @@ package com.earth2me.essentials; import net.ess3.api.IEssentials; -import org.bukkit.Bukkit; import java.io.BufferedInputStream; import java.io.BufferedReader; @@ -38,7 +37,7 @@ public ManagedFile(final String filename, final IEssentials ess) { throw new IOException("Could not delete file " + file.toString()); } } catch (final IOException ex) { - Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex); + Essentials.getWrappedLogger().log(Level.SEVERE, ex.getMessage(), ex); } } @@ -46,7 +45,7 @@ public ManagedFile(final String filename, final IEssentials ess) { try { copyResourceAscii("/" + filename, file); } catch (final IOException ex) { - Bukkit.getLogger().log(Level.SEVERE, tl("itemsCsvNotLoaded", filename), ex); + Essentials.getWrappedLogger().log(Level.SEVERE, tl("itemsCsvNotLoaded", filename), ex); } } } @@ -113,7 +112,7 @@ public static boolean checkForVersion(final File file, final String version) thr if (correct.equals(test)) { return true; } else { - Bukkit.getLogger().warning("File " + file.toString() + " has been modified by user and file version differs, please update the file manually."); + Essentials.getWrappedLogger().warning("File " + file.toString() + " has been modified by user and file version differs, please update the file manually."); } } } @@ -147,7 +146,7 @@ public List getLines() { return lines; } } catch (final IOException ex) { - Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex); + Essentials.getWrappedLogger().log(Level.SEVERE, ex.getMessage(), ex); return Collections.emptyList(); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java b/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java index a222a15f64d..d1edb3e028c 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java +++ b/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java @@ -138,7 +138,7 @@ public boolean canSpawn(final IEssentials ess) { return true; } catch (final Throwable npe) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "Itemstack is invalid", npe); + ess.getLogger().log(Level.INFO, "Itemstack is invalid", npe); } return false; } @@ -150,7 +150,7 @@ public void parseStringMeta(final CommandSource sender, final boolean allowUnsaf stack = ess.getServer().getUnsafe().modifyItemStack(stack, Joiner.on(' ').join(Arrays.asList(string).subList(fromArg, string.length))); } catch (final NullPointerException npe) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "Itemstack is invalid", npe); + ess.getLogger().log(Level.INFO, "Itemstack is invalid", npe); } } catch (final NoSuchMethodError nsme) { throw new Exception(tl("noMetaJson"), nsme); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Mob.java b/Essentials/src/main/java/com/earth2me/essentials/Mob.java index 13538e3dcf6..11f51b41d80 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Mob.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Mob.java @@ -169,7 +169,7 @@ public static Mob fromBukkitType(final EntityType type) { public Entity spawn(final World world, final Server server, final Location loc) throws MobException { final Entity entity = world.spawn(loc, this.bukkitType.getEntityClass()); if (entity == null) { - EssentialsLogger.getLogger().log(Level.WARNING, tl("unableToSpawnMob")); + Essentials.getWrappedLogger().log(Level.WARNING, tl("unableToSpawnMob")); throw new MobException(); } return entity; diff --git a/Essentials/src/main/java/com/earth2me/essentials/MobData.java b/Essentials/src/main/java/com/earth2me/essentials/MobData.java index 9826998e4de..43d09afe664 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/MobData.java +++ b/Essentials/src/main/java/com/earth2me/essentials/MobData.java @@ -414,7 +414,7 @@ public void setData(final Entity spawned, final Player target, final String rawD } } } else { - EssentialsLogger.getLogger().warning("Unknown mob data type: " + this.toString()); + Essentials.getWrappedLogger().warning("Unknown mob data type: " + this.toString()); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/Settings.java b/Essentials/src/main/java/com/earth2me/essentials/Settings.java index 1400878e839..c0b1c618245 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Settings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Settings.java @@ -385,7 +385,7 @@ private Map _getCommandCosts() { final String command = entry.getKey(); final CommentedConfigurationNode node = entry.getValue(); if (command.charAt(0) == '/') { - EssentialsLogger.getLogger().warning("Invalid command cost. '" + command + "' should not start with '/'."); + ess.getLogger().warning("Invalid command cost. '" + command + "' should not start with '/'."); } try { if (ConfigurateUtil.isDouble(node)) { @@ -398,10 +398,10 @@ private Map _getCommandCosts() { final double cost = Double.parseDouble(costString.trim().replace("$", "").replace(getCurrencySymbol(), "").replaceAll("\\W", "")); newMap.put(command.toLowerCase(Locale.ENGLISH), BigDecimal.valueOf(cost)); } else { - EssentialsLogger.getLogger().warning("Invalid command cost for: " + command); + ess.getLogger().warning("Invalid command cost for: " + command); } } catch (final Exception ex) { - EssentialsLogger.getLogger().warning("Invalid command cost for: " + command); + ess.getLogger().warning("Invalid command cost for: " + command); } } return newMap; @@ -586,7 +586,7 @@ public String getChatFormat(final String group) { chatFormats.put(group, mFormat); } if (isDebug()) { - EssentialsLogger.getLogger().info(String.format("Found format '%s' for group '%s'", mFormat, group)); + ess.getLogger().info(String.format("Found format '%s' for group '%s'", mFormat, group)); } return mFormat; } @@ -684,7 +684,7 @@ public void reloadConfig() { boolean mapModified = false; if (!disabledBukkitCommands.isEmpty()) { if (isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "Re-adding " + disabledBukkitCommands.size() + " disabled commands!"); + ess.getLogger().log(Level.INFO, "Re-adding " + disabledBukkitCommands.size() + " disabled commands!"); } ess.getKnownCommandsProvider().getKnownCommands().putAll(disabledBukkitCommands); disabledBukkitCommands.clear(); @@ -696,12 +696,12 @@ public void reloadConfig() { final Command toDisable = ess.getPluginCommand(effectiveAlias); if (toDisable != null) { if (isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "Attempting removal of " + effectiveAlias); + ess.getLogger().log(Level.INFO, "Attempting removal of " + effectiveAlias); } final Command removed = ess.getKnownCommandsProvider().getKnownCommands().remove(effectiveAlias); if (removed != null) { if (isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "Adding command " + effectiveAlias + " to disabled map!"); + ess.getLogger().log(Level.INFO, "Adding command " + effectiveAlias + " to disabled map!"); } disabledBukkitCommands.put(effectiveAlias, removed); } @@ -718,7 +718,7 @@ public void reloadConfig() { if (mapModified) { if (isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "Syncing commands"); + ess.getLogger().log(Level.INFO, "Syncing commands"); } if (reloadCount.get() < 2) { ess.scheduleSyncDelayedTask(() -> ess.getSyncCommandsProvider().syncCommands()); @@ -797,7 +797,7 @@ private List _getItemSpawnBlacklist() { //noinspection deprecation final IItemDb itemDb = ess.getItemDb(); if (itemDb == null || !itemDb.isReady()) { - EssentialsLogger.getLogger().log(Level.FINE, "Skipping item spawn blacklist read; item DB not yet loaded."); + ess.getLogger().log(Level.FINE, "Skipping item spawn blacklist read; item DB not yet loaded."); return epItemSpwn; } for (String itemName : config.getString("item-spawn-blacklist", "").split(",")) { @@ -809,7 +809,7 @@ private List _getItemSpawnBlacklist() { final ItemStack iStack = itemDb.get(itemName); epItemSpwn.add(iStack.getType()); } catch (final Exception ex) { - EssentialsLogger.getLogger().log(Level.SEVERE, tl("unknownItemInList", itemName, "item-spawn-blacklist"), ex); + ess.getLogger().log(Level.SEVERE, tl("unknownItemInList", itemName, "item-spawn-blacklist"), ex); } } return epItemSpwn; @@ -837,7 +837,7 @@ private List _getEnabledSigns() { try { newSigns.add(Signs.valueOf(signName).getSign()); } catch (final Exception ex) { - EssentialsLogger.getLogger().log(Level.SEVERE, tl("unknownItemInList", signName, "enabledSigns")); + ess.getLogger().log(Level.SEVERE, tl("unknownItemInList", signName, "enabledSigns")); continue; } signsEnabled = true; @@ -951,7 +951,7 @@ public List getProtectList(final String configName) { } if (mat == null) { - EssentialsLogger.getLogger().log(Level.SEVERE, tl("unknownItemInList", itemName, configName)); + ess.getLogger().log(Level.SEVERE, tl("unknownItemInList", itemName, configName)); } else { list.add(mat); } @@ -1573,7 +1573,7 @@ private Map _getCommandCooldowns() { try { pattern = Pattern.compile(cmdEntry.substring(1)); } catch (final PatternSyntaxException e) { - EssentialsLogger.getLogger().warning("Command cooldown error: " + e.getMessage()); + ess.getLogger().warning("Command cooldown error: " + e.getMessage()); } } else { // Escape above Regex @@ -1595,12 +1595,12 @@ private Map _getCommandCooldowns() { } } if (!(value instanceof Number)) { - EssentialsLogger.getLogger().warning("Command cooldown error: '" + value + "' is not a valid cooldown"); + ess.getLogger().warning("Command cooldown error: '" + value + "' is not a valid cooldown"); continue; } final double cooldown = ((Number) value).doubleValue(); if (cooldown < 1) { - EssentialsLogger.getLogger().warning("Command cooldown with very short " + cooldown + " cooldown."); + ess.getLogger().warning("Command cooldown with very short " + cooldown + " cooldown."); } result.put(pattern, (long) cooldown * 1000); // convert to milliseconds @@ -1626,7 +1626,7 @@ public Entry getCommandCooldownEntry(final String label) { // Check if label matches current pattern (command-cooldown in config) final boolean matches = entry.getKey().matcher(label).matches(); if (isDebug()) { - EssentialsLogger.getLogger().info(String.format("Checking command '%s' against cooldown '%s': %s", label, entry.getKey(), matches)); + ess.getLogger().info(String.format("Checking command '%s' against cooldown '%s': %s", label, entry.getKey(), matches)); } if (matches) { @@ -1693,7 +1693,7 @@ private List _getUnprotectedSign() { try { newSigns.add(Signs.valueOf(signName).getSign()); } catch (final Exception ex) { - EssentialsLogger.getLogger().log(Level.SEVERE, tl("unknownItemInList", signName, "unprotected-sign-names")); + ess.getLogger().log(Level.SEVERE, tl("unknownItemInList", signName, "unprotected-sign-names")); } } return newSigns; @@ -1878,7 +1878,7 @@ private Set> _getNickBlacklist() { try { blacklist.add(Pattern.compile(entry).asPredicate()); } catch (final PatternSyntaxException e) { - EssentialsLogger.getLogger().warning("Invalid nickname blacklist regex: " + entry); + ess.getLogger().warning("Invalid nickname blacklist regex: " + entry); } }); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Teleport.java b/Essentials/src/main/java/com/earth2me/essentials/Teleport.java index 91e481aa357..6038b2e3578 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Teleport.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Teleport.java @@ -325,7 +325,7 @@ void respawnNow(final IUser teleportee, final TeleportCause cause) throws Except now(teleportee, new LocationTarget(bed), cause); } else { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().info("Could not find bed spawn, forcing respawn event."); + ess.getLogger().info("Could not find bed spawn, forcing respawn event."); } final PlayerRespawnEvent pre = new PlayerRespawnEvent(player, player.getWorld().getSpawnLocation(), false); ess.getServer().getPluginManager().callEvent(pre); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Trade.java b/Essentials/src/main/java/com/earth2me/essentials/Trade.java index 58c03af6df9..7d241658c3d 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Trade.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Trade.java @@ -79,7 +79,7 @@ public static void log(final String type, final String subtype, final String eve try { fw = new FileWriter(new File(ess.getDataFolder(), "trade.log"), true); } catch (final IOException ex) { - EssentialsLogger.getLogger().log(Level.SEVERE, null, ex); + Essentials.getWrappedLogger().log(Level.SEVERE, null, ex); } } final StringBuilder sb = new StringBuilder(); @@ -158,7 +158,7 @@ public static void log(final String type, final String subtype, final String eve fw.write(sb.toString()); fw.flush(); } catch (final IOException ex) { - EssentialsLogger.getLogger().log(Level.SEVERE, null, ex); + Essentials.getWrappedLogger().log(Level.SEVERE, null, ex); } } @@ -167,7 +167,7 @@ public static void closeLog() { try { fw.close(); } catch (final IOException ex) { - EssentialsLogger.getLogger().log(Level.SEVERE, null, ex); + Essentials.getWrappedLogger().log(Level.SEVERE, null, ex); } fw = null; } @@ -189,7 +189,7 @@ public void isAffordableFor(final IUser user) throws ChargeException { public void isAffordableFor(final IUser user, final CompletableFuture future) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "checking if " + user.getName() + " can afford charge."); + ess.getLogger().log(Level.INFO, "checking if " + user.getName() + " can afford charge."); } if (getMoney() != null && getMoney().signum() > 0 && !user.canAfford(getMoney())) { @@ -220,7 +220,7 @@ public boolean pay(final IUser user) throws MaxMoneyException { public Map pay(final IUser user, final OverflowType type) throws MaxMoneyException { if (getMoney() != null && getMoney().signum() > 0) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "paying user " + user.getName() + " via trade " + getMoney().toPlainString()); + ess.getLogger().log(Level.INFO, "paying user " + user.getName() + " via trade " + getMoney().toPlainString()); } user.giveMoney(getMoney()); } @@ -232,7 +232,7 @@ public Map pay(final IUser user, final OverflowType type) th switch (type) { case ABORT: if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "abort paying " + user.getName() + " itemstack " + getItemStack().toString() + " due to lack of inventory space "); + ess.getLogger().log(Level.INFO, "abort paying " + user.getName() + " itemstack " + getItemStack().toString() + " due to lack of inventory space "); } return overFlow; @@ -243,7 +243,7 @@ public Map pay(final IUser user, final OverflowType type) th user.getBase().updateInventory(); if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "paying " + user.getName() + " partial itemstack " + getItemStack().toString() + " with overflow " + returnStack.get(0).toString()); + ess.getLogger().log(Level.INFO, "paying " + user.getName() + " partial itemstack " + getItemStack().toString() + " with overflow " + returnStack.get(0).toString()); } return returnStack; @@ -268,12 +268,12 @@ public Map pay(final IUser user, final OverflowType type) th } } if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "paying " + user.getName() + " partial itemstack " + getItemStack().toString() + " and dropping overflow " + leftOver.get(0).toString()); + ess.getLogger().log(Level.INFO, "paying " + user.getName() + " partial itemstack " + getItemStack().toString() + " and dropping overflow " + leftOver.get(0).toString()); } break; } } else if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "paying " + user.getName() + " itemstack " + getItemStack().toString()); + ess.getLogger().log(Level.INFO, "paying " + user.getName() + " itemstack " + getItemStack().toString()); } user.getBase().updateInventory(); } @@ -299,11 +299,11 @@ public void charge(final IUser user) throws ChargeException { public void charge(final IUser user, final CompletableFuture future) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "attempting to charge user " + user.getName()); + ess.getLogger().log(Level.INFO, "attempting to charge user " + user.getName()); } if (getMoney() != null) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "charging user " + user.getName() + " money " + getMoney().toPlainString()); + ess.getLogger().log(Level.INFO, "charging user " + user.getName() + " money " + getMoney().toPlainString()); } if (!user.canAfford(getMoney()) && getMoney().signum() > 0) { future.completeExceptionally(new ChargeException(tl("notEnoughMoney", NumberUtil.displayCurrency(getMoney(), ess)))); @@ -313,7 +313,7 @@ public void charge(final IUser user, final CompletableFuture future) { } if (getItemStack() != null) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "charging user " + user.getName() + " itemstack " + getItemStack().toString()); + ess.getLogger().log(Level.INFO, "charging user " + user.getName() + " itemstack " + getItemStack().toString()); } if (!user.getBase().getInventory().containsAtLeast(getItemStack(), getItemStack().getAmount())) { future.completeExceptionally(new ChargeException(tl("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase(Locale.ENGLISH).replace("_", " ")))); @@ -332,7 +332,7 @@ public void charge(final IUser user, final CompletableFuture future) { } if (getExperience() != null) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "charging user " + user.getName() + " exp " + getExperience()); + ess.getLogger().log(Level.INFO, "charging user " + user.getName() + " exp " + getExperience()); } final int experience = SetExpFix.getTotalExperience(user.getBase()); if (experience < getExperience() && getExperience() > 0) { @@ -342,7 +342,7 @@ public void charge(final IUser user, final CompletableFuture future) { SetExpFix.setTotalExperience(user.getBase(), experience - getExperience()); } if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "charge user " + user.getName() + " completed"); + ess.getLogger().log(Level.INFO, "charge user " + user.getName() + " completed"); } } @@ -379,7 +379,7 @@ public BigDecimal getCommandCost(final IUser user) { } if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "calculated command (" + command + ") cost for " + user.getName() + " as " + cost); + ess.getLogger().log(Level.INFO, "calculated command (" + command + ") cost for " + user.getName() + " as " + cost); } } if (cost.signum() != 0 && (user.isAuthorized("essentials.nocommandcost.all") || user.isAuthorized("essentials.nocommandcost." + command))) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/UUIDMap.java b/Essentials/src/main/java/com/earth2me/essentials/UUIDMap.java index 347b93dfa47..54385a512fb 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/UUIDMap.java +++ b/Essentials/src/main/java/com/earth2me/essentials/UUIDMap.java @@ -1,7 +1,6 @@ package com.earth2me.essentials; import com.google.common.io.Files; -import org.bukkit.Bukkit; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -52,7 +51,7 @@ public void loadAllUsers(final ConcurrentSkipListMap names, final } if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "Reading usermap from disk"); + ess.getLogger().log(Level.INFO, "Reading usermap from disk"); } if (loading) { @@ -90,7 +89,7 @@ public void loadAllUsers(final ConcurrentSkipListMap names, final } loading = false; } catch (final IOException ex) { - Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex); + Essentials.getWrappedLogger().log(Level.SEVERE, ex.getMessage(), ex); } } @@ -100,7 +99,7 @@ public void writeUUIDMap() { public void forceWriteUUIDMap() { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "Forcing usermap write to disk"); + ess.getLogger().log(Level.INFO, "Forcing usermap write to disk"); } pendingWrite = true; writeTaskRunnable.run(); @@ -147,9 +146,9 @@ public void run() { Files.move(configFile, new File(endFile.getParentFile(), "usermap.bak.csv")); } } catch (final Exception ex2) { - Bukkit.getLogger().log(Level.SEVERE, ex2.getMessage(), ex2); + Essentials.getWrappedLogger().log(Level.SEVERE, ex2.getMessage(), ex2); } - Bukkit.getLogger().log(Level.WARNING, ex.getMessage(), ex); + Essentials.getWrappedLogger().log(Level.WARNING, ex.getMessage(), ex); } } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index bbdf2a67b96..8a8e71b67f7 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -127,7 +127,7 @@ public boolean isAuthorized(final IEssentialsCommand cmd, final String permissio public boolean isAuthorized(final String node) { final boolean result = isAuthorizedCheck(node); if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "checking if " + base.getName() + " has " + node + " - " + result); + ess.getLogger().log(Level.INFO, "checking if " + base.getName() + " has " + node + " - " + result); } return result; } @@ -136,7 +136,7 @@ public boolean isAuthorized(final String node) { public boolean isPermissionSet(final String node) { final boolean result = isPermSetCheck(node); if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "checking if " + base.getName() + " has " + node + " (set-explicit) - " + result); + ess.getLogger().log(Level.INFO, "checking if " + base.getName() + " has " + node + " (set-explicit) - " + result); } return result; } @@ -158,9 +158,9 @@ private boolean isAuthorizedCheck(final String node) { return ess.getPermissionsHandler().hasPermission(base, node); } catch (final Exception ex) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage(), ex); + ess.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage(), ex); } else { - EssentialsLogger.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage()); + ess.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage()); } return false; @@ -176,9 +176,9 @@ private boolean isPermSetCheck(final String node) { return ess.getPermissionsHandler().isPermissionSet(base, node); } catch (final Exception ex) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage(), ex); + ess.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage(), ex); } else { - EssentialsLogger.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage()); + ess.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage()); } return false; @@ -194,9 +194,9 @@ private TriState isAuthorizedExactCheck(final String node) { return ess.getPermissionsHandler().isPermissionSetExact(base, node); } catch (final Exception ex) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage(), ex); + ess.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage(), ex); } else { - EssentialsLogger.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage()); + ess.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage()); } return TriState.UNSET; @@ -279,7 +279,7 @@ public void takeMoney(final BigDecimal value, final CommandSource initiator, fin try { setMoney(getMoney().subtract(value), cause); } catch (final MaxMoneyException ex) { - EssentialsLogger.getLogger().log(Level.WARNING, "Invalid call to takeMoney, total balance can't be more than the max-money limit.", ex); + ess.getLogger().log(Level.WARNING, "Invalid call to takeMoney, total balance can't be more than the max-money limit.", ex); } sendMessage(tl("takenFromAccount", NumberUtil.displayCurrency(value, ess))); if (initiator != null) { @@ -518,7 +518,7 @@ public void setDisplayNick() { this.getBase().setPlayerListName(name); } catch (final IllegalArgumentException e) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "Playerlist for " + name + " was not updated. Name clashed with another online player."); + ess.getLogger().log(Level.INFO, "Playerlist for " + name + " was not updated. Name clashed with another online player."); } } } @@ -567,7 +567,7 @@ public BigDecimal getMoney() { final BigDecimal value = _getMoney(); final long elapsed = System.nanoTime() - start; if (elapsed > ess.getSettings().getEconomyLagWarning()) { - EssentialsLogger.getLogger().log(Level.INFO, "Lag Notice - Slow Economy Response - Request took over " + elapsed / 1000000.0 + "ms!"); + ess.getLogger().log(Level.INFO, "Lag Notice - Slow Economy Response - Request took over {0}ms!", elapsed / 1000000.0); } return value; } @@ -580,7 +580,7 @@ public void setMoney(final BigDecimal value) throws MaxMoneyException { private BigDecimal _getMoney() { if (ess.getSettings().isEcoDisabled()) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().info("Internal economy functions disabled, aborting balance check."); + ess.getLogger().info("Internal economy functions disabled, aborting balance check."); } return BigDecimal.ZERO; } @@ -594,7 +594,7 @@ private BigDecimal _getMoney() { public void setMoney(final BigDecimal value, final UserBalanceUpdateEvent.Cause cause) throws MaxMoneyException { if (ess.getSettings().isEcoDisabled()) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().info("Internal economy functions disabled, aborting balance change."); + ess.getLogger().info("Internal economy functions disabled, aborting balance change."); } return; } @@ -869,7 +869,7 @@ public boolean isGodModeEnabledRaw() { public String getGroup() { final String result = ess.getPermissionsHandler().getGroup(base); if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "looking up groupname of " + base.getName() + " - " + result); + ess.getLogger().log(Level.INFO, "looking up groupname of " + base.getName() + " - " + result); } return result; } @@ -878,7 +878,7 @@ public String getGroup() { public boolean inGroup(final String group) { final boolean result = ess.getPermissionsHandler().inGroup(base, group); if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "checking if " + base.getName() + " is in group " + group + " - " + result); + ess.getLogger().log(Level.INFO, "checking if " + base.getName() + " is in group " + group + " - " + result); } return result; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/UserData.java b/Essentials/src/main/java/com/earth2me/essentials/UserData.java index 3fbb5384da2..2e3fb2a657b 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/UserData.java +++ b/Essentials/src/main/java/com/earth2me/essentials/UserData.java @@ -51,7 +51,7 @@ protected UserData(final Player base, final IEssentials ess) { try { filename = base.getUniqueId().toString(); } catch (final Throwable ex) { - EssentialsLogger.getLogger().warning("Falling back to old username system for " + base.getName()); + ess.getLogger().warning("Falling back to old username system for " + base.getName()); filename = base.getName(); } @@ -85,14 +85,14 @@ public final void reloadConfig() { try { holder = config.getRootNode().get(UserConfigHolder.class); } catch (SerializationException e) { - EssentialsLogger.getLogger().log(Level.SEVERE, "Error while reading user config: " + config.getFile().getName(), e); + ess.getLogger().log(Level.SEVERE, "Error while reading user config: " + config.getFile().getName(), e); throw new RuntimeException(e); } config.setSaveHook(() -> { try { config.getRootNode().set(UserConfigHolder.class, holder); } catch (SerializationException e) { - EssentialsLogger.getLogger().log(Level.SEVERE, "Error while saving user config: " + config.getFile().getName(), e); + ess.getLogger().log(Level.SEVERE, "Error while saving user config: " + config.getFile().getName(), e); throw new RuntimeException(e); } }); diff --git a/Essentials/src/main/java/com/earth2me/essentials/UserMap.java b/Essentials/src/main/java/com/earth2me/essentials/UserMap.java index 40cc732b3d6..35f5eefe614 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/UserMap.java +++ b/Essentials/src/main/java/com/earth2me/essentials/UserMap.java @@ -95,7 +95,7 @@ public User getUser(final String name) { final String sanitizedName = StringUtil.safeString(name); try { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().warning("Looking up username " + name + " (" + sanitizedName + ") ..."); + ess.getLogger().warning("Looking up username " + name + " (" + sanitizedName + ") ..."); } if (names.containsKey(sanitizedName)) { @@ -104,12 +104,12 @@ public User getUser(final String name) { } if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().warning(name + "(" + sanitizedName + ") has no known usermap entry"); + ess.getLogger().warning(name + "(" + sanitizedName + ") has no known usermap entry"); } final File userFile = getUserFileFromString(sanitizedName); if (userFile.exists()) { - EssentialsLogger.getLogger().info("Importing user " + name + " to usermap."); + ess.getLogger().info("Importing user " + name + " to usermap."); final User user = new User(new OfflinePlayer(sanitizedName, ess.getServer()), ess); trackUUID(user.getBase().getUniqueId(), user.getName(), true); return user; @@ -117,7 +117,7 @@ public User getUser(final String name) { return null; } catch (final UncheckedExecutionException ex) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.WARNING, "Exception while getting user for " + name + " (" + sanitizedName + ")", ex); + ess.getLogger().log(Level.WARNING, ex, () -> String.format("Exception while getting user for %s (%s)", name, sanitizedName)); } return null; } @@ -132,7 +132,7 @@ public User getUser(final UUID uuid) { } } catch (final ExecutionException | UncheckedExecutionException ex) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.WARNING, "Exception while getting user for " + uuid, ex); + ess.getLogger().log(Level.WARNING, ex, () -> "Exception while getting user for " + uuid); } return null; } @@ -148,11 +148,11 @@ public void trackUUID(final UUID uuid, final String name, final boolean replace) uuidMap.writeUUIDMap(); } else if (!isUUIDMatch(uuid, keyName)) { if (replace) { - EssentialsLogger.getLogger().info("Found new UUID for " + name + ". Replacing " + names.get(keyName).toString() + " with " + uuid.toString()); + ess.getLogger().info("Found new UUID for " + name + ". Replacing " + names.get(keyName).toString() + " with " + uuid.toString()); names.put(keyName, uuid); uuidMap.writeUUIDMap(); } else { - EssentialsLogger.getLogger().log(Level.INFO, MessageFormat.format(WARN_UUID_NOT_REPLACE, uuid.toString(), name, names.get(keyName).toString()), new RuntimeException()); + ess.getLogger().log(Level.INFO, MessageFormat.format(WARN_UUID_NOT_REPLACE, uuid.toString(), name, names.get(keyName).toString()), new RuntimeException()); } } } @@ -193,7 +193,7 @@ public User load(final org.bukkit.OfflinePlayer player) throws UserDoesNotExistE if (player instanceof Player) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().info("Loading online OfflinePlayer into user map..."); + ess.getLogger().info("Loading online OfflinePlayer into user map..."); } final User user = new User((Player) player, ess); trackUUID(player.getUniqueId(), player.getName(), true); @@ -202,7 +202,7 @@ public User load(final org.bukkit.OfflinePlayer player) throws UserDoesNotExistE final File userFile = getUserFileFromID(player.getUniqueId()); if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().info("Loading OfflinePlayer into user map. Has data: " + userFile.exists() + " for " + player); + ess.getLogger().info("Loading OfflinePlayer into user map. Has data: " + userFile.exists() + " for " + player); } final OfflinePlayer essPlayer = new OfflinePlayer(player.getUniqueId(), ess.getServer()); @@ -211,7 +211,7 @@ public User load(final org.bukkit.OfflinePlayer player) throws UserDoesNotExistE essPlayer.setName(user.getLastAccountName()); } else { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().info("OfflinePlayer usermap load saving user data for " + player); + ess.getLogger().info("OfflinePlayer usermap load saving user data for " + player); } // this code makes me sad @@ -242,7 +242,7 @@ public void invalidateAll() { public void removeUser(final String name) { if (names == null) { - EssentialsLogger.getLogger().warning("Name collection is null, cannot remove user."); + ess.getLogger().warning("Name collection is null, cannot remove user."); return; } final UUID uuid = names.get(name); @@ -308,7 +308,7 @@ public File getUserFileFromString(final String name) { public User getUserFromBukkit(String name) { name = StringUtil.safeString(name); if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().warning("Using potentially blocking Bukkit UUID lookup for: " + name); + ess.getLogger().warning("Using potentially blocking Bukkit UUID lookup for: " + name); } // Don't attempt to look up entirely invalid usernames if (name == null || !validUserPattern.matcher(name).matches()) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/Warps.java b/Essentials/src/main/java/com/earth2me/essentials/Warps.java index 7938397cbd6..e1b441ee064 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Warps.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Warps.java @@ -133,7 +133,7 @@ public final void reloadConfig() { warpPoints.put(new StringIgnoreCase(name), conf); } } catch (final Exception ex) { - EssentialsLogger.getLogger().log(Level.WARNING, tl("loadWarpError", filename), ex); + Essentials.getWrappedLogger().log(Level.WARNING, tl("loadWarpError", filename), ex); } } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/api/Economy.java b/Essentials/src/main/java/com/earth2me/essentials/api/Economy.java index af3cebaf052..a848d70074a 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/api/Economy.java +++ b/Essentials/src/main/java/com/earth2me/essentials/api/Economy.java @@ -1,6 +1,5 @@ package com.earth2me.essentials.api; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; import com.earth2me.essentials.config.EssentialsUserConfiguration; @@ -53,8 +52,8 @@ private static void createNPCFile(String name) { final UUID npcUUID = UUID.nameUUIDFromBytes(("NPC:" + name).getBytes(Charsets.UTF_8)); final File npcFile = new File(folder, npcUUID + ".yml"); if (npcFile.exists()) { - EssentialsLogger.getLogger().log(Level.SEVERE, MessageFormat.format(WARN_NPC_RECREATE_1, name, npcUUID.toString()), new RuntimeException()); - EssentialsLogger.getLogger().log(Level.SEVERE, WARN_NPC_RECREATE_2); + ess.getLogger().log(Level.SEVERE, MessageFormat.format(WARN_NPC_RECREATE_1, name, npcUUID.toString()), new RuntimeException()); + ess.getLogger().log(Level.SEVERE, WARN_NPC_RECREATE_2); } final EssentialsUserConfiguration npcConfig = new EssentialsUserConfiguration(name, npcUUID, npcFile); npcConfig.load(); @@ -89,7 +88,7 @@ private static User getUserByName(final String name) { if (player != null) { user = ess.getUser(player.getUniqueId()); if (user != null) { - EssentialsLogger.getLogger().log(Level.INFO, MessageFormat.format(WARN_PLAYER_UUID_NO_NAME, name, player.getUniqueId().toString()), new RuntimeException()); + ess.getLogger().log(Level.INFO, MessageFormat.format(WARN_PLAYER_UUID_NO_NAME, name, player.getUniqueId().toString()), new RuntimeException()); } } } @@ -189,7 +188,7 @@ public static void setMoney(final String name, final double balance) throws User try { setMoney(name, BigDecimal.valueOf(balance)); } catch (final ArithmeticException e) { - EssentialsLogger.getLogger().log(Level.WARNING, "Failed to set balance of " + name + " to " + balance + ": " + e.getMessage(), e); + ess.getLogger().log(Level.WARNING, "Failed to set balance of " + name + " to " + balance + ": " + e.getMessage(), e); } } @@ -267,7 +266,7 @@ public static void add(final String name, final double amount) throws UserDoesNo try { add(name, BigDecimal.valueOf(amount)); } catch (final ArithmeticException e) { - EssentialsLogger.getLogger().log(Level.WARNING, "Failed to add " + amount + " to balance of " + name + ": " + e.getMessage(), e); + ess.getLogger().log(Level.WARNING, "Failed to add " + amount + " to balance of " + name + ": " + e.getMessage(), e); } } @@ -339,7 +338,7 @@ public static void subtract(final String name, final double amount) throws UserD try { substract(name, BigDecimal.valueOf(amount)); } catch (final ArithmeticException e) { - EssentialsLogger.getLogger().log(Level.WARNING, "Failed to subtract " + amount + " of balance of " + name + ": " + e.getMessage(), e); + ess.getLogger().log(Level.WARNING, "Failed to subtract " + amount + " of balance of " + name + ": " + e.getMessage(), e); } } @@ -409,7 +408,7 @@ public static void divide(final String name, final double amount) throws UserDoe try { divide(name, BigDecimal.valueOf(amount)); } catch (final ArithmeticException e) { - EssentialsLogger.getLogger().log(Level.WARNING, "Failed to divide balance of " + name + " by " + amount + ": " + e.getMessage(), e); + ess.getLogger().log(Level.WARNING, "Failed to divide balance of " + name + " by " + amount + ": " + e.getMessage(), e); } } @@ -481,7 +480,7 @@ public static void multiply(final String name, final double amount) throws UserD try { multiply(name, BigDecimal.valueOf(amount)); } catch (final ArithmeticException e) { - EssentialsLogger.getLogger().log(Level.WARNING, "Failed to multiply balance of " + name + " by " + amount + ": " + e.getMessage(), e); + ess.getLogger().log(Level.WARNING, "Failed to multiply balance of " + name + " by " + amount + ": " + e.getMessage(), e); } } @@ -602,7 +601,7 @@ public static boolean hasEnough(final String name, final double amount) throws U try { return hasEnough(name, BigDecimal.valueOf(amount)); } catch (final ArithmeticException e) { - EssentialsLogger.getLogger().log(Level.WARNING, "Failed to compare balance of " + name + " with " + amount + ": " + e.getMessage(), e); + ess.getLogger().log(Level.WARNING, "Failed to compare balance of " + name + " with " + amount + ": " + e.getMessage(), e); return false; } } @@ -663,7 +662,7 @@ public static boolean hasMore(final String name, final double amount) throws Use try { return hasMore(name, BigDecimal.valueOf(amount)); } catch (final ArithmeticException e) { - EssentialsLogger.getLogger().log(Level.WARNING, "Failed to compare balance of " + name + " with " + amount + ": " + e.getMessage(), e); + ess.getLogger().log(Level.WARNING, "Failed to compare balance of " + name + " with " + amount + ": " + e.getMessage(), e); return false; } } @@ -725,7 +724,7 @@ public static boolean hasLess(final String name, final double amount) throws Use try { return hasLess(name, BigDecimal.valueOf(amount)); } catch (final ArithmeticException e) { - EssentialsLogger.getLogger().log(Level.WARNING, "Failed to compare balance of " + name + " with " + amount + ": " + e.getMessage(), e); + ess.getLogger().log(Level.WARNING, "Failed to compare balance of " + name + " with " + amount + ": " + e.getMessage(), e); return false; } } @@ -832,7 +831,7 @@ public static String format(final double amount) { try { return format(BigDecimal.valueOf(amount)); } catch (final NumberFormatException e) { - EssentialsLogger.getLogger().log(Level.WARNING, "Failed to display " + amount + ": " + e.getMessage(), e); + ess.getLogger().log(Level.WARNING, "Failed to display " + amount + ": " + e.getMessage(), e); return "NaN"; } } @@ -899,7 +898,7 @@ public static boolean createNPC(final String name) { createNPCFile(name); return true; } - EssentialsLogger.getLogger().log(Level.WARNING, MessageFormat.format(WARN_EXISTING_NPC_CREATE, name, user.getConfigUUID()), new RuntimeException()); + ess.getLogger().log(Level.WARNING, MessageFormat.format(WARN_EXISTING_NPC_CREATE, name, user.getConfigUUID()), new RuntimeException()); return false; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java index a89597b6944..0aa0ce63986 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbalancetop.java @@ -1,7 +1,6 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.CommandSource; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.textreader.SimpleTextInput; import com.earth2me.essentials.textreader.TextPager; import com.earth2me.essentials.utils.NumberUtil; @@ -92,7 +91,7 @@ private class Viewer implements Runnable { public void run() { if (ess.getSettings().isEcoDisabled()) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().info("Internal economy functions disabled, aborting baltop."); + ess.getLogger().info("Internal economy functions disabled, aborting baltop."); } return; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcreatekit.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcreatekit.java index 3d989eeaf44..81d4519b5db 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcreatekit.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcreatekit.java @@ -1,7 +1,6 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.CommandSource; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.DateUtil; import com.earth2me.essentials.utils.PasteUtil; @@ -92,18 +91,18 @@ private void uploadPaste(final CommandSource sender, final String kitName, final sender.sendMessage(tl("createKitSuccess", kitName, delayFormat, result.getPasteUrl())); sender.sendMessage(separator); if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().info(sender.getSender().getName() + " created a kit: " + result.getPasteUrl()); + ess.getLogger().info(sender.getSender().getName() + " created a kit: " + result.getPasteUrl()); } } }); future.exceptionally(throwable -> { sender.sendMessage(tl("createKitFailed", kitName)); - EssentialsLogger.getLogger().log(Level.SEVERE, "Error creating kit: ", throwable); + ess.getLogger().log(Level.SEVERE, "Error creating kit: ", throwable); return null; }); } catch (Exception e) { sender.sendMessage(tl("createKitFailed", kitName)); - EssentialsLogger.getLogger().log(Level.SEVERE, "Error creating kit: ", e); + ess.getLogger().log(Level.SEVERE, "Error creating kit: ", e); } }); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandessentials.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandessentials.java index 680b5b0964c..5977ea6a787 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandessentials.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandessentials.java @@ -1,7 +1,6 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.CommandSource; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.EssentialsUpgrade; import com.earth2me.essentials.User; import com.earth2me.essentials.UserMap; @@ -364,8 +363,8 @@ private void runDump(Server server, CommandSource sender, String commandLabel, S sender.sendMessage(tl("dumpUrl", dumpUrl)); sender.sendMessage(tl("dumpDeleteKey", result.getDeletionKey())); if (sender.isPlayer()) { - EssentialsLogger.getLogger().info(tl("dumpConsoleUrl", dumpUrl)); - EssentialsLogger.getLogger().info(tl("dumpDeleteKey", result.getDeletionKey())); + ess.getLogger().info(tl("dumpConsoleUrl", dumpUrl)); + ess.getLogger().info(tl("dumpDeleteKey", result.getDeletionKey())); } } files.clear(); @@ -413,7 +412,7 @@ private void runNya(final Server server, final CommandSource sender, final Strin private void runMoo(final Server server, final CommandSource sender, final String command, final String[] args) { if (args.length == 2 && args[1].equals("moo")) { for (final String s : CONSOLE_MOO) { - EssentialsLogger.getLogger().info(s); + ess.getLogger().info(s); } for (final Player player : ess.getOnlinePlayers()) { player.sendMessage(PLAYER_MOO); @@ -477,7 +476,7 @@ private void runCleanup(final Server server, final CommandSource sender, final S } if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().info("Deleting user: " + user.getName() + " Money: " + moneyCount + " Homes: " + homeCount + " Last seen: " + DateUtil.formatDateDiff(lastLog)); + ess.getLogger().info("Deleting user: " + user.getName() + " Money: " + moneyCount + " Homes: " + homeCount + " Last seen: " + DateUtil.formatDateDiff(lastLog)); } user.reset(); @@ -511,7 +510,7 @@ private void runHomes(final Server server, final CommandSource sender, final Str user.delHome(homeName); } } catch (Exception e) { - EssentialsLogger.getLogger().info("Unable to delete home " + homeName + " for " + user.getName()); + ess.getLogger().info("Unable to delete home " + homeName + " for " + user.getName()); } } } @@ -537,7 +536,7 @@ private void runHomes(final Server server, final CommandSource sender, final Str user.delHome(homeName); } } catch (Exception e) { - EssentialsLogger.getLogger().info("Unable to delete home " + homeName + " for " + user.getName()); + ess.getLogger().info("Unable to delete home " + homeName + " for " + user.getName()); } } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandgc.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandgc.java index 4a9d1cbb00e..462c38bc047 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandgc.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandgc.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.CommandSource; +import com.earth2me.essentials.Essentials; import com.earth2me.essentials.utils.DateUtil; import com.earth2me.essentials.utils.NumberUtil; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Chunk; import org.bukkit.Server; @@ -57,7 +57,7 @@ protected void run(final Server server, final CommandSource sender, final String tileEntities += chunk.getTileEntities().length; } } catch (final java.lang.ClassCastException ex) { - Bukkit.getLogger().log(Level.SEVERE, "Corrupted chunk data on world " + w, ex); + Essentials.getWrappedLogger().log(Level.SEVERE, "Corrupted chunk data on world " + w, ex); } sender.sendMessage(tl("gcWorld", worldType, w.getName(), w.getLoadedChunks().length, w.getEntities().size(), tileEntities)); diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandkit.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandkit.java index c2ef4c968df..28fc58911ac 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandkit.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandkit.java @@ -1,7 +1,6 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.CommandSource; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.Kit; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.StringUtil; @@ -88,7 +87,7 @@ private void giveKits(final User userTo, final User userFrom, final String kitNa } catch (final NoChargeException ex) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "Soft kit error, abort spawning " + kit.getName(), ex); + ess.getLogger().log(Level.INFO, "Soft kit error, abort spawning " + kit.getName(), ex); } } catch (final Exception ex) { ess.showError(userFrom.getSource(), ex, "\\ kit: " + kit.getName()); diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsell.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsell.java index a9876bab48f..f9cd09bf508 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsell.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsell.java @@ -1,6 +1,5 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.NumberUtil; @@ -118,7 +117,7 @@ private BigDecimal sellItem(final User user, final ItemStack is, final String[] Trade.log("Command", "Sell", "Item", user.getName(), new Trade(ris, ess), user.getName(), new Trade(result, ess), user.getLocation(), user.getMoney(), ess); user.giveMoney(result, null, UserBalanceUpdateEvent.Cause.COMMAND_SELL); user.sendMessage(tl("itemSold", NumberUtil.displayCurrency(result, ess), amount, is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(worth, ess))); - EssentialsLogger.getLogger().log(Level.INFO, tl("itemSoldConsole", user.getName(), is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(result, ess), amount, NumberUtil.displayCurrency(worth, ess), user.getDisplayName())); + ess.getLogger().log(Level.INFO, tl("itemSoldConsole", user.getName(), is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(result, ess), amount, NumberUtil.displayCurrency(worth, ess), user.getDisplayName())); return result; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java index 528d4961104..f97a8faf4d7 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpaccept.java @@ -1,7 +1,6 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.AsyncTeleport; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.IUser; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; @@ -100,7 +99,7 @@ private void handleTeleport(final User user, final IUser.TpaRequest request, Str Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().info("TPA accept cancelled by API for " + user.getName() + " (requested by " + requester.getName() + ")"); + ess.getLogger().info("TPA accept cancelled by API for " + user.getName() + " (requested by " + requester.getName() + ")"); } return; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java index 9653fc1bd7e..7c1877e0319 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtpdeny.java @@ -1,6 +1,5 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.IUser; import com.earth2me.essentials.User; import net.essentialsx.api.v2.events.TeleportRequestResponseEvent; @@ -85,7 +84,7 @@ private boolean sendEvent(User user, User player, IUser.TpaRequest request) { Bukkit.getPluginManager().callEvent(event); final boolean cancelled = event.isCancelled(); if (cancelled && ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().info("TPA deny cancelled by API for " + user.getName() + " (requested by " + player.getName() + ")"); + ess.getLogger().info("TPA deny cancelled by API for " + user.getName() + " (requested by " + player.getName() + ")"); } return event.isCancelled(); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/EssentialsCommand.java b/Essentials/src/main/java/com/earth2me/essentials/commands/EssentialsCommand.java index 42c6aef20a5..8418dcfd335 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/EssentialsCommand.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/EssentialsCommand.java @@ -1,7 +1,6 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.CommandSource; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.IEssentialsModule; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; @@ -315,7 +314,7 @@ protected final List tabCompleteCommand(final CommandSource sender, fina final int numArgs = args.length - index - 1; if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().info(numArgs + " " + index + " " + Arrays.toString(args)); + ess.getLogger().info(numArgs + " " + index + " " + Arrays.toString(args)); } String[] effectiveArgs = new String[numArgs]; System.arraycopy(args, index, effectiveArgs, 0, numArgs); @@ -323,7 +322,7 @@ protected final List tabCompleteCommand(final CommandSource sender, fina effectiveArgs = new String[] {""}; } if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().info(command + " -- " + Arrays.toString(effectiveArgs)); + ess.getLogger().info(command + " -- " + Arrays.toString(effectiveArgs)); } return command.tabComplete(sender.getSender(), label, effectiveArgs); @@ -333,7 +332,7 @@ protected final List tabCompleteCommand(final CommandSource sender, fina public void showError(final CommandSender sender, final Throwable throwable, final String commandLabel) { sender.sendMessage(tl("errorWithMessage", throwable.getMessage())); if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, tl("errorCallingCommand", commandLabel), throwable); + ess.getLogger().log(Level.INFO, tl("errorCallingCommand", commandLabel), throwable); throwable.printStackTrace(); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/config/ConfigurationSaveTask.java b/Essentials/src/main/java/com/earth2me/essentials/config/ConfigurationSaveTask.java index 083e88869ec..b6d4c7461b9 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/config/ConfigurationSaveTask.java +++ b/Essentials/src/main/java/com/earth2me/essentials/config/ConfigurationSaveTask.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.config; -import com.earth2me.essentials.EssentialsLogger; +import com.earth2me.essentials.Essentials; import org.spongepowered.configurate.CommentedConfigurationNode; import org.spongepowered.configurate.ConfigurateException; import org.spongepowered.configurate.yaml.YamlConfigurationLoader; @@ -31,7 +31,7 @@ public void run() { try { loader.save(node); } catch (ConfigurateException e) { - EssentialsLogger.getLogger().log(Level.SEVERE, e.getMessage(), e); + Essentials.getWrappedLogger().log(Level.SEVERE, e.getMessage(), e); } finally { pendingWrites.decrementAndGet(); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsConfiguration.java b/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsConfiguration.java index c6a0af7c88f..9e2eb89edbb 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsConfiguration.java +++ b/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsConfiguration.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.config; -import com.earth2me.essentials.EssentialsLogger; +import com.earth2me.essentials.Essentials; import com.earth2me.essentials.config.annotations.DeleteIfIncomplete; import com.earth2me.essentials.config.annotations.DeleteOnEmpty; import com.earth2me.essentials.config.entities.CommandCooldown; @@ -132,7 +132,7 @@ public Map getLocationSectionMap(final String path) { try { result.put(entry.getKey().toLowerCase(Locale.ENGLISH), jailNode.get(LazyLocation.class)); } catch (SerializationException e) { - EssentialsLogger.getLogger().log(Level.WARNING, "Error serializing key " + entry.getKey(), e); + Essentials.getWrappedLogger().log(Level.WARNING, "Error serializing key " + entry.getKey(), e); } } return result; @@ -146,7 +146,7 @@ public void setExplicitList(final String path, final List list, final Typ try { toSplitRoot(path, configurationNode).set(type, list); } catch (SerializationException e) { - EssentialsLogger.getLogger().log(Level.SEVERE, e.getMessage(), e); + Essentials.getWrappedLogger().log(Level.SEVERE, e.getMessage(), e); } } @@ -162,7 +162,7 @@ public List getList(final String path, Class type) { } return list; } catch (SerializationException e) { - EssentialsLogger.getLogger().log(Level.SEVERE, e.getMessage(), e); + Essentials.getWrappedLogger().log(Level.SEVERE, e.getMessage(), e); return new ArrayList<>(); } } @@ -300,7 +300,7 @@ public void removeProperty(String path) { try { node.set(null); } catch (SerializationException e) { - EssentialsLogger.getLogger().log(Level.SEVERE, e.getMessage(), e); + Essentials.getWrappedLogger().log(Level.SEVERE, e.getMessage(), e); } } } @@ -309,7 +309,7 @@ private void setInternal(final String path, final Object value) { try { toSplitRoot(path, configurationNode).set(value); } catch (SerializationException e) { - EssentialsLogger.getLogger().log(Level.SEVERE, e.getMessage(), e); + Essentials.getWrappedLogger().log(Level.SEVERE, e.getMessage(), e); } } @@ -335,13 +335,13 @@ public CommentedConfigurationNode toSplitRoot(String path, final CommentedConfig public synchronized void load() { if (pendingWrites.get() != 0) { - EssentialsLogger.getLogger().log(Level.INFO, "Parsing config file " + configFile + " has been aborted due to " + pendingWrites.get() + " current pending write(s)."); + Essentials.getWrappedLogger().log(Level.INFO, "Parsing config file {0} has been aborted due to {1} current pending write(s).", new Object[]{configFile, pendingWrites.get()}); return; } if (configFile.getParentFile() != null && !configFile.getParentFile().exists()) { if (!configFile.getParentFile().mkdirs()) { - EssentialsLogger.getLogger().log(Level.SEVERE, tl("failedToCreateConfig", configFile.toString())); + Essentials.getWrappedLogger().log(Level.SEVERE, tl("failedToCreateConfig", configFile.toString())); return; } } @@ -353,10 +353,10 @@ public synchronized void load() { convertAltFile(); } else if (templateName != null) { try (final InputStream is = resourceClass.getResourceAsStream(templateName)) { - EssentialsLogger.getLogger().log(Level.INFO, tl("creatingConfigFromTemplate", configFile.toString())); + Essentials.getWrappedLogger().log(Level.INFO, tl("creatingConfigFromTemplate", configFile.toString())); Files.copy(is, configFile.toPath()); } catch (IOException e) { - EssentialsLogger.getLogger().log(Level.SEVERE, tl("failedToWriteConfig", configFile.toString()), e); + Essentials.getWrappedLogger().log(Level.SEVERE, tl("failedToWriteConfig", configFile.toString()), e); } } } @@ -366,12 +366,12 @@ public synchronized void load() { } catch (final ParsingException e) { final File broken = new File(configFile.getAbsolutePath() + ".broken." + System.currentTimeMillis()); if (configFile.renameTo(broken)) { - EssentialsLogger.getLogger().log(Level.SEVERE, "The file " + configFile.toString() + " is broken, it has been renamed to " + broken.toString(), e.getCause()); + Essentials.getWrappedLogger().log(Level.SEVERE, "The file " + configFile.toString() + " is broken, it has been renamed to " + broken.toString(), e.getCause()); return; } - EssentialsLogger.getLogger().log(Level.SEVERE, "The file " + configFile.toString() + " is broken. A backup file has failed to be created", e.getCause()); + Essentials.getWrappedLogger().log(Level.SEVERE, "The file " + configFile.toString() + " is broken. A backup file has failed to be created", e.getCause()); } catch (final ConfigurateException e) { - EssentialsLogger.getLogger().log(Level.SEVERE, e.getMessage(), e); + Essentials.getWrappedLogger().log(Level.SEVERE, e.getMessage(), e); } finally { // Something is wrong! We need a node! I hope the backup worked! if (configurationNode == null) { @@ -434,7 +434,7 @@ public synchronized void blockingSave() { try { delaySave().get(); } catch (final InterruptedException | ExecutionException e) { - EssentialsLogger.getLogger().log(Level.SEVERE, e.getMessage(), e); + Essentials.getWrappedLogger().log(Level.SEVERE, e.getMessage(), e); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsUserConfiguration.java b/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsUserConfiguration.java index 462ff667b54..35d7c1e9008 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsUserConfiguration.java +++ b/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsUserConfiguration.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.config; -import com.earth2me.essentials.EssentialsLogger; +import com.earth2me.essentials.Essentials; import com.google.common.base.Charsets; import com.google.common.io.Files; @@ -44,7 +44,7 @@ public void convertLegacyFile() { //noinspection UnstableApiUsage Files.move(file, new File(configFile.getParentFile(), uuid + ".yml")); } catch (final IOException ex) { - EssentialsLogger.getLogger().log(Level.WARNING, "Failed to migrate user: " + username, ex); + Essentials.getWrappedLogger().log(Level.WARNING, "Failed to migrate user: " + username, ex); } setProperty("last-account-name", username); @@ -69,7 +69,7 @@ public void convertAltFile() { //noinspection UnstableApiUsage Files.move(getAltFile(), new File(configFile.getParentFile(), uuid + ".yml")); } catch (final IOException ex) { - EssentialsLogger.getLogger().log(Level.WARNING, "Failed to migrate user: " + username, ex); + Essentials.getWrappedLogger().log(Level.WARNING, "Failed to migrate user: " + username, ex); } } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/economy/EconomyLayers.java b/Essentials/src/main/java/com/earth2me/essentials/economy/EconomyLayers.java index c6ed3022497..a4184e5588a 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/economy/EconomyLayers.java +++ b/Essentials/src/main/java/com/earth2me/essentials/economy/EconomyLayers.java @@ -1,7 +1,6 @@ package com.earth2me.essentials.economy; import com.earth2me.essentials.Essentials; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.economy.layers.VaultLayer; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; @@ -41,7 +40,7 @@ public static void onEnable(final Essentials ess) { } final EconomyLayer layer = onPluginEnable(plugin); if (layer != null) { - EssentialsLogger.getLogger().log(Level.INFO, "Essentials found a compatible payment resolution method: " + layer.getName() + " (v" + layer.getPluginVersion() + ")!"); + ess.getLogger().log(Level.INFO, "Essentials found a compatible payment resolution method: " + layer.getName() + " (v" + layer.getPluginVersion() + ")!"); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/economy/vault/VaultEconomyProvider.java b/Essentials/src/main/java/com/earth2me/essentials/economy/vault/VaultEconomyProvider.java index 254b263d375..672256d690b 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/economy/vault/VaultEconomyProvider.java +++ b/Essentials/src/main/java/com/earth2me/essentials/economy/vault/VaultEconomyProvider.java @@ -1,7 +1,6 @@ package com.earth2me.essentials.economy.vault; import com.earth2me.essentials.Essentials; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.api.NoLoanPermittedException; import com.earth2me.essentials.api.UserDoesNotExistException; import com.earth2me.essentials.config.EssentialsUserConfiguration; @@ -300,8 +299,8 @@ public boolean createPlayerAccount(OfflinePlayer player) { } final File npcFile = new File(folder, player.getUniqueId() + ".yml"); if (npcFile.exists()) { - EssentialsLogger.getLogger().log(Level.SEVERE, MessageFormat.format(WARN_NPC_RECREATE_1, player.getName(), player.getUniqueId().toString()), new RuntimeException()); - EssentialsLogger.getLogger().log(Level.SEVERE, WARN_NPC_RECREATE_2); + ess.getLogger().log(Level.SEVERE, MessageFormat.format(WARN_NPC_RECREATE_1, player.getName(), player.getUniqueId().toString()), new RuntimeException()); + ess.getLogger().log(Level.SEVERE, WARN_NPC_RECREATE_2); } final EssentialsUserConfiguration npcConfig = new EssentialsUserConfiguration(player.getName(), player.getUniqueId(), npcFile); npcConfig.load(); @@ -316,7 +315,7 @@ public boolean createPlayerAccount(OfflinePlayer player) { // Loading a v4 UUID that we somehow didn't track, mark it as a normal player and hope for the best, vault sucks :/ try { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().info("Vault requested a player account creation for a v4 UUID: " + player); + ess.getLogger().info("Vault requested a player account creation for a v4 UUID: " + player); } ess.getUserMap().load(player); return true; diff --git a/Essentials/src/main/java/com/earth2me/essentials/items/AbstractItemDb.java b/Essentials/src/main/java/com/earth2me/essentials/items/AbstractItemDb.java index 9a4424c6f16..4feb311c180 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/items/AbstractItemDb.java +++ b/Essentials/src/main/java/com/earth2me/essentials/items/AbstractItemDb.java @@ -1,6 +1,5 @@ package com.earth2me.essentials.items; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.IConf; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.FormatUtil; @@ -106,7 +105,7 @@ public ItemStack get(final String id) throws Exception { ItemStack tryResolverDeserialize(final String id) { for (final PluginKey key : resolverMap.keySet()) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().info(String.format("Trying to deserialize item '%s' with resolver '%s'...", id, key)); + ess.getLogger().info(String.format("Trying to deserialize item '%s' with resolver '%s'...", id, key)); } final Function resolver = resolverMap.get(key); @@ -123,7 +122,7 @@ ItemStack tryResolverDeserialize(final String id) { String tryResolverSerialize(final ItemStack stack) { for (final PluginKey key : resolverMap.keySet()) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().info(String.format("Trying to serialize '%s' with resolver '%s'...", stack.toString(), key)); + ess.getLogger().info(String.format("Trying to serialize '%s' with resolver '%s'...", stack.toString(), key)); } final ItemResolver resolver = resolverMap.get(key); diff --git a/Essentials/src/main/java/com/earth2me/essentials/items/CustomItemResolver.java b/Essentials/src/main/java/com/earth2me/essentials/items/CustomItemResolver.java index 8a7032b8e91..3e575427674 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/items/CustomItemResolver.java +++ b/Essentials/src/main/java/com/earth2me/essentials/items/CustomItemResolver.java @@ -1,7 +1,6 @@ package com.earth2me.essentials.items; import com.earth2me.essentials.Essentials; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.IConf; import com.earth2me.essentials.config.ConfigurateUtil; import com.earth2me.essentials.config.EssentialsConfiguration; @@ -62,7 +61,7 @@ public void reloadConfig() { final Map section = ConfigurateUtil.getRawMap(config.getSection("aliases")); if (section.isEmpty()) { - EssentialsLogger.getLogger().warning("No aliases found in custom_items.yml."); + ess.getLogger().warning("No aliases found in custom_items.yml."); return; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/items/FlatItemDb.java b/Essentials/src/main/java/com/earth2me/essentials/items/FlatItemDb.java index 4ac1edd2f71..e8edab47dd5 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/items/FlatItemDb.java +++ b/Essentials/src/main/java/com/earth2me/essentials/items/FlatItemDb.java @@ -1,6 +1,5 @@ package com.earth2me.essentials.items; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.ManagedFile; import com.earth2me.essentials.utils.EnumUtil; import com.earth2me.essentials.utils.MaterialUtil; @@ -53,7 +52,7 @@ public void reloadConfig() { } this.rebuild(); - EssentialsLogger.getLogger().info(String.format("Loaded %s items from items.json.", listNames().size())); + ess.getLogger().info(String.format("Loaded %s items from items.json.", listNames().size())); } private void rebuild() { @@ -99,7 +98,7 @@ private void loadJSON(final String source) { if (valid) { allAliases.add(key); } else { - EssentialsLogger.getLogger().warning(String.format("Failed to add item: \"%s\": %s", key, element.toString())); + ess.getLogger().warning(String.format("Failed to add item: \"%s\": %s", key, element.toString())); } } } @@ -114,7 +113,7 @@ public ItemStack get(String id, final boolean useResolvers) throws Exception { } id = id.toLowerCase(); - final String[] split = id.split(":"); + final String[] split = id.split("(? ess.getSettings().getPermissionsLagWarning()) { - EssentialsLogger.getLogger().log(Level.WARNING, String.format("Permissions lag notice with (%s). Response took %fms. Summary: %s", getName(), elapsed / 1000000.0, summary)); + ess.getLogger().log(Level.WARNING, String.format("Permissions lag notice with (%s). Response took %fms. Summary: %s", getName(), elapsed / 1000000.0, summary)); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/signs/EssentialsSign.java b/Essentials/src/main/java/com/earth2me/essentials/signs/EssentialsSign.java index 70f276f451a..cb0aaaf96b2 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/signs/EssentialsSign.java +++ b/Essentials/src/main/java/com/earth2me/essentials/signs/EssentialsSign.java @@ -2,7 +2,6 @@ import com.earth2me.essentials.ChargeException; import com.earth2me.essentials.CommandSource; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.MetaItemStack; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; @@ -108,7 +107,7 @@ protected final boolean onSignCreate(final SignChangeEvent event, final IEssenti ess.getServer().getPluginManager().callEvent(signEvent); if (signEvent.isCancelled()) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().info("SignCreateEvent cancelled for sign " + signEvent.getEssentialsSign().getName()); + ess.getLogger().info("SignCreateEvent cancelled for sign " + signEvent.getEssentialsSign().getName()); } return false; } @@ -130,7 +129,7 @@ protected final boolean onSignCreate(final SignChangeEvent event, final IEssenti public String getSuccessName(final IEssentials ess) { final String successName = getSuccessName(); if (successName == null) { - EssentialsLogger.getLogger().severe("signFormatSuccess message must use the {0} argument."); + ess.getLogger().severe("signFormatSuccess message must use the {0} argument."); } return successName; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/signs/SignBlockListener.java b/Essentials/src/main/java/com/earth2me/essentials/signs/SignBlockListener.java index c87a49d5222..5b238fe7aec 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/signs/SignBlockListener.java +++ b/Essentials/src/main/java/com/earth2me/essentials/signs/SignBlockListener.java @@ -1,6 +1,5 @@ package com.earth2me.essentials.signs; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.I18n; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.FormatUtil; @@ -51,7 +50,7 @@ public boolean protectSignsAndBlocks(final Block block, final Player player) thr // prevent any signs be broken by destroying the block they are attached to if (EssentialsSign.checkIfBlockBreaksSigns(block)) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "Prevented that a block was broken next to a sign."); + ess.getLogger().log(Level.INFO, "Prevented that a block was broken next to a sign."); } return true; } @@ -69,7 +68,7 @@ public boolean protectSignsAndBlocks(final Block block, final Player player) thr for (final EssentialsSign sign : ess.getSettings().enabledSigns()) { if (sign.areHeavyEventRequired() && sign.getBlocks().contains(block.getType()) && !sign.onBlockBreak(block, player, ess)) { - EssentialsLogger.getLogger().log(Level.INFO, "A block was protected by a sign."); + ess.getLogger().log(Level.INFO, "A block was protected by a sign."); return true; } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/signs/SignPlayerListener.java b/Essentials/src/main/java/com/earth2me/essentials/signs/SignPlayerListener.java index c19419e7e73..ff2638c7d3f 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/signs/SignPlayerListener.java +++ b/Essentials/src/main/java/com/earth2me/essentials/signs/SignPlayerListener.java @@ -1,6 +1,5 @@ package com.earth2me.essentials.signs; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.utils.MaterialUtil; import net.ess3.api.IEssentials; import org.bukkit.Material; @@ -41,7 +40,7 @@ public void onSignPlayerInteract(final PlayerInteractEvent event) { targetBlock = ess.getUser(event.getPlayer()).getTargetBlock(5); } catch (final IllegalStateException ex) { if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.WARNING, ex.getMessage(), ex); + ess.getLogger().log(Level.WARNING, ex.getMessage(), ex); } } block = targetBlock; diff --git a/Essentials/src/main/java/com/earth2me/essentials/textreader/BookInput.java b/Essentials/src/main/java/com/earth2me/essentials/textreader/BookInput.java index cd3fcb8a821..1826f77f4c1 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/textreader/BookInput.java +++ b/Essentials/src/main/java/com/earth2me/essentials/textreader/BookInput.java @@ -1,6 +1,5 @@ package com.earth2me.essentials.textreader; -import com.earth2me.essentials.EssentialsLogger; import net.ess3.api.IEssentials; import java.io.BufferedReader; @@ -45,7 +44,7 @@ public BookInput(final String filename, final boolean createFile, final IEssenti length = input.read(buffer); } } - EssentialsLogger.getLogger().info("File " + filename + ".txt does not exist. Creating one for you."); + ess.getLogger().info("File " + filename + ".txt does not exist. Creating one for you."); } } if (!file.exists()) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/textreader/HelpInput.java b/Essentials/src/main/java/com/earth2me/essentials/textreader/HelpInput.java index d6a4f13419d..3fb835b8b72 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/textreader/HelpInput.java +++ b/Essentials/src/main/java/com/earth2me/essentials/textreader/HelpInput.java @@ -1,6 +1,5 @@ package com.earth2me.essentials.textreader; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.User; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; @@ -120,7 +119,7 @@ public HelpInput(final User user, final String match, final IEssentials ess) { } catch (final NullPointerException ignored) { } catch (final Exception ex) { if (!reported) { - EssentialsLogger.getLogger().log(Level.WARNING, tl("commandHelpFailedForPlugin", pluginNameLow), ex); + ess.getLogger().log(Level.WARNING, tl("commandHelpFailedForPlugin", pluginNameLow), ex); } reported = true; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/textreader/KeywordReplacer.java b/Essentials/src/main/java/com/earth2me/essentials/textreader/KeywordReplacer.java index 70f28f09f97..3bc099e0812 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/textreader/KeywordReplacer.java +++ b/Essentials/src/main/java/com/earth2me/essentials/textreader/KeywordReplacer.java @@ -1,7 +1,6 @@ package com.earth2me.essentials.textreader; import com.earth2me.essentials.CommandSource; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.ExecuteTimer; import com.earth2me.essentials.PlayerList; import com.earth2me.essentials.User; @@ -155,7 +154,7 @@ private void replaceKeywords(final CommandSource sender) { execTimer.mark("Text Replace"); final String timeroutput = execTimer.end(); if (ess.getSettings().isDebug()) { - EssentialsLogger.getLogger().log(Level.INFO, "Keyword Replacer " + timeroutput); + ess.getLogger().log(Level.INFO, "Keyword Replacer " + timeroutput); } } diff --git a/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuild.java b/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuild.java index 6a65eafcadb..445a686c2de 100644 --- a/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuild.java +++ b/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuild.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.antibuild; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.metrics.MetricsWrapper; import org.bukkit.Material; import org.bukkit.plugin.Plugin; @@ -9,6 +10,7 @@ import java.util.EnumMap; import java.util.List; import java.util.Map; +import java.util.logging.Logger; public class EssentialsAntiBuild extends JavaPlugin implements IAntiBuild { private final transient Map settingsBoolean = new EnumMap<>(AntiBuildConfig.class); @@ -37,6 +39,16 @@ public void onEnable() { } } + @Override + public Logger getLogger() { + try { + return EssentialsLogger.getLoggerProvider(this); + } catch (Throwable ignored) { + // In case Essentials isn't installed/loaded + return super.getLogger(); + } + } + @Override public boolean checkProtectionItems(final AntiBuildConfig list, final Material mat) { final List itemList = settingsList.get(list); diff --git a/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java b/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java index e11072ab7d2..92a0f5599f2 100644 --- a/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java +++ b/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java @@ -1,10 +1,8 @@ package com.earth2me.essentials.antibuild; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.VersionUtil; import net.ess3.api.IEssentials; -import net.ess3.provider.LoggerProvider; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.ArmorStand; @@ -39,7 +37,6 @@ import static com.earth2me.essentials.I18n.tl; public class EssentialsAntiBuildListener implements Listener { - private final static LoggerProvider logger = EssentialsLogger.getLoggerProvider("EssentialsAntiBuild"); final private transient IAntiBuild prot; final private transient IEssentials ess; @@ -66,7 +63,7 @@ private static boolean isEntityPickupEvent() { private boolean metaPermCheck(final User user, final String action, final Block block) { if (block == null) { if (ess.getSettings().isDebug()) { - logger.log(Level.INFO, "AntiBuild permission check failed, invalid block."); + prot.getLogger().log(Level.INFO, "AntiBuild permission check failed, invalid block."); } return false; } @@ -79,7 +76,7 @@ private boolean metaPermCheck(final User user, final String action, final Block private boolean metaPermCheck(final User user, final String action, final ItemStack item) { if (item == null) { if (ess.getSettings().isDebug()) { - logger.log(Level.INFO, "AntiBuild permission check failed, invalid item."); + prot.getLogger().log(Level.INFO, "AntiBuild permission check failed, invalid item."); } return false; } @@ -103,7 +100,7 @@ private boolean metaPermCheck(final User user, final String action, final Materi return user.isAuthorized(dataPerm); } else { if (ess.getSettings().isDebug()) { - logger.log(Level.INFO, "DataValue perm on " + user.getName() + " is not directly set: " + dataPerm); + prot.getLogger().log(Level.INFO, "DataValue perm on " + user.getName() + " is not directly set: " + dataPerm); } } } diff --git a/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsConnect.java b/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsConnect.java index 10c9825eebc..410da6a2c0d 100644 --- a/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsConnect.java +++ b/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsConnect.java @@ -1,10 +1,8 @@ package com.earth2me.essentials.antibuild; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.IConf; import com.earth2me.essentials.User; import net.ess3.api.IEssentials; -import net.ess3.provider.LoggerProvider; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -14,13 +12,12 @@ import static com.earth2me.essentials.I18n.tl; class EssentialsConnect { - private final static LoggerProvider logger = EssentialsLogger.getLoggerProvider("EssentialsAntiBuild"); private final transient IEssentials ess; private final transient IAntiBuild protect; EssentialsConnect(final Plugin essPlugin, final Plugin essProtect) { if (!essProtect.getDescription().getVersion().equals(essPlugin.getDescription().getVersion())) { - logger.log(Level.WARNING, tl("versionMismatchAll")); + essProtect.getLogger().log(Level.WARNING, tl("versionMismatchAll")); } ess = (IEssentials) essPlugin; protect = (IAntiBuild) essProtect; @@ -36,7 +33,7 @@ IEssentials getEssentials() { void alert(final User user, final String item, final String type) { final Location loc = user.getLocation(); final String warnMessage = tl("alertFormat", user.getName(), type, item, loc.getWorld().getName() + "," + loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ()); - logger.log(Level.WARNING, warnMessage); + protect.getLogger().log(Level.WARNING, warnMessage); for (final Player p : ess.getServer().getOnlinePlayers()) { final User alertUser = ess.getUser(p); if (alertUser.isAuthorized("essentials.protect.alerts")) { diff --git a/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChat.java b/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChat.java index 8e5a9790c66..341075888b6 100644 --- a/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChat.java +++ b/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChat.java @@ -13,6 +13,7 @@ import java.util.HashMap; import java.util.Map; import java.util.logging.Level; +import java.util.logging.Logger; import static com.earth2me.essentials.I18n.tl; @@ -25,7 +26,7 @@ public void onEnable() { final PluginManager pluginManager = getServer().getPluginManager(); ess = (IEssentials) pluginManager.getPlugin("Essentials"); if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) { - EssentialsLogger.getLoggerProvider("EssentialsChat").log(Level.WARNING, tl("versionMismatchAll")); + getLogger().log(Level.WARNING, tl("versionMismatchAll")); } if (!ess.isEnabled()) { this.setEnabled(false); @@ -34,9 +35,9 @@ public void onEnable() { final Map chatStore = Collections.synchronizedMap(new HashMap<>()); - final EssentialsChatPlayerListenerLowest playerListenerLowest = new EssentialsChatPlayerListenerLowest(getServer(), ess, chatStore); - final EssentialsChatPlayerListenerNormal playerListenerNormal = new EssentialsChatPlayerListenerNormal(getServer(), ess, chatStore); - final EssentialsChatPlayerListenerHighest playerListenerHighest = new EssentialsChatPlayerListenerHighest(getServer(), ess, chatStore); + final EssentialsChatPlayerListenerLowest playerListenerLowest = new EssentialsChatPlayerListenerLowest(getServer(), ess, this, chatStore); + final EssentialsChatPlayerListenerNormal playerListenerNormal = new EssentialsChatPlayerListenerNormal(getServer(), ess, this, chatStore); + final EssentialsChatPlayerListenerHighest playerListenerHighest = new EssentialsChatPlayerListenerHighest(getServer(), ess, this, chatStore); pluginManager.registerEvents(playerListenerLowest, this); pluginManager.registerEvents(playerListenerNormal, this); pluginManager.registerEvents(playerListenerHighest, this); @@ -46,6 +47,16 @@ public void onEnable() { } } + @Override + public Logger getLogger() { + try { + return EssentialsLogger.getLoggerProvider(this); + } catch (Throwable ignored) { + // In case Essentials isn't installed/loaded + return super.getLogger(); + } + } + @Override public boolean onCommand(final CommandSender sender, final Command command, final String commandLabel, final String[] args) { metrics.markCommand(command.getName(), true); diff --git a/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayer.java b/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayer.java index 80e35e9528b..c3d991ac279 100644 --- a/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayer.java +++ b/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayer.java @@ -1,11 +1,9 @@ package com.earth2me.essentials.chat; import com.earth2me.essentials.ChargeException; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; import net.ess3.api.IEssentials; -import net.ess3.provider.LoggerProvider; import org.bukkit.Server; import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerChatEvent; @@ -13,13 +11,14 @@ import java.util.Map; public abstract class EssentialsChatPlayer implements Listener { - static final LoggerProvider logger = EssentialsLogger.getLoggerProvider("EssentialsChat"); final transient IEssentials ess; + final transient EssentialsChat essChat; final transient Server server; private final transient Map chatStorage; - EssentialsChatPlayer(final Server server, final IEssentials ess, final Map chatStorage) { + EssentialsChatPlayer(final Server server, final IEssentials ess, final EssentialsChat essChat, final Map chatStorage) { this.ess = ess; + this.essChat = essChat; this.server = server; this.chatStorage = chatStorage; } diff --git a/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayerListenerHighest.java b/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayerListenerHighest.java index f59436f1d4a..863c2ed65d1 100644 --- a/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayerListenerHighest.java +++ b/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayerListenerHighest.java @@ -9,8 +9,8 @@ import java.util.Map; public class EssentialsChatPlayerListenerHighest extends EssentialsChatPlayer { - EssentialsChatPlayerListenerHighest(final Server server, final IEssentials ess, final Map chatStorage) { - super(server, ess, chatStorage); + EssentialsChatPlayerListenerHighest(final Server server, final IEssentials ess, final EssentialsChat essChat, final Map chatStorage) { + super(server, ess, essChat, chatStorage); } @EventHandler(priority = EventPriority.HIGHEST) diff --git a/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java b/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java index 0032b35854d..8e113e8f6e9 100644 --- a/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java +++ b/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java @@ -15,8 +15,8 @@ import java.util.Map; public class EssentialsChatPlayerListenerLowest extends EssentialsChatPlayer { - EssentialsChatPlayerListenerLowest(final Server server, final IEssentials ess, final Map chatStorage) { - super(server, ess, chatStorage); + EssentialsChatPlayerListenerLowest(final Server server, final IEssentials ess, final EssentialsChat essChat, final Map chatStorage) { + super(server, ess, essChat, chatStorage); } @EventHandler(priority = EventPriority.LOWEST) diff --git a/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayerListenerNormal.java b/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayerListenerNormal.java index a216a1e7fb8..7726dbaca97 100644 --- a/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayerListenerNormal.java +++ b/EssentialsChat/src/main/java/com/earth2me/essentials/chat/EssentialsChatPlayerListenerNormal.java @@ -21,8 +21,8 @@ import static com.earth2me.essentials.I18n.tl; public class EssentialsChatPlayerListenerNormal extends EssentialsChatPlayer { - EssentialsChatPlayerListenerNormal(final Server server, final IEssentials ess, final Map chatStorage) { - super(server, ess, chatStorage); + EssentialsChatPlayerListenerNormal(final Server server, final IEssentials ess, final EssentialsChat essChat, final Map chatStorage) { + super(server, ess, essChat, chatStorage); } @EventHandler(priority = EventPriority.NORMAL) @@ -88,7 +88,7 @@ public void onPlayerChat(final AsyncPlayerChatEvent event) { outList.add(event.getPlayer()); } catch (final UnsupportedOperationException ex) { if (ess.getSettings().isDebug()) { - logger.log(Level.INFO, "Plugin triggered custom chat event, local chat handling aborted.", ex); + essChat.getLogger().log(Level.INFO, "Plugin triggered custom chat event, local chat handling aborted.", ex); } return; } diff --git a/EssentialsDiscord/src/main/java/net/essentialsx/discord/DiscordSettings.java b/EssentialsDiscord/src/main/java/net/essentialsx/discord/DiscordSettings.java index 9c321eb68b9..81a91907dc4 100644 --- a/EssentialsDiscord/src/main/java/net/essentialsx/discord/DiscordSettings.java +++ b/EssentialsDiscord/src/main/java/net/essentialsx/discord/DiscordSettings.java @@ -20,7 +20,6 @@ import java.util.regex.PatternSyntaxException; import static com.earth2me.essentials.I18n.tl; -import static net.essentialsx.discord.EssentialsDiscord.LOGGER; public class DiscordSettings implements IConf { private final EssentialsConfiguration config; @@ -360,7 +359,7 @@ private MessageFormat generateMessageFormat(String content, String defaultStr, b @Override public void reloadConfig() { if (plugin.isInvalidStartup()) { - LOGGER.warning(tl("discordReloadInvalid")); + plugin.getLogger().warning(tl("discordReloadInvalid")); return; } @@ -406,7 +405,7 @@ public void reloadConfig() { try { filters.add(Pattern.compile(chatFilterString)); } catch (PatternSyntaxException e) { - LOGGER.log(java.util.logging.Level.WARNING, "Invalid pattern for \"chat.discord-filter\": " + e.getMessage()); + plugin.getLogger().log(java.util.logging.Level.WARNING, "Invalid pattern for \"chat.discord-filter\": " + e.getMessage()); } } } @@ -420,7 +419,7 @@ public void reloadConfig() { discordFilter = Collections.emptyList(); } } catch (PatternSyntaxException e) { - LOGGER.log(java.util.logging.Level.WARNING, "Invalid pattern for \"chat.discord-filter\": " + e.getMessage()); + plugin.getLogger().log(java.util.logging.Level.WARNING, "Invalid pattern for \"chat.discord-filter\": " + e.getMessage()); discordFilter = Collections.emptyList(); } } @@ -434,7 +433,7 @@ public void reloadConfig() { try { filters.add(Pattern.compile(filterString)); } catch (PatternSyntaxException e) { - LOGGER.log(java.util.logging.Level.WARNING, "Invalid pattern for \"console.log-level\": " + e.getMessage()); + plugin.getLogger().log(java.util.logging.Level.WARNING, "Invalid pattern for \"console.log-level\": " + e.getMessage()); } } } @@ -448,7 +447,7 @@ public void reloadConfig() { consoleFilter = Collections.emptyList(); } } catch (PatternSyntaxException e) { - LOGGER.log(java.util.logging.Level.WARNING, "Invalid pattern for \"console.log-level\": " + e.getMessage()); + plugin.getLogger().log(java.util.logging.Level.WARNING, "Invalid pattern for \"console.log-level\": " + e.getMessage()); consoleFilter = Collections.emptyList(); } } diff --git a/EssentialsDiscord/src/main/java/net/essentialsx/discord/EssentialsDiscord.java b/EssentialsDiscord/src/main/java/net/essentialsx/discord/EssentialsDiscord.java index 8c6474a598a..b2936a11ec3 100644 --- a/EssentialsDiscord/src/main/java/net/essentialsx/discord/EssentialsDiscord.java +++ b/EssentialsDiscord/src/main/java/net/essentialsx/discord/EssentialsDiscord.java @@ -4,7 +4,6 @@ import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.IEssentialsModule; import com.earth2me.essentials.metrics.MetricsWrapper; -import net.ess3.provider.LoggerProvider; import net.essentialsx.discord.interactions.InteractionControllerImpl; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -14,11 +13,11 @@ import java.util.List; import java.util.logging.Level; +import java.util.logging.Logger; import static com.earth2me.essentials.I18n.tl; public class EssentialsDiscord extends JavaPlugin implements IEssentialsModule { - protected static LoggerProvider LOGGER; private transient IEssentials ess; private transient MetricsWrapper metrics = null; @@ -33,16 +32,14 @@ public void onEnable() { setEnabled(false); return; } - LOGGER = EssentialsLogger.getLoggerProvider("EssentialsDiscord"); - if (!getDescription().getVersion().equals(ess.getDescription().getVersion())) { - LOGGER.log(Level.WARNING, tl("versionMismatchAll")); + getLogger().log(Level.WARNING, tl("versionMismatchAll")); } // JDK-8274349 - Mitigation for a regression in Java 17 on 1 core systems which was fixed in 17.0.2 final String[] javaVersion = System.getProperty("java.version").split("\\."); if (Runtime.getRuntime().availableProcessors() <= 1 && javaVersion[0].startsWith("17") && (javaVersion.length < 2 || (javaVersion[1].equals("0") && javaVersion[2].startsWith("1")))) { - LOGGER.log(Level.INFO, "Essentials is mitigating JDK-8274349"); + getLogger().log(Level.INFO, "Essentials is mitigating JDK-8274349"); System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "1"); } @@ -61,7 +58,7 @@ public void onEnable() { jda.startup(); ess.scheduleSyncDelayedTask(() -> ((InteractionControllerImpl) jda.getInteractionController()).processBatchRegistration()); } catch (Exception e) { - LOGGER.log(Level.SEVERE, tl("discordErrorLogin", e.getMessage())); + getLogger().log(Level.SEVERE, tl("discordErrorLogin", e.getMessage())); if (ess.getSettings().isDebug()) { e.printStackTrace(); } @@ -70,6 +67,25 @@ public void onEnable() { } } + @Override + public Logger getLogger() { + try { + return EssentialsLogger.getLoggerProvider(this); + } catch (Throwable ignored) { + // In case Essentials isn't installed/loaded + return super.getLogger(); + } + } + + public static Logger getWrappedLogger() { + try { + return EssentialsLogger.getLoggerProvider("EssentialsDiscord"); + } catch (Throwable ignored) { + // In case Essentials isn't installed/loaded + return Logger.getLogger("EssentialsDiscord"); + } + } + public void onReload() { if (jda != null && !jda.isInvalidStartup()) { jda.updatePresence(); diff --git a/EssentialsDiscord/src/main/java/net/essentialsx/discord/JDADiscordService.java b/EssentialsDiscord/src/main/java/net/essentialsx/discord/JDADiscordService.java index 2bc33e99d34..a9057d9f6fb 100644 --- a/EssentialsDiscord/src/main/java/net/essentialsx/discord/JDADiscordService.java +++ b/EssentialsDiscord/src/main/java/net/essentialsx/discord/JDADiscordService.java @@ -4,7 +4,6 @@ import club.minnced.discord.webhook.WebhookClientBuilder; import club.minnced.discord.webhook.send.WebhookMessage; import club.minnced.discord.webhook.send.WebhookMessageBuilder; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.IEssentialsModule; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.FormatUtil; @@ -22,7 +21,6 @@ import net.dv8tion.jda.api.utils.cache.CacheFlag; import net.ess3.nms.refl.providers.AchievementListenerProvider; import net.ess3.nms.refl.providers.AdvancementListenerProvider; -import net.ess3.provider.LoggerProvider; import net.ess3.provider.providers.PaperAdvancementListenerProvider; import net.essentialsx.api.v2.events.discord.DiscordMessageEvent; import net.essentialsx.api.v2.services.discord.DiscordService; @@ -55,13 +53,14 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.logging.Level; +import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; import static com.earth2me.essentials.I18n.tl; public class JDADiscordService implements DiscordService, IEssentialsModule { - private final static LoggerProvider logger = EssentialsLogger.getLoggerProvider("EssentialsDiscord"); + private final static Logger logger = EssentialsDiscord.getWrappedLogger(); private final EssentialsDiscord plugin; private final Unsafe unsafe = this::getJda; diff --git a/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionControllerImpl.java b/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionControllerImpl.java index 42ba5fade1f..2101544d8a3 100644 --- a/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionControllerImpl.java +++ b/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionControllerImpl.java @@ -1,6 +1,5 @@ package net.essentialsx.discord.interactions; -import com.earth2me.essentials.EssentialsLogger; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.exceptions.ErrorResponseException; import net.dv8tion.jda.api.hooks.ListenerAdapter; @@ -8,12 +7,12 @@ import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.requests.ErrorResponse; -import net.ess3.provider.LoggerProvider; import net.essentialsx.api.v2.services.discord.InteractionCommand; import net.essentialsx.api.v2.services.discord.InteractionCommandArgument; import net.essentialsx.api.v2.services.discord.InteractionController; import net.essentialsx.api.v2.services.discord.InteractionEvent; import net.essentialsx.api.v2.services.discord.InteractionException; +import net.essentialsx.discord.EssentialsDiscord; import net.essentialsx.discord.JDADiscordService; import net.essentialsx.discord.util.DiscordUtil; import org.jetbrains.annotations.NotNull; @@ -24,12 +23,12 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; +import java.util.logging.Logger; import static com.earth2me.essentials.I18n.tl; public class InteractionControllerImpl extends ListenerAdapter implements InteractionController { - private final static LoggerProvider logger = EssentialsLogger.getLoggerProvider("EssentialsDiscord"); - + private static final Logger logger = EssentialsDiscord.getWrappedLogger(); private final JDADiscordService jda; private final Map commandMap = new ConcurrentHashMap<>(); diff --git a/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionEventImpl.java b/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionEventImpl.java index e9e0e425886..c6c60193444 100644 --- a/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionEventImpl.java +++ b/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionEventImpl.java @@ -1,27 +1,27 @@ package net.essentialsx.discord.interactions; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.utils.FormatUtil; import com.google.common.base.Joiner; import net.dv8tion.jda.api.MessageBuilder; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.interactions.commands.OptionMapping; -import net.ess3.provider.LoggerProvider; import net.essentialsx.api.v2.services.discord.InteractionChannel; import net.essentialsx.api.v2.services.discord.InteractionEvent; import net.essentialsx.api.v2.services.discord.InteractionMember; +import net.essentialsx.discord.EssentialsDiscord; import net.essentialsx.discord.util.DiscordUtil; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; +import java.util.logging.Logger; /** * A class which provides information about what triggered an interaction event. */ public class InteractionEventImpl implements InteractionEvent { - private final static LoggerProvider logger = EssentialsLogger.getLoggerProvider("EssentialsDiscord"); + private final static Logger logger = EssentialsDiscord.getWrappedLogger(); private final SlashCommandEvent event; private final InteractionMember member; private final List replyBuffer = new ArrayList<>(); diff --git a/EssentialsDiscord/src/main/java/net/essentialsx/discord/listeners/DiscordListener.java b/EssentialsDiscord/src/main/java/net/essentialsx/discord/listeners/DiscordListener.java index e0062eba5ce..5f7a07d4a92 100644 --- a/EssentialsDiscord/src/main/java/net/essentialsx/discord/listeners/DiscordListener.java +++ b/EssentialsDiscord/src/main/java/net/essentialsx/discord/listeners/DiscordListener.java @@ -1,6 +1,5 @@ package net.essentialsx.discord.listeners; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.utils.FormatUtil; import com.earth2me.essentials.utils.StringUtil; import com.vdurmont.emoji.EmojiParser; @@ -10,8 +9,8 @@ import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.ess3.api.IUser; -import net.ess3.provider.LoggerProvider; import net.essentialsx.api.v2.events.discord.DiscordRelayEvent; +import net.essentialsx.discord.EssentialsDiscord; import net.essentialsx.discord.JDADiscordService; import net.essentialsx.discord.interactions.InteractionChannelImpl; import net.essentialsx.discord.interactions.InteractionMemberImpl; @@ -23,10 +22,11 @@ import java.util.Collections; import java.util.List; import java.util.logging.Level; +import java.util.logging.Logger; import java.util.regex.Pattern; public class DiscordListener extends ListenerAdapter { - private final static LoggerProvider logger = EssentialsLogger.getLoggerProvider("EssentialsDiscord"); + private final static Logger logger = EssentialsDiscord.getWrappedLogger(); private final JDADiscordService plugin; diff --git a/EssentialsDiscord/src/main/java/net/essentialsx/discord/util/ConsoleInjector.java b/EssentialsDiscord/src/main/java/net/essentialsx/discord/util/ConsoleInjector.java index b926ddb0a5e..977efb37b79 100644 --- a/EssentialsDiscord/src/main/java/net/essentialsx/discord/util/ConsoleInjector.java +++ b/EssentialsDiscord/src/main/java/net/essentialsx/discord/util/ConsoleInjector.java @@ -1,11 +1,10 @@ package net.essentialsx.discord.util; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.utils.FormatUtil; import com.google.common.base.Splitter; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.utils.TimeFormat; -import net.ess3.provider.LoggerProvider; +import net.essentialsx.discord.EssentialsDiscord; import net.essentialsx.discord.JDADiscordService; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.core.LogEvent; @@ -23,7 +22,7 @@ @Plugin(name = "EssentialsX-ConsoleInjector", category = "Core", elementType = "appender", printObject = true) public class ConsoleInjector extends AbstractAppender { - private final static LoggerProvider logger = EssentialsLogger.getLoggerProvider("EssentialsDiscord"); + private final static java.util.logging.Logger logger = EssentialsDiscord.getWrappedLogger(); private final JDADiscordService jda; private final BlockingQueue messageQueue = new LinkedBlockingQueue<>(); diff --git a/EssentialsGeoIP/src/main/java/com/earth2me/essentials/geoip/EssentialsGeoIP.java b/EssentialsGeoIP/src/main/java/com/earth2me/essentials/geoip/EssentialsGeoIP.java index b09e0539b18..aa848de9216 100644 --- a/EssentialsGeoIP/src/main/java/com/earth2me/essentials/geoip/EssentialsGeoIP.java +++ b/EssentialsGeoIP/src/main/java/com/earth2me/essentials/geoip/EssentialsGeoIP.java @@ -3,16 +3,15 @@ import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.metrics.MetricsWrapper; import net.ess3.api.IEssentials; -import net.ess3.provider.LoggerProvider; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import java.util.logging.Level; +import java.util.logging.Logger; import static com.earth2me.essentials.I18n.tl; public class EssentialsGeoIP extends JavaPlugin { - private final static LoggerProvider logger = EssentialsLogger.getLoggerProvider("EssentialsGeoIP"); private transient MetricsWrapper metrics = null; @@ -21,21 +20,33 @@ public void onEnable() { final PluginManager pm = getServer().getPluginManager(); final IEssentials ess = (IEssentials) pm.getPlugin("Essentials"); if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) { - logger.log(Level.WARNING, tl("versionMismatchAll")); + getLogger().log(Level.WARNING, tl("versionMismatchAll")); } if (!ess.isEnabled()) { this.setEnabled(false); return; } - final EssentialsGeoIPPlayerListener playerListener = new EssentialsGeoIPPlayerListener(getDataFolder(), ess); + Logger.getLogger(com.fasterxml.jackson.databind.ext.Java7Support.class.getName()).setLevel(Level.SEVERE); + + final EssentialsGeoIPPlayerListener playerListener = new EssentialsGeoIPPlayerListener(getDataFolder(), ess, this); pm.registerEvents(playerListener, this); - logger.log(Level.INFO, "This product includes GeoLite2 data created by MaxMind, available from http://www.maxmind.com/."); + getLogger().log(Level.INFO, "This product includes GeoLite2 data created by MaxMind, available from http://www.maxmind.com/."); if (metrics == null) { metrics = new MetricsWrapper(this, 3815, false); } } + @Override + public Logger getLogger() { + try { + return EssentialsLogger.getLoggerProvider(this); + } catch (Throwable ignored) { + // In case Essentials isn't installed/loaded + return super.getLogger(); + } + } + } diff --git a/EssentialsGeoIP/src/main/java/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java b/EssentialsGeoIP/src/main/java/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java index 140fa6b5250..a52c66b363c 100644 --- a/EssentialsGeoIP/src/main/java/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java +++ b/EssentialsGeoIP/src/main/java/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java @@ -1,6 +1,5 @@ package com.earth2me.essentials.geoip; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.IConf; import com.earth2me.essentials.User; import com.earth2me.essentials.config.EssentialsConfiguration; @@ -12,7 +11,6 @@ import com.maxmind.geoip2.model.CityResponse; import com.maxmind.geoip2.model.CountryResponse; import net.ess3.api.IEssentials; -import net.ess3.provider.LoggerProvider; import net.essentialsx.api.v2.events.AsyncUserDataLoadEvent; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -38,15 +36,16 @@ import static com.earth2me.essentials.I18n.tl; public class EssentialsGeoIPPlayerListener implements Listener, IConf { - private static final LoggerProvider logger = EssentialsLogger.getLoggerProvider("EssentialsGeoIP"); private final File dataFolder; private final EssentialsConfiguration config; private final transient IEssentials ess; + private final transient EssentialsGeoIP essGeo; private DatabaseReader mmreader = null; // initialize maxmind geoip2 reader private File databaseFile; - EssentialsGeoIPPlayerListener(final File dataFolder, final IEssentials ess) { + EssentialsGeoIPPlayerListener(final File dataFolder, final IEssentials ess, final EssentialsGeoIP essGeo) { this.ess = ess; + this.essGeo = essGeo; this.dataFolder = dataFolder; this.config = new EssentialsConfiguration(new File(dataFolder, "config.yml"), "/config.yml", EssentialsGeoIP.class); reloadConfig(); @@ -67,7 +66,7 @@ private void delayedJoin(final Player player) { final StringBuilder sb = new StringBuilder(); if (mmreader == null) { - logger.log(Level.WARNING, tl("geoIpErrorOnJoin", u.getName())); + essGeo.getLogger().log(Level.WARNING, tl("geoIpErrorOnJoin", u.getName())); return; } @@ -107,10 +106,10 @@ private void delayedJoin(final Player player) { } // GeoIP2 API forced this when address not found in their DB. jar will not complied without this. // TODO: Maybe, we can set a new custom msg about addr-not-found in messages.properties. - logger.log(Level.INFO, tl("cantReadGeoIpDB") + " " + ex.getLocalizedMessage()); + essGeo.getLogger().log(Level.INFO, tl("cantReadGeoIpDB") + " " + ex.getLocalizedMessage()); } catch (final IOException | GeoIp2Exception ex) { // GeoIP2 API forced this when address not found in their DB. jar will not complied without this. - logger.log(Level.SEVERE, tl("cantReadGeoIpDB") + " " + ex.getLocalizedMessage()); + essGeo.getLogger().log(Level.SEVERE, tl("cantReadGeoIpDB") + " " + ex.getLocalizedMessage()); } if (config.getBoolean("show-on-whois", true)) { u.setGeoLocation(sb.toString()); @@ -154,7 +153,7 @@ public final void reloadConfig() { if (config.getBoolean("database.download-if-missing", true)) { downloadDatabase(); } else { - logger.log(Level.SEVERE, tl("cantFindGeoIpDB")); + essGeo.getLogger().log(Level.SEVERE, tl("cantFindGeoIpDB")); return; } } else if (config.getBoolean("database.update.enable", true)) { @@ -178,7 +177,7 @@ public final void reloadConfig() { mmreader = new DatabaseReader.Builder(databaseFile).build(); } } catch (final IOException ex) { - logger.log(Level.SEVERE, tl("cantReadGeoIpDB"), ex); + essGeo.getLogger().log(Level.SEVERE, tl("cantReadGeoIpDB"), ex); } } @@ -191,16 +190,16 @@ private void downloadDatabase() { url = config.getString("database.download-url", null); } if (url == null || url.isEmpty()) { - logger.log(Level.SEVERE, tl("geoIpUrlEmpty")); + essGeo.getLogger().log(Level.SEVERE, tl("geoIpUrlEmpty")); return; } final String licenseKey = config.getString("database.license-key", ""); if (licenseKey == null || licenseKey.isEmpty()) { - logger.log(Level.SEVERE, tl("geoIpLicenseMissing")); + essGeo.getLogger().log(Level.SEVERE, tl("geoIpLicenseMissing")); return; } url = url.replace("{LICENSEKEY}", licenseKey); - logger.log(Level.INFO, tl("downloadingGeoIp")); + essGeo.getLogger().log(Level.INFO, tl("downloadingGeoIp")); final URL downloadUrl = new URL(url); final URLConnection conn = downloadUrl.openConnection(); conn.setConnectTimeout(10000); @@ -234,9 +233,9 @@ private void downloadDatabase() { output.close(); input.close(); } catch (final MalformedURLException ex) { - logger.log(Level.SEVERE, tl("geoIpUrlInvalid"), ex); + essGeo.getLogger().log(Level.SEVERE, tl("geoIpUrlInvalid"), ex); } catch (final IOException ex) { - logger.log(Level.SEVERE, tl("connectionFailed"), ex); + essGeo.getLogger().log(Level.SEVERE, tl("connectionFailed"), ex); } } diff --git a/EssentialsProtect/src/main/java/com/earth2me/essentials/protect/EssentialsConnect.java b/EssentialsProtect/src/main/java/com/earth2me/essentials/protect/EssentialsConnect.java index 4d0657818c9..77af0c1469d 100644 --- a/EssentialsProtect/src/main/java/com/earth2me/essentials/protect/EssentialsConnect.java +++ b/EssentialsProtect/src/main/java/com/earth2me/essentials/protect/EssentialsConnect.java @@ -1,9 +1,7 @@ package com.earth2me.essentials.protect; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.IConf; import net.ess3.api.IEssentials; -import net.ess3.provider.LoggerProvider; import org.bukkit.plugin.Plugin; import java.util.logging.Level; @@ -11,13 +9,12 @@ import static com.earth2me.essentials.I18n.tl; class EssentialsConnect { - private static final LoggerProvider logger = EssentialsLogger.getLoggerProvider("EssentialsProtect"); private final IEssentials ess; private final IProtect protect; EssentialsConnect(final Plugin essPlugin, final Plugin essProtect) { if (!essProtect.getDescription().getVersion().equals(essPlugin.getDescription().getVersion())) { - logger.log(Level.WARNING, tl("versionMismatchAll")); + essProtect.getLogger().log(Level.WARNING, tl("versionMismatchAll")); } ess = (IEssentials) essPlugin; protect = (IProtect) essProtect; diff --git a/EssentialsProtect/src/main/java/com/earth2me/essentials/protect/EssentialsProtect.java b/EssentialsProtect/src/main/java/com/earth2me/essentials/protect/EssentialsProtect.java index ee8e51385ac..d3496c19b1a 100644 --- a/EssentialsProtect/src/main/java/com/earth2me/essentials/protect/EssentialsProtect.java +++ b/EssentialsProtect/src/main/java/com/earth2me/essentials/protect/EssentialsProtect.java @@ -3,7 +3,6 @@ import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.metrics.MetricsWrapper; import com.earth2me.essentials.utils.VersionUtil; -import net.ess3.provider.LoggerProvider; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; @@ -15,9 +14,9 @@ import java.util.List; import java.util.Map; import java.util.logging.Level; +import java.util.logging.Logger; public class EssentialsProtect extends JavaPlugin implements IProtect { - private static LoggerProvider LOGGER; private final Map settingsBoolean = new EnumMap<>(ProtectConfig.class); private final Map settingsString = new EnumMap<>(ProtectConfig.class); private final Map> settingsList = new EnumMap<>(ProtectConfig.class); @@ -27,8 +26,6 @@ public class EssentialsProtect extends JavaPlugin implements IProtect { @Override public void onEnable() { - LOGGER = EssentialsLogger.getLoggerProvider("EssentialsProtect"); - final PluginManager pm = this.getServer().getPluginManager(); final Plugin essPlugin = pm.getPlugin("Essentials"); if (essPlugin == null || !essPlugin.isEnabled()) { @@ -43,8 +40,18 @@ public void onEnable() { } } + @Override + public Logger getLogger() { + try { + return EssentialsLogger.getLoggerProvider(this); + } catch (Throwable ignored) { + // In case Essentials isn't installed/loaded + return super.getLogger(); + } + } + private void initialize(final PluginManager pm, final Plugin essPlugin) { - LOGGER.log(Level.INFO, "Continuing to enable Protect."); + getLogger().log(Level.INFO, "Continuing to enable Protect."); ess = new EssentialsConnect(essPlugin, this); final EssentialsProtectBlockListener blockListener = new EssentialsProtectBlockListener(this); @@ -77,14 +84,14 @@ private void enableEmergencyMode(final PluginManager pm) { for (final Player player : getServer().getOnlinePlayers()) { player.sendMessage("Essentials Protect is in emergency mode. Check your log for errors."); } - LOGGER.log(Level.SEVERE, "Essentials not installed or failed to load. Essentials Protect is in emergency mode now."); + getLogger().log(Level.SEVERE, "Essentials not installed or failed to load. Essentials Protect is in emergency mode now."); } void disableEmergencyMode() { final PluginManager pm = this.getServer().getPluginManager(); final Plugin essPlugin = pm.getPlugin("Essentials"); if (essPlugin == null || !essPlugin.isEnabled()) { - LOGGER.log(Level.SEVERE, "Tried to disable emergency mode, but Essentials still isn't enabled!"); + getLogger().log(Level.SEVERE, "Tried to disable emergency mode, but Essentials still isn't enabled!"); return; } @@ -93,7 +100,7 @@ void disableEmergencyMode() { for (final Player player : getServer().getOnlinePlayers()) { player.sendMessage("Essentials Protect is no longer in emergency mode."); } - LOGGER.log(Level.SEVERE, "Essentials was loaded late! Essentials Protect is no longer in emergency mode."); + getLogger().log(Level.SEVERE, "Essentials was loaded late! Essentials Protect is no longer in emergency mode."); initialize(pm, essPlugin); } diff --git a/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawn.java b/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawn.java index 6cad7aba7b5..d16c51fde08 100644 --- a/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawn.java +++ b/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawn.java @@ -13,6 +13,7 @@ import org.bukkit.plugin.java.JavaPlugin; import java.util.logging.Level; +import java.util.logging.Logger; import static com.earth2me.essentials.I18n.tl; @@ -26,7 +27,7 @@ public void onEnable() { final PluginManager pluginManager = getServer().getPluginManager(); ess = (IEssentials) pluginManager.getPlugin("Essentials"); if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) { - EssentialsLogger.getLoggerProvider("EssentialsSpawn").log(Level.WARNING, tl("versionMismatchAll")); + getLogger().log(Level.WARNING, tl("versionMismatchAll")); } if (!ess.isEnabled()) { this.setEnabled(false); @@ -55,6 +56,25 @@ public void onEnable() { } } + @Override + public Logger getLogger() { + try { + return EssentialsLogger.getLoggerProvider(this); + } catch (Throwable ignored) { + // In case Essentials isn't installed/loaded + return super.getLogger(); + } + } + + public static Logger getWrappedLogger() { + try { + return EssentialsLogger.getLoggerProvider("EssentialsDiscord"); + } catch (Throwable ignored) { + // In case Essentials isn't installed/loaded + return Logger.getLogger("EssentialsDiscord"); + } + } + @Override public void onDisable() { } diff --git a/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java b/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java index 3ac4260f02b..59d8b4efeed 100644 --- a/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java +++ b/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java @@ -1,6 +1,5 @@ package com.earth2me.essentials.spawn; -import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.Kit; import com.earth2me.essentials.OfflinePlayer; import com.earth2me.essentials.User; @@ -9,7 +8,6 @@ import com.earth2me.essentials.textreader.SimpleTextPager; import com.earth2me.essentials.utils.VersionUtil; import net.ess3.api.IEssentials; -import net.ess3.provider.LoggerProvider; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.Listener; @@ -21,11 +19,12 @@ import java.util.Locale; import java.util.concurrent.CompletableFuture; import java.util.logging.Level; +import java.util.logging.Logger; import static com.earth2me.essentials.I18n.tl; class EssentialsSpawnPlayerListener implements Listener { - private static final LoggerProvider logger = EssentialsLogger.getLoggerProvider("EssentialsSpawn"); + private static final Logger logger = EssentialsSpawn.getWrappedLogger(); private final transient IEssentials ess; private final transient SpawnStorage spawns; diff --git a/EssentialsXMPP/src/main/java/com/earth2me/essentials/xmpp/EssentialsXMPP.java b/EssentialsXMPP/src/main/java/com/earth2me/essentials/xmpp/EssentialsXMPP.java index 5ddc91c014c..18e5f446599 100644 --- a/EssentialsXMPP/src/main/java/com/earth2me/essentials/xmpp/EssentialsXMPP.java +++ b/EssentialsXMPP/src/main/java/com/earth2me/essentials/xmpp/EssentialsXMPP.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.xmpp; +import com.earth2me.essentials.EssentialsLogger; import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.metrics.MetricsWrapper; import net.ess3.api.IUser; @@ -13,6 +14,7 @@ import java.util.List; import java.util.Locale; import java.util.logging.Level; +import java.util.logging.Logger; import static com.earth2me.essentials.I18n.tl; @@ -60,6 +62,25 @@ public void onEnable() { } } + @Override + public Logger getLogger() { + try { + return EssentialsLogger.getLoggerProvider(this); + } catch (Throwable ignored) { + // In case Essentials isn't installed/loaded + return super.getLogger(); + } + } + + public static Logger getWrappedLogger() { + try { + return EssentialsLogger.getLoggerProvider("EssentialsDiscord"); + } catch (Throwable ignored) { + // In case Essentials isn't installed/loaded + return Logger.getLogger("EssentialsDiscord"); + } + } + @Override public void onDisable() { if (xmpp != null) { diff --git a/EssentialsXMPP/src/main/java/com/earth2me/essentials/xmpp/XMPPManager.java b/EssentialsXMPP/src/main/java/com/earth2me/essentials/xmpp/XMPPManager.java index d8dc4c03515..c1e59e04e4f 100644 --- a/EssentialsXMPP/src/main/java/com/earth2me/essentials/xmpp/XMPPManager.java +++ b/EssentialsXMPP/src/main/java/com/earth2me/essentials/xmpp/XMPPManager.java @@ -35,7 +35,7 @@ import static com.earth2me.essentials.I18n.tl; public class XMPPManager extends Handler implements MessageListener, ChatManagerListener, IConf { - private static final Logger logger = Logger.getLogger("EssentialsXMPP"); + private static final Logger logger = EssentialsXMPP.getWrappedLogger(); private static final SimpleFormatter formatter = new SimpleFormatter(); private final transient EssentialsConfiguration config; private final transient Map chats = Collections.synchronizedMap(new HashMap<>()); From 80bd6aa87907c28a8053e018a0f15b8b509d2319 Mon Sep 17 00:00:00 2001 From: MD <1917406+mdcfe@users.noreply.github.com> Date: Mon, 27 Jun 2022 19:38:59 +0100 Subject: [PATCH 7/8] Fix issues from review --- .../java/com/earth2me/essentials/EssentialsUpgrade.java | 6 +++--- Essentials/src/main/java/com/earth2me/essentials/I18n.java | 1 + .../java/com/earth2me/essentials/commands/Commandgc.java | 3 +-- .../main/java/com/earth2me/essentials/items/FlatItemDb.java | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsUpgrade.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsUpgrade.java index 8e4ec15e46b..3c4cce66b46 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsUpgrade.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsUpgrade.java @@ -720,7 +720,7 @@ private void deleteOldItemsCsv() { doneFile.setProperty("deleteOldItemsCsv", true); doneFile.save(); } catch (final IOException ex) { - Essentials.getWrappedLogger().log(Level.SEVERE, ex.getMessage(), ex); + ess.getLogger().log(Level.SEVERE, ex.getMessage(), ex); } } } @@ -746,7 +746,7 @@ private void updateSpawnsToNewSpawnsConfig() { config.blockingSave(); } } catch (final Exception ex) { - Essentials.getWrappedLogger().log(Level.SEVERE, ex.getMessage(), ex); + ess.getLogger().log(Level.SEVERE, ex.getMessage(), ex); } } doneFile.setProperty("updateSpawnsToNewSpawnsConfig", true); @@ -774,7 +774,7 @@ private void updateJailsToNewJailsConfig() { config.blockingSave(); } } catch (final Exception ex) { - Essentials.getWrappedLogger().log(Level.SEVERE, ex.getMessage(), ex); + ess.getLogger().log(Level.SEVERE, ex.getMessage(), ex); } } doneFile.setProperty("updateJailsToNewJailsConfig", true); diff --git a/Essentials/src/main/java/com/earth2me/essentials/I18n.java b/Essentials/src/main/java/com/earth2me/essentials/I18n.java index 582a14fbe34..51a9fa22fa2 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/I18n.java +++ b/Essentials/src/main/java/com/earth2me/essentials/I18n.java @@ -88,6 +88,7 @@ private String translate(final String string) { } } catch (final MissingResourceException ex) { if (ess == null || ess.getSettings().isDebug()) { + ess.getLogger().log(Level.WARNING, String.format("Missing translation key \"%s\" in translation file %s", ex.getKey(), localeBundle.getLocale().toString()), ex); } return defaultBundle.getString(string); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandgc.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandgc.java index 462c38bc047..5f7392cdea3 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandgc.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandgc.java @@ -1,7 +1,6 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.CommandSource; -import com.earth2me.essentials.Essentials; import com.earth2me.essentials.utils.DateUtil; import com.earth2me.essentials.utils.NumberUtil; import org.bukkit.ChatColor; @@ -57,7 +56,7 @@ protected void run(final Server server, final CommandSource sender, final String tileEntities += chunk.getTileEntities().length; } } catch (final java.lang.ClassCastException ex) { - Essentials.getWrappedLogger().log(Level.SEVERE, "Corrupted chunk data on world " + w, ex); + ess.getLogger().log(Level.SEVERE, "Corrupted chunk data on world " + w, ex); } sender.sendMessage(tl("gcWorld", worldType, w.getName(), w.getLoadedChunks().length, w.getEntities().size(), tileEntities)); diff --git a/Essentials/src/main/java/com/earth2me/essentials/items/FlatItemDb.java b/Essentials/src/main/java/com/earth2me/essentials/items/FlatItemDb.java index e8edab47dd5..7e6fcf49bef 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/items/FlatItemDb.java +++ b/Essentials/src/main/java/com/earth2me/essentials/items/FlatItemDb.java @@ -113,7 +113,7 @@ public ItemStack get(String id, final boolean useResolvers) throws Exception { } id = id.toLowerCase(); - final String[] split = id.split("(? Date: Mon, 27 Jun 2022 19:46:44 +0100 Subject: [PATCH 8/8] More fix more issues from more review --- Essentials/src/main/java/com/earth2me/essentials/I18n.java | 2 +- .../java/com/earth2me/essentials/spawn/EssentialsSpawn.java | 4 ++-- .../java/com/earth2me/essentials/xmpp/EssentialsXMPP.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/I18n.java b/Essentials/src/main/java/com/earth2me/essentials/I18n.java index 51a9fa22fa2..ed30d66cc02 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/I18n.java +++ b/Essentials/src/main/java/com/earth2me/essentials/I18n.java @@ -125,7 +125,7 @@ public void updateLocale(final String loc) { } ResourceBundle.clearCache(); messageFormatCache = new HashMap<>(); - Essentials.getWrappedLogger().log(Level.INFO, String.format("Using locale %s", currentLocale.toString())); + ess.getLogger().log(Level.INFO, String.format("Using locale %s", currentLocale.toString())); try { localeBundle = ResourceBundle.getBundle(MESSAGES, currentLocale, new UTF8PropertiesControl()); diff --git a/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawn.java b/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawn.java index d16c51fde08..fd2a2b42134 100644 --- a/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawn.java +++ b/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawn.java @@ -68,10 +68,10 @@ public Logger getLogger() { public static Logger getWrappedLogger() { try { - return EssentialsLogger.getLoggerProvider("EssentialsDiscord"); + return EssentialsLogger.getLoggerProvider("EssentialsSpawn"); } catch (Throwable ignored) { // In case Essentials isn't installed/loaded - return Logger.getLogger("EssentialsDiscord"); + return Logger.getLogger("EssentialsSpawn"); } } diff --git a/EssentialsXMPP/src/main/java/com/earth2me/essentials/xmpp/EssentialsXMPP.java b/EssentialsXMPP/src/main/java/com/earth2me/essentials/xmpp/EssentialsXMPP.java index 18e5f446599..dee2e2673a5 100644 --- a/EssentialsXMPP/src/main/java/com/earth2me/essentials/xmpp/EssentialsXMPP.java +++ b/EssentialsXMPP/src/main/java/com/earth2me/essentials/xmpp/EssentialsXMPP.java @@ -74,10 +74,10 @@ public Logger getLogger() { public static Logger getWrappedLogger() { try { - return EssentialsLogger.getLoggerProvider("EssentialsDiscord"); + return EssentialsLogger.getLoggerProvider("EssentialsXMPP"); } catch (Throwable ignored) { // In case Essentials isn't installed/loaded - return Logger.getLogger("EssentialsDiscord"); + return Logger.getLogger("EssentialsXMPP"); } }