From 1cbc4ed16c0891323b95fd4af227f28148fbc8f0 Mon Sep 17 00:00:00 2001 From: asofold Date: Sat, 29 Sep 2012 17:12:09 +0200 Subject: [PATCH] Use access methods for all normal logging to console. --- src/fr/neatmonster/nocheatplus/NoCheatPlus.java | 5 +++-- .../nocheatplus/actions/ActionFactory.java | 9 +++++---- .../nocheatplus/actions/types/CommandAction.java | 3 ++- .../nocheatplus/actions/types/LogAction.java | 2 +- .../nocheatplus/command/actions/BanCommand.java | 3 ++- .../nocheatplus/command/actions/KickCommand.java | 3 ++- .../nocheatplus/command/actions/TempKickCommand.java | 3 ++- .../nocheatplus/utilities/BlockProperties.java | 10 +++++----- .../nocheatplus/utilities/CheckUtils.java | 12 ++++++++++++ .../nocheatplus/utilities/LagMeasureTask.java | 6 +++--- src/fr/neatmonster/nocheatplus/utilities/Stats.java | 2 +- 11 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/fr/neatmonster/nocheatplus/NoCheatPlus.java b/src/fr/neatmonster/nocheatplus/NoCheatPlus.java index 74f8bf89..e865e208 100644 --- a/src/fr/neatmonster/nocheatplus/NoCheatPlus.java +++ b/src/fr/neatmonster/nocheatplus/NoCheatPlus.java @@ -45,6 +45,7 @@ import fr.neatmonster.nocheatplus.net.NCPNetServerHandler; import fr.neatmonster.nocheatplus.players.DataManager; import fr.neatmonster.nocheatplus.players.Permissions; import fr.neatmonster.nocheatplus.utilities.BlockProperties; +import fr.neatmonster.nocheatplus.utilities.CheckUtils; import fr.neatmonster.nocheatplus.utilities.LagMeasureTask; import fr.neatmonster.nocheatplus.utilities.TickTask; import fr.neatmonster.nocheatplus.utilities.Updates; @@ -209,7 +210,7 @@ public class NoCheatPlus extends JavaPlugin implements Listener { ConfigManager.cleanup(); // Tell the server administrator the we finished unloading NoCheatPlus. - System.out.println("[NoCheatPlus] Version " + pdfFile.getVersion() + " is disabled."); + CheckUtils.logInfo("[NoCheatPlus] Version " + pdfFile.getVersion() + " is disabled."); } /* (non-Javadoc) @@ -313,7 +314,7 @@ public class NoCheatPlus extends JavaPlugin implements Listener { BlockProperties.dumpBlocks(config.getBoolean(ConfPaths.BLOCKBREAK_FASTBREAK_DEBUG, false)); // Tell the server administrator that we finished loading NoCheatPlus now. - System.out.println("[NoCheatPlus] Version " + getDescription().getVersion() + " is enabled."); + CheckUtils.logInfo("[NoCheatPlus] Version " + getDescription().getVersion() + " is enabled."); } public void onPlayerJoinLow(final PlayerJoinEvent event) { diff --git a/src/fr/neatmonster/nocheatplus/actions/ActionFactory.java b/src/fr/neatmonster/nocheatplus/actions/ActionFactory.java index 4da8446e..e0ebf289 100644 --- a/src/fr/neatmonster/nocheatplus/actions/ActionFactory.java +++ b/src/fr/neatmonster/nocheatplus/actions/ActionFactory.java @@ -9,6 +9,7 @@ import fr.neatmonster.nocheatplus.actions.types.CancelAction; import fr.neatmonster.nocheatplus.actions.types.CommandAction; import fr.neatmonster.nocheatplus.actions.types.DummyAction; import fr.neatmonster.nocheatplus.actions.types.LogAction; +import fr.neatmonster.nocheatplus.utilities.CheckUtils; /* * MMP"""""""MM dP oo MM""""""""`M dP @@ -94,7 +95,7 @@ public class ActionFactory { } list.setActions(vl, createActions(def.split("\\s+"))); } catch (final Exception e) { - System.out.println("[NoCheatPlus] Couldn't parse action definition 'vl:" + s + "'."); + CheckUtils.logWarning("[NoCheatPlus] Couldn't parse action definition 'vl:" + s + "'."); } } @@ -117,7 +118,7 @@ public class ActionFactory { try { actions.add(createAction(def)); } catch (final IllegalArgumentException e) { - System.out.println("[NoCheatPlus] " + e.getMessage()); + CheckUtils.logWarning("[NoCheatPlus] Failed to create action: " + e.getMessage()); actions.add(new DummyAction(def)); } } @@ -148,7 +149,7 @@ public class ActionFactory { delay = Integer.parseInt(parts[1]); repeat = Integer.parseInt(parts[2]); } catch (final Exception e) { - System.out.println("[NoCheatPlus] Couldn't parse details of command '" + definition + CheckUtils.logWarning("[NoCheatPlus] Couldn't parse details of command '" + definition + "', will use default values instead."); delay = 0; repeat = 0; @@ -185,7 +186,7 @@ public class ActionFactory { toChat = parts[3].contains("i"); toFile = parts[3].contains("f"); } catch (final Exception e) { - System.out.println("[NoCheatPlus] Couldn't parse details of log action '" + definition + CheckUtils.logWarning("[NoCheatPlus] Couldn't parse details of log action '" + definition + "', will use default values instead."); e.printStackTrace(); delay = 0; diff --git a/src/fr/neatmonster/nocheatplus/actions/types/CommandAction.java b/src/fr/neatmonster/nocheatplus/actions/types/CommandAction.java index 1864d5be..90bdcd1c 100644 --- a/src/fr/neatmonster/nocheatplus/actions/types/CommandAction.java +++ b/src/fr/neatmonster/nocheatplus/actions/types/CommandAction.java @@ -4,6 +4,7 @@ import org.bukkit.Bukkit; import org.bukkit.command.CommandException; import fr.neatmonster.nocheatplus.checks.ViolationData; +import fr.neatmonster.nocheatplus.utilities.CheckUtils; /* * MM'""""'YMM dP @@ -53,7 +54,7 @@ public class CommandAction extends ActionWithParameters { try { Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command); } catch (final CommandException e) { - System.out.println("[NoCheatPlus] Failed to execute the command '" + command + "': " + e.getMessage() + CheckUtils.logWarning("[NoCheatPlus] Failed to execute the command '" + command + "': " + e.getMessage() + ", please check if everything is setup correct."); } catch (final Exception e) { // I don't care in this case, your problem if your command fails. diff --git a/src/fr/neatmonster/nocheatplus/actions/types/LogAction.java b/src/fr/neatmonster/nocheatplus/actions/types/LogAction.java index a7682e5e..d139378f 100644 --- a/src/fr/neatmonster/nocheatplus/actions/types/LogAction.java +++ b/src/fr/neatmonster/nocheatplus/actions/types/LogAction.java @@ -76,7 +76,7 @@ public class LogAction extends ActionWithParameters { otherPlayer.sendMessage(ChatColor.RED + "NCP: " + ChatColor.WHITE + CheckUtils.replaceColors(message)); if (toConsole && configurationFile.getBoolean(ConfPaths.LOGGING_CONSOLE)) - System.out.println("[NoCheatPlus] " + CheckUtils.removeColors(message)); + CheckUtils.logInfo("[NoCheatPlus] " + CheckUtils.removeColors(message)); if (toFile && configurationFile.getBoolean(ConfPaths.LOGGING_FILE)) CheckUtils.fileLogger.info(CheckUtils.removeColors(message)); } diff --git a/src/fr/neatmonster/nocheatplus/command/actions/BanCommand.java b/src/fr/neatmonster/nocheatplus/command/actions/BanCommand.java index 4308758b..bfb8b660 100644 --- a/src/fr/neatmonster/nocheatplus/command/actions/BanCommand.java +++ b/src/fr/neatmonster/nocheatplus/command/actions/BanCommand.java @@ -9,6 +9,7 @@ import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.NoCheatPlus; import fr.neatmonster.nocheatplus.command.DelayableCommand; import fr.neatmonster.nocheatplus.players.Permissions; +import fr.neatmonster.nocheatplus.utilities.CheckUtils; public class BanCommand extends DelayableCommand { @@ -40,7 +41,7 @@ public class BanCommand extends DelayableCommand { player.kickPlayer(reason); OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(name); offlinePlayer.setBanned(true); - System.out.println("[NoCheatPlus] (" + sender.getName() + ") Banned " + offlinePlayer.getName() + " : " + reason); + CheckUtils.logInfo("[NoCheatPlus] (" + sender.getName() + ") Banned " + offlinePlayer.getName() + " : " + reason); } } diff --git a/src/fr/neatmonster/nocheatplus/command/actions/KickCommand.java b/src/fr/neatmonster/nocheatplus/command/actions/KickCommand.java index 060c70e9..3b6a0f39 100644 --- a/src/fr/neatmonster/nocheatplus/command/actions/KickCommand.java +++ b/src/fr/neatmonster/nocheatplus/command/actions/KickCommand.java @@ -8,6 +8,7 @@ import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.NoCheatPlus; import fr.neatmonster.nocheatplus.command.DelayableCommand; import fr.neatmonster.nocheatplus.players.Permissions; +import fr.neatmonster.nocheatplus.utilities.CheckUtils; public class KickCommand extends DelayableCommand { @@ -37,7 +38,7 @@ public class KickCommand extends DelayableCommand { Player player = Bukkit.getPlayerExact(name); if (player == null) return; player.kickPlayer(reason); - System.out.println("[NoCheatPlus] (" + sender.getName() + ") Kicked " + player.getName() + " : " + reason); + CheckUtils.logInfo("[NoCheatPlus] (" + sender.getName() + ") Kicked " + player.getName() + " : " + reason); } } diff --git a/src/fr/neatmonster/nocheatplus/command/actions/TempKickCommand.java b/src/fr/neatmonster/nocheatplus/command/actions/TempKickCommand.java index 429713a5..3c844780 100644 --- a/src/fr/neatmonster/nocheatplus/command/actions/TempKickCommand.java +++ b/src/fr/neatmonster/nocheatplus/command/actions/TempKickCommand.java @@ -8,6 +8,7 @@ import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.NoCheatPlus; import fr.neatmonster.nocheatplus.command.DelayableCommand; import fr.neatmonster.nocheatplus.players.Permissions; +import fr.neatmonster.nocheatplus.utilities.CheckUtils; public class TempKickCommand extends DelayableCommand { @@ -50,6 +51,6 @@ public class TempKickCommand extends DelayableCommand { NoCheatPlus.denyLogin(name, duration); if (player == null) return; player.kickPlayer(reason); - System.out.println("[NoCheatPlus] (" + sender.getName() + ") Kicked " + player.getName() + " for " + duration/60000 +" minutes: " + reason); + CheckUtils.logInfo("[NoCheatPlus] (" + sender.getName() + ") Kicked " + player.getName() + " for " + duration/60000 +" minutes: " + reason); } } diff --git a/src/fr/neatmonster/nocheatplus/utilities/BlockProperties.java b/src/fr/neatmonster/nocheatplus/utilities/BlockProperties.java index 5f4065a5..e7df81bc 100644 --- a/src/fr/neatmonster/nocheatplus/utilities/BlockProperties.java +++ b/src/fr/neatmonster/nocheatplus/utilities/BlockProperties.java @@ -454,8 +454,8 @@ public class BlockProperties { public static void dumpBlocks(boolean all) { List missing = new LinkedList(); if (all) { - System.out.println("[NoCheatPlus] Dump block properties for fastbreak check:"); - System.out.println("--- Present entries -------------------------------"); + CheckUtils.logInfo("[NoCheatPlus] Dump block properties for fastbreak check:"); + CheckUtils.logInfo("--- Present entries -------------------------------"); } for (int i = 0; i < blocks.length; i++){ String mat; @@ -471,13 +471,13 @@ public class BlockProperties { if (mat.equals("?")) continue; missing.add("* MISSING "+i + "(" + mat +") "); } - else if (all) System.out.println(i + ": (" + mat + ") " + blocks[i].toString()); + else if (all) CheckUtils.logInfo(i + ": (" + mat + ") " + blocks[i].toString()); } if (!missing.isEmpty()){ Bukkit.getLogger().warning("[NoCheatPlus] The block breaking data is incomplete, interpret some as stone :"); - System.out.println("--- Missing entries -------------------------------"); + CheckUtils.logWarning("--- Missing entries -------------------------------"); for (String spec : missing){ - System.out.println(spec); + CheckUtils.logWarning(spec); } } } diff --git a/src/fr/neatmonster/nocheatplus/utilities/CheckUtils.java b/src/fr/neatmonster/nocheatplus/utilities/CheckUtils.java index 831ef90b..b8ed2497 100644 --- a/src/fr/neatmonster/nocheatplus/utilities/CheckUtils.java +++ b/src/fr/neatmonster/nocheatplus/utilities/CheckUtils.java @@ -288,4 +288,16 @@ public class CheckUtils { else if (diff > Math.PI) return diff - 2.0 * Math.PI; else return diff; } + + public static void logSevere(final String msg) { + Bukkit.getLogger().severe((msg)); + } + + public static void logWarning(final String msg) { + Bukkit.getLogger().warning((msg)); + } + + public static void logInfo(final String msg) { + Bukkit.getLogger().info((msg)); + } } diff --git a/src/fr/neatmonster/nocheatplus/utilities/LagMeasureTask.java b/src/fr/neatmonster/nocheatplus/utilities/LagMeasureTask.java index 3d853d56..b08c2902 100644 --- a/src/fr/neatmonster/nocheatplus/utilities/LagMeasureTask.java +++ b/src/fr/neatmonster/nocheatplus/utilities/LagMeasureTask.java @@ -41,7 +41,7 @@ public class LagMeasureTask implements Runnable { try { Bukkit.getServer().getScheduler().cancelTask(instance.lagMeasureTaskId); } catch (final Exception e) { - System.out.println("[NoCheatPlus] Couldn't cancel LagMeasureTask: " + e.getMessage() + "."); + CheckUtils.logWarning("[NoCheatPlus] Couldn't cancel LagMeasureTask: " + e.getMessage() + "."); } instance.lagMeasureTaskId = -1; } @@ -98,9 +98,9 @@ public class LagMeasureTask implements Runnable { // Show the debug messages. if (ConfigManager.getConfigFile().getBoolean(ConfPaths.LOGGING_DEBUG)) if (oldStatus != skipCheck && skipCheck) - System.out.println("[NoCheatPlus] Detected server lag, some checks will not work."); + CheckUtils.logInfo("[NoCheatPlus] Detected server lag, some checks will not work."); else if (oldStatus != skipCheck && !skipCheck) - System.out.println("[NoCheatPlus] Server lag seems to have stopped, reenabling checks."); + CheckUtils.logInfo("[NoCheatPlus] Server lag seems to have stopped, reenabling checks."); final long time = System.currentTimeMillis(); lastInGameSecondDuration = time - lastInGameSecondTime; diff --git a/src/fr/neatmonster/nocheatplus/utilities/Stats.java b/src/fr/neatmonster/nocheatplus/utilities/Stats.java index abc33700..f475df89 100644 --- a/src/fr/neatmonster/nocheatplus/utilities/Stats.java +++ b/src/fr/neatmonster/nocheatplus/utilities/Stats.java @@ -81,7 +81,7 @@ public final class Stats { if ( ts > tsStats+periodStats){ tsStats = ts; // print out stats ! - System.out.println(getStatsStr()); + CheckUtils.logInfo(getStatsStr()); } } }