mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-10-06 10:27:26 +02:00
experimental Logging support.
Choose where and what to log. (needs some additional code changes before it is actually useful)
This commit is contained in:
parent
461097af56
commit
83d984edeb
78
src/cc/co/evenprime/bukkit/nocheat/NoCheatConfiguration.java
Normal file
78
src/cc/co/evenprime/bukkit/nocheat/NoCheatConfiguration.java
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
package cc.co.evenprime.bukkit.nocheat;
|
||||||
|
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.logging.ConsoleHandler;
|
||||||
|
import java.util.logging.FileHandler;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import java.util.logging.SimpleFormatter;
|
||||||
|
|
||||||
|
import org.bukkit.util.config.Configuration;
|
||||||
|
|
||||||
|
public class NoCheatConfiguration {
|
||||||
|
|
||||||
|
public static final String loggerName = "cc.co.evenprime.bukkit.nocheat";
|
||||||
|
public static final Logger logger = Logger.getLogger(loggerName);
|
||||||
|
|
||||||
|
private NoCheatConfiguration() {}
|
||||||
|
|
||||||
|
public static void config(File configurationFile) {
|
||||||
|
|
||||||
|
if(!configurationFile.exists()) {
|
||||||
|
createStandardConfigFile(configurationFile);
|
||||||
|
}
|
||||||
|
Configuration c = new Configuration(configurationFile);
|
||||||
|
c.load();
|
||||||
|
|
||||||
|
logger.setLevel(Level.INFO);
|
||||||
|
logger.setUseParentHandlers(false);
|
||||||
|
|
||||||
|
ConsoleHandler ch = new ConsoleHandler();
|
||||||
|
|
||||||
|
ch.setLevel(stringToLevel(c.getString("logging.logtoconsole")));
|
||||||
|
ch.setFormatter(Logger.getLogger("Minecraft").getHandlers()[0].getFormatter());
|
||||||
|
logger.addHandler(ch);
|
||||||
|
|
||||||
|
FileHandler fh = null;
|
||||||
|
try {
|
||||||
|
fh = new FileHandler(c.getString("logging.filename"), true);
|
||||||
|
fh.setLevel(stringToLevel(c.getString("logging.logtofile")));
|
||||||
|
fh.setFormatter(Logger.getLogger("Minecraft").getHandlers()[0].getFormatter());
|
||||||
|
logger.addHandler(fh);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Level stringToLevel(String string) {
|
||||||
|
|
||||||
|
if(string == null) {
|
||||||
|
return Level.OFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(string.trim().equals("info")) return Level.INFO;
|
||||||
|
if(string.trim().equals("warn")) return Level.WARNING;
|
||||||
|
if(string.trim().equals("severe")) return Level.SEVERE;
|
||||||
|
return Level.OFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void createStandardConfigFile(File f) {
|
||||||
|
try {
|
||||||
|
BufferedWriter w = new BufferedWriter(new FileWriter(f));
|
||||||
|
|
||||||
|
w.write("logging:"); w.newLine();
|
||||||
|
w.write(" filename: nocheat.log"); w.newLine();
|
||||||
|
w.write(" logtofile: info"); w.newLine();
|
||||||
|
w.write(" logtoconsole: severe"); w.newLine();
|
||||||
|
w.flush(); w.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -27,8 +27,8 @@ public class NoCheatPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
private final NoCheatPluginPlayerListener playerListener;
|
private final NoCheatPluginPlayerListener playerListener;
|
||||||
private final NoCheatPluginVehicleListener vehicleListener;
|
private final NoCheatPluginVehicleListener vehicleListener;
|
||||||
|
|
||||||
public static final Logger log = Logger.getLogger("Minecraft");
|
public static Logger log;
|
||||||
public static PermissionHandler Permissions = null;
|
public static PermissionHandler Permissions = null;
|
||||||
|
|
||||||
public NoCheatPlugin(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) {
|
public NoCheatPlugin(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) {
|
||||||
@ -36,9 +36,14 @@ public class NoCheatPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
playerListener = new NoCheatPluginPlayerListener(this);
|
playerListener = new NoCheatPluginPlayerListener(this);
|
||||||
vehicleListener = new NoCheatPluginVehicleListener(this, playerListener);
|
vehicleListener = new NoCheatPluginVehicleListener(this, playerListener);
|
||||||
|
|
||||||
|
setupConfig();
|
||||||
|
|
||||||
|
log = NoCheatConfiguration.logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDisable() { }
|
public void onDisable() {
|
||||||
|
}
|
||||||
|
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
|
||||||
@ -50,7 +55,7 @@ public class NoCheatPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
|
|
||||||
PluginDescriptionFile pdfFile = this.getDescription();
|
PluginDescriptionFile pdfFile = this.getDescription();
|
||||||
log.info( "NoCheat version " + pdfFile.getVersion() + " is enabled!" );
|
Logger.getLogger("Minecraft").info( "NoCheat version " + pdfFile.getVersion() + " is enabled!" );
|
||||||
|
|
||||||
setupPermissions();
|
setupPermissions();
|
||||||
}
|
}
|
||||||
@ -68,4 +73,12 @@ public class NoCheatPlugin extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setupConfig() {
|
||||||
|
NoCheatConfiguration.config(new File("nocheat.yml"));
|
||||||
|
|
||||||
|
// Test config
|
||||||
|
Logger l = Logger.getLogger(NoCheatConfiguration.loggerName);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user