From e1f89e7904d4e5a6cf281beea68e599c28c0d47e Mon Sep 17 00:00:00 2001 From: Thijs Wiefferink Date: Mon, 8 Aug 2016 22:06:31 +0200 Subject: [PATCH] Cleanup some leftover logging in an old style --- .../java/me/wiefferink/areashop/AreaShop.java | 54 +++++++++++++------ .../areashop/messages/LanguageManager.java | 8 --- .../wiefferink/areashop/messages/Message.java | 10 ++-- 3 files changed, 42 insertions(+), 30 deletions(-) diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/AreaShop.java b/AreaShop/src/main/java/me/wiefferink/areashop/AreaShop.java index a0efe4f..cbe75a9 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/AreaShop.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/AreaShop.java @@ -154,7 +154,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface { Integer build = null; Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard"); if (plugin == null || !(plugin instanceof WorldGuardPlugin)) { - getLogger().severe("WorldGuard plugin is not present or has not loaded correctly"); + error("WorldGuard plugin is not present or has not loaded correctly"); error = true; } else { worldGuard = (WorldGuardPlugin)plugin; @@ -168,7 +168,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface { try { build = Integer.parseInt(buildNumber); } catch(NumberFormatException e) { - getLogger().warning("Could not correctly parse the build of WorldGuard, raw version: "+rawVersion+", buildNumber: "+buildNumber); + warn("Could not correctly parse the build of WorldGuard, raw version: "+rawVersion+", buildNumber: "+buildNumber); } } // Clear stuff from the version string that is not a number @@ -192,7 +192,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface { fixes = Integer.parseInt(versionParts[2]); } } catch(NumberFormatException e) { - getLogger().warning("Something went wrong while parsing WorldGuard version number: "+rawVersion); + warn("Something went wrong while parsing WorldGuard version number: "+rawVersion); } // Determine correct implementation to use if(major >= 6 && minor >= 1 && fixes > 3) { @@ -203,7 +203,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface { } else { // Build 1672 is broken, flags changed but no FlagContext added yet error = true; - getLogger().severe("Build 1672 of WorldGuard is broken, update to a later build or a stable version!"); + error("Build 1672 of WorldGuard is broken, update to a later build or a stable version!"); } } else if(worldGuard.getDescription().getVersion().startsWith("5.")) { wgVersion = "5"; @@ -218,7 +218,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface { worldGuardInterface = (WorldGuardInterface)clazz.getConstructor(AreaShopInterface.class).newInstance(this); // Set our handler } } catch (final Exception e) { - getLogger().severe("Could not load the handler for WorldGuard (tried to load "+wgVersion+"), report this problem to the author:"+ExceptionUtils.getStackTrace(e)); + error("Could not load the handler for WorldGuard (tried to load "+wgVersion+"), report this problem to the author:"+ExceptionUtils.getStackTrace(e)); error = true; wgVersion = null; } @@ -228,7 +228,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface { String weVersion = null; plugin = getServer().getPluginManager().getPlugin("WorldEdit"); if (plugin == null || !(plugin instanceof WorldEditPlugin)) { - getLogger().severe("WorldEdit plugin is not present or has not loaded correctly"); + error("WorldEdit plugin is not present or has not loaded correctly"); error = true; } else { worldEdit = (WorldEditPlugin)plugin; @@ -245,7 +245,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface { worldEditInterface = (WorldEditInterface)clazz.getConstructor(AreaShopInterface.class).newInstance(this); // Set our handler } } catch (final Exception e) { - getLogger().severe("Could not load the handler for WorldEdit (tried to load "+weVersion+"), report this problem to the author: "+ExceptionUtils.getStackTrace(e)); + error("Could not load the handler for WorldEdit (tried to load "+weVersion+"), report this problem to the author: "+ExceptionUtils.getStackTrace(e)); error = true; weVersion = null; } @@ -253,7 +253,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface { // Check if Vault is present if(getServer().getPluginManager().getPlugin("Vault") == null) { - getLogger().severe("Vault plugin is not present or has not loaded correctly"); + error("Vault plugin is not present or has not loaded correctly"); error = true; } @@ -273,7 +273,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface { languageManager = new LanguageManager(this); if(error) { - getLogger().severe("The plugin has not started, fix the errors listed above"); + error("The plugin has not started, fix the errors listed above"); } else { // Register the event listeners getServer().getPluginManager().registerEvents(new SignChangeListener(this), this); @@ -308,7 +308,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface { AreaShop.debug("Result=" + updater.getResult().toString() + ", Latest=" + updater.getLatestName() + ", Type=" + updater.getLatestType()); updateAvailable = updater.getResult() == UpdateResult.UPDATE_AVAILABLE; if(updateAvailable) { - AreaShop.getInstance().getLogger().info("Update from AreaShop V" + AreaShop.getInstance().getDescription().getVersion() + " to " + updater.getLatestName() + " available, get the latest version at http://dev.bukkit.org/bukkit-plugins/regionbuyandrent/"); + AreaShop.info("Update from AreaShop V"+AreaShop.getInstance().getDescription().getVersion()+" to "+updater.getLatestName()+" available, get the latest version at http://dev.bukkit.org/bukkit-plugins/regionbuyandrent/"); new BukkitRunnable() { @Override public void run() { @@ -465,7 +465,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface { public Economy getEconomy() { RegisteredServiceProvider economy = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); if (economy == null || economy.getProvider() == null) { - getLogger().severe("There is no economy provider to support Vault, make sure you installed an economy plugin"); + error("There is no economy provider to support Vault, make sure you installed an economy plugin"); return null; } return economy.getProvider(); @@ -518,7 +518,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface { try { Bukkit.getPluginManager().addPermission(perm); } catch(IllegalArgumentException e) { - getLogger().warning("Could not add the following permission to be used as limit: "+perm.getName()); + warn("Could not add the following permission to be used as limit: "+perm.getName()); } } } @@ -617,10 +617,22 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface { } } + /** + * Send a message to a target without a prefix + * @param target The target to send the message to + * @param key The key of the language string + * @param replacements The replacements to insert in the message + */ public void messageNoPrefix(Object target, String key, Object... replacements) { Message.fromKey(key).replacements(replacements).send(target); } + /** + * Send a message to a target, prefixed by the default chat prefix + * @param target The target to send the message to + * @param key The key of the language string + * @param replacements The replacements to insert in the message + */ public void message(Object target, String key, Object... replacements) { Message.fromKey(key).prefix().replacements(replacements).send(target); } @@ -653,7 +665,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface { */ public static void debug(Object... message) { if(AreaShop.getInstance().debug) { - AreaShop.getInstance().getLogger().info("Debug: "+StringUtils.join(message, " ")); + info("Debug: "+StringUtils.join(message, " ")); } } /** @@ -663,6 +675,14 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface { AreaShop.debug(message); } + /** + * Print an information message to the console + * @param message The message to print + */ + public static void info(String... message) { + AreaShop.getInstance().getLogger().info(StringUtils.join(message, " ")); + } + /** * Print a warning to the console * @param message The message to print @@ -672,11 +692,11 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface { } /** - * Print an information message to the console - * @param message The message to print + * Print an error to the console + * @param message The messagfe to print */ - public static void info(String... message) { - AreaShop.getInstance().getLogger().info(StringUtils.join(message, " ")); + public static void error(String... message) { + AreaShop.getInstance().getLogger().severe(StringUtils.join(message, " ")); } /** diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/messages/LanguageManager.java b/AreaShop/src/main/java/me/wiefferink/areashop/messages/LanguageManager.java index cc58ae6..fd90c79 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/messages/LanguageManager.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/messages/LanguageManager.java @@ -19,14 +19,6 @@ public class LanguageManager { */ public LanguageManager(AreaShop plugin) { this.plugin = plugin; - startup(); - - } - - /** - * Save the default language files and open the current and backup language file - */ - public void startup() { this.saveDefaults(); currentLanguage = loadLanguage(plugin.getConfig().getString("language")); defaultLanguage = loadLanguage(languages[0]); diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/messages/Message.java b/AreaShop/src/main/java/me/wiefferink/areashop/messages/Message.java index 395b224..73c3cff 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/messages/Message.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/messages/Message.java @@ -184,7 +184,7 @@ public class Message { try { String jsonString = FancyMessageFormat.convertToJSON(message); if(jsonString.length() > MAXIMUMJSONLENGTH) { - AreaShop.getInstance().getLogger().severe("Message with key "+key+" could not be send, results in a JSON string that is too big to send to the client, start of the message: "+Utils.getMessageStart(this, 100)); + AreaShop.error("Message with key "+key+" could not be send, results in a JSON string that is too big to send to the client, start of the message: "+Utils.getMessageStart(this, 100)); return this; } boolean result = Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw "+((Player)target).getName()+" "+jsonString); @@ -192,7 +192,7 @@ public class Message { fancyWorks = result; } catch(Exception e) { fancyWorks = false; - AreaShop.getInstance().getLogger().warning("Sending fancy message did not work, falling back to plain messages. Message key: "+key); + AreaShop.warn("Sending fancy message did not work, falling back to plain messages. Message key: "+key); AreaShop.debug(ExceptionUtils.getStackTrace(e)); } } @@ -209,7 +209,7 @@ public class Message { } else if(target instanceof Logger) { ((Logger)target).info(plainMessage); } else { - AreaShop.getInstance().getLogger().warning("Could not send message, target is wrong: "+plainMessage); + AreaShop.warn("Could not send message, target is wrong: "+plainMessage); } } return this; @@ -272,7 +272,7 @@ public class Message { if(limit.reached()) { if(!limit.notified) { limit.notified = true; - AreaShop.getInstance().getLogger().severe("Reached replacement limit, probably has replacements loops, problematic message key: "+limit.message.key+", first characters of the message: "+Utils.getMessageStart(limit.message, 100)); + AreaShop.error("Reached replacement limit, probably has replacements loops, problematic message key: "+limit.message.key+", first characters of the message: "+Utils.getMessageStart(limit.message, 100)); } break; } @@ -284,7 +284,7 @@ public class Message { } catch(StackOverflowError e) { limit.left = 0; limit.notified = true; - AreaShop.getInstance().getLogger().severe("Too many recursive replacements for message with key: "+limit.message.key+" (probably includes itself as replacement), start of the message: "+Utils.getMessageStart(limit.message, 100)); + AreaShop.error("Too many recursive replacements for message with key: "+limit.message.key+" (probably includes itself as replacement), start of the message: "+Utils.getMessageStart(limit.message, 100)); } }