Search in sources :

Example 1 with TextParseException

use of org.spongepowered.api.text.serializer.TextParseException in project LanternServer by LanternPowered.

the class CommandTitle method completeSpec.

@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
    specBuilder.arguments(GenericArguments.playerOrSource(Text.of("player"))).child(CommandSpec.builder().executor((src, args) -> {
        args.<Player>getOne("player").get().clearTitle();
        src.sendMessage(t("commands.title.success"));
        return CommandResult.success();
    }).build(), "clear").child(CommandSpec.builder().arguments(GenericArguments2.remainingString(Text.of("title"))).executor((src, args) -> {
        Text title;
        try {
            title = TextSerializers.JSON.deserialize(args.<String>getOne("title").get());
        } catch (TextParseException e) {
            throw new CommandException(t("commands.tellraw.jsonException", e.getMessage()));
        }
        args.<Player>getOne("player").get().sendTitle(Title.builder().title(title).build());
        src.sendMessage(t("commands.title.success"));
        return CommandResult.success();
    }).build(), "title").child(CommandSpec.builder().arguments(GenericArguments2.remainingString(Text.of("title"))).executor((src, args) -> {
        Text title;
        try {
            title = TextSerializers.JSON.deserialize(args.<String>getOne("title").get());
        } catch (TextParseException e) {
            throw new CommandException(t("commands.tellraw.jsonException", e.getMessage()));
        }
        args.<Player>getOne("player").get().sendTitle(Title.builder().subtitle(title).build());
        src.sendMessage(t("commands.title.success"));
        return CommandResult.success();
    }).build(), "subtitle").child(CommandSpec.builder().executor((src, args) -> {
        args.<Player>getOne("player").get().resetTitle();
        src.sendMessage(t("commands.title.success"));
        return CommandResult.success();
    }).build(), "reset").child(CommandSpec.builder().arguments(GenericArguments.integer(Text.of("fadeIn")), GenericArguments.integer(Text.of("stay")), GenericArguments.integer(Text.of("fadeOut"))).executor((src, args) -> {
        args.<Player>getOne("player").get().sendTitle(Title.builder().fadeIn(args.<Integer>getOne("fadeIn").get()).stay(args.<Integer>getOne("stay").get()).fadeOut(args.<Integer>getOne("fadeOut").get()).build());
        src.sendMessage(t("commands.title.success"));
        return CommandResult.success();
    }).build(), "times");
}
Also used : CommandException(org.spongepowered.api.command.CommandException) CommandResult(org.spongepowered.api.command.CommandResult) TextSerializers(org.spongepowered.api.text.serializer.TextSerializers) Text(org.spongepowered.api.text.Text) TranslationHelper.t(org.lanternpowered.server.text.translation.TranslationHelper.t) GenericArguments2(org.lanternpowered.server.command.element.GenericArguments2) Title(org.spongepowered.api.text.title.Title) Player(org.spongepowered.api.entity.living.player.Player) TextParseException(org.spongepowered.api.text.serializer.TextParseException) GenericArguments(org.spongepowered.api.command.args.GenericArguments) PluginContainer(org.spongepowered.api.plugin.PluginContainer) CommandSpec(org.spongepowered.api.command.spec.CommandSpec) Player(org.spongepowered.api.entity.living.player.Player) Text(org.spongepowered.api.text.Text) CommandException(org.spongepowered.api.command.CommandException) TextParseException(org.spongepowered.api.text.serializer.TextParseException)

Aggregations

GenericArguments2 (org.lanternpowered.server.command.element.GenericArguments2)1 TranslationHelper.t (org.lanternpowered.server.text.translation.TranslationHelper.t)1 CommandException (org.spongepowered.api.command.CommandException)1 CommandResult (org.spongepowered.api.command.CommandResult)1 GenericArguments (org.spongepowered.api.command.args.GenericArguments)1 CommandSpec (org.spongepowered.api.command.spec.CommandSpec)1 Player (org.spongepowered.api.entity.living.player.Player)1 PluginContainer (org.spongepowered.api.plugin.PluginContainer)1 Text (org.spongepowered.api.text.Text)1 TextParseException (org.spongepowered.api.text.serializer.TextParseException)1 TextSerializers (org.spongepowered.api.text.serializer.TextSerializers)1 Title (org.spongepowered.api.text.title.Title)1