net.minecraft.server.command.CommandSource Java Examples

The following examples show how to use net.minecraft.server.command.CommandSource. 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: AchievementCommand.java    From multiconnect with MIT License 6 votes vote down vote up
public static void register(CommandDispatcher<CommandSource> dispatcher) {
    dispatcher.register(literal("achievement")
        .then(literal("give")
            .then(literal("*")
                .executes(ctx -> 0)
                .then(argument("player", players())
                    .executes(ctx -> 0)))
            .then(argument("achievement", achievement())
                .executes(ctx -> 0)
                .then(argument("player", players())
                    .executes(ctx -> 0))))
        .then(literal("take")
            .then(literal("*")
                .executes(ctx -> 0)
                .then(argument("player", players())
                    .executes(ctx -> 0)))
            .then(argument("achievement", achievement())
                .executes(ctx -> 0)
                .then(argument("player", players())
                    .executes(ctx -> 0)))));
}
 
Example #2
Source File: VRCommandHandler.java    From ViaFabric with MIT License 6 votes vote down vote up
public CompletableFuture<Suggestions> suggestion(CommandContext<? extends CommandSource> ctx, SuggestionsBuilder builder) {
    String[] args;
    try {
        args = StringArgumentType.getString(ctx, "args").split(" ", -1);
    } catch (IllegalArgumentException ignored) {
        args = new String[]{""};
    }
    String[] pref = args.clone();
    pref[pref.length - 1] = "";
    String prefix = String.join(" ", pref);
    onTabComplete(new NMSCommandSender(ctx.getSource()), args)
            .stream()
            .map(it -> {
                SuggestionsBuilder b = new SuggestionsBuilder(builder.getInput(), prefix.length() + builder.getStart());
                b.suggest(it);
                return b;
            })
            .forEach(builder::add);
    return builder.buildFuture();
}
 
Example #3
Source File: FabricClientSparkPlugin.java    From spark with GNU General Public License v3.0 6 votes vote down vote up
@Override
public CompletableFuture<Suggestions> getSuggestions(CommandContext<CommandSource> context, SuggestionsBuilder builder) throws CommandSyntaxException {
    String[] split = context.getInput().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 FabricCommandSender(this.minecraft.player, this), args)) {
            builder.suggest(suggestion);
        }
        return builder.build();
    });
}
 
Example #4
Source File: MixinClientPlayNetworkHandler.java    From multiconnect with MIT License 6 votes vote down vote up
@Inject(method = "onGameJoin", at = @At("RETURN"))
private void onOnGameJoin(GameJoinS2CPacket packet, CallbackInfo ci) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_12_2) {
        onSynchronizeTags(new SynchronizeTagsS2CPacket(new RegistryTagManager()));

        Protocol_1_12_2 protocol = (Protocol_1_12_2) ConnectionInfo.protocol;
        List<Recipe<?>> recipes = new ArrayList<>();
        List<RecipeInfo<?>> recipeInfos = protocol.getCraftingRecipes();
        for (int i = 0; i < recipeInfos.size(); i++) {
            recipes.add(recipeInfos.get(i).create(new Identifier(String.valueOf(i))));
        }
        onSynchronizeRecipes(new SynchronizeRecipesS2CPacket(recipes));

        CommandDispatcher<CommandSource> dispatcher = new CommandDispatcher<>();
        Commands_1_12_2.registerAll(dispatcher, null);
        onCommandTree(new CommandTreeS2CPacket(dispatcher.getRoot()));
        TabCompletionManager.requestCommandList();
    }
}
 
Example #5
Source File: RecipeCommand.java    From multiconnect with MIT License 6 votes vote down vote up
public static void register(CommandDispatcher<CommandSource> dispatcher) {
    dispatcher.register(literal("recipe")
        .then(literal("give")
            .then(argument("player", players())
                .then(literal("*")
                    .executes(ctx -> 0))
                .then(argument("recipe", identifier())
                    .suggests(SuggestionProviders.ASK_SERVER)
                    .executes(ctx -> 0))))
        .then(literal("take")
            .then(argument("player", players())
                .then(literal("*")
                    .executes(ctx -> 0))
                .then(argument("recipe", identifier())
                    .suggests(SuggestionProviders.ASK_SERVER)
                    .executes(ctx -> 0)))));
}
 
Example #6
Source File: ParticleCommand.java    From multiconnect with MIT License 6 votes vote down vote up
public static void register(CommandDispatcher<CommandSource> dispatcher) {
    dispatcher.register(literal("particle")
        .then(argument("type", particle()))
            .then(argument("pos", vec3())
                .then(argument("vx", doubleArg())
                    .then(argument("vy", doubleArg())
                        .then(argument("vz", doubleArg())
                            .then(argument("speed", doubleArg())
                                .executes(ctx -> 0)
                                .then(argument("count", integer(0))
                                    .executes(ctx -> 0)
                                    .then(argument("mode", word())
                                        .suggests((ctx, builder) -> {
                                            CommandSource.suggestMatching(new String[] {"normal", "force"}, builder);
                                            return builder.buildFuture();
                                        })
                                        .executes(ctx -> 0)
                                        .then(argument("player", players())
                                            .executes(ctx -> 0)
                                            .then(argument("param1", integer())
                                                .executes(ctx -> 0)
                                                .then(argument("param2", integer()))))))))))));
}
 
Example #7
Source File: AdvancementCommand.java    From multiconnect with MIT License 6 votes vote down vote up
private static ArgumentBuilder<CommandSource, ?> tail() {
    return argument("player", players())
            .then(literal("only")
                .then(argument("advancement", identifier())
                    .suggests(ADVANCEMENT_SUGGESTOR)
                    .executes(ctx -> 0)
                    .then(argument("criteria", word())
                        .suggests(CRITERIA_SUGGESTOR)
                        .executes(ctx -> 0))))
            .then(literal("until")
                .then(argument("advancement", identifier())
                    .suggests(ADVANCEMENT_SUGGESTOR)
                    .executes(ctx -> 0)))
            .then(literal("from")
                .then(argument("advancement", identifier())
                    .suggests(ADVANCEMENT_SUGGESTOR)
                    .executes(ctx -> 0)))
            .then(literal("through")
                .then(argument("advancement", identifier())
                    .suggests(ADVANCEMENT_SUGGESTOR)
                    .executes(ctx -> 0)))
            .then(literal("everything")
                .executes(ctx -> 0));
}
 
Example #8
Source File: EntityArgumentType_1_12_2.java    From multiconnect with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
    if (!(context.getSource() instanceof CommandSource))
        return builder.buildFuture();

    StringReader reader = new StringReader(builder.getInput());
    reader.setCursor(builder.getStart());

    CompletableFuture<Suggestions> playerCompletions;
    if ((reader.canRead() && reader.peek() == '@') || !suggestPlayerNames) {
        playerCompletions = Suggestions.empty();
    } else {
        playerCompletions = ((CommandSource) context.getSource()).getCompletions((CommandContext<CommandSource>) context, builder.restart());
    }

    EntitySelectorParser parser = new EntitySelectorParser(reader, singleTarget, playersOnly);
    try {
        parser.parse();
    } catch (CommandSyntaxException ignore) {
    }
    CompletableFuture<Suggestions> selectorCompletions = parser.suggestor.apply(builder.restart());

    return CompletableFuture.allOf(playerCompletions, selectorCompletions)
            .thenCompose(v -> UnionArgumentType.mergeSuggestions(playerCompletions.join(), selectorCompletions.join()));
}
 
Example #9
Source File: FabricClientSparkPlugin.java    From spark with GNU General Public License v3.0 6 votes vote down vote up
private void checkCommandRegistered() {
    CommandDispatcher<CommandSource> dispatcher = getPlayerCommandDispatcher();
    if (dispatcher == null) {
        return;
    }

    try {
        if (dispatcher != this.dispatcher) {
            this.dispatcher = dispatcher;
            registerCommands(this.dispatcher, c -> Command.SINGLE_SUCCESS, this, "sparkc", "sparkclient");
            FabricSparkGameHooks.INSTANCE.setChatSendCallback(this::onClientChat);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #10
Source File: TimeCommand.java    From multiconnect with MIT License 6 votes vote down vote up
public static void register(CommandDispatcher<CommandSource> dispatcher) {
    dispatcher.register(literal("time")
        .then(literal("set")
            .then(argument("time", union(enumArg("day", "night"), integer(0)))
                .executes(ctx -> 0)))
        .then(literal("add")
            .then(argument("time", integer(0))
                .executes(ctx -> 0)))
        .then(literal("query")
            .then(literal("daytime")
                .executes(ctx -> 0))
            .then(literal("day")
                .executes(ctx -> 0))
            .then(literal("gametime")
                .executes(ctx -> 0))));
}
 
Example #11
Source File: PlaySoundCommand.java    From multiconnect with MIT License 6 votes vote down vote up
public static void register(CommandDispatcher<CommandSource> dispatcher) {
    for (String category : new String[] {"master", "music", "record", "weather", "block", "hostile", "neutral", "player", "ambient", "voice"}) {
        dispatcher.register(literal("playsound")
            .then(argument("sound", identifier())
                .suggests((ctx, builder) -> CommandSource.suggestIdentifiers(Registry.SOUND_EVENT.getIds(), builder))
                .then(literal(category)
                    .then(argument("player", players())
                        .executes(ctx -> 0)
                        .then(argument("pos", vec3())
                            .executes(ctx -> 0)
                            .then(argument("volume", floatArg(0))
                                .executes(ctx -> 0)
                                .then(argument("pitch", doubleArg(0, 2))
                                    .executes(ctx -> 0)
                                    .then(argument("minVolume", doubleArg(0, 1))
                                        .executes(ctx -> 0)))))))));
    }
}
 
Example #12
Source File: WhitelistCommand.java    From multiconnect with MIT License 6 votes vote down vote up
public static void register(CommandDispatcher<CommandSource> dispatcher) {
    dispatcher.register(literal("whitelist")
        .then(literal("on")
            .executes(ctx -> 0))
        .then(literal("off")
            .executes(ctx -> 0))
        .then(literal("list")
            .executes(ctx -> 0))
        .then(literal("add")
            .then(argument("player", word())
                .suggests(SuggestionProviders.ASK_SERVER)
                .executes(ctx -> 0)))
        .then(literal("remove")
            .then(argument("player", word())
                .suggests(SuggestionProviders.ASK_SERVER)
                .executes(ctx -> 0)))
        .then(literal("reload")
            .executes(ctx -> 0)));
}
 
Example #13
Source File: ViaFabric.java    From ViaFabric with MIT License 5 votes vote down vote up
public static <S extends CommandSource> LiteralArgumentBuilder<S> command(String commandName) {
    return LiteralArgumentBuilder.<S>literal(commandName)
            .then(
                    RequiredArgumentBuilder
                            .<S, String>argument("args", StringArgumentType.greedyString())
                            .executes(((VRCommandHandler) Via.getManager().getCommandHandler())::execute)
                            .suggests(((VRCommandHandler) Via.getManager().getCommandHandler())::suggestion)
            )
            .executes(((VRCommandHandler) Via.getManager().getCommandHandler())::execute);
}
 
Example #14
Source File: FillCommand.java    From multiconnect with MIT License 5 votes vote down vote up
public static void register(CommandDispatcher<CommandSource> dispatcher) {
    dispatcher.register(literal("fill")
        .then(argument("pos1", blockPos())
            .then(argument("pos2", blockPos())
                .then(argument("block", blockState())
                    .executes(ctx -> 0)
                    .then(argument("oldBlockHandling", enumArg("replace", "destroy", "keep", "hollow", "outline"))
                        .executes(ctx -> 0)
                        .then(argument("nbt", nbtCompound())
                            .executes(ctx -> 0)))))));
}
 
Example #15
Source File: VRCommandHandler.java    From ViaFabric with MIT License 5 votes vote down vote up
public int execute(CommandContext<? extends CommandSource> ctx) {
    String[] args = new String[0];
    try {
        args = StringArgumentType.getString(ctx, "args").split(" ");
    } catch (IllegalArgumentException ignored) {
    }
    onCommand(
            new NMSCommandSender(ctx.getSource()),
            args
    );
    return 1;
}
 
Example #16
Source File: TestForCommand.java    From multiconnect with MIT License 5 votes vote down vote up
public static void register(CommandDispatcher<CommandSource> dispatcher) {
    dispatcher.register(literal("testfor")
        .then(argument("entity", entities())
            .executes(ctx -> 0)
            .then(argument("nbt", nbtCompound())
                .executes(ctx -> 0))));
}
 
Example #17
Source File: BlockStateArgumentType_1_12_2.java    From multiconnect with MIT License 5 votes vote down vote up
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
    int spaceIndex = builder.getRemaining().indexOf(' ');
    if (spaceIndex == -1) {
        CommandSource.suggestIdentifiers(Registry.BLOCK.getIds().stream().filter(id -> isValidBlock(Registry.BLOCK.get(id))), builder);
        return builder.buildFuture();
    }

    Identifier blockId = Identifier.tryParse(builder.getInput().substring(builder.getStart(), builder.getStart() + spaceIndex));

    String propertiesStr = builder.getInput().substring(builder.getStart() + spaceIndex + 1);

    int commaIndex = propertiesStr.lastIndexOf(',');
    int equalsIndex = propertiesStr.lastIndexOf('=');
    builder = builder.createOffset(builder.getStart() + spaceIndex + commaIndex + 2);

    if (commaIndex == -1 && equalsIndex == -1) {
        CommandSource.suggestMatching(new String[] {"default"}, builder);
        if (test)
            CommandSource.suggestMatching(new String[] {"*"}, builder);
    }

    if (blockId == null || !BlockStateReverseFlattening.OLD_PROPERTIES.containsKey(blockId))
        return builder.buildFuture();

    if (equalsIndex <= commaIndex) {
        CommandSource.suggestMatching(BlockStateReverseFlattening.OLD_PROPERTIES.get(blockId).stream().map(str -> str + "="), builder);
    } else {
        String property = builder.getInput().substring(builder.getStart(), builder.getStart() + equalsIndex - commaIndex - 1);
        List<String> values = BlockStateReverseFlattening.OLD_PROPERTY_VALUES.get(Pair.of(blockId, property));
        builder = builder.createOffset(builder.getStart() + equalsIndex - commaIndex);
        CommandSource.suggestMatching(values, builder);
    }

    return builder.buildFuture();
}
 
Example #18
Source File: EntityArgumentType_1_12_2.java    From multiconnect with MIT License 5 votes vote down vote up
private void suggestOption() {
    int start = reader.getCursor();
    List<String> seenOptionsCopy = new ArrayList<>(seenOptions);

    suggestor = builder -> {
        SuggestionsBuilder normalOptionBuilder = builder.createOffset(start);
        CommandSource.suggestMatching(SELECTOR_OPTIONS.keySet().stream()
                .filter(opt -> SELECTOR_OPTIONS.get(opt).isAllowed(this))
                .filter(opt -> !seenOptionsCopy.contains(opt))
                .map(opt -> opt + "=")
                .collect(Collectors.toSet()), normalOptionBuilder);
        CompletableFuture<Suggestions> normalOptions = normalOptionBuilder.buildFuture();

        SuggestionsBuilder scoreOptionBuilder = builder.createOffset(start);
        CompletableFuture<Suggestions> scoreOptions = getScoreObjectives().thenCompose(objectives -> {
            CommandSource.suggestMatching(objectives.stream()
                    .map(str -> "score_" + str)
                    .filter(str -> !seenOptionsCopy.contains(str))
                    .map(str -> str + "="),
                    scoreOptionBuilder);
            CommandSource.suggestMatching(objectives.stream()
                    .map(str -> "score_" + str + "_min")
                    .filter(str -> !seenOptionsCopy.contains(str))
                    .map(str -> str + "="),
                    scoreOptionBuilder);
            return scoreOptionBuilder.buildFuture();
        });

        return CompletableFuture.allOf(normalOptions, scoreOptions)
                .thenCompose(v -> UnionArgumentType.mergeSuggestions(normalOptions.join(), scoreOptions.join()));
    };
}
 
Example #19
Source File: Protocol_1_11_2.java    From multiconnect with MIT License 5 votes vote down vote up
@Override
public void registerCommands(CommandDispatcher<CommandSource> dispatcher, Set<String> serverCommands) {
    super.registerCommands(dispatcher, serverCommands);

    BrigadierRemover.of(dispatcher).get("advancement").remove();
    BrigadierRemover.of(dispatcher).get("function").remove();
    BrigadierRemover.of(dispatcher).get("recipe").remove();
    BrigadierRemover.of(dispatcher).get("reload").remove();

    Commands_1_12_2.registerVanilla(dispatcher, serverCommands, "achievement", AchievementCommand::register);
}
 
Example #20
Source File: WorldborderCommand.java    From multiconnect with MIT License 5 votes vote down vote up
public static void register(CommandDispatcher<CommandSource> dispatcher) {
    dispatcher.register(literal("worldborder")
        .then(literal("set")
            .then(argument("sizeInBlocks", doubleArg(1, 6E7))
                .executes(ctx -> 0)
                .then(argument("timeInSeconds", longArg(0, Long.MAX_VALUE / 1000))
                    .executes(ctx -> 0))))
        .then(literal("center")
            .then(argument("pos", vec2())
                .executes(ctx -> 0)))
        .then(literal("damage")
            .then(literal("buffer")
                .then(argument("sizeInBlocks", doubleArg(0))
                    .executes(ctx -> 0)))
            .then(literal("amount")
                .then(argument("damagePerBlock", doubleArg(0))
                    .executes(ctx -> 0))))
        .then(literal("warning")
            .then(literal("time")
                .then(argument("seconds", integer(0))
                    .executes(ctx -> 0)))
            .then(literal("distance")
                .then(argument("warningDistance", integer(0)))))
        .then(literal("get")
            .executes(ctx -> 0))
        .then(literal("add")
            .then(argument("sizeInBlocks", doubleArg(-6E7, 6E7))
                .executes(ctx -> 0)
                .then(argument("timeInSeconds", longArg(0, Long.MAX_VALUE / 1000))
                    .executes(ctx -> 0)))));
}
 
Example #21
Source File: SpawnpointCommand.java    From multiconnect with MIT License 5 votes vote down vote up
public static void register(CommandDispatcher<CommandSource> dispatcher) {
    dispatcher.register(literal("spawnpoint")
        .executes(ctx -> 0)
        .then(argument("player", players())
            .executes(ctx -> 0)
            .then(argument("pos", blockPos())
                .executes(ctx -> 0))));
}
 
Example #22
Source File: TriggerCommand.java    From multiconnect with MIT License 5 votes vote down vote up
public static void register(CommandDispatcher<CommandSource> dispatcher) {
    dispatcher.register(literal("trigger")
        .then(argument("objective", word())
            .suggests(SuggestionProviders.ASK_SERVER)
            .then(literal("add")
                .then(argument("value", integer())
                    .executes(ctx -> 0)))
            .then(literal("set")
                .then(argument("value", integer())
                    .executes(ctx -> 0)))));
}
 
Example #23
Source File: FunctionCommand.java    From multiconnect with MIT License 5 votes vote down vote up
public static void register(CommandDispatcher<CommandSource> dispatcher) {
    dispatcher.register(literal("function")
        .then(argument("name", identifier())
            .suggests(SuggestionProviders.ASK_SERVER)
            .executes(ctx -> 0)
            .then(literal("if")
                .then(argument("selector", entities())
                    .executes(ctx -> 0)))
            .then(literal("unless")
                .then(argument("selector", entities())
                    .executes(ctx -> 0)))));
}
 
Example #24
Source File: TestForBlocksCommand.java    From multiconnect with MIT License 5 votes vote down vote up
public static void register(CommandDispatcher<CommandSource> dispatcher) {
    dispatcher.register(literal("testforblocks")
        .then(argument("pos1", blockPos())
            .then(argument("pos2", blockPos())
                .then(argument("pos", blockPos())
                    .executes(ctx -> 0)
                    .then(argument("mode", enumArg("masked", "all"))
                        .executes(ctx -> 0))))));
}
 
Example #25
Source File: ScoreboardCommand.java    From multiconnect with MIT License 5 votes vote down vote up
private static CommandNode<CommandSource> addPlayerList(ArgumentBuilder<CommandSource, ?> parentBuilder) {
    CommandNode<CommandSource> parent = parentBuilder.executes(ctx -> 0).build();
    CommandNode<CommandSource> child = argument("player", entities())
            .executes(ctx -> 0)
            .redirect(parent)
            .build();
    parent.addChild(child);
    return parent;
}
 
Example #26
Source File: ClearCommand.java    From multiconnect with MIT License 5 votes vote down vote up
public static void register(CommandDispatcher<CommandSource> dispatcher) {
    dispatcher.register(literal("clear")
        .executes(ctx -> 0)
        .then(argument("player", players())
            .executes(ctx -> 0)
            .then(argument("item", item())
                .executes(ctx -> 0)
                .then(argument("damage", integer(-1))
                    .executes(ctx -> 0)
                    .then(argument("maxCount", integer(-1))
                        .executes(ctx -> 0)
                        .then(argument("nbt", nbtCompound())
                            .executes(ctx -> 0)))))));
}
 
Example #27
Source File: SetblockCommand.java    From multiconnect with MIT License 5 votes vote down vote up
public static void register(CommandDispatcher<CommandSource> dispatcher) {
    dispatcher.register(literal("setblock")
        .then(argument("pos", blockPos())
            .then(argument("block", blockState())
                .executes(ctx -> 0)
                .then(argument("oldBlockHandling", enumArg("replace", "destroy", "keep"))
                    .executes(ctx -> 0)
                    .then(argument("nbt", nbtCompound())
                        .executes(ctx -> 0))))));
}
 
Example #28
Source File: StatsCommand.java    From multiconnect with MIT License 5 votes vote down vote up
private static ArgumentBuilder<CommandSource, ?> set() {
    return literal("set")
            .then(argument("stat", statsType())
                .then(argument("selector", entities())
                    .then(argument("objective", word())
                        .suggests(SuggestionProviders.ASK_SERVER)
                        .executes(ctx -> 0))));
}
 
Example #29
Source File: StatsCommand.java    From multiconnect with MIT License 5 votes vote down vote up
public static void register(CommandDispatcher<CommandSource> dispatcher) {
    dispatcher.register(literal("stats")
        .then(literal("block")
            .then(argument("pos", blockPos())
                .then(set())
                .then(clear())))
        .then(literal("entity")
            .then(argument("target", entities())
                .then(set())
                .then(clear()))));
}
 
Example #30
Source File: GamemodeCommand.java    From multiconnect with MIT License 5 votes vote down vote up
public static void register(CommandDispatcher<CommandSource> dispatcher) {
    dispatcher.register(literal("gamemode")
        .then(argument("mode", union(enumArg("survival", "creative", "adventure", "spectator", "s", "c", "a", "sp"), integer(0, 3)))
            .executes(ctx -> 0)
            .then(argument("target", players())
                .executes(ctx -> 0))));
}