Skip to content

Commit

Permalink
add new flag list clearsplit action
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Aug 16, 2018
1 parent d1cb882 commit 476cc60
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
27 changes: 24 additions & 3 deletions plugin/src/main/java/net/aufdemrand/denizen/flags/FlagManager.java
Expand Up @@ -112,7 +112,7 @@ public class FlagManager {
// Valid flag actions
public static enum Action {
SET_VALUE, SET_BOOLEAN, INCREASE, DECREASE, MULTIPLY,
DIVIDE, INSERT, REMOVE, SPLIT, DELETE
DIVIDE, INSERT, REMOVE, SPLIT, SPLIT_NEW, DELETE
}


Expand Down Expand Up @@ -486,18 +486,34 @@ public int add(Object obj) {
public int split(Object obj) {
checkExpired();
dList split = dList.valueOf(obj.toString());

if (split.size() > 0) {
for (String val : split) {
if (val.length() > 0) {
value.values.add(val);
}
}

save();
rebuild();
}
return size();
}

public int splitNew(Object obj) {
checkExpired();
dList split = dList.valueOf(obj.toString());
if (split.size() > 0) {
value.values.clear();
for (String val : split) {
if (val.length() > 0) {
value.values.add(val);
}
}
save();
rebuild();
}
else {
clear();
}
return size();
}

Expand Down Expand Up @@ -882,8 +898,13 @@ public void doAction(Action action, Element value, Integer index) {
split(val);
break;

case SPLIT_NEW:
splitNew(val);
break;

case DELETE:
clear();
break;
}
}

Expand Down
Expand Up @@ -1559,6 +1559,10 @@ public void registerCoreMembers() {
// - flag server cool_people:<-:p@morphan1
//
// @Usage
// Use to clear a flag and fill it with a new list of values.
// - flag server cool_people:!|:p@mcmonkey4eva|p@morphan1|p@xenmai
//
// @Usage
// Use to completely remove a flag.
// - flag server cool_people:!
//
Expand Down
Expand Up @@ -150,6 +150,9 @@ else if (flagArgs[1].equals("<-")) {
else if (flagArgs[1].equals("||") || flagArgs[1].equals("|")) {
scriptEntry.addObject("action", FlagManager.Action.SPLIT);
}
else if (flagArgs[1].equals("!|")) {
scriptEntry.addObject("action", FlagManager.Action.SPLIT_NEW);
}
else if (flagArgs[1].equals("++") || flagArgs[1].equals("+")) {
scriptEntry.addObject("action", FlagManager.Action.INCREASE);
}
Expand Down

0 comments on commit 476cc60

Please sign in to comment.