Search in sources :

Example 11 with HoverEvent

use of net.minecraft.text.HoverEvent in project meteor-client by MeteorDevelopment.

the class BindsCommand method build.

@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
    builder.executes(context -> {
        // Modules
        List<Module> modules = Modules.get().getAll().stream().filter(module -> module.keybind.isSet()).collect(Collectors.toList());
        ChatUtils.info("--- Bound Modules ((highlight)%d(default)) ---", modules.size());
        for (Module module : modules) {
            HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, getTooltip(module));
            MutableText text = new LiteralText(module.title).formatted(Formatting.WHITE);
            text.setStyle(text.getStyle().withHoverEvent(hoverEvent));
            MutableText sep = new LiteralText(" - ");
            sep.setStyle(sep.getStyle().withHoverEvent(hoverEvent));
            text.append(sep.formatted(Formatting.GRAY));
            MutableText key = new LiteralText(module.keybind.toString());
            key.setStyle(key.getStyle().withHoverEvent(hoverEvent));
            text.append(key.formatted(Formatting.GRAY));
            ChatUtils.sendMsg(text);
        }
        return SINGLE_SUCCESS;
    });
}
Also used : LiteralText(net.minecraft.text.LiteralText) HoverEvent(net.minecraft.text.HoverEvent) Collectors(java.util.stream.Collectors) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) CommandSource(net.minecraft.command.CommandSource) SINGLE_SUCCESS(com.mojang.brigadier.Command.SINGLE_SUCCESS) Formatting(net.minecraft.util.Formatting) List(java.util.List) Command(meteordevelopment.meteorclient.systems.commands.Command) Module(meteordevelopment.meteorclient.systems.modules.Module) Modules(meteordevelopment.meteorclient.systems.modules.Modules) MutableText(net.minecraft.text.MutableText) ChatUtils(meteordevelopment.meteorclient.utils.player.ChatUtils) Utils(meteordevelopment.meteorclient.utils.Utils) MutableText(net.minecraft.text.MutableText) HoverEvent(net.minecraft.text.HoverEvent) Module(meteordevelopment.meteorclient.systems.modules.Module) LiteralText(net.minecraft.text.LiteralText)

Example 12 with HoverEvent

use of net.minecraft.text.HoverEvent in project meteor-client by MeteorDevelopment.

the class CommandsCommand method getCommandText.

private BaseText getCommandText(Command command) {
    // Hover tooltip
    BaseText tooltip = new LiteralText("");
    tooltip.append(new LiteralText(Utils.nameToTitle(command.getName())).formatted(Formatting.BLUE, Formatting.BOLD)).append("\n");
    BaseText aliases = new LiteralText(Config.get().prefix.get() + command.getName());
    if (command.getAliases().size() > 0) {
        aliases.append(", ");
        for (String alias : command.getAliases()) {
            if (alias.isEmpty())
                continue;
            aliases.append(Config.get().prefix.get() + alias);
            if (!alias.equals(command.getAliases().get(command.getAliases().size() - 1)))
                aliases.append(", ");
        }
    }
    tooltip.append(aliases.formatted(Formatting.GRAY)).append("\n\n");
    tooltip.append(new LiteralText(command.getDescription()).formatted(Formatting.WHITE));
    // Text
    BaseText text = new LiteralText(Utils.nameToTitle(command.getName()));
    if (command != Commands.get().getAll().get(Commands.get().getAll().size() - 1))
        text.append(new LiteralText(", ").formatted(Formatting.GRAY));
    text.setStyle(text.getStyle().withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, tooltip)).withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, Config.get().prefix.get() + command.getName())));
    return text;
}
Also used : BaseText(net.minecraft.text.BaseText) HoverEvent(net.minecraft.text.HoverEvent) ClickEvent(net.minecraft.text.ClickEvent) LiteralText(net.minecraft.text.LiteralText)

Example 13 with HoverEvent

use of net.minecraft.text.HoverEvent 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)

Example 14 with HoverEvent

use of net.minecraft.text.HoverEvent in project fabric-name-history-lookup by Woolyenough.

the class ClientCommands method namemc.

private static int namemc(CommandContext<FabricClientCommandSource> context) {
    CompletableFuture.runAsync(() -> {
        String name = context.getInput().split(" ")[1];
        String[] playerNameAndUUID = get_player_name_and_uuid(name);
        String username = playerNameAndUUID[0];
        if (Objects.equals(username, "None")) {
            context.getSource().sendFeedback(new LiteralText("§7[Click] §eSearch " + name + " on NameMC §c§o(account does not exist)").styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://namemc.com/profile/" + name)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(name + "\n\n§7§oClick to open NameMC")))));
        } else {
            context.getSource().sendFeedback(new LiteralText("§7[Click] §eLook at " + username + "'s NameMC page").styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://namemc.com/profile/" + username)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(username + "\n\n§7§oClick to open NameMC")))));
        }
    });
    return 0;
}
Also used : ClientModInitializer(net.fabricmc.api.ClientModInitializer) LiteralText(net.minecraft.text.LiteralText) java.util(java.util) CommandContext(com.mojang.brigadier.context.CommandContext) FabricClientCommandSource(net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource) Environment(net.fabricmc.api.Environment) CompletableFuture(java.util.concurrent.CompletableFuture) EntityArgumentType(net.minecraft.command.argument.EntityArgumentType) HoverEvent(net.minecraft.text.HoverEvent) ClientCommandManager(net.fabricmc.fabric.api.client.command.v1.ClientCommandManager) ClickEvent(net.minecraft.text.ClickEvent) EnvType(net.fabricmc.api.EnvType) MojangAPI(net.woolyenough.namelookup.modules.MojangAPI) HoverEvent(net.minecraft.text.HoverEvent) ClickEvent(net.minecraft.text.ClickEvent) LiteralText(net.minecraft.text.LiteralText)

Example 15 with HoverEvent

use of net.minecraft.text.HoverEvent in project meteor-rejects by AntiCope.

the class Seeds method sendInvalidVersionWarning.

private static void sendInvalidVersionWarning(String seed, String targetVer) {
    BaseText msg = new LiteralText(String.format("Couldn't resolve minecraft version \"%s\". Using %s instead. If you wish to change the version run: ", targetVer, MCVersion.latest().name));
    String cmd = String.format("%sseed %s ", Config.get().prefix, seed);
    BaseText cmdText = new LiteralText(cmd + "<version>");
    cmdText.setStyle(cmdText.getStyle().withUnderline(true).withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, cmd)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("run command"))));
    msg.append(cmdText);
    msg.setStyle(msg.getStyle().withColor(Formatting.YELLOW));
    ChatUtils.sendMsg("Seed", msg);
}
Also used : BaseText(net.minecraft.text.BaseText) HoverEvent(net.minecraft.text.HoverEvent) ClickEvent(net.minecraft.text.ClickEvent) LiteralText(net.minecraft.text.LiteralText)

Aggregations

HoverEvent (net.minecraft.text.HoverEvent)23 LiteralText (net.minecraft.text.LiteralText)23 ClickEvent (net.minecraft.text.ClickEvent)13 BaseText (net.minecraft.text.BaseText)9 ItemStack (net.minecraft.item.ItemStack)7 MutableText (net.minecraft.text.MutableText)7 Formatting (net.minecraft.util.Formatting)7 CommandSource (net.minecraft.command.CommandSource)6 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)5 Text (net.minecraft.text.Text)5 SINGLE_SUCCESS (com.mojang.brigadier.Command.SINGLE_SUCCESS)4 IntegerArgumentType (com.mojang.brigadier.arguments.IntegerArgumentType)4 NbtCompound (net.minecraft.nbt.NbtCompound)4 CommandContext (com.mojang.brigadier.context.CommandContext)3 java.util (java.util)3 NbtPathArgumentType (net.minecraft.command.argument.NbtPathArgumentType)3 CreativeInventoryActionC2SPacket (net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket)3 Command (org.bleachhack.command.Command)3 BleachLogger (org.bleachhack.util.BleachLogger)3 CommandDispatcher (com.mojang.brigadier.CommandDispatcher)2