diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/CommandFilter.java b/ProtocolLib/src/main/java/com/comphenix/protocol/CommandFilter.java index de13c50a..6f60277e 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/CommandFilter.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/CommandFilter.java @@ -221,12 +221,16 @@ public class CommandFilter extends CommandBase { // Owner plugin private final Plugin plugin; + // Whether or not the command is enabled + private ProtocolConfig config; + // Script engine private ScriptEngine engine; - public CommandFilter(ErrorReporter reporter, Plugin plugin) { + public CommandFilter(ErrorReporter reporter, Plugin plugin, ProtocolConfig config) { super(reporter, CommandBase.PERMISSION_ADMIN, NAME, 2); this.plugin = plugin; + this.config = config; // Start the engine initalizeScript(); @@ -264,13 +268,18 @@ public class CommandFilter extends CommandBase { // Pass! return true; } - + /* * Description: Adds or removes a simple packet listener. Usage: / add|remove name [packet IDs] */ @Override protected boolean handleCommand(CommandSender sender, String[] args) { + if (!config.isDebug()) { + sender.sendMessage(ChatColor.RED + "Debug mode must be enabled in the configuration first!"); + return true; + } + final SubCommand command = parseCommand(args, 0); final String name = args[1]; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolConfig.java b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolConfig.java index 87e5b523..4ce0bf06 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolConfig.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolConfig.java @@ -40,6 +40,8 @@ class ProtocolConfig { private static final String IGNORE_VERSION_CHECK = "ignore version check"; private static final String BACKGROUND_COMPILER_ENABLED = "background compiler"; + private static final String DEBUG_MODE_ENABLED = "debug"; + private static final String INJECTION_METHOD = "injection method"; private static final String UPDATER_NOTIFY = "notify"; @@ -140,6 +142,24 @@ class ProtocolConfig { public void setAutoDownload(boolean value) { updater.set(UPDATER_DOWNLAD, value); } + + /** + * Determine whether or not debug mode is enabled. + *

+ * This grants access to the filter command. + * @return TRUE if it is, FALSE otherwise. + */ + public boolean isDebug() { + return global.getBoolean(DEBUG_MODE_ENABLED, false); + } + + /** + * Set whether or not debug mode is enabled. + * @param value - TRUE if it is enabled, FALSE otherwise. + */ + public void setDebug(boolean value) { + global.set(DEBUG_MODE_ENABLED, value); + } /** * Retrieve the amount of time to wait until checking for a new update. diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java index dcb120c5..7304eabb 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/ProtocolLibrary.java @@ -130,6 +130,11 @@ public class ProtocolLibrary extends JavaPlugin { } } + // Print the state of the debug mode + if (config.isDebug()) { + logger.warning("Debug mode is enabled!"); + } + try { // Check for other versions checkConflictingVersions(); @@ -162,7 +167,7 @@ public class ProtocolLibrary extends JavaPlugin { // Initialize command handlers commandProtocol = new CommandProtocol(detailedReporter, this, updater, config); - commandFilter = new CommandFilter(detailedReporter, this); + commandFilter = new CommandFilter(detailedReporter, this, config); commandPacket = new CommandPacket(detailedReporter, this, logger, commandFilter, protocolManager); // Send logging information to player listeners too diff --git a/ProtocolLib/src/main/resources/config.yml b/ProtocolLib/src/main/resources/config.yml index 46869ad7..e9185886 100644 --- a/ProtocolLib/src/main/resources/config.yml +++ b/ProtocolLib/src/main/resources/config.yml @@ -18,4 +18,7 @@ global: ignore version check: # Override the starting injecting method - injection method: \ No newline at end of file + injection method: + + # Whether or not to enable the filter command + debug: false \ No newline at end of file