Search in sources :

Example 1 with ClickEvent

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

the class ClientCommands method names.

private static int names(CommandContext<FabricClientCommandSource> context) {
    CompletableFuture.runAsync(() -> {
        String name = context.getInput().split(" ")[1];
        String[] playerNameAndUUID = get_player_name_and_uuid(name);
        String username = playerNameAndUUID[0];
        String uuid = playerNameAndUUID[1];
        if (Objects.equals(username, "None")) {
            context.getSource().sendError(new LiteralText("No account exists by that name .-."));
        } else {
            context.getSource().sendFeedback(new LiteralText("§7[Hover] §eView name history of " + username).styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://namemc.com/profile/" + username)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, get_player_name_history(username, uuid).append(new LiteralText("\n\n§7§oClick to open in 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 2 with ClickEvent

use of net.minecraft.text.ClickEvent in project BleachHack by BleachDrinker420.

the class CmdBetterChat method onCommand.

@Override
public void onCommand(String alias, String[] args) throws Exception {
    if (args.length < 2) {
        throw new CmdSyntaxException();
    }
    BetterChat chat = ModuleManager.getModule(BetterChat.class);
    if (args[0].equalsIgnoreCase("filter")) {
        if (args[1].equalsIgnoreCase("list")) {
            MutableText text = new LiteralText("Filter Entries:");
            int i = 1;
            for (Pattern pat : chat.filterPatterns) {
                text = text.append(new LiteralText("\n\u00a76" + i + " > \u00a7f" + pat.pattern()).styled(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to remove this filter."))).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, getPrefix() + "betterchat filter remove " + pat.pattern()))));
                i++;
            }
            BleachLogger.info(text);
        } else if (args[1].equalsIgnoreCase("add")) {
            String arg = String.join(" ", ArrayUtils.subarray(args, 2, args.length)).trim();
            chat.filterPatterns.add(Pattern.compile(arg));
            JsonArray jsonFilter = new JsonArray();
            chat.filterPatterns.forEach(p -> jsonFilter.add(p.toString()));
            BleachFileHelper.saveMiscSetting("betterChatFilter", jsonFilter);
            BleachLogger.info("Added \"" + arg + "\" to the filter patterns.");
        } else if (args[1].equalsIgnoreCase("remove")) {
            String arg = String.join(" ", ArrayUtils.subarray(args, 2, args.length)).trim();
            if (chat.filterPatterns.removeIf(p -> p.toString().equals(arg))) {
                JsonArray jsonFilter = new JsonArray();
                chat.filterPatterns.forEach(p -> jsonFilter.add(p.toString()));
                BleachFileHelper.saveMiscSetting("betterChatFilter", jsonFilter);
                BleachLogger.info("Removed \"" + arg + "\" from the filter patterns.");
            } else {
                BleachLogger.info("Could not find \"" + arg + "\" in the pattern list.");
            }
        } else {
            throw new CmdSyntaxException();
        }
    } else if (args[0].equalsIgnoreCase("prefix")) {
        if (args[1].equalsIgnoreCase("current")) {
            BleachLogger.info("Current prefix: \"" + chat.prefix + "\"");
        } else if (args[1].equalsIgnoreCase("reset")) {
            chat.prefix = "";
            BleachFileHelper.saveMiscSetting("betterChatPrefix", new JsonPrimitive(chat.prefix));
            BleachLogger.info("Reset the customchat prefix!");
        } else if (args[1].equalsIgnoreCase("set") && args.length >= 3) {
            chat.prefix = String.join(" ", ArrayUtils.subarray(args, 2, args.length)).trim() + " ";
            BleachFileHelper.saveMiscSetting("betterChatPrefix", new JsonPrimitive(chat.prefix));
            BleachLogger.info("Set prefix to: \"" + chat.prefix + "\"");
        } else {
            throw new CmdSyntaxException();
        }
    } else if (args[0].equalsIgnoreCase("suffix")) {
        if (args[1].equalsIgnoreCase("current")) {
            BleachLogger.info("Current suffix: \"" + chat.suffix + "\"");
        } else if (args[1].equalsIgnoreCase("reset")) {
            chat.suffix = " \u25ba \u0432\u029f\u0454\u03b1c\u043d\u043d\u03b1c\u043a";
            BleachFileHelper.saveMiscSetting("betterChatSuffix", new JsonPrimitive(chat.suffix));
            BleachLogger.info("Reset the customchat suffix!");
        } else if (args[1].equalsIgnoreCase("set") && args.length >= 3) {
            chat.suffix = String.join(" ", ArrayUtils.subarray(args, 2, args.length)).trim() + " ";
            BleachFileHelper.saveMiscSetting("betterChatSuffix", new JsonPrimitive(chat.suffix));
            BleachLogger.info("Set suffix to: \"" + chat.suffix + "\"");
        } else {
            throw new CmdSyntaxException();
        }
    } else {
        throw new CmdSyntaxException();
    }
}
Also used : MutableText(net.minecraft.text.MutableText) JsonArray(com.google.gson.JsonArray) CommandCategory(org.bleachhack.command.CommandCategory) LiteralText(net.minecraft.text.LiteralText) CmdSyntaxException(org.bleachhack.command.exception.CmdSyntaxException) Command(org.bleachhack.command.Command) ArrayUtils(org.apache.commons.lang3.ArrayUtils) BleachFileHelper(org.bleachhack.util.io.BleachFileHelper) HoverEvent(net.minecraft.text.HoverEvent) ModuleManager(org.bleachhack.module.ModuleManager) BetterChat(org.bleachhack.module.mods.BetterChat) JsonArray(com.google.gson.JsonArray) ClickEvent(net.minecraft.text.ClickEvent) BleachLogger(org.bleachhack.util.BleachLogger) MutableText(net.minecraft.text.MutableText) Pattern(java.util.regex.Pattern) JsonPrimitive(com.google.gson.JsonPrimitive) Pattern(java.util.regex.Pattern) HoverEvent(net.minecraft.text.HoverEvent) BetterChat(org.bleachhack.module.mods.BetterChat) CmdSyntaxException(org.bleachhack.command.exception.CmdSyntaxException) JsonPrimitive(com.google.gson.JsonPrimitive) ClickEvent(net.minecraft.text.ClickEvent) LiteralText(net.minecraft.text.LiteralText)

Example 3 with ClickEvent

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

the class BookBot method onTick.

@EventHandler
private void onTick(TickEvent.Post event) {
    FindItemResult writableBook = InvUtils.find(Items.WRITABLE_BOOK);
    // Check if there is a book to write
    if (!writableBook.found()) {
        toggle();
        return;
    }
    // Move the book into hand
    if (!writableBook.isMainHand()) {
        InvUtils.move().from(writableBook.slot()).toHotbar(mc.player.getInventory().selectedSlot);
        return;
    }
    // If somehow it failed, just dont do anything until it tries again
    FindItemResult finalBook = InvUtils.findInHotbar(Items.WRITABLE_BOOK);
    if (!finalBook.isMainHand())
        return;
    // Check delay
    if (delayTimer > 0) {
        delayTimer--;
        return;
    }
    // Reset delay
    delayTimer = delay.get();
    if (mode.get() == Mode.Random) {
        int origin = onlyAscii.get() ? 0x21 : 0x0800;
        int bound = onlyAscii.get() ? 0x7E : 0x10FFFF;
        writeBook(// Generate a random load of ints to use as random characters
        random.ints(origin, bound).filter(i -> !Character.isWhitespace(i) && i != '\r' && i != '\n').iterator());
    } else if (mode.get() == Mode.File) {
        // Ignore if somehow the file got deleted
        if ((file == null || !file.exists()) && mode.get() == Mode.File) {
            info("No file selected, please select a file in the GUI.");
            toggle();
            return;
        }
        // Handle the file being empty
        if (file.length() == 0) {
            MutableText message = new LiteralText("");
            message.append(new LiteralText("The bookbot file is empty! ").formatted(Formatting.RED));
            message.append(new LiteralText("Click here to edit it.").setStyle(Style.EMPTY.withFormatting(Formatting.UNDERLINE, Formatting.RED).withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, file.getAbsolutePath()))));
            info(message);
            toggle();
            return;
        }
        // Read each line of the file and construct a string with the needed line breaks
        try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
            StringBuilder file = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                file.append(line).append('\n');
            }
            reader.close();
            // Write the file string to a book
            writeBook(file.toString().chars().iterator());
        } catch (IOException ignored) {
            error("Failed to read the file.");
        }
    }
}
Also used : MutableText(net.minecraft.text.MutableText) ClickEvent(net.minecraft.text.ClickEvent) FindItemResult(meteordevelopment.meteorclient.utils.player.FindItemResult) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) NbtString(net.minecraft.nbt.NbtString) IOException(java.io.IOException) LiteralText(net.minecraft.text.LiteralText) EventHandler(meteordevelopment.orbit.EventHandler)

Example 4 with ClickEvent

use of net.minecraft.text.ClickEvent in project mclogs-fabric by aternosorg.

the class CommandMclogsList method register.

static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
    dispatcher.register(literal("mclogs").then(literal("list").requires(source -> source.hasPermissionLevel(2)).executes((context) -> {
        ServerCommandSource source = context.getSource();
        try {
            String[] logs = MclogsFabricLoader.getLogs(context);
            if (logs.length == 0) {
                source.sendFeedback(new LiteralText("No logs available!"), false);
                return 0;
            }
            LiteralText feedback = new LiteralText("Available Logs:");
            for (String log : logs) {
                Style s = Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/mclogs share " + log));
                LiteralText tempText = new LiteralText("\n" + log);
                tempText.setStyle(s);
                feedback.append(tempText);
            }
            source.sendFeedback(feedback, false);
            return logs.length;
        } catch (Exception e) {
            MclogsFabricLoader.logger.error("An error occurred when listing your logs.");
            MclogsFabricLoader.logger.error(e);
            LiteralText error = new LiteralText("An error occurred. Check your log for more details.");
            source.sendError(error);
            return -1;
        }
    })));
}
Also used : LiteralText(net.minecraft.text.LiteralText) Style(net.minecraft.text.Style) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) ClickEvent(net.minecraft.text.ClickEvent) CommandManager.literal(net.minecraft.server.command.CommandManager.literal) ClickEvent(net.minecraft.text.ClickEvent) Style(net.minecraft.text.Style) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) LiteralText(net.minecraft.text.LiteralText)

Example 5 with ClickEvent

use of net.minecraft.text.ClickEvent in project mclogs-fabric by aternosorg.

the class MclogsFabricLoader method share.

public static int share(ServerCommandSource source, String filename) {
    MclogsAPI.mcversion = source.getMinecraftServer().getVersion();
    logger.log(Level.INFO, "Sharing " + filename);
    source.sendFeedback(new LiteralText("Sharing " + filename), false);
    try {
        Path logs = source.getMinecraftServer().getFile("logs/").toPath();
        Path log = logs.resolve(filename);
        if (!log.getParent().equals(logs)) {
            throw new FileNotFoundException();
        }
        APIResponse response = MclogsAPI.share(log);
        if (response.success) {
            LiteralText feedback = new LiteralText("Your log has been uploaded: ");
            feedback.setStyle(Style.EMPTY.withColor(Formatting.GREEN));
            LiteralText link = new LiteralText(response.url);
            Style linkStyle = Style.EMPTY.withColor(Formatting.BLUE);
            linkStyle = linkStyle.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, response.url));
            link.setStyle(linkStyle);
            source.sendFeedback(feedback.append(link), true);
            return 1;
        } else {
            logger.error("An error occurred when uploading your log: ");
            logger.error(response.error);
            LiteralText error = new LiteralText("An error occurred. Check your log for more details");
            source.sendError(error);
            return 0;
        }
    } catch (FileNotFoundException | IllegalArgumentException e) {
        LiteralText error = new LiteralText("The log file " + filename + " doesn't exist. Use '/mclogs list' to list all logs.");
        source.sendError(error);
        return -1;
    } catch (IOException e) {
        source.sendError(new LiteralText("An error occurred. Check your log for more details"));
        logger.error("Could not get log file!");
        logger.error(e);
        return 0;
    }
}
Also used : Path(java.nio.file.Path) APIResponse(gs.mclo.java.APIResponse) ClickEvent(net.minecraft.text.ClickEvent) FileNotFoundException(java.io.FileNotFoundException) Style(net.minecraft.text.Style) IOException(java.io.IOException) LiteralText(net.minecraft.text.LiteralText)

Aggregations

ClickEvent (net.minecraft.text.ClickEvent)19 LiteralText (net.minecraft.text.LiteralText)19 HoverEvent (net.minecraft.text.HoverEvent)13 BaseText (net.minecraft.text.BaseText)6 MutableText (net.minecraft.text.MutableText)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 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 CmdSyntaxException (org.bleachhack.command.exception.CmdSyntaxException)3 SINGLE_SUCCESS (com.mojang.brigadier.Command.SINGLE_SUCCESS)2