diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java index 7d42a211..ddda39c0 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java @@ -52,8 +52,10 @@ public abstract class ConfPaths { private static final String LOGGING_EXTENDED = LOGGING + "extended."; public static final String LOGGING_EXTENDED_STATUS = LOGGING_EXTENDED + "status"; private static final String LOGGING_EXTENDED_ALLVIOLATIONS = LOGGING_EXTENDED + "allviolations."; - public static final String LOGGING_EXTENDED_ALLVIOLATIONS_TRACE = LOGGING_EXTENDED_ALLVIOLATIONS + "trace"; - public static final String LOGGING_EXTENDED_ALLVIOLATIONS_NOTIFY = LOGGING_EXTENDED_ALLVIOLATIONS + "notify"; + public static final String LOGGING_EXTENDED_ALLVIOLATIONS_DEBUGONLY = LOGGING_EXTENDED_ALLVIOLATIONS + "debugonly"; + private static final String LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND = LOGGING_EXTENDED_ALLVIOLATIONS + "backend."; + public static final String LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND_TRACE = LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND + "trace"; + public static final String LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND_NOTIFY = LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND + "notify"; @GlobalConfig private static final String MISCELLANEOUS = "miscellaneous."; diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java index ee4b4aa6..2490a2bf 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java @@ -40,8 +40,9 @@ public class DefaultConfig extends ConfigFile { set(ConfPaths.LOGGING_ACTIVE, true); set(ConfPaths.LOGGING_MAXQUEUESIZE, 5000); set(ConfPaths.LOGGING_EXTENDED_STATUS, false); - set(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_TRACE, false); - set(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_NOTIFY, false); + set(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_DEBUGONLY, false); + set(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND_TRACE, false); + set(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND_NOTIFY, false); set(ConfPaths.LOGGING_BACKEND_CONSOLE_ACTIVE, true); set(ConfPaths.LOGGING_BACKEND_CONSOLE_PREFIX, "[NoCheatPlus] "); set(ConfPaths.LOGGING_BACKEND_CONSOLE_ASYNCHRONOUS, true); diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/hooks/allviolations/AllViolationsConfig.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/hooks/allviolations/AllViolationsConfig.java index 7fe9a806..b6f28bf1 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/hooks/allviolations/AllViolationsConfig.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/hooks/allviolations/AllViolationsConfig.java @@ -15,13 +15,17 @@ public class AllViolationsConfig { /** Log all violations to the in-game notification channel. */ public final boolean allToNotify; + + /** Only log if the player is being "debugged". Currently incomplete. */ + public final boolean debugOnly; // TODO: More config on what to print (uuid, etc., default tags). // TODO: More filtering like in TestNCP. public AllViolationsConfig(ConfigFile config) { - allToTrace = config.getBoolean(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_TRACE); - allToNotify = config.getBoolean(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_NOTIFY); + debugOnly = config.getBoolean(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_DEBUGONLY); + allToTrace = config.getBoolean(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND_TRACE); + allToNotify = config.getBoolean(ConfPaths.LOGGING_EXTENDED_ALLVIOLATIONS_BACKEND_NOTIFY); } public boolean doesLogAnything() { diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/hooks/allviolations/AllViolationsHook.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/hooks/allviolations/AllViolationsHook.java index 2c4da0c7..4d77de0c 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/hooks/allviolations/AllViolationsHook.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/hooks/allviolations/AllViolationsHook.java @@ -10,6 +10,8 @@ import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.NCPAPIProvider; import fr.neatmonster.nocheatplus.actions.ParameterName; import fr.neatmonster.nocheatplus.checks.CheckType; +import fr.neatmonster.nocheatplus.checks.access.CheckDataFactory; +import fr.neatmonster.nocheatplus.checks.access.ICheckData; import fr.neatmonster.nocheatplus.checks.access.IViolationInfo; import fr.neatmonster.nocheatplus.hooks.ILast; import fr.neatmonster.nocheatplus.hooks.IStats; @@ -30,7 +32,7 @@ public class AllViolationsHook implements NCPHook, ILast, IStats { private AllViolationsConfig config; private Integer hookId = null; - + /** White list. */ private final ParameterName[] parameters; private final String[] noParameterTexts; @@ -88,7 +90,23 @@ public class AllViolationsHook implements NCPHook, ILast, IStats { if (config == null) { return false; } - // Generate message. + if (config.debugOnly) { + // TODO: Better mix the debug flag into IViolationInfo, for best performance. + final CheckDataFactory factory = checkType.getDataFactory(); + if (factory == null) { + return false; + } + final ICheckData data = factory.getData(player); + if (data == null || !data.getDebug()) { + return false; + } + } + log(checkType, player, info, config); + return false; + } + + private void log(final CheckType checkType, final Player player, final IViolationInfo info, final AllViolationsConfig config) { + // Generate the message. // TODO: More colors? final StringBuilder builder = new StringBuilder(300); final String playerName = player.getName(); @@ -110,7 +128,7 @@ public class AllViolationsHook implements NCPHook, ILast, IStats { } } final String message = builder.toString(); - // Send to where it is appropriate. + // Send the message. final LogManager logManager = NCPAPIProvider.getNoCheatPlusAPI().getLogManager(); if (config.allToNotify) { logManager.info(Streams.NOTIFY_INGAME, message); @@ -118,7 +136,6 @@ public class AllViolationsHook implements NCPHook, ILast, IStats { if (config.allToTrace) { logManager.info(Streams.TRACE_FILE, ChatColor.stripColor(message)); } - return false; } }