diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/AsyncCheck.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/AsyncCheck.java deleted file mode 100644 index b68d7564..00000000 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/AsyncCheck.java +++ /dev/null @@ -1,25 +0,0 @@ -package fr.neatmonster.nocheatplus.checks; - -import org.bukkit.entity.Player; - -import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager; -import fr.neatmonster.nocheatplus.logging.LogUtil; - -public abstract class AsyncCheck extends Check { - - public AsyncCheck(CheckType type) { - super(type); - } - - @Override - public boolean isEnabled(Player player) { - try { - if (!type.isEnabled(player) || type.hasCachedPermission(player)) - return false; - } catch (final Exception e) { - LogUtil.scheduleLogSevere(e); - } - return !NCPExemptionManager.isExempted(player, type); - } - -} diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/Check.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/Check.java index d213ee3c..06dbe581 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/Check.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/Check.java @@ -3,6 +3,7 @@ package fr.neatmonster.nocheatplus.checks; import java.util.HashMap; import java.util.Map; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.NCPAPIProvider; @@ -162,12 +163,19 @@ public abstract class Check implements MCAccessHolder{ * @return true, if the check is enabled */ public boolean isEnabled(final Player player) { - try { - if (!type.isEnabled(player) || player.hasPermission(type.getPermission())) + if (!type.isEnabled(player)) { + return false; + } + // TODO: Checking for the thread might be a temporary measure. + if (Bukkit.isPrimaryThread()) { + // Check permissions directly. + if (player.hasPermission(type.getPermission())) { return false; - } catch (final Exception e) { - // TODO: this should be mostly obsolete. - LogUtil.logSevere(e); + } + } + else if (type.hasCachedPermission(player)) { + // Assume asynchronously running check. + return false; } return !NCPExemptionManager.isExempted(player, type); } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/access/ACheckConfig.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/access/ACheckConfig.java index 23b9ab20..ed5bb9d3 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/access/ACheckConfig.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/access/ACheckConfig.java @@ -13,24 +13,38 @@ public abstract class ACheckConfig implements ICheckConfig { /** For on the fly debug setting. */ public boolean debug = false; - /** For adaption to server side lag. */ + /** If to adapt to server side lag. */ public final boolean lag; + /** Permissions to hold in player data cache, not final for flexibility. */ + protected String[] cachePermissions; + /** * * @param config * @param pathPrefix Path prefix for the check section (example for use: prefix+"debug"). */ public ACheckConfig(final ConfigFile config, final String pathPrefix){ - // TODO: Path prefix construction is somewhat inconsistent with debug hierarchy ? + this(config, pathPrefix, null); + } + + /** + * + * @param config + * @param pathPrefix Path prefix for the check section (example for use: prefix+"debug"). + * @param cachePermissions cachePermissions Permissions to hold in player data cache. Can be null. + */ + public ACheckConfig(final ConfigFile config, final String pathPrefix, final String[] cachePermissions){ + // TODO: Path prefix construction is somewhat inconsistent with debug hierarchy ? debug = config.getBoolean(pathPrefix + ConfPaths.SUB_DEBUG, config.getBoolean(ConfPaths.CHECKS_DEBUG, false)); // TODO: Use lag flag where appropriate and document it (or get rid of it). lag = config.getBoolean(pathPrefix + ConfPaths.SUB_LAG, true) && config.getBoolean(ConfPaths.MISCELLANEOUS_LAG, true); + this.cachePermissions = cachePermissions; } @Override public String[] getCachePermissions() { - return null; + return cachePermissions; } @Override diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/access/AsyncCheckConfig.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/access/AsyncCheckConfig.java deleted file mode 100644 index ed281f18..00000000 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/access/AsyncCheckConfig.java +++ /dev/null @@ -1,31 +0,0 @@ -package fr.neatmonster.nocheatplus.checks.access; - -import fr.neatmonster.nocheatplus.config.ConfigFile; - -/** - * CheckConfig for async checks such as chat, adding permissions to cache. - * @author mc_dev - * - */ -public abstract class AsyncCheckConfig extends ACheckConfig { - - /** Permissions to hold in player data cache, not final for flexibility. */ - protected String[] cachePermissions; - - /** - * - * @param config - * @param pathPrefix Path prefix for the check section (example for use: prefix+"debug"). - * @param cachePermissions cachePermissions Permissions to hold in player data cache. - */ - public AsyncCheckConfig(final ConfigFile config, final String pathPrefix, final String[] cachePermissions){ - super(config, pathPrefix); - this.cachePermissions = cachePermissions; - } - - @Override - public String[] getCachePermissions() { - return cachePermissions; - } - -} diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/chat/Captcha.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/chat/Captcha.java index 5a0fe9d1..4d80732e 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/chat/Captcha.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/chat/Captcha.java @@ -4,7 +4,7 @@ import java.util.Random; import org.bukkit.entity.Player; -import fr.neatmonster.nocheatplus.checks.AsyncCheck; +import fr.neatmonster.nocheatplus.checks.Check; import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.permissions.Permissions; import fr.neatmonster.nocheatplus.utilities.ColorUtil; @@ -14,7 +14,7 @@ import fr.neatmonster.nocheatplus.utilities.ColorUtil; * @author mc_dev * */ -public class Captcha extends AsyncCheck implements ICaptcha{ +public class Captcha extends Check implements ICaptcha{ public Captcha() { super(CheckType.CHAT_CAPTCHA); diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/chat/ChatConfig.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/chat/ChatConfig.java index a546164a..84a22346 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/chat/ChatConfig.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/chat/ChatConfig.java @@ -7,7 +7,7 @@ import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.actions.ActionList; import fr.neatmonster.nocheatplus.checks.CheckType; -import fr.neatmonster.nocheatplus.checks.access.AsyncCheckConfig; +import fr.neatmonster.nocheatplus.checks.access.ACheckConfig; import fr.neatmonster.nocheatplus.checks.access.CheckConfigFactory; import fr.neatmonster.nocheatplus.checks.access.ICheckConfig; import fr.neatmonster.nocheatplus.checks.chat.analysis.engine.EnginePlayerConfig; @@ -21,7 +21,7 @@ import fr.neatmonster.nocheatplus.utilities.ColorUtil; * Configurations specific for the "chat" checks. Every world gets one of these assigned to it, or if a world doesn't * get it's own, it will use the "global" version. */ -public class ChatConfig extends AsyncCheckConfig { +public class ChatConfig extends ACheckConfig { /** The factory creating configurations. */ public static final CheckConfigFactory factory = new CheckConfigFactory() { diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/chat/Color.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/chat/Color.java index 7f29fb26..562a3010 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/chat/Color.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/chat/Color.java @@ -2,13 +2,13 @@ package fr.neatmonster.nocheatplus.checks.chat; import org.bukkit.entity.Player; -import fr.neatmonster.nocheatplus.checks.AsyncCheck; +import fr.neatmonster.nocheatplus.checks.Check; import fr.neatmonster.nocheatplus.checks.CheckType; /** * The Color check verifies that no color codes are sent in players' messages. */ -public class Color extends AsyncCheck { +public class Color extends Check { /** * Instantiates a new color check. diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/chat/Text.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/chat/Text.java index 798c7a66..4ab1e7ee 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/chat/Text.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/chat/Text.java @@ -9,7 +9,7 @@ import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.NCPAPIProvider; import fr.neatmonster.nocheatplus.actions.ParameterName; -import fr.neatmonster.nocheatplus.checks.AsyncCheck; +import fr.neatmonster.nocheatplus.checks.Check; import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.checks.ViolationData; import fr.neatmonster.nocheatplus.checks.chat.analysis.MessageLetterCount; @@ -29,7 +29,7 @@ import fr.neatmonster.nocheatplus.utilities.StringUtil; * @author mc_dev * */ -public class Text extends AsyncCheck implements INotifyReload{ +public class Text extends Check implements INotifyReload { private LetterEngine engine = null;