org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer#com.mojang.brigadier.CommandDispatcher源码实例Demo

下面列出了org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer#com.mojang.brigadier.CommandDispatcher 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@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();
    }
}
 
源代码2 项目: multiconnect   文件: RecipeCommand.java
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)))));
}
 
源代码3 项目: spark   文件: FabricSparkPlugin.java
public static <T> void registerCommands(CommandDispatcher<T> dispatcher, Command<T> executor, SuggestionProvider<T> suggestor, String... aliases) {
    if (aliases.length == 0) {
        return;
    }

    String mainName = aliases[0];
    LiteralArgumentBuilder<T> command = LiteralArgumentBuilder.<T>literal(mainName)
            .executes(executor)
            .then(RequiredArgumentBuilder.<T, String>argument("args", StringArgumentType.greedyString())
                    .suggests(suggestor)
                    .executes(executor)
            );

    LiteralCommandNode<T> node = dispatcher.register(command);
    for (int i = 1; i < aliases.length; i++) {
        dispatcher.register(LiteralArgumentBuilder.<T>literal(aliases[i]).redirect(node));
    }
}
 
源代码4 项目: spark   文件: ForgeServerSparkPlugin.java
public static void register(ForgeSparkMod mod, FMLServerStartingEvent event) {
    MinecraftServer server = event.getServer();
    ForgeServerSparkPlugin plugin = new ForgeServerSparkPlugin(mod, server);

    CommandDispatcher<CommandSource> dispatcher = event.getCommandDispatcher();
    registerCommands(dispatcher, plugin, plugin, "spark");
    PermissionAPI.registerNode("spark", DefaultPermissionLevel.OP, "Access to the spark command");
}
 
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);
}
 
源代码6 项目: fabric-carpet   文件: CameraModeCommand.java
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
{
    LiteralArgumentBuilder<ServerCommandSource> camera = literal("c").
            requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandCameramode)).
            executes((c) -> cameraMode(c.getSource(), c.getSource().getPlayer())).
            then(argument("player", EntityArgumentType.player()).
                    executes( (c) -> cameraMode(c.getSource(), EntityArgumentType.getPlayer(c, "player"))));

    LiteralArgumentBuilder<ServerCommandSource> survival = literal("s").
            requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandCameramode)).
            executes((c) -> survivalMode(
                    c.getSource(),
                    c.getSource().getPlayer())).
            then(argument("player", EntityArgumentType.player()).
                    executes( (c) -> survivalMode(c.getSource(), EntityArgumentType.getPlayer(c, "player"))));

    dispatcher.register(camera);
    dispatcher.register(survival);
}
 
源代码7 项目: multiconnect   文件: WhitelistCommand.java
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)));
}
 
源代码8 项目: fabric-carpet   文件: CounterCommand.java
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
{
    LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = CommandManager.literal("counter").executes((context)
     -> listAllCounters(context.getSource(), false)).requires((player) ->
            CarpetSettings.hopperCounters);

    literalargumentbuilder.
            then((CommandManager.literal("reset").executes( (p_198489_1_)->
                    resetCounter(p_198489_1_.getSource(), null))));
    for (DyeColor enumDyeColor: DyeColor.values())
    {
        String color = enumDyeColor.toString();
        literalargumentbuilder.
                then((CommandManager.literal(color).executes( (p_198489_1_)-> displayCounter(p_198489_1_.getSource(), color, false))));
        literalargumentbuilder.then(CommandManager.literal(color).
                then(CommandManager.literal("reset").executes((context) ->
                        resetCounter(context.getSource(), color))));
        literalargumentbuilder.then(CommandManager.literal(color).
                then(CommandManager.literal("realtime").executes((context) ->
                        displayCounter(context.getSource(), color, true))));
    }
    dispatcher.register(literalargumentbuilder);
}
 
源代码9 项目: multiconnect   文件: TitleCommand.java
public static void register(CommandDispatcher<CommandSource> dispatcher) {
    dispatcher.register(literal("title")
        .then(argument("player", players())
            .then(literal("title")
                .then(argument("value", text())
                    .executes(ctx -> 0)))
            .then(literal("subtitle")
                .then(argument("value", text())
                    .executes(ctx -> 0)))
            .then(literal("actionbar")
                .then(argument("value", text())
                    .executes(ctx -> 0)))
            .then(literal("clear")
                .executes(ctx -> 0))
            .then(literal("reset")
                .executes(ctx -> 0))
            .then(literal("times")
                .then(argument("fadeIn", integer())
                    .then(argument("stay", integer())
                        .then(argument("fadeOut", integer())
                            .executes(ctx -> 0)))))));
}
 
源代码10 项目: spark   文件: ForgeSparkPlugin.java
public static <T> void registerCommands(CommandDispatcher<T> dispatcher, Command<T> executor, SuggestionProvider<T> suggestor, String... aliases) {
    if (aliases.length == 0) {
        return;
    }

    String mainName = aliases[0];
    LiteralArgumentBuilder<T> command = LiteralArgumentBuilder.<T>literal(mainName)
            .executes(executor)
            .then(RequiredArgumentBuilder.<T, String>argument("args", StringArgumentType.greedyString())
                    .suggests(suggestor)
                    .executes(executor)
            );

    LiteralCommandNode<T> node = dispatcher.register(command);
    for (int i = 1; i < aliases.length; i++) {
        dispatcher.register(LiteralArgumentBuilder.<T>literal(aliases[i]).redirect(node));
    }
}
 
源代码11 项目: spark   文件: FabricClientSparkPlugin.java
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();
    }
}
 
源代码12 项目: multiconnect   文件: PlaySoundCommand.java
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)))))))));
    }
}
 
源代码13 项目: fabric-carpet   文件: CarpetServer.java
public static void registerCarpetCommands(CommandDispatcher<ServerCommandSource> dispatcher)
{
    TickCommand.register(dispatcher);
    ProfileCommand.register(dispatcher);
    CounterCommand.register(dispatcher);
    LogCommand.register(dispatcher);
    SpawnCommand.register(dispatcher);
    PlayerCommand.register(dispatcher);
    CameraModeCommand.register(dispatcher);
    InfoCommand.register(dispatcher);
    DistanceCommand.register(dispatcher);
    PerimeterInfoCommand.register(dispatcher);
    DrawCommand.register(dispatcher);
    ScriptCommand.register(dispatcher);
    MobAICommand.register(dispatcher);
    // registering command of extensions that has registered before either server is created
    // for all other, they will have them registered when they add themselves
    extensions.forEach(e -> e.registerCommands(dispatcher));
    currentCommandDispatcher = dispatcher;
    
    if (FabricLoader.getInstance().isDevelopmentEnvironment())
        TestCommand.register(dispatcher);
}
 
源代码14 项目: fabric-carpet   文件: PerimeterInfoCommand.java
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
{
    LiteralArgumentBuilder<ServerCommandSource> command = literal("perimeterinfo").
            requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandPerimeterInfo)).
            executes( (c) -> perimeterDiagnose(
                    c.getSource(),
                    new BlockPos(c.getSource().getPosition()),
                    null)).
            then(argument("center position", BlockPosArgumentType.blockPos()).
                    executes( (c) -> perimeterDiagnose(
                            c.getSource(),
                            BlockPosArgumentType.getBlockPos(c, "center position"),
                            null)).
                    then(argument("mob",EntitySummonArgumentType.entitySummon()).
                            suggests(SuggestionProviders.SUMMONABLE_ENTITIES).
                            executes( (c) -> perimeterDiagnose(
                                    c.getSource(),
                                    BlockPosArgumentType.getBlockPos(c, "center position"),
                                    EntitySummonArgumentType.getEntitySummon(c, "mob").toString()
                            ))));
    dispatcher.register(command);
}
 
源代码15 项目: BoundingBoxOutlineReloaded   文件: ClientInterop.java
public static void registerClientCommands(CommandDispatcher<ISuggestionProvider> commandDispatcher) {
    SeedCommand.register(commandDispatcher);
    SpawningSphereCommand.register(commandDispatcher);
    CustomCommand.register(commandDispatcher);
    ConfigCommand.register(commandDispatcher);
    StructuresCommand.register(commandDispatcher);
}
 
源代码16 项目: BlueMap   文件: Commands.java
public Commands(Plugin plugin, CommandDispatcher<S> dispatcher, Function<S, CommandSource> commandSourceInterface) {
	this.plugin = plugin;
	this.dispatcher = dispatcher;
	this.commandSourceInterface = commandSourceInterface;
	
	this.helper = new CommandHelper(plugin);
	
	init();
}
 
源代码17 项目: multiconnect   文件: Protocol_1_11_2.java
@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);
}
 
源代码18 项目: brigadier   文件: ExecuteBenchmarks.java
@Setup
public void setup() {
    dispatcher = new CommandDispatcher<>();
    dispatcher.register(literal("command").executes(c -> 0));
    dispatcher.register(literal("redirect").redirect(dispatcher.getRoot()));
    dispatcher.register(literal("fork").fork(dispatcher.getRoot(), o -> Lists.newArrayList(new Object(), new Object(), new Object())));
    simple = dispatcher.parse("command", new Object());
    singleRedirect = dispatcher.parse("redirect command", new Object());
    forkedRedirect = dispatcher.parse("fork command", new Object());
}
 
源代码19 项目: multiconnect   文件: GiveCommand.java
public static void register(CommandDispatcher<CommandSource> dispatcher) {
    dispatcher.register(literal("give")
        .then(argument("player", players())
            .then(argument("item", item())
                .executes(ctx -> 0)
                .then(argument("count", integer(1, 64))
                    .executes(ctx -> 0)
                    .then(argument("damage", integer(0, Short.MAX_VALUE))
                        .executes(ctx -> 0)
                        .then(argument("nbt", nbtCompound())
                            .executes(ctx -> 0)))))));
}
 
源代码20 项目: multiconnect   文件: TestForBlockCommand.java
public static void register(CommandDispatcher<CommandSource> dispatcher) {
    dispatcher.register(literal("testforblock")
        .then(argument("pos", blockPos())
            .then(argument("block", testBlockState())
                .executes(ctx -> 0)
                .then(argument("nbt", nbtCompound())
                    .executes(ctx -> 0)))));
}
 
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);
}
 
源代码22 项目: multiconnect   文件: Commands_1_12_2.java
public static void registerAll(CommandDispatcher<CommandSource> dispatcher, Set<String> serverCommands) {
    ((Protocol_1_12_2) ConnectionInfo.protocol).registerCommands(dispatcher, serverCommands);

    if (serverCommands != null) {
        for (String command : serverCommands) {
            if (dispatcher.getRoot().getChild(command) == null) {
                dispatcher.register(literal(command)
                        .executes(ctx -> 0)
                        .then(argument("args", StringArgumentType.greedyString())
                                .suggests(SuggestionProviders.ASK_SERVER)
                                .executes(ctx -> 0)));
            }
        }
    }
}
 
源代码23 项目: multiconnect   文件: StopSoundCommand.java
public static void register(CommandDispatcher<CommandSource> dispatcher) {
    dispatcher.register(literal("stopsound")
        .then(argument("player", players())
            .executes(ctx -> 0)
            .then(argument("category", enumArg("master", "music", "record", "weather", "block", "hostile", "neutral", "player", "ambient", "voice"))
                .executes(ctx -> 0)
                .then(argument("sound", identifier())
                    .suggests((ctx, builder) -> CommandSource.suggestIdentifiers(Registry.SOUND_EVENT.getIds(), builder))
                    .executes(ctx -> 0)))));
}
 
源代码24 项目: multiconnect   文件: DebugCommand.java
public static void register(CommandDispatcher<CommandSource> dispatcher) {
    dispatcher.register(literal("debug")
        .then(literal("start")
            .executes(ctx -> 0))
        .then(literal("stop")
            .executes(ctx -> 0)));
}
 
源代码25 项目: multiconnect   文件: EffectCommand.java
public static void register(CommandDispatcher<CommandSource> dispatcher) {
    dispatcher.register(literal("effect")
        .then(argument("target", entities())
            .then(literal("clear")
                .executes(ctx -> 0))
            .then(argument("effect", mobEffect())
                .executes(ctx -> 0)
                .then(argument("seconds", integer(0, 1000000))
                    .executes(ctx -> 0)
                    .then(argument("amplifier", integer(0, 255))
                        .executes(ctx -> 0)
                        .then(argument("hideParticles", bool())
                            .executes(ctx -> 0)))))));
}
 
源代码26 项目: multiconnect   文件: ReplaceItemCommand.java
public static void register(CommandDispatcher<CommandSource> dispatcher) {
    dispatcher.register(literal("replaceitem")
        .then(literal("block")
            .then(argument("pos", blockPos())
                .then(tail())))
        .then(literal("entity")
            .then(argument("target", entities())
                .then(tail()))));
}
 
源代码27 项目: multiconnect   文件: TeleportCommand.java
public static void register(CommandDispatcher<CommandSource> dispatcher) {
    dispatcher.register(literal("teleport")
        .then(argument("victim", entities())
            .then(argument("pos", blockPos())
                .executes(ctx -> 0)
                .then(argument("rot", rotation())
                    .executes(ctx -> 0)))));
}
 
源代码28 项目: spark   文件: ForgeClientSparkPlugin.java
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();
    }
}
 
源代码29 项目: multiconnect   文件: SetblockCommand.java
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))))));
}
 
源代码30 项目: multiconnect   文件: TestForBlocksCommand.java
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))))));
}