Skip to content

Commit b0369b7

Browse files
committed
migrate to EditorString
1 parent 5e66b5e commit b0369b7

File tree

9 files changed

+295
-75
lines changed

9 files changed

+295
-75
lines changed

editor-extra/src/main/java/io/github/projectunified/minigamecore/editor/extra/action/BooleanAction.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.github.projectunified.minigamecore.editor.EditorAction;
44
import io.github.projectunified.minigamecore.editor.EditorActor;
5+
import io.github.projectunified.minigamecore.editor.EditorString;
56

67
import java.util.Arrays;
78
import java.util.Collections;
@@ -11,9 +12,14 @@
1112
* The {@link EditorAction} for boolean value
1213
*/
1314
public abstract class BooleanAction implements EditorAction {
15+
/**
16+
* The string of the usage of the boolean action
17+
*/
18+
public static final EditorString USAGE = EditorString.of("action.boolean.usage", "<true|false>");
19+
1420
@Override
15-
public String usage() {
16-
return "<true|false>";
21+
public EditorString usage() {
22+
return USAGE;
1723
}
1824

1925
@Override

editor-extra/src/main/java/io/github/projectunified/minigamecore/editor/extra/action/EnumAction.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.github.projectunified.minigamecore.editor.EditorAction;
44
import io.github.projectunified.minigamecore.editor.EditorActor;
5+
import io.github.projectunified.minigamecore.editor.EditorString;
56

67
import java.util.Collections;
78
import java.util.List;
@@ -15,6 +16,15 @@
1516
* @param <T> the type of the enum
1617
*/
1718
public abstract class EnumAction<T extends Enum<T>> implements EditorAction {
19+
/**
20+
* The string of the usage of the enum action
21+
*/
22+
public static final EditorString USAGE = EditorString.of("action.enum.usage", "<value>");
23+
/**
24+
* The string of the message when the actor uses an invalid value
25+
*/
26+
public static final EditorString INVALID_VALUE = EditorString.of("action.enum.invalid_value", "Invalid value: %s");
27+
1828
private final Class<T> enumClass;
1929

2030
/**
@@ -36,8 +46,8 @@ public EnumAction(Class<T> enumClass) {
3646
public abstract void execute(EditorActor actor, T value, String[] args);
3747

3848
@Override
39-
public String usage() {
40-
return "<value>";
49+
public EditorString usage() {
50+
return USAGE;
4151
}
4252

4353
@Override
@@ -58,7 +68,7 @@ public void execute(EditorActor actor, String[] args) {
5868
T value = Enum.valueOf(enumClass, args[0].toUpperCase(Locale.ROOT));
5969
execute(actor, value, args);
6070
} catch (IllegalArgumentException e) {
61-
actor.sendMessage("Invalid value: " + args[0], false);
71+
actor.sendMessage(INVALID_VALUE, args[0]);
6272
}
6373
}
6474
}

editor-extra/src/main/java/io/github/projectunified/minigamecore/editor/extra/action/NumberAction.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.github.projectunified.minigamecore.editor.EditorAction;
44
import io.github.projectunified.minigamecore.editor.EditorActor;
5+
import io.github.projectunified.minigamecore.editor.EditorString;
56

67
import java.util.Arrays;
78
import java.util.Collections;
@@ -15,9 +16,18 @@
1516
* The {@link EditorAction} for number value
1617
*/
1718
public abstract class NumberAction implements EditorAction {
19+
/**
20+
* The string of the usage of the number action
21+
*/
22+
public static final EditorString USAGE = EditorString.of("action.number.usage", "<value>");
23+
/**
24+
* The string of the message when the actor uses an invalid value
25+
*/
26+
public static final EditorString INVALID_VALUE = EditorString.of("action.enum.invalid_value", "Invalid value: %s");
27+
1828
@Override
19-
public String usage() {
20-
return "<value>";
29+
public EditorString usage() {
30+
return USAGE;
2131
}
2232

2333
@Override
@@ -57,7 +67,7 @@ public void execute(EditorActor actor, String[] args) {
5767
try {
5868
execute(actor, Double.parseDouble(value), Arrays.copyOfRange(args, 1, args.length));
5969
} catch (NumberFormatException e) {
60-
actor.sendMessage("Invalid Number: " + value, false);
70+
actor.sendMessage(INVALID_VALUE, value);
6171
}
6272
}
6373
}

0 commit comments

Comments
 (0)