Starsector API
Loading...
Searching...
No Matches
unsetAll.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.rulecmd;
2
3import java.util.ArrayList;
4import java.util.List;
5import java.util.Map;
6
7import com.fs.starfarer.api.campaign.InteractionDialogAPI;
8import com.fs.starfarer.api.campaign.rules.MemKeys;
9import com.fs.starfarer.api.campaign.rules.MemoryAPI;
10import com.fs.starfarer.api.util.Misc.Token;
11
12public class unsetAll extends BaseCommandPlugin {
13
14 public boolean execute(String ruleId, InteractionDialogAPI dialog, List<Token> params, Map<String, MemoryAPI> memoryMap) {
15
16 String string = params.get(0).string;
17 int index = string.indexOf(".");
18 String memoryKey;
19 String varPrefix;
20 if (index > 0) {
21 memoryKey = string.substring(1, index);
22 varPrefix = "$" + string.substring(index + 1);
23 } else {
24 memoryKey = MemKeys.LOCAL;
25 varPrefix = string;
26 }
27
28 MemoryAPI memory = memoryMap.get(memoryKey);
29 List<String> unset = new ArrayList<String>();
30 for (String key : memory.getKeys()) {
31 if (key.startsWith(varPrefix)) {
32 unset.add(key);
33 }
34 }
35 for (String key : unset) {
36 memory.unset(key);
37 }
38
39
40 return true;
41 }
42
43}
boolean execute(String ruleId, InteractionDialogAPI dialog, List< Token > params, Map< String, MemoryAPI > memoryMap)
Definition unsetAll.java:14