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");
}
Aggregations