use of fr.neatmonster.nocheatplus.logging.LogManager in project NoCheatPlus by NoCheatPlus.
the class GenericLogAction method execute.
@Override
public void execute(final ViolationData violationData) {
// TODO: Consider permission caching or removing the feature? [Besides, check earlier?]
final RegisteredPermission permissionSilent = violationData.getPermissionSilent();
// TODO: Store PlayerData in ViolationData ? Must query cache here.
if (permissionSilent != null && DataManager.getPlayerData(violationData.player).hasPermission(permissionSilent, violationData.player)) {
return;
}
final LogManager logManager = NCPAPIProvider.getNoCheatPlusAPI().getLogManager();
final String message = getMessage(violationData);
final String messageNoColor = stripColor ? ColorUtil.removeColors(message) : null;
final String messageWithColor = replaceColor ? ColorUtil.replaceColors(message) : null;
final ConfigFile configFile = checkActive ? ConfigManager.getConfigFile() : null;
for (int i = 0; i < configs.length; i++) {
final GenericLogActionConfig config = configs[i];
if (checkActive && config.configPathActive != null && !configFile.getBoolean(config.configPathActive)) {
continue;
}
logManager.log(config.streamID, config.level, config.chatColor ? messageWithColor : messageNoColor);
}
}
use of fr.neatmonster.nocheatplus.logging.LogManager in project NoCheatPlus by NoCheatPlus.
the class ReloadCommand method handleReloadCommand.
/**
* Handle the '/nocheatplus reload' command.
*
* @param sender
* the sender
* @return true, if successful
*/
private void handleReloadCommand(final CommandSender sender) {
final LogManager logManager = NCPAPIProvider.getNoCheatPlusAPI().getLogManager();
if (!sender.equals(Bukkit.getConsoleSender())) {
sender.sendMessage(TAG + "Reloading configuration...");
}
logManager.info(Streams.INIT, TAG + "Reloading configuration...");
// Do the actual reload.
ConfigManager.cleanup();
// (Magic/TODO)
final WorldDataManager worldDataManager = (WorldDataManager) NCPAPIProvider.getNoCheatPlusAPI().getWorldDataManager();
ConfigManager.init(access, worldDataManager);
if (logManager instanceof INotifyReload) {
// TODO: This is a band-aid.
((INotifyReload) logManager).onReload();
}
// Remove all cached configs from data.
NCPAPIProvider.getNoCheatPlusAPI().getPlayerDataManager().removeCachedConfigs();
// Reset debug flags to default (temp, heavy).
DataManager.restoreDefaultDebugFlags();
// Tell the registered listeners to adapt to new config, first sort them (!).
Collections.sort(notifyReload, Order.cmpSetupOrder);
for (final INotifyReload component : notifyReload) {
component.onReload();
}
// Say to the other plugins that we've reloaded the configuration.
Bukkit.getPluginManager().callEvent(new NCPReloadEvent());
// Log reloading done.
if (!sender.equals(Bukkit.getConsoleSender())) {
sender.sendMessage(TAG + "Configuration reloaded!");
}
logManager.info(Streams.INIT, TAG + "Configuration reloaded.");
// Queued (!).
logManager.info(Streams.DEFAULT_FILE, StringUtil.join(VersionCommand.getVersionInfo(), "\n"));
}
use of fr.neatmonster.nocheatplus.logging.LogManager in project NoCheatPlus by NoCheatPlus.
the class BlockProperties method dumpBlocks.
/**
* Dump blocks.
*
* @param all
* the all
*/
public static void dumpBlocks(boolean all) {
final LogManager logManager = NCPAPIProvider.getNoCheatPlusAPI().getLogManager();
List<String> missing = new LinkedList<String>();
List<String> allBlocks = new LinkedList<String>();
if (all) {
allBlocks.add("Dump block properties for fastbreak check:");
allBlocks.add("--- Present entries -------------------------------");
}
List<String> tags = new ArrayList<String>();
for (Material temp : Material.values()) {
String mat;
try {
if (!temp.isBlock()) {
continue;
}
mat = temp.toString();
} catch (Exception e) {
mat = "?";
}
tags.clear();
addFlagNames(getBlockFlags(temp), tags);
String tagsJoined = tags.isEmpty() ? "" : " / " + StringUtil.join(tags, "+");
if (blocks.get(temp) == null) {
if (mat.equals("?")) {
continue;
}
missing.add("* MISSING (" + mat + tagsJoined + ") ");
} else {
if (all) {
allBlocks.add(": (" + mat + tagsJoined + ") " + getBlockProps(temp).toString());
}
}
}
if (all) {
logManager.info(Streams.DEFAULT_FILE, StringUtil.join(allBlocks, "\n"));
}
if (!missing.isEmpty()) {
missing.add(0, "--- Missing entries -------------------------------");
missing.add(0, "The block breaking data is incomplete, default to allow instant breaking:");
logManager.warning(Streams.INIT, StringUtil.join(missing, "\n"));
}
}
use of fr.neatmonster.nocheatplus.logging.LogManager in project NoCheatPlus by NoCheatPlus.
the class AllViolationsHook method log.
private void log(final CheckType checkType, final Player player, final IViolationInfo info, final boolean toTrace, final boolean toNotify) {
// Generate the message.
// TODO: More colors?
final StringBuilder builder = new StringBuilder(300);
final String playerName = player.getName();
builder.append("[VL] [" + checkType.toString() + "] ");
builder.append("[" + ChatColor.YELLOW + playerName);
builder.append(ChatColor.WHITE + "] ");
final String displayName = ChatColor.stripColor(player.getDisplayName()).trim();
if (!playerName.equals(displayName)) {
builder.append("[->" + ChatColor.YELLOW + displayName + ChatColor.WHITE + "] ");
}
builder.append("VL=" + StringUtil.fdec1.format(info.getTotalVl()));
builder.append("(+" + StringUtil.fdec1.format(info.getAddedVl()) + ")");
builder.append(ChatColor.GRAY);
for (int i = 0; i < parameters.length; i++) {
final ParameterName name = parameters[i];
final String value = info.getParameter(name);
if (value != null && !value.isEmpty() && !value.equals(this.noParameterTexts[i])) {
builder.append(" " + name.getText() + "=" + value);
}
}
final String message = builder.toString();
// Send the message.
final LogManager logManager = NCPAPIProvider.getNoCheatPlusAPI().getLogManager();
if (toNotify) {
logManager.info(Streams.NOTIFY_INGAME, message);
}
if (toTrace) {
logManager.info(Streams.TRACE_FILE, ChatColor.stripColor(message));
}
}
use of fr.neatmonster.nocheatplus.logging.LogManager 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;
}
Aggregations