Search in sources :

Example 16 with ClickEvent

use of net.minecraft.text.ClickEvent 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 17 with ClickEvent

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

Example 18 with ClickEvent

use of net.minecraft.text.ClickEvent in project Client by MatHax.

the class NbtCommand method build.

@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
    builder.then(literal("add").then(argument("nbt_data", CompoundNbtTagArgumentType.nbtTag()).executes(s -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (validBasic(stack)) {
            NbtCompound tag = CompoundNbtTagArgumentType.getNbt(s, "nbt_data");
            NbtCompound source = stack.getOrCreateNbt();
            if (tag != null) {
                source.copyFrom(tag);
                setStack(stack);
            } else {
                error("Some of the NBT data could not be found, try using: " + Config.get().prefix + "nbt set {nbt}");
            }
        }
        return SINGLE_SUCCESS;
    })));
    builder.then(literal("set").then(argument("nbt_data", CompoundNbtTagArgumentType.nbtTag()).executes(s -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (validBasic(stack)) {
            NbtCompound tag = s.getArgument("nbt_data", NbtCompound.class);
            stack.setNbt(tag);
            setStack(stack);
        }
        return SINGLE_SUCCESS;
    })));
    builder.then(literal("remove").then(argument("nbt_path", NbtPathArgumentType.nbtPath()).executes(s -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (validBasic(stack)) {
            NbtPathArgumentType.NbtPath path = s.getArgument("nbt_path", NbtPathArgumentType.NbtPath.class);
            path.remove(stack.getNbt());
        }
        return SINGLE_SUCCESS;
    })));
    builder.then(literal("get").executes(s -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (stack == null) {
            error("You must hold an item in your main hand.");
        } else {
            NbtCompound tag = stack.getNbt();
            String nbt = tag == null ? "{}" : tag.asString();
            BaseText copyButton = new LiteralText("NBT");
            copyButton.setStyle(copyButton.getStyle().withFormatting(Formatting.UNDERLINE).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, this.toString("copy"))).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Copy the NBT data to your clipboard."))));
            BaseText text = new LiteralText("");
            text.append(copyButton);
            text.append(new LiteralText(": " + nbt));
            info(text);
        }
        return SINGLE_SUCCESS;
    }));
    builder.then(literal("copy").executes(s -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (stack == null) {
            error("You must hold an item in your main hand.");
        } else {
            NbtCompound tag = stack.getOrCreateNbt();
            mc.keyboard.setClipboard(tag.toString());
            BaseText nbt = new LiteralText("NBT");
            nbt.setStyle(nbt.getStyle().withFormatting(Formatting.UNDERLINE).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(tag.toString()))));
            BaseText text = new LiteralText("");
            text.append(nbt);
            text.append(new LiteralText(" data copied!"));
            info(text);
        }
        return SINGLE_SUCCESS;
    }));
    builder.then(literal("count").then(argument("count", IntegerArgumentType.integer(-127, 127)).executes(context -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (validBasic(stack)) {
            int count = IntegerArgumentType.getInteger(context, "count");
            stack.setCount(count);
            setStack(stack);
            info("Set mainhand stack count to %s.", count);
        }
        return SINGLE_SUCCESS;
    })));
}
Also used : LiteralText(net.minecraft.text.LiteralText) CompoundNbtTagArgumentType(mathax.client.systems.commands.arguments.CompoundNbtTagArgumentType) CreativeInventoryActionC2SPacket(net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket) HoverEvent(net.minecraft.text.HoverEvent) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) Config(mathax.client.systems.config.Config) CommandSource(net.minecraft.command.CommandSource) SINGLE_SUCCESS(com.mojang.brigadier.Command.SINGLE_SUCCESS) ItemStack(net.minecraft.item.ItemStack) NbtCompound(net.minecraft.nbt.NbtCompound) BaseText(net.minecraft.text.BaseText) Formatting(net.minecraft.util.Formatting) NbtPathArgumentType(net.minecraft.command.argument.NbtPathArgumentType) ClickEvent(net.minecraft.text.ClickEvent) Command(mathax.client.systems.commands.Command) IntegerArgumentType(com.mojang.brigadier.arguments.IntegerArgumentType) BaseText(net.minecraft.text.BaseText) HoverEvent(net.minecraft.text.HoverEvent) NbtCompound(net.minecraft.nbt.NbtCompound) NbtPathArgumentType(net.minecraft.command.argument.NbtPathArgumentType) ClickEvent(net.minecraft.text.ClickEvent) ItemStack(net.minecraft.item.ItemStack) LiteralText(net.minecraft.text.LiteralText)

Example 19 with ClickEvent

use of net.minecraft.text.ClickEvent in project Hypnotic-Client by Hypnotic-Development.

the class NBT method build.

@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
    builder.then(literal("add").then(argument("nbt_data", CompoundNbtTagArgumentType.nbtTag()).executes(s -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (validBasic(stack)) {
            NbtCompound tag = CompoundNbtTagArgumentType.getTag(s, "nbt_data");
            NbtCompound source = stack.getNbt();
            if (tag != null && source != null) {
                stack.getNbt().copyFrom(tag);
                setStack(stack);
            } else {
                error("Some of the NBT data could not be found, try using: " + CommandManager.INSTANCE.getPrefix() + "nbt set {nbt}");
            }
        }
        return SINGLE_SUCCESS;
    })));
    builder.then(literal("set").then(argument("nbt_data", CompoundNbtTagArgumentType.nbtTag()).executes(s -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (validBasic(stack)) {
            NbtCompound tag = s.getArgument("nbt_data", NbtCompound.class);
            stack.setNbt(tag);
            setStack(stack);
        }
        return SINGLE_SUCCESS;
    })));
    builder.then(literal("remove").then(argument("nbt_path", NbtPathArgumentType.nbtPath()).executes(s -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (validBasic(stack)) {
            NbtPathArgumentType.NbtPath path = s.getArgument("nbt_path", NbtPathArgumentType.NbtPath.class);
            path.remove(stack.getNbt());
        }
        return SINGLE_SUCCESS;
    })));
    builder.then(literal("get").executes(s -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (stack == null) {
            error("You must hold an item in your main hand.");
        } else {
            NbtCompound tag = stack.getNbt();
            String nbt = tag == null ? "none" : tag.asString();
            BaseText copyButton = new LiteralText("NBT");
            copyButton.setStyle(copyButton.getStyle().withFormatting(Formatting.UNDERLINE).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, this.toString("copy"))).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Copy the NBT data to your clipboard."))));
            BaseText text = new LiteralText("");
            text.append(copyButton);
            text.append(new LiteralText(": " + nbt));
            info(text);
        }
        return SINGLE_SUCCESS;
    }));
    builder.then(literal("copy").executes(s -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (stack == null) {
            error("You must hold an item in your main hand.");
        } else {
            NbtCompound tag = stack.getNbt();
            if (tag == null)
                error("No NBT data on this item.");
            else {
                mc.keyboard.setClipboard(tag.toString());
                BaseText nbt = new LiteralText("NBT");
                nbt.setStyle(nbt.getStyle().withFormatting(Formatting.UNDERLINE).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(tag.toString()))));
                BaseText text = new LiteralText("");
                text.append(nbt);
                text.append(new LiteralText(" data copied!"));
                info(text);
            }
        }
        return SINGLE_SUCCESS;
    }));
    builder.then(literal("count").then(argument("count", IntegerArgumentType.integer(-127, 127)).executes(context -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (validBasic(stack)) {
            int count = IntegerArgumentType.getInteger(context, "count");
            stack.setCount(count);
            setStack(stack);
            info("Set mainhand stack count to " + count);
        }
        return SINGLE_SUCCESS;
    })));
}
Also used : LiteralText(net.minecraft.text.LiteralText) CreativeInventoryActionC2SPacket(net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket) HoverEvent(net.minecraft.text.HoverEvent) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) CompoundNbtTagArgumentType(dev.hypnotic.command.argtypes.CompoundNbtTagArgumentType) CommandSource(net.minecraft.command.CommandSource) ItemStack(net.minecraft.item.ItemStack) NbtCompound(net.minecraft.nbt.NbtCompound) BaseText(net.minecraft.text.BaseText) Formatting(net.minecraft.util.Formatting) NbtPathArgumentType(net.minecraft.command.argument.NbtPathArgumentType) ClickEvent(net.minecraft.text.ClickEvent) IntegerArgumentType(com.mojang.brigadier.arguments.IntegerArgumentType) CommandManager(dev.hypnotic.command.CommandManager) Command(dev.hypnotic.command.Command) BaseText(net.minecraft.text.BaseText) HoverEvent(net.minecraft.text.HoverEvent) NbtCompound(net.minecraft.nbt.NbtCompound) NbtPathArgumentType(net.minecraft.command.argument.NbtPathArgumentType) ClickEvent(net.minecraft.text.ClickEvent) ItemStack(net.minecraft.item.ItemStack) LiteralText(net.minecraft.text.LiteralText)

Example 20 with ClickEvent

use of net.minecraft.text.ClickEvent in project Hypnotic-Client by Hypnotic-Development.

the class About method build.

@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
    builder.executes(context -> {
        ChatUtils.tellPlayerRaw(ColorUtils.red + "\n\u00A7l\u00A7nHypnotic\n");
        ChatUtils.tellPlayerRaw(ColorUtils.red + "Current build" + ColorUtils.gray + ": " + Hypnotic.version);
        ChatUtils.tellPlayerRaw(ColorUtils.red + "Modules" + ColorUtils.gray + ": " + ModuleManager.INSTANCE.modules.size());
        ChatUtils.tellPlayerRaw(ColorUtils.red + "Commands" + ColorUtils.gray + ": " + CommandManager.INSTANCE.getCommands().size());
        ChatUtils.tellPlayerRaw(new LiteralText(ColorUtils.red + "Website" + ColorUtils.gray + ": ").append(ChatUtils.clickableText(ColorUtils.gray + "https://hypnotic.dev", new ClickEvent(Action.OPEN_URL, "https://hypnotic.dev"))));
        ChatUtils.tellPlayerRaw("\n\n\u00A7c                 .,;;;,.                \n" + "                .xXNNN0:    .....       \n" + "               .lXMMMNd.   ;OXXKd.      \n" + "               :KWMWNk'   ,OWMM0:       \n" + "              'kWMW0d;   .dNMMNo.       \n" + "             .oNMMXl..   cXMMWx.        \n" + "            .cKMMWk,.  .;OWMW0:.        \n" + "  ..;ldxkkxxOXWMMWKkkxkOXWMMWXOxxxxxxxdo\n" + ".:kXWWXOdc:oKMMMKo:;;;l0WMMNkc;;;;;;;;,.\n" + "ONMWKd,.  .dXMMKc.    ;0MMWO'           \n" + "MMMXc.   .dNMWO:     'OWMM0:            \n" + "MMWXc...l0NNKo.    ..cKNNKl.            \n" + "OKNWKOkO0Od:.        .','..             \n" + "..;:cc:,..   \n");
        return SINGLE_SUCCESS;
    });
}
Also used : ClickEvent(net.minecraft.text.ClickEvent) LiteralText(net.minecraft.text.LiteralText)

Aggregations

ClickEvent (net.minecraft.text.ClickEvent)24 LiteralText (net.minecraft.text.LiteralText)24 HoverEvent (net.minecraft.text.HoverEvent)16 MutableText (net.minecraft.text.MutableText)8 BaseText (net.minecraft.text.BaseText)6 ItemStack (net.minecraft.item.ItemStack)5 NbtCompound (net.minecraft.nbt.NbtCompound)5 Formatting (net.minecraft.util.Formatting)5 IntegerArgumentType (com.mojang.brigadier.arguments.IntegerArgumentType)4 IOException (java.io.IOException)4 CommandSource (net.minecraft.command.CommandSource)4 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)4 Style (net.minecraft.text.Style)4 CommandDispatcher (com.mojang.brigadier.CommandDispatcher)3 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)3 CommandContext (com.mojang.brigadier.context.CommandContext)3 NbtPathArgumentType (net.minecraft.command.argument.NbtPathArgumentType)3 CreativeInventoryActionC2SPacket (net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket)3 CommandManager.literal (net.minecraft.server.command.CommandManager.literal)3 ServerCommandSource (net.minecraft.server.command.ServerCommandSource)3