-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStringArgumentType.java
62 lines (53 loc) · 2.61 KB
/
StringArgumentType.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class StringArgumentType implements ArgumentType<String> {
private static final List<String> VALID_COMMANDS = Arrays.asList(
"bhoptarget", "bhop", "permissions", "setPermission",
"airAcceleration", "airStrafeSpeed", "groundSpeed",
"bunnyHopMultiplier", "maxAirSpeed", "friction",
"config", "help"
);
private StringArgumentType() {
}
public static StringArgumentType string() {
return new StringArgumentType();
}
@Override
public String parse(StringReader reader) throws CommandSyntaxException {
return reader.readUnquotedString();
}
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
String remaining = builder.getRemaining().toLowerCase();
if (remaining.startsWith("bhop")) {
if (remaining.equals("bhop")) {
return builder.suggest("bhop", "bhoptarget").buildFuture();
} else if (remaining.equals("bhopt")) {
return builder.suggest("bhoptarget").buildFuture();
}
} else if (remaining.startsWith("air")) {
if (remaining.equals("air")) {
return builder.suggest("airAcceleration", "airStrafeSpeed").buildFuture();
} else if (remaining.equals("aira")) {
return builder.suggest("airAcceleration", "airStrafeSpeed").buildFuture();
} else if (remaining.equals("airac")) {
return builder.suggest("airAcceleration").buildFuture();
} else if (remaining.equals("airstr")) {
return builder.suggest("airStrafeSpeed").buildFuture();
}
}
List<String> suggestions = VALID_COMMANDS.stream()
.filter(command -> command.startsWith(remaining) && !command.equals("bhop") && !command.equals("bhoptarget") && !command.equals("airAcceleration") && !command.equals("airStrafeSpeed"))
.collect(Collectors.toList());
return builder.suggestFromElements(suggestions).buildFuture();
}
}