From 379fd75068eb860f97839c7ad568c9470bf0c10b Mon Sep 17 00:00:00 2001 From: Evenprime Date: Sun, 13 Mar 2011 14:27:21 +0100 Subject: [PATCH] Added support for logging to irc with CraftIRC plugin + small fixes to logging. --- plugin.yml | 2 +- .../bukkit/nocheat/NoCheatConfiguration.java | 15 ++++- .../bukkit/nocheat/NoCheatPlugin.java | 59 ++++++++++++++----- 3 files changed, 58 insertions(+), 18 deletions(-) diff --git a/plugin.yml b/plugin.yml index 3c081904..c5f47294 100644 --- a/plugin.yml +++ b/plugin.yml @@ -3,7 +3,7 @@ name: NoCheatPlugin author: Evenprime main: cc.co.evenprime.bukkit.nocheat.NoCheatPlugin -version: 0.6.7b +version: 0.6.7c commands: nocheat: diff --git a/src/cc/co/evenprime/bukkit/nocheat/NoCheatConfiguration.java b/src/cc/co/evenprime/bukkit/nocheat/NoCheatConfiguration.java index 6cd96be0..a4f218f5 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/NoCheatConfiguration.java +++ b/src/cc/co/evenprime/bukkit/nocheat/NoCheatConfiguration.java @@ -50,7 +50,10 @@ public class NoCheatConfiguration { public static String airbuildAction = ""; // The log level above which players with the permission nocheat.notify will get informed about violations - public static Level notifyLevel = Level.OFF; + public static Level chatLevel = Level.OFF; + public static Level ircLevel = Level.OFF; + + public static String ircTag = ""; // Our two log outputs, the console and a file private static ConsoleHandler ch = null; @@ -96,7 +99,11 @@ public class NoCheatConfiguration { } } - notifyLevel = stringToLevel(c.getString("logging.logtonotify")); + chatLevel = stringToLevel(c.getString("logging.logtonotify")); // deprecated, will be deleted eventually + chatLevel = stringToLevel(c.getString("logging.logtochat")); + + ircLevel = stringToLevel(c.getString("logging.logtoirc")); + ircTag = c.getString("logging.logtoirctag", "nocheat"); speedhackCheckActive = c.getBoolean("active.speedhack", true); movingCheckActive = c.getBoolean("active.moving", true); @@ -157,7 +164,9 @@ public class NoCheatConfiguration { w.write(" filename: plugins/NoCheat/nocheat.log"); w.newLine(); w.write(" logtofile: low"); w.newLine(); w.write(" logtoconsole: high"); w.newLine(); - w.write(" logtonotify: med"); w.newLine(); + w.write(" logtochat: med"); w.newLine(); + w.write(" logtoirc: med"); w.newLine(); + w.write(" logtoirctag: nocheat"); w.newLine(); w.write("# Checks and Bugfixes that are activated (true or false)"); w.newLine(); w.write("active:"); w.newLine(); w.write(" speedhack: true"); w.newLine(); diff --git a/src/cc/co/evenprime/bukkit/nocheat/NoCheatPlugin.java b/src/cc/co/evenprime/bukkit/nocheat/NoCheatPlugin.java index a2e78fbb..cffb4645 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/NoCheatPlugin.java +++ b/src/cc/co/evenprime/bukkit/nocheat/NoCheatPlugin.java @@ -19,6 +19,7 @@ import cc.co.evenprime.bukkit.nocheat.listeners.NoCheatBlockListener; import cc.co.evenprime.bukkit.nocheat.listeners.NoCheatEntityListener; import cc.co.evenprime.bukkit.nocheat.listeners.NoCheatPlayerListener; +import com.ensifera.animosity.craftirc.CraftIRC; import com.nijikokun.bukkit.Permissions.Permissions; import com.nijiko.permissions.PermissionHandler; import org.bukkit.plugin.Plugin; @@ -37,7 +38,7 @@ public class NoCheatPlugin extends JavaPlugin { private NoCheatPlayerListener playerListener; private NoCheatBlockListener blockListener; private NoCheatEntityListener entityListener; - + // My main logger private static Logger log; @@ -45,6 +46,9 @@ public class NoCheatPlugin extends JavaPlugin { // Permissions 2.0, if available public static PermissionHandler Permissions = null; + + // CraftIRC 2.0, if available + public static CraftIRC Irc = null; // Store data between Events public static Map playerData = new HashMap(); @@ -123,6 +127,8 @@ public class NoCheatPlugin extends JavaPlugin { public void onDisable() { + + PluginDescriptionFile pdfFile = this.getDescription(); Logger.getLogger("Minecraft").info( "[NoCheatPlugin] version [" + pdfFile.getVersion() + "] is disabled."); } @@ -144,16 +150,17 @@ public class NoCheatPlugin extends JavaPlugin { PluginDescriptionFile pdfFile = this.getDescription(); - // Get, if available, the Permissions plugin - setupPermissions(); - // parse the nocheat.yml config file setupConfig(); - + + // Get, if available, the Permissions and irc plugin + setupPermissions(); + setupIRC(); + Logger.getLogger("Minecraft").info( "[NoCheatPlugin] version [" + pdfFile.getVersion() + "] is enabled with the following checks: "+getActiveChecksAsString()); } - /** + /** * Get, if available, a reference to the Permissions-plugin */ public void setupPermissions() { @@ -161,7 +168,7 @@ public class NoCheatPlugin extends JavaPlugin { Plugin test = this.getServer().getPluginManager().getPlugin("Permissions"); - if(test != null) { + if(test != null && test instanceof Permissions) { p = ((Permissions)test).getHandler(); if(p == null) { this.getServer().getPluginManager().enablePlugin(test); @@ -171,13 +178,32 @@ public class NoCheatPlugin extends JavaPlugin { if(p == null) { PluginDescriptionFile pdfFile = this.getDescription(); - log.info("[NoCheatPlugin] version [" + pdfFile.getVersion() + "] couldn't find Permissions plugin. Fallback to 'isOp()' equals 'nocheat.*'"); - Permissions = null; + Logger.getLogger("Minecraft").warning("[NoCheatPlugin] version [" + pdfFile.getVersion() + "] couldn't find Permissions plugin. Fallback to 'isOp()' equals 'nocheat.*'"); } - else - Permissions = p; + + Permissions = p; } + /** + * Get, if available, a reference to the Permissions-plugin + */ + public void setupIRC() { + CraftIRC p = null; + + Plugin test = this.getServer().getPluginManager().getPlugin("CraftIRC"); + + if(test != null && test instanceof CraftIRC) { + p = (CraftIRC)test; + } + + if(p == null) { + PluginDescriptionFile pdfFile = this.getDescription(); + Logger.getLogger("Minecraft").warning("[NoCheatPlugin] version [" + pdfFile.getVersion() + "] couldn't find CrafTIRC plugin. Disabling logging to IRC."); + } + + Irc = p; + } + /** * Log a violation message to all locations declared in the config file * @param message @@ -185,13 +211,14 @@ public class NoCheatPlugin extends JavaPlugin { private static void log(Level l, String message) { if(l != null) { logToChat(l, message); + logToIRC(l, message); log.log(l, message); } } private static void logToChat(Level l, String message) { - if(NoCheatConfiguration.notifyLevel.intValue() <= l.intValue()) { + if(NoCheatConfiguration.chatLevel.intValue() <= l.intValue()) { for(Player player : p.getServer().getOnlinePlayers()) { if(hasPermission(player, "nocheat.notify")) { player.sendMessage("["+l.getName()+"] " + message); @@ -199,6 +226,11 @@ public class NoCheatPlugin extends JavaPlugin { } } } + private static void logToIRC(Level l, String message) { + if(Irc != null && NoCheatConfiguration.ircLevel.intValue() <= l.intValue()) { + Irc.sendMessageToTag("["+l.getName()+"] " + message , NoCheatConfiguration.ircTag); + } + } public static void logAction(String actions, String message) { if(actions == null) return; @@ -233,13 +265,12 @@ public class NoCheatPlugin extends JavaPlugin { return true; else return false; - } /** * Read the config file */ - public void setupConfig() { + private void setupConfig() { NoCheatConfiguration.config(new File("plugins/NoCheat/nocheat.yml")); }