Search in sources :

Example 1 with Identified

use of net.kyori.adventure.identity.Identified in project SpongeCommon by SpongePowered.

the class ChatTest method registerCommands.

@Listener
public void registerCommands(final RegisterCommandEvent<Command.Parameterized> event) {
    // /togglebossbar
    event.register(this.container, Command.builder().permission("chattest.togglebossbar").executor(ctx -> {
        if (this.barVisible) {
            this.game.server().hideBossBar(ChatTest.INFO_BAR);
        } else {
            this.game.server().showBossBar(ChatTest.INFO_BAR);
        }
        this.barVisible = !this.barVisible;
        return CommandResult.success();
    }).build(), "togglebossbar");
    event.register(this.container, Command.builder().permission("chattest.sendbook").executor(ctx -> {
        ctx.cause().audience().openBook(Book.builder().title(Component.text("A story")).author(Component.text("You")).pages(Component.translatable("chattest.book.1"), Component.translatable("chattest.book.2")));
        return CommandResult.success();
    }).build(), "sendbook");
    final Parameter.Value<ServerPlayer> targetArg = Parameter.player().key("target").build();
    final Parameter.Value<Component> messageArg = Parameter.jsonText().key("message").build();
    event.register(this.container, Command.builder().permission("chatttest.tell-resolve").addParameters(targetArg, messageArg).executor(ctx -> {
        final ServerPlayer target = ctx.requireOne(targetArg);
        final Component message = ctx.requireOne(messageArg);
        final Component resolvedMessage = SpongeComponents.resolve(message, ctx.cause(), target, ResolveOperations.CONTEXTUAL_COMPONENTS);
        target.sendMessage(ctx.cause().first(Identified.class).map(Identified::identity).orElse(Identity.nil()), resolvedMessage);
        return CommandResult.success();
    }).build(), "tellresolve");
}
Also used : Identified(net.kyori.adventure.identity.Identified) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) Parameter(org.spongepowered.api.command.parameter.Parameter) Component(net.kyori.adventure.text.Component) Listener(org.spongepowered.api.event.Listener)

Aggregations

Identified (net.kyori.adventure.identity.Identified)1 Component (net.kyori.adventure.text.Component)1 Parameter (org.spongepowered.api.command.parameter.Parameter)1 ServerPlayer (org.spongepowered.api.entity.living.player.server.ServerPlayer)1 Listener (org.spongepowered.api.event.Listener)1