use of fr.neatmonster.nocheatplus.logging.StreamID in project NoCheatPlus by NoCheatPlus.
the class StreamCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) {
if (!demandConsoleCommandSender(sender)) {
return true;
}
if (args.length < 4) {
return false;
}
LogManager man = NCPAPIProvider.getNoCheatPlusAPI().getLogManager();
String message = null;
String messageColor = null;
String messageNoColor = null;
for (String streamDef : args[2].split("\\+")) {
Level level = null;
boolean color = false;
boolean noColor = false;
// Check for color def.
if (streamDef.indexOf('?') != -1) {
String[] split = streamDef.split("\\?");
if (split.length != 2) {
sender.sendMessage("Bad flag (color|nocolor): " + streamDef);
continue;
}
streamDef = split[0];
String temp = split[1].toLowerCase();
if (temp.matches("^(nc|noc|nocol|nocolor)$")) {
noColor = true;
} else if (temp.matches("^(c|col|color)$")) {
color = true;
} else {
sender.sendMessage("Bad flag (color|nocolor): " + temp);
continue;
}
}
// Parse level first.
if (streamDef.indexOf('@') != -1) {
String[] split = streamDef.split("@");
if (split.length != 2) {
sender.sendMessage("Bad level definition: " + streamDef);
continue;
}
streamDef = split[0];
// Attempt to parse level.
try {
// Convert to upper-case to ignore case.
level = Level.parse(split[1].toUpperCase());
} catch (IllegalArgumentException e) {
sender.sendMessage("Bad level: " + split[1]);
continue;
}
}
// Get StreamID, account for shortcuts.
StreamID streamId = man.getStreamID(streamDef);
if (streamId == null) {
String altStreamDef = streamDef.toLowerCase();
if (altStreamDef.equals("notify")) {
// Default level should be INFO.
streamId = Streams.NOTIFY_INGAME;
} else if (altStreamDef.equals("debug")) {
streamId = Streams.TRACE_FILE;
if (level == null) {
level = Level.FINE;
}
} else if (altStreamDef.equals("status")) {
streamId = Streams.STATUS;
} else if (altStreamDef.equals("init")) {
streamId = Streams.INIT;
} else if (altStreamDef.equals("console")) {
// Prefer the plugin logger.
streamId = Streams.PLUGIN_LOGGER;
} else if (altStreamDef.equals("file")) {
streamId = Streams.DEFAULT_FILE;
} else {
sender.sendMessage("Bad stream id: " + streamDef);
continue;
}
}
// Finally log.
if (level == null) {
// Instead: context-dependent?
level = Level.INFO;
}
if (message == null) {
message = StringUtil.join(args, 3, " ");
}
final String logMessage;
if (noColor) {
if (messageNoColor == null) {
messageNoColor = ChatColor.stripColor(ColorUtil.removeColors(message));
}
logMessage = messageNoColor;
} else if (color) {
if (messageColor == null) {
messageColor = ColorUtil.replaceColors(message);
}
logMessage = messageColor;
} else {
logMessage = message;
}
man.log(streamId, level, logMessage);
}
// (No success message.)
return true;
}
use of fr.neatmonster.nocheatplus.logging.StreamID in project NoCheatPlus by NoCheatPlus.
the class NoCheatPlus method setupBasics.
/**
* Lazy initialization of basics (static API, configuration, logging).
*/
private void setupBasics() {
// Ensure permissions are registered early.
for (RegisteredPermission rp : Permissions.getPermissions()) {
if (permissionRegistry.getPermissionInfo(rp.getId()) == null) {
permissionRegistry.addRegisteredPermission(rp);
}
}
// API.
updateNoCheatPlusAPI();
// Initialize server version.
if (ServerVersion.getMinecraftVersion() == GenericVersion.UNKNOWN_VERSION) {
BukkitVersion.init();
}
// Pre config setup.
if (getGenericInstance(ActionFactoryFactory.class) == null) {
// Set to default.
setActionFactoryFactory(null);
}
// Configuration.
if (!ConfigManager.isInitialized()) {
ConfigManager.init(this, worldDataManager);
// Basic setup for exemption (uses CheckType). This is redundant, but should not hurt.
NCPExemptionManager.setExemptionSettings(new ExemptionSettings(ConfigManager.getConfigFile()));
}
// Logging.
if (logManager == null || logManager.getStreamID(Streams.STATUS.name) != Streams.STATUS) {
logManager = new BukkitLogManager(this);
StaticLog.setStreamID(Streams.INIT);
StaticLog.setUseLogManager(true);
logManager.info(Streams.INIT, "Logging system initialized.");
logManager.info(Streams.INIT, "Detected Minecraft version: " + ServerVersion.getMinecraftVersion());
genericInstanceRegistry.setLogger(logManager, new IGetStreamId() {
@Override
public StreamID getStreamId() {
// TODO Auto-generated method stub
return NoCheatPlus.this.getRegistryStreamId();
}
}, "[GenericInstanceRegistry] ");
}
}
Aggregations