use of org.spongepowered.common.command.manager.SpongeCommandManager in project SpongeCommon by SpongePowered.
the class ServerGamePacketListenerImplMixin method impl$getSuggestionsFromNonBrigCommand.
@Inject(method = "handleCustomCommandSuggestions", at = @At(value = "NEW", target = "com/mojang/brigadier/StringReader", remap = false), cancellable = true)
private void impl$getSuggestionsFromNonBrigCommand(final ServerboundCommandSuggestionPacket packet, final CallbackInfo ci) {
final String rawCommand = packet.getCommand();
final String[] command = CommandUtil.extractCommandString(rawCommand);
final CommandCause cause = CommandCause.create();
final SpongeCommandManager manager = SpongeCommandManager.get(this.server);
if (!rawCommand.contains(" ")) {
final SuggestionsBuilder builder = new SuggestionsBuilder(command[0], 0);
if (command[0].isEmpty()) {
manager.getAliasesForCause(cause).forEach(builder::suggest);
} else {
manager.getAliasesThatStartWithForCause(cause, command[0]).forEach(builder::suggest);
}
this.connection.send(new ClientboundCommandSuggestionsPacket(packet.getId(), builder.build()));
ci.cancel();
} else {
final Optional<CommandMapping> mappingOptional = manager.commandMapping(command[0].toLowerCase(Locale.ROOT)).filter(x -> !(x.registrar() instanceof BrigadierBasedRegistrar));
if (mappingOptional.isPresent()) {
final CommandMapping mapping = mappingOptional.get();
if (mapping.registrar().canExecute(cause, mapping)) {
final SuggestionsBuilder builder = CommandUtil.createSuggestionsForRawCommand(rawCommand, command, cause, mapping);
this.connection.send(new ClientboundCommandSuggestionsPacket(packet.getId(), builder.build()));
} else {
this.connection.send(new ClientboundCommandSuggestionsPacket(packet.getId(), Suggestions.empty().join()));
}
ci.cancel();
}
}
}
use of org.spongepowered.common.command.manager.SpongeCommandManager in project SpongeCommon by SpongePowered.
the class CommandsMixin method impl$useSpongeDispatcher.
// We prepare our own dispatcher and commands manager, to redirect registrations to our system
@Redirect(method = "<init>", at = @At(value = "NEW", args = "class=com/mojang/brigadier/CommandDispatcher", remap = false))
private CommandDispatcher<CommandSourceStack> impl$useSpongeDispatcher() {
final SpongeCommandManager manager = Launch.instance().lifecycle().platformInjector().getInstance(SpongeCommandManager.class);
manager.init();
this.impl$commandManager = manager;
return new DelegatingCommandDispatcher(manager.getBrigadierRegistrar());
}
Aggregations