diff --git a/src/core/CommandEnabler.java b/src/core/CommandEnabler.java index 71eb4d4..fff6e78 100644 --- a/src/core/CommandEnabler.java +++ b/src/core/CommandEnabler.java @@ -18,12 +18,15 @@ public class CommandEnabler implements IConfigSection public static final String enabled = "1"; public static final String disabled = "0"; public static final boolean defaultEnabledState = true; + public static final String commandSplit = ","; public static final String HeaderName = "Command Enabler"; // Local variables private HashMap enabledMap; // Quick lookup - private ArrayList keyList; // Tracking ordering for later - + private HashMap likeNames; // Single names mapped to multiple names for use in enabledMap. + private ArrayList keyList; // Tracking ordering for later + + // Instance public static CommandEnabler instance; // Constructor @@ -37,6 +40,7 @@ public class CommandEnabler implements IConfigSection GlobalLog.log(LogFilter.Core, "Initializing " + this.getClass().getSimpleName()); enabledMap = new HashMap<>(); keyList = new ArrayList<>(); + likeNames = new HashMap(); instance = this; } @@ -57,8 +61,10 @@ public class CommandEnabler implements IConfigSection String key = item.key; String value = item.value; + // Keep track of the key itself keyList.add(key); + // Write if it's enabled or disabled. if(value.equalsIgnoreCase(enabled)) { enabledMap.putIfAbsent(key, true); @@ -67,6 +73,13 @@ public class CommandEnabler implements IConfigSection { enabledMap.putIfAbsent(key, false); } + + // Keep track of alternate names + String[] keys = key.split(commandSplit); + for(int i = 0; i < keys.length; ++i) + { + likeNames.putIfAbsent(keys[i], key); + } } } @@ -117,12 +130,15 @@ public class CommandEnabler implements IConfigSection { String toCheck = key.toLowerCase(); - if(enabledMap.containsKey(toCheck)) - { - return enabledMap.get(toCheck); - } + // Look up to see if we have the key anywhere. If not, default to enabled. + // It should be noted that this is just checking for disabled commands, we don't + // determine if a key is actually a real command in here or not. + String fullKey = likeNames.getOrDefault(toCheck, null); + if(fullKey == null) + return true; - return true; + // If we have it, look it up. If we can't find it, default to true. + return enabledMap.getOrDefault(fullKey, true); } @Override diff --git a/src/core/CommandManager.java b/src/core/CommandManager.java index 73befc7..2c72484 100644 --- a/src/core/CommandManager.java +++ b/src/core/CommandManager.java @@ -36,12 +36,6 @@ public class CommandManager if(pair == null || pair.Second == null) return; - // If we haven't already split a multisplit command (or even assessed that), - // then verify if we even need to register the commands at all. If it's - // not enabled, don't register it. - if(pair.First != null && !commandEnabler.isEnabled(pair.First)) - return; - String key = pair.Second; if(key.contains(",")) @@ -80,6 +74,12 @@ public class CommandManager if(input == null || !input.isValid()) return false; + // If we haven't already split a multisplit command (or even assessed that), + // then verify if we even need to register the commands at all. If it's + // not enabled, don't register it. + if(input.key != null && !commandEnabler.isEnabled(input.key)) + return false; + Command command = commands.get(input.key); if(command != null) {