Skip to content

Commit

Permalink
interact scripts: (experimental) use key order
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 9, 2021
1 parent db0f056 commit b4c15a7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ enum Toggle {TRUE, FALSE, TOGGLE}

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

for (Argument arg : scriptEntry.getProcessedArgs()) {
if (!scriptEntry.hasObject("action") && arg.matchesEnum(Toggle.values())) {
scriptEntry.addObject("action", arg.asElement());
Expand All @@ -56,7 +55,6 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
arg.reportUnhandled();
}
}

scriptEntry.defaultObject("action", new ElementTag("toggle"));
if (!Utilities.entryHasNPC(scriptEntry)) {
throw new InvalidArgumentsException("This command requires a linked NPC!");
Expand All @@ -66,14 +64,11 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag action = scriptEntry.getElement("action");

if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), Utilities.getEntryNPC(scriptEntry).debug() + action.debug());
Debug.report(scriptEntry, getName(), Utilities.getEntryNPC(scriptEntry), action);
}

NPC npc = Utilities.getEntryNPC(scriptEntry).getCitizen();
Toggle toggle = Toggle.valueOf(action.asString().toUpperCase());

npc.setProtected(!(toggle == Toggle.TOGGLE ? npc.isProtected() : action.asBoolean()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public Map<String, String> getIdMapFor(Class<? extends AbstractTrigger> trigger,
String keyBase = "steps." + step + "." + triggerName + " trigger";
if (contains(keyBase)) {
// Trigger exists in Player's current step, get ids.
Map<String, String> idMap = new HashMap<>();
Map<String, String> idMap = new LinkedHashMap<>();
// Iterate through IDs to build the idMap
try {
for (StringHolder id : getConfigurationSection(keyBase).getKeys(false)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,19 +259,10 @@ public ChatContext process(Player player, String message) {

String messageLow = CoreUtilities.toLowerCase(message);

// Use TreeMap to sort chat triggers alphabetically
TreeMap<String, String> idMap = new TreeMap<>(script.getIdMapFor(ChatTrigger.class, denizenPlayer));
Map<String, String> idMap = script.getIdMapFor(ChatTrigger.class, denizenPlayer);

if (!idMap.isEmpty()) {
// Iterate through the different id entries in the step's chat trigger
List<Map.Entry<String, String>> entries = new ArrayList<>(idMap.entrySet());
entries.sort((o1, o2) -> {
if (o1 == null || o2 == null) {
return 0;
}
return o1.getKey().compareToIgnoreCase(o2.getKey());
});
for (Map.Entry<String, String> entry : entries) {
for (Map.Entry<String, String> entry : idMap.entrySet()) {

// Check if the chat trigger specified in the specified id's 'trigger:' key
// matches the text the player has said
Expand Down

0 comments on commit b4c15a7

Please sign in to comment.