Search in sources :

Example 1 with Discarpet

use of Discarpet.Discarpet in project carpet-discarpet by replaceitem.

the class DiscarpetCommand method register.

public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
    dispatcher.register(literal("discarpet").requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(2)).executes(commandContext -> {
        String version = FabricLoader.getInstance().getModContainer("discarpet").get().getMetadata().getVersion().getFriendlyString();
        MutableText text = new LiteralText("Discarpet version " + version).formatted(Formatting.BLUE);
        text.append("\nFor help, see the ");
        text.append(new LiteralText("documentation").setStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://github.com/replaceitem/carpet-discarpet/blob/master/docs/Full.md")).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to get to the Discarpet documentation"))).withFormatting(Formatting.UNDERLINE).withColor(Formatting.DARK_BLUE)));
        commandContext.getSource().sendFeedback(text, true);
        return 1;
    }).then(literal("list").executes(commandContext -> {
        Set<String> botIDs = Discarpet.discordBots.keySet();
        final LiteralText t;
        if (botIDs.size() == 0) {
            t = (LiteralText) new LiteralText("There are no bots active:\n").formatted(Formatting.RED);
        } else {
            t = (LiteralText) new LiteralText("There are " + botIDs.size() + " bots active\n").formatted(Formatting.GREEN);
        }
        botIDs.forEach(id -> t.append(new LiteralText(id + "\n").formatted(Formatting.BLUE)));
        commandContext.getSource().sendFeedback(t, true);
        return botIDs.size();
    })).then(literal("getInvite").then(CommandManager.argument("id", StringArgumentType.string()).suggests(BOTS).executes(commandContext -> {
        String id = StringArgumentType.getString(commandContext, "id");
        String invite = Discarpet.discordBots.get(id).getInvite();
        Text text = ((new LiteralText("Click here to get the invite link for the bot")).styled((style) -> {
            return style.withColor(Formatting.BLUE).withFormatting(Formatting.UNDERLINE).withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, invite)).withHoverEvent(new HoverEvent(net.minecraft.text.HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to open the invite link"))).withInsertion(invite);
        }));
        commandContext.getSource().sendFeedback(text, false);
        return 1;
    }))).then(literal("reload").executes(commandContext -> {
        Discarpet.loadConfig(commandContext.getSource());
        return 1;
    })));
}
Also used : Discarpet(Discarpet.Discarpet) FabricLoader(net.fabricmc.loader.api.FabricLoader) LiteralText(net.minecraft.text.LiteralText) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) Set(java.util.Set) CommandManager.literal(net.minecraft.server.command.CommandManager.literal) HoverEvent(net.minecraft.text.HoverEvent) CommandManager(net.minecraft.server.command.CommandManager) CommandSource(net.minecraft.command.CommandSource) StringArgumentType(com.mojang.brigadier.arguments.StringArgumentType) Style(net.minecraft.text.Style) Formatting(net.minecraft.util.Formatting) ClickEvent(net.minecraft.text.ClickEvent) MutableText(net.minecraft.text.MutableText) Text(net.minecraft.text.Text) SuggestionProvider(com.mojang.brigadier.suggestion.SuggestionProvider) MutableText(net.minecraft.text.MutableText) HoverEvent(net.minecraft.text.HoverEvent) ClickEvent(net.minecraft.text.ClickEvent) LiteralText(net.minecraft.text.LiteralText) MutableText(net.minecraft.text.MutableText) Text(net.minecraft.text.Text) LiteralText(net.minecraft.text.LiteralText)

Aggregations

Discarpet (Discarpet.Discarpet)1 CommandDispatcher (com.mojang.brigadier.CommandDispatcher)1 StringArgumentType (com.mojang.brigadier.arguments.StringArgumentType)1 SuggestionProvider (com.mojang.brigadier.suggestion.SuggestionProvider)1 Set (java.util.Set)1 FabricLoader (net.fabricmc.loader.api.FabricLoader)1 CommandSource (net.minecraft.command.CommandSource)1 CommandManager (net.minecraft.server.command.CommandManager)1 CommandManager.literal (net.minecraft.server.command.CommandManager.literal)1 ServerCommandSource (net.minecraft.server.command.ServerCommandSource)1 ClickEvent (net.minecraft.text.ClickEvent)1 HoverEvent (net.minecraft.text.HoverEvent)1 LiteralText (net.minecraft.text.LiteralText)1 MutableText (net.minecraft.text.MutableText)1 Style (net.minecraft.text.Style)1 Text (net.minecraft.text.Text)1 Formatting (net.minecraft.util.Formatting)1