Search in sources :

Example 1 with HoverEvent

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

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

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

the class BetterChat method onPacketRead.

@BleachSubscribe
public void onPacketRead(EventPacket.Read event) {
    if (event.getPacket() instanceof GameMessageS2CPacket) {
        GameMessageS2CPacket packet = (GameMessageS2CPacket) event.getPacket();
        if (packet.getLocation() == MessageType.GAME_INFO)
            return;
        Text message = packet.getMessage().shallowCopy();
        if (getSetting(6).asToggle().getState()) {
            message = Texts.forEachWord(message, (string, style) -> {
                String stripped = Formatting.strip(string);
                if (stripped.matches("['\u00a1-\u00f5]+\u00ff[0-~]+")) {
                    String decrypted = decrypt(stripped);
                    if (decrypted != null) {
                        return new LiteralText("<").styled(s -> s.withColor(BleachHack.watermark.getColor1())).append(new LiteralText(decrypted).styled(s -> s.withColor(0xffffff).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(string).setStyle(style))))).append(new LiteralText(">").styled(s -> s.withColor(BleachHack.watermark.getColor2())));
                    }
                }
                return null;
            });
        }
        if (!filterPatterns.isEmpty() && getSetting(4).asToggle().getState()) {
            int mode = getSetting(4).asToggle().getChild(0).asMode().getMode();
            if (mode == 0) {
                for (Pattern pattern : filterPatterns) {
                    message = Texts.replaceAll(message, pattern, (string, style) -> new LiteralText(StringUtils.repeat('|', string.length() * 2)).styled(s -> s.withColor(Formatting.GRAY).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(string).setStyle(style)))));
                }
            } else {
                for (Pattern pat : filterPatterns) {
                    if (pat.matcher(message.getString()).find()) {
                        if (mode == 1) {
                            Text messageCopy = message.shallowCopy();
                            message = new LiteralText("\u00a77Blocked Message").styled(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, messageCopy)));
                            break;
                        } else {
                            event.setCancelled(true);
                            return;
                        }
                    }
                }
            }
        }
        if (getSetting(3).asToggle().getState()) {
            DateTimeFormatter formatter = getSetting(3).asToggle().getChild(0).asToggle().getState() ? DateTimeFormatter.ofPattern("HH:mm:ss") : DateTimeFormatter.ofPattern("HH:mm");
            message = new LiteralText("\u00a78[\u00a77" + LocalDateTime.now().format(formatter) + "\u00a78] ").append(message);
        }
        if (!message.equals(packet.getMessage())) {
            packet.message = message;
        }
    }
}
Also used : JsonParseException(com.google.gson.JsonParseException) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe) LiteralText(net.minecraft.text.LiteralText) java.util(java.util) ChatMessageC2SPacket(net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket) ModuleCategory(org.bleachhack.module.ModuleCategory) MessageType(net.minecraft.network.MessageType) Command(org.bleachhack.command.Command) LocalDateTime(java.time.LocalDateTime) Hashing(com.google.common.hash.Hashing) ArrayUtils(org.apache.commons.lang3.ArrayUtils) BleachFileHelper(org.bleachhack.util.io.BleachFileHelper) HoverEvent(net.minecraft.text.HoverEvent) StringUtils(org.apache.commons.lang3.StringUtils) JsonElement(com.google.gson.JsonElement) SettingMode(org.bleachhack.setting.module.SettingMode) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) CharMap(org.bleachhack.module.mods.BetterChat.CustomFont.CharMap) BleachLogger(org.bleachhack.util.BleachLogger) Ascii85(com.github.fzakaria.ascii85.Ascii85) EventPacket(org.bleachhack.event.events.EventPacket) GameMessageS2CPacket(net.minecraft.network.packet.s2c.play.GameMessageS2CPacket) Texts(org.bleachhack.util.Texts) PatternSyntaxException(java.util.regex.PatternSyntaxException) BleachHack(org.bleachhack.BleachHack) StandardCharsets(java.nio.charset.StandardCharsets) Module(org.bleachhack.module.Module) Formatting(net.minecraft.util.Formatting) DateTimeFormatter(java.time.format.DateTimeFormatter) Entry(java.util.Map.Entry) Text(net.minecraft.text.Text) SettingToggle(org.bleachhack.setting.module.SettingToggle) Pattern(java.util.regex.Pattern) HoverEvent(net.minecraft.text.HoverEvent) Pattern(java.util.regex.Pattern) GameMessageS2CPacket(net.minecraft.network.packet.s2c.play.GameMessageS2CPacket) LiteralText(net.minecraft.text.LiteralText) Text(net.minecraft.text.Text) DateTimeFormatter(java.time.format.DateTimeFormatter) LiteralText(net.minecraft.text.LiteralText) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Example 4 with HoverEvent

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

the class CmdHelp method onCommand.

@Override
public void onCommand(String alias, String[] args) throws Exception {
    String cmd = args.length == 0 ? "" : args[0];
    if (cmd.isEmpty()) {
        BleachLogger.info("Commands:");
    } else {
        BleachLogger.info("Syntax for " + getPrefix() + cmd.toLowerCase(Locale.ENGLISH) + ":");
    }
    for (Command c : CommandManager.getCommands()) {
        if (!cmd.isEmpty() && Stream.of(c.getAliases()).noneMatch(cmd::equalsIgnoreCase))
            continue;
        MutableText text = new LiteralText(getPrefix() + c.getAliases()[0] + ": \u00a7f" + c.getDescription()).styled(s -> s.withColor(BleachLogger.INFO_COLOR));
        BleachLogger.noPrefix(text.styled(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, c.getHelpTooltip()))));
    }
}
Also used : MutableText(net.minecraft.text.MutableText) CommandCategory(org.bleachhack.command.CommandCategory) CommandManager(org.bleachhack.command.CommandManager) LiteralText(net.minecraft.text.LiteralText) Stream(java.util.stream.Stream) Locale(java.util.Locale) Command(org.bleachhack.command.Command) BleachLogger(org.bleachhack.util.BleachLogger) MutableText(net.minecraft.text.MutableText) HoverEvent(net.minecraft.text.HoverEvent) HoverEvent(net.minecraft.text.HoverEvent) Command(org.bleachhack.command.Command) LiteralText(net.minecraft.text.LiteralText)

Example 5 with HoverEvent

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

the class BleachCreditsScreen method getBoosterText.

private Text getBoosterText(ImmutablePair<Boolean, String> pair) {
    int color = pair.getLeft() ? 0x1abc9c : 0xf579ff;
    String[] split = pair.getRight().split("#");
    return new LiteralText(split[0]).styled(s -> s.withColor(color).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(pair.getRight()).styled(s1 -> s1.withColor(color)))));
}
Also used : WindowScreen(org.bleachhack.gui.window.WindowScreen) JsonObject(com.google.gson.JsonObject) LiteralText(net.minecraft.text.LiteralText) BodyHandlers(java.net.http.HttpResponse.BodyHandlers) BleachJsonHelper(org.bleachhack.util.io.BleachJsonHelper) BleachHack(org.bleachhack.BleachHack) MatrixStack(net.minecraft.client.util.math.MatrixStack) Items(net.minecraft.item.Items) WindowWidget(org.bleachhack.gui.window.widget.WindowWidget) HoverEvent(net.minecraft.text.HoverEvent) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) BleachOnlineMang(org.bleachhack.util.io.BleachOnlineMang) WindowTextWidget(org.bleachhack.gui.window.widget.WindowTextWidget) ItemStack(net.minecraft.item.ItemStack) Window(org.bleachhack.gui.window.Window) WindowScrollbarWidget(org.bleachhack.gui.window.widget.WindowScrollbarWidget) ImmutablePairList(org.bleachhack.util.collections.ImmutablePairList) Text(net.minecraft.text.Text) HoverEvent(net.minecraft.text.HoverEvent) 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