From 044305c013c493104d6d714b26a87fa7c07329fe Mon Sep 17 00:00:00 2001 From: Matthew Cech Date: Sun, 14 Apr 2019 01:59:34 -0700 Subject: [PATCH] + Added command enabler --- commands.config | 35 +++++++++++++++++++++++++++++++++++ locCommands.config | 2 +- src/core/CommandEnabler.java | 23 ++++++++++++++++++----- 3 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 commands.config diff --git a/commands.config b/commands.config new file mode 100644 index 0000000..a654586 --- /dev/null +++ b/commands.config @@ -0,0 +1,35 @@ +indicator=on +boop=on +tony, stark, dontfeelgood, dontfeelsogood=on +yeet=on +role=on +ping=on +rating=on +roll=on +blur=on +choose=on +poll=on +rpstart=on +bet=on +perish, thenperish=on +teey=on +stats=on +beans=on +eightball, 8ball=on +vote=on +results=on +wolfram=on +map=on +info, about=on +givebeans=on +c++, g++, cplus, cpp=on +work=on +showpoll=on +rpend=on +rpg=on +tweet=on +java, jdoodle=on +help=on +buildHelp=on +invite=on +shutdown=on diff --git a/locCommands.config b/locCommands.config index 4266161..f60a1b9 100644 --- a/locCommands.config +++ b/locCommands.config @@ -1,6 +1,6 @@ [ObjectBuilderFactory] indicator= -boop=bap, spaghetti, turboyeet +boop= tony, stark, dontfeelgood, dontfeelsogood= yeet= role= diff --git a/src/core/CommandEnabler.java b/src/core/CommandEnabler.java index 12ee7b1..4c17cd6 100644 --- a/src/core/CommandEnabler.java +++ b/src/core/CommandEnabler.java @@ -31,6 +31,7 @@ public class CommandEnabler public CommandEnabler() { + GlobalLog.Log(LogFilter.Core, "Initializing " + this.getClass().getSimpleName()); enabledMap = new HashMap<>(); keyList = new ArrayList<>(); @@ -45,18 +46,22 @@ public class CommandEnabler File f = new File(filename); if(f.isFile() && f.canRead()) { - String content = FileUtils.ReadContent(f); + String content = FileUtils.ReadContent(f).trim(); String[] lines = content.split("" + pairSeparator); for(int i = 0; i < lines.length; ++i) { String[] pair = lines[i].split(pairSplit); + + if(pair.length < 2) + continue; + String key = pair[0].trim(); - String value = pair[0].trim().toLowerCase(); + String value = pair[1].trim().toLowerCase(); keyList.add(key); - - if(value == enabled) + + if(value.equalsIgnoreCase(enabled)) enabledMap.putIfAbsent(key, true); else enabledMap.putIfAbsent(key, false); @@ -71,7 +76,14 @@ public class CommandEnabler ArrayList unloc = LocCommands.GetUnlocalizedCommands(); for(int i = 0; i < unloc.size(); ++i) - enabledMap.putIfAbsent(unloc.get(i), defaultEnabledState); + { + String command = unloc.get(i); + if(enabledMap.putIfAbsent(command, defaultEnabledState) == null) + { + GlobalLog.Log(LogFilter.Strings, "Identified new toggleable raw command: " + command); + keyList.add(command); + } + } } // Write out enabled/disabled file info. @@ -101,6 +113,7 @@ public class CommandEnabler } } + // Looks up a key to see if it's enabled or not public boolean IsEnabled(String key) { if(enabledMap.containsKey(key))