net.minecraft.command.ISuggestionProvider Java Examples

The following examples show how to use net.minecraft.command.ISuggestionProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ForgeClientSparkPlugin.java    From spark with GNU General Public License v3.0 6 votes vote down vote up
@Override
public CompletableFuture<Suggestions> getSuggestions(CommandContext<ISuggestionProvider> context, SuggestionsBuilder builder) throws CommandSyntaxException {
    String chat = context.getInput();
    String[] split = chat.split(" ");
    if (split.length == 0 || (!split[0].equals("/sparkc") && !split[0].equals("/sparkclient"))) {
        return Suggestions.empty();
    }

    String[] args = Arrays.copyOfRange(split, 1, split.length);

    return CompletableFuture.supplyAsync(() -> {
        for (String suggestion : this.platform.tabCompleteCommand(new ForgeCommandSender(this.minecraft.player, this), args)) {
            builder.suggest(suggestion);
        }
        return builder.build();
    });
}
 
Example #2
Source File: ConfigCommand.java    From BoundingBoxOutlineReloaded with MIT License 6 votes vote down vote up
public static void register(CommandDispatcher<ISuggestionProvider> commandDispatcher) {
    LiteralArgumentBuilder command = Commands.literal(COMMAND)
            .then(buildCommands(GET, ConfigCommand::getCommandForSetting))
            .then(buildCommands(ArgumentNames.SET, ConfigCommand::setCommandForSetting))
            .then(buildCommands(RESET, ConfigCommand::resetCommandForSetting)
                    .executes(context1 -> {
                        ConfigManager.getSettings().forEach(Setting::reset);
                        ConfigManager.saveConfig();
                        return 0;
                    }))
            .then(Commands.literal(SAVE)
                    .executes(context -> {
                        ConfigManager.saveConfig();
                        return 0;
                    }))
            .then(Commands.literal(SHOW_GUI)
                    .executes(context -> {
                        SettingsScreen.show();
                        return 0;
                    }));

    commandDispatcher.register(command);
}
 
Example #3
Source File: CustomCommand.java    From BoundingBoxOutlineReloaded with MIT License 6 votes vote down vote up
public static void register(CommandDispatcher<ISuggestionProvider> commandDispatcher) {
    LiteralArgumentBuilder command = Commands.literal(COMMAND)
            .then(BoxCommandBuilder.build(BOX))
            .then(BeaconCommandBuilder.build(BEACON))
            .then(LineCommandBuilder.build(LINE))
            .then(SphereCommandBuilder.build(SPHERE))
            .then(Commands.literal(ArgumentNames.CLEAR)
                    .executes(context -> {
                        CustomBoxProvider.clear();
                        CustomBeaconProvider.clear();
                        CustomLineProvider.clear();
                        CustomSphereProvider.clear();

                        CommandHelper.feedback(context, "bbor.commands.custom.cleared.all");
                        return 0;
                    }));
    commandDispatcher.register(command);
}
 
Example #4
Source File: ForgeClientSparkPlugin.java    From spark with GNU General Public License v3.0 5 votes vote down vote up
private void checkCommandRegistered() {
    CommandDispatcher<ISuggestionProvider> dispatcher = getPlayerCommandDispatcher();
    if (dispatcher == null) {
        return;
    }

    try {
        if (dispatcher != this.dispatcher) {
            this.dispatcher = dispatcher;
            registerCommands(this.dispatcher, context -> Command.SINGLE_SUCCESS, this, "sparkc", "sparkclient");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #5
Source File: StructuresCommand.java    From BoundingBoxOutlineReloaded with MIT License 5 votes vote down vote up
public static void register(CommandDispatcher<ISuggestionProvider> commandDispatcher) {
    LiteralArgumentBuilder command = Commands.literal(COMMAND)
            .then(Commands.literal(LOAD)
                    .executes(context -> {
                        LoadSavesScreen.show();
                        return 0;
                    }))
            .then(Commands.literal(ArgumentNames.CLEAR)
                    .executes(context -> {
                        ClientInterop.clearStructures();
                        return 0;
                    }));

    commandDispatcher.register(command);
}
 
Example #6
Source File: SpawningSphereCommand.java    From BoundingBoxOutlineReloaded with MIT License 5 votes vote down vote up
public static void register(CommandDispatcher<ISuggestionProvider> commandDispatcher) {
    LiteralArgumentBuilder command = Commands.literal(COMMAND)
            .then(Commands.literal(ArgumentNames.SET)
                    .then(Commands.argument(ArgumentNames.POS, Arguments.point())
                            .executes(SpawningSphereCommand::setSphere))
                    .executes(SpawningSphereCommand::setSphere))
            .then(Commands.literal(ArgumentNames.CLEAR)
                    .executes(context -> {
                        boolean cleared = SpawningSphereProvider.clear();

                        String format = cleared ? "bbor.commands.spawningSphere.cleared" : "bbor.commands.spawningSphere.notSet";
                        CommandHelper.feedback(context, format);
                        return 0;
                    }))
            .then(Commands.literal(CALCULATE_SPAWNABLE)
                    .executes(context -> {
                        if (!SpawningSphereProvider.hasSpawningSphereInDimension(Player.getDimensionId())) {
                            CommandHelper.feedback(context, "bbor.commands.spawningSphere.notSet");
                            return 0;
                        }

                        Counts counts = new Counts();
                        World world = Minecraft.getInstance().world;
                        SpawningSphereProvider.calculateSpawnableSpacesCount(pos -> {
                            counts.spawnable++;
                            if (world.getLightFor(LightType.SKY, pos) > 7)
                                counts.nightSpawnable++;
                        });
                        SpawningSphereProvider.setSpawnableSpacesCount(counts.spawnable);

                        CommandHelper.feedback(context, "bbor.commands.spawningSphere.calculated",
                                String.format("%,d", counts.spawnable),
                                String.format("%,d", counts.nightSpawnable));
                        return 0;
                    }));
    commandDispatcher.register(command);
}
 
Example #7
Source File: ClientInterop.java    From BoundingBoxOutlineReloaded with MIT License 5 votes vote down vote up
public static boolean interceptChatMessage(String message) {
    if (message.startsWith("/bbor:")) {
        ClientPlayNetHandler connection = Minecraft.getInstance().getConnection();
        if (connection != null) {
            CommandDispatcher<ISuggestionProvider> commandDispatcher = connection.func_195515_i();
            CommandSource commandSource = Minecraft.getInstance().player.getCommandSource();
            try {
                commandDispatcher.execute(message.substring(1), commandSource);
            } catch (CommandSyntaxException exception) {
                commandSource.sendErrorMessage(TextComponentUtils.toTextComponent(exception.getRawMessage()));
                if (exception.getInput() != null && exception.getCursor() >= 0) {
                    ITextComponent suggestion = new StringTextComponent("")
                            .applyTextStyle(TextFormatting.GRAY)
                            .applyTextStyle(style -> style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, message)));
                    int textLength = Math.min(exception.getInput().length(), exception.getCursor());
                    if (textLength > 10) {
                        suggestion.appendText("...");
                    }

                    suggestion.appendText(exception.getInput().substring(Math.max(0, textLength - 10), textLength));
                    if (textLength < exception.getInput().length()) {
                        suggestion.appendSibling(new StringTextComponent(exception.getInput().substring(textLength))
                                .applyTextStyles(TextFormatting.RED, TextFormatting.UNDERLINE));
                    }

                    suggestion.appendSibling(new TranslationTextComponent("command.context.here")
                            .applyTextStyles(TextFormatting.RED, TextFormatting.ITALIC));
                    commandSource.sendErrorMessage(suggestion);
                }
            }
        }
        return true;
    }
    return false;
}
 
Example #8
Source File: ClientInterop.java    From BoundingBoxOutlineReloaded with MIT License 5 votes vote down vote up
public static void registerClientCommands(CommandDispatcher<ISuggestionProvider> commandDispatcher) {
    SeedCommand.register(commandDispatcher);
    SpawningSphereCommand.register(commandDispatcher);
    CustomCommand.register(commandDispatcher);
    ConfigCommand.register(commandDispatcher);
    StructuresCommand.register(commandDispatcher);
}
 
Example #9
Source File: ForgeClientSparkPlugin.java    From spark with GNU General Public License v3.0 4 votes vote down vote up
private CommandDispatcher<ISuggestionProvider> getPlayerCommandDispatcher() {
    return Optional.ofNullable(this.minecraft.player)
            .map(player -> player.connection)
            .map(ClientPlayNetHandler::getCommandDispatcher)
            .orElse(null);
}