Skip to content

Commit 5c4856d

Browse files
committed
new action pattern to fix some quirks
1 parent 9f1e9f0 commit 5c4856d

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/main/java/me/hsgamer/bettergui/builder/ActionBuilder.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
import me.hsgamer.hscore.common.CollectionUtils;
1212

1313
import java.util.List;
14+
import java.util.Optional;
15+
import java.util.regex.Matcher;
16+
import java.util.regex.Pattern;
1417
import java.util.stream.Collectors;
1518

1619
/**
@@ -48,8 +51,19 @@ public List<Action> build(Menu menu, Object object) {
4851
}
4952

5053
public interface Input extends ActionInput, MenuElement {
54+
Pattern pattern = Pattern.compile("\\s*([\\w\\-$]+)\\s*(?:\\((.*?)\\))?\\s*(?::\\s*(.*))?");
55+
5156
static Input create(Menu menu, String input) {
52-
ActionInput actionInput = ActionInput.create(input);
57+
ActionInput actionInput;
58+
Matcher matcher = pattern.matcher(input);
59+
if (matcher.matches()) {
60+
String type = matcher.group(1);
61+
String option = Optional.ofNullable(matcher.group(2)).orElse("");
62+
String value = Optional.ofNullable(matcher.group(3)).orElse("");
63+
actionInput = ActionInput.create(type, option, value);
64+
} else {
65+
actionInput = ActionInput.create("", "", input);
66+
}
5367
return new Input() {
5468
@Override
5569
public String getType() {

0 commit comments

Comments
 (0)