mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-24 05:47:59 +01:00
Fixed autocomplete for race arguments
This commit is contained in:
parent
8e30e8539a
commit
bbfebe009a
1 changed files with 15 additions and 0 deletions
|
@ -2,12 +2,16 @@ package com.minelittlepony.unicopia.command;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.Race;
|
import com.minelittlepony.unicopia.Race;
|
||||||
import com.mojang.brigadier.StringReader;
|
import com.mojang.brigadier.StringReader;
|
||||||
import com.mojang.brigadier.arguments.ArgumentType;
|
import com.mojang.brigadier.arguments.ArgumentType;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||||
|
|
||||||
class RaceArgument implements ArgumentType<Race> {
|
class RaceArgument implements ArgumentType<Race> {
|
||||||
static final Collection<String> EXAMPLES = Arrays.stream(Race.values())
|
static final Collection<String> EXAMPLES = Arrays.stream(Race.values())
|
||||||
|
@ -20,6 +24,17 @@ class RaceArgument implements ArgumentType<Race> {
|
||||||
return Race.fromName(reader.readUnquotedString(), Race.EARTH);
|
return Race.fromName(reader.readUnquotedString(), Race.EARTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <S> CompletableFuture<Suggestions> listSuggestions(final CommandContext<S> context, final SuggestionsBuilder builder) {
|
||||||
|
Arrays.stream(Race.values())
|
||||||
|
.filter(Race::isUsable)
|
||||||
|
.map(i -> i.name().toLowerCase())
|
||||||
|
.filter(i -> i.startsWith(builder.getRemaining().toLowerCase()))
|
||||||
|
.forEach(i -> builder.suggest(i.toLowerCase()));
|
||||||
|
|
||||||
|
return builder.buildFuture();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<String> getExamples() {
|
public Collection<String> getExamples() {
|
||||||
return EXAMPLES;
|
return EXAMPLES;
|
||||||
|
|
Loading…
Reference in a new issue