use of com.sk89q.worldedit.event.platform.CommandEvent 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