From 8452fad8a392cef1d7603615ab6e3bf9a6f5756b Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 12 Oct 2016 18:41:45 +0200 Subject: [PATCH] Hide messages in the console on auto reload --- .../java/de/epiceric/shopchest/ShopChest.java | 4 +- .../de/epiceric/shopchest/ShopCommand.java | 2 +- .../de/epiceric/shopchest/config/Config.java | 52 +++++++++++-------- .../epiceric/shopchest/utils/ShopUtils.java | 5 +- 4 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/main/java/de/epiceric/shopchest/ShopChest.java b/src/main/java/de/epiceric/shopchest/ShopChest.java index 5ac4ad7..337ccfe 100644 --- a/src/main/java/de/epiceric/shopchest/ShopChest.java +++ b/src/main/java/de/epiceric/shopchest/ShopChest.java @@ -240,7 +240,7 @@ public class ShopChest extends JavaPlugin { ShopReloadEvent event = new ShopReloadEvent(Bukkit.getConsoleSender()); Bukkit.getServer().getPluginManager().callEvent(event); - if (!event.isCancelled()) getLogger().info("Successfully reloaded " + String.valueOf(shopUtils.reloadShops(true)) + " shops."); + if (!event.isCancelled()) shopUtils.reloadShops(true, false); } }, config.auto_reload_time * 20, config.auto_reload_time * 20); } @@ -364,7 +364,7 @@ public class ShopChest extends JavaPlugin { */ private void initializeShops() { debug("Initializing Shops..."); - int count = shopUtils.reloadShops(false); + int count = shopUtils.reloadShops(false, false); getLogger().info("Initialized " + count + " Shops"); debug("Initialized " + count + " Shops"); } diff --git a/src/main/java/de/epiceric/shopchest/ShopCommand.java b/src/main/java/de/epiceric/shopchest/ShopCommand.java index 1112af9..8e468de 100644 --- a/src/main/java/de/epiceric/shopchest/ShopCommand.java +++ b/src/main/java/de/epiceric/shopchest/ShopCommand.java @@ -225,7 +225,7 @@ class ShopCommand extends BukkitCommand { return; } - int count = shopUtils.reloadShops(true); + int count = shopUtils.reloadShops(true, true); plugin.debug(player.getName() + " has reloaded " + count + " shops"); player.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.RELOADED_SHOPS, new LocalizedMessage.ReplacedRegex(Regex.AMOUNT, String.valueOf(count)))); } diff --git a/src/main/java/de/epiceric/shopchest/config/Config.java b/src/main/java/de/epiceric/shopchest/config/Config.java index 214a2f8..969a783 100644 --- a/src/main/java/de/epiceric/shopchest/config/Config.java +++ b/src/main/java/de/epiceric/shopchest/config/Config.java @@ -143,7 +143,7 @@ public class Config { plugin.saveDefaultConfig(); plugin.reloadConfig(); - reload(true, true); + reload(true, true, true); } /** @@ -161,7 +161,7 @@ public class Config { plugin.saveConfig(); plugin.reloadConfig(); - reload(false, langChange); + reload(false, langChange, false); return; } catch (NumberFormatException e) { /* Value not an integer */ } @@ -172,7 +172,7 @@ public class Config { plugin.saveConfig(); plugin.reloadConfig(); - reload(false, langChange); + reload(false, langChange, false); return; } catch (NumberFormatException e) { /* Value not a double */ } @@ -187,7 +187,7 @@ public class Config { plugin.saveConfig(); plugin.reloadConfig(); - reload(false, langChange); + reload(false, langChange, false); } /** @@ -205,7 +205,7 @@ public class Config { plugin.saveConfig(); plugin.reloadConfig(); - reload(false, false); + reload(false, false, false); return; } catch (NumberFormatException e) { /* Value not an integer */ } @@ -216,7 +216,7 @@ public class Config { plugin.saveConfig(); plugin.reloadConfig(); - reload(false, false); + reload(false, false, false); return; } catch (NumberFormatException e) { /* Value not a double */ } @@ -231,7 +231,7 @@ public class Config { plugin.saveConfig(); plugin.reloadConfig(); - reload(false, false); + reload(false, false, false); } public void remove(String property, String value) { @@ -243,7 +243,7 @@ public class Config { plugin.saveConfig(); plugin.reloadConfig(); - reload(false, false); + reload(false, false, false); return; } catch (NumberFormatException e) { /* Value not an integer */ } @@ -254,7 +254,7 @@ public class Config { plugin.saveConfig(); plugin.reloadConfig(); - reload(false, false); + reload(false, false, false); return; } catch (NumberFormatException e) { /* Value not a double */ } @@ -269,13 +269,13 @@ public class Config { plugin.saveConfig(); plugin.reloadConfig(); - reload(false, false); + reload(false, false, false); } /** * Reload the configuration values from config.yml */ - public void reload(boolean firstLoad, boolean langReload) { + public void reload(boolean firstLoad, boolean langReload, boolean showMessages) { database_mysql_ping_interval = plugin.getConfig().getInt("database.mysql.ping-interval"); database_mysql_host = plugin.getConfig().getString("database.mysql.hostname"); database_mysql_port = plugin.getConfig().getInt("database.mysql.port"); @@ -309,7 +309,7 @@ public class Config { main_command_name = plugin.getConfig().getString("main-command-name"); language_file = plugin.getConfig().getString("language-file"); - if (firstLoad || langReload) loadLanguageConfig(); + if (firstLoad || langReload) loadLanguageConfig(showMessages); if (!firstLoad && langReload) LanguageUtils.load(); } @@ -320,7 +320,7 @@ public class Config { return langConfig; } - private void loadLanguageConfig() { + private void loadLanguageConfig(boolean showMessages) { langConfig = new LanguageConfiguration(plugin); File langFolder = new File(plugin.getDataFolder(), "lang"); @@ -340,9 +340,9 @@ public class Config { if (r == null) { r = plugin._getTextResource("lang/en_US.lang"); - plugin.getLogger().info("Using locale \"en_US\" (Streamed from jar file)"); + if (showMessages) plugin.getLogger().info("Using locale \"en_US\" (Streamed from jar file)"); } else { - plugin.getLogger().info("Using locale \"" + langConfigFile.getName().substring(0, langConfigFile.getName().length() - 5) + "\" (Streamed from jar file)"); + if (showMessages) plugin.getLogger().info("Using locale \"" + langConfigFile.getName().substring(0, langConfigFile.getName().length() - 5) + "\" (Streamed from jar file)"); } BufferedReader br = new BufferedReader(r); @@ -358,25 +358,31 @@ public class Config { langConfig.loadFromString(sb.toString()); } catch (IOException | InvalidConfigurationException ex) { - plugin.debug(ex); - plugin.getLogger().warning("Using default language values"); + if (showMessages) { + plugin.getLogger().warning("Using default language values"); + ex.printStackTrace(); + } } } else { try { langConfig.load(langDefaultFile); - plugin.getLogger().info("Using locale \"en_US\""); + if (showMessages) plugin.getLogger().info("Using locale \"en_US\""); } catch (IOException | InvalidConfigurationException e) { - plugin.debug(e); - plugin.getLogger().warning("Using default language values"); + if (showMessages) { + plugin.getLogger().warning("Using default language values"); + e.printStackTrace(); + } } } } else { try { - plugin.getLogger().info("Using locale \"" + langConfigFile.getName().substring(0, langConfigFile.getName().length() - 5) + "\""); + if (showMessages) plugin.getLogger().info("Using locale \"" + langConfigFile.getName().substring(0, langConfigFile.getName().length() - 5) + "\""); langConfig.load(langConfigFile); } catch (IOException | InvalidConfigurationException ex) { - plugin.debug(ex); - plugin.getLogger().warning("Using default language values"); + if (showMessages) { + plugin.getLogger().warning("Using default language values"); + ex.printStackTrace(); + } } } } diff --git a/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java b/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java index 37bd4f2..827945b 100644 --- a/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java +++ b/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java @@ -201,14 +201,15 @@ public class ShopUtils { /** * Reload the shops * @param reloadConfig Whether the configuration should also be reloaded + * @param showConsoleMessages Whether messages about the language file should be shown in the console * @return Amount of shops, which were reloaded */ - public int reloadShops(boolean reloadConfig) { + public int reloadShops(boolean reloadConfig, boolean showConsoleMessages) { plugin.debug("Reloading shops..."); plugin.getShopDatabase().connect(); - if (reloadConfig) plugin.getShopChestConfig().reload(false, true); + if (reloadConfig) plugin.getShopChestConfig().reload(false, true, showConsoleMessages); int highestId = plugin.getShopDatabase().getHighestID();