Skip to content

Commit 4f00174

Browse files
xxyyliteralplus
authored andcommitted
Simplify TextProvider, Fix all @text ending with space
This commit simplifies TextProvider to be a lot clearer and also avoid swallowing an unnecessary exception. Furthermore, it changes its behaviour so that created text does not always have a space at the end. Usually, people don't mean to add an unnecessary space at the end of their text argument if they don't put more text. The motivation for this commit is that I am currently experiencing the space problem in my usage of this library. Thanks!
1 parent 6026dbc commit 4f00174

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

intake/src/main/java/com/sk89q/intake/parametric/provider/TextProvider.java

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package com.sk89q.intake.parametric.provider;
2121

2222
import com.sk89q.intake.argument.ArgumentException;
23-
import com.sk89q.intake.argument.MissingArgumentException;
2423
import com.sk89q.intake.argument.CommandArgs;
2524

2625
import javax.annotation.Nullable;
@@ -34,25 +33,13 @@ class TextProvider extends StringProvider {
3433
@Nullable
3534
@Override
3635
public String get(CommandArgs arguments, List<? extends Annotation> modifiers) throws ArgumentException {
37-
StringBuilder builder = new StringBuilder();
38-
boolean first = true;
39-
while (true) {
40-
if (!first) {
41-
builder.append(" ");
42-
}
43-
try {
44-
builder.append(arguments.next());
45-
} catch (MissingArgumentException ignored) {
46-
break;
47-
}
48-
first = false;
36+
StringBuilder builder = new StringBuilder(arguments.next()); //throws an exception if there's no first arg
37+
while (arguments.hasNext()) {
38+
builder.append(" ").append(arguments.next());
4939
}
50-
if (first) {
51-
throw new MissingArgumentException();
52-
}
53-
String v = builder.toString();
54-
validate(v, modifiers);
55-
return v;
40+
String text = builder.toString();
41+
validate(text, modifiers);
42+
return text;
5643
}
5744

5845
}

0 commit comments

Comments
 (0)