use of com.sk89q.worldedit.event.platform.CommandSuggestionEvent in project FastAsyncWorldEdit by IntellectualSites.
the class CommandWrapper method suggest.
private static CompletableFuture<Suggestions> suggest(CommandContext<ServerCommandSource> context, SuggestionsBuilder builder) throws CommandSyntaxException {
CommandSuggestionEvent event = new CommandSuggestionEvent(FabricAdapter.adaptPlayer(context.getSource().getPlayer()), builder.getInput());
WorldEdit.getInstance().getEventBus().post(event);
List<Substring> suggestions = event.getSuggestions();
ImmutableList.Builder<Suggestion> result = ImmutableList.builder();
for (Substring suggestion : suggestions) {
String suggestionText = suggestion.getSubstring();
// Ensure there is a space!
if (suggestion.getStart() == suggestion.getEnd() && suggestion.getEnd() == builder.getInput().length() && !builder.getInput().endsWith(" ") && !builder.getInput().endsWith("\"")) {
suggestionText = " " + suggestionText;
}
result.add(new Suggestion(StringRange.between(suggestion.getStart(), suggestion.getEnd()), suggestionText));
}
return CompletableFuture.completedFuture(Suggestions.create(builder.getInput(), result.build()));
}
use of com.sk89q.worldedit.event.platform.CommandSuggestionEvent in project FastAsyncWorldEdit by IntellectualSites.
the class CommandWrapper method suggest.
private static CompletableFuture<Suggestions> suggest(CommandContext<CommandSource> context, SuggestionsBuilder builder) throws CommandSyntaxException {
CommandSuggestionEvent event = new CommandSuggestionEvent(ForgeAdapter.adaptPlayer(context.getSource().asPlayer()), builder.getInput());
WorldEdit.getInstance().getEventBus().post(event);
List<Substring> suggestions = event.getSuggestions();
ImmutableList.Builder<Suggestion> result = ImmutableList.builder();
for (Substring suggestion : suggestions) {
String suggestionText = suggestion.getSubstring();
// Ensure there is a space!
if (suggestion.getStart() == suggestion.getEnd() && suggestion.getEnd() == builder.getInput().length() && !builder.getInput().endsWith(" ") && !builder.getInput().endsWith("\"")) {
suggestionText = " " + suggestionText;
}
result.add(new Suggestion(StringRange.between(suggestion.getStart(), suggestion.getEnd()), suggestionText));
}
return CompletableFuture.completedFuture(Suggestions.create(builder.getInput(), result.build()));
}
use of com.sk89q.worldedit.event.platform.CommandSuggestionEvent in project FastAsyncWorldEdit by IntellectualSites.
the class SpongePlatform method registerCommands.
@Override
public void registerCommands(CommandManager manager) {
for (Command command : manager.getAllCommands().collect(toList())) {
CommandAdapter adapter = new CommandAdapter(command) {
@Override
public CommandResult process(CommandSource source, String arguments) throws org.spongepowered.api.command.CommandException {
CommandEvent weEvent = new CommandEvent(SpongeWorldEdit.inst().wrapCommandSource(source), command.getName() + " " + arguments);
WorldEdit.getInstance().getEventBus().post(weEvent);
return weEvent.isCancelled() ? CommandResult.success() : CommandResult.empty();
}
@Override
public List<String> getSuggestions(CommandSource source, String arguments, @Nullable Location<org.spongepowered.api.world.World> targetPosition) throws CommandException {
CommandSuggestionEvent weEvent = new CommandSuggestionEvent(SpongeWorldEdit.inst().wrapCommandSource(source), command.getName() + " " + arguments);
WorldEdit.getInstance().getEventBus().post(weEvent);
return CommandUtil.fixSuggestions(arguments, weEvent.getSuggestions());
}
};
ImmutableList.Builder<String> aliases = ImmutableList.builder();
aliases.add(command.getName()).addAll(command.getAliases());
Sponge.getCommandManager().register(SpongeWorldEdit.inst(), adapter, aliases.build());
}
}
Aggregations