Search in sources :

Example 26 with ClickEvent

use of net.minecraft.util.text.event.ClickEvent in project SpongeVanilla by SpongePowered.

the class ChatFormatter method format.

@Nullable
public static ITextComponent format(String s) {
    Matcher matcher = URL_PATTERN.matcher(s);
    if (!matcher.find()) {
        return null;
    }
    ITextComponent result = null;
    int pos = 0;
    do {
        int start = matcher.start();
        int end = matcher.end();
        String displayUrl = s.substring(start, end);
        String url = displayUrl;
        try {
            if (new URI(url).getScheme() == null) {
                url = DEFAULT_SCHEME + url;
            }
        } catch (URISyntaxException e) {
            // Invalid URL so just ignore it
            continue;
        }
        if (pos < start) {
            if (result == null) {
                result = new TextComponentString(s.substring(pos, start));
            } else {
                result.appendText(s.substring(pos, start));
            }
        }
        pos = end;
        ITextComponent link = new TextComponentString(displayUrl);
        link.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url));
        if (result == null) {
            result = new TextComponentString("");
        }
        result.appendSibling(link);
    } while (matcher.find());
    // If there is something left, append the rest
    if (pos < s.length()) {
        if (result == null) {
            result = new TextComponentString(s.substring(pos));
        } else {
            result.appendText(s.substring(pos));
        }
    }
    return result;
}
Also used : Matcher(java.util.regex.Matcher) ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) TextComponentString(net.minecraft.util.text.TextComponentString) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) TextComponentString(net.minecraft.util.text.TextComponentString) Nullable(javax.annotation.Nullable)

Example 27 with ClickEvent

use of net.minecraft.util.text.event.ClickEvent in project Cavern2 by kegare.

the class ClientEventHooks method onConnected.

@SubscribeEvent
public void onConnected(ClientConnectedToServerEvent event) {
    Minecraft mc = FMLClientHandler.instance().getClient();
    if (GeneralConfig.versionNotify) {
        ITextComponent message;
        ITextComponent name = new TextComponentString(Cavern.metadata.name);
        name.getStyle().setColor(TextFormatting.AQUA);
        if (Version.isOutdated()) {
            ITextComponent latest = new TextComponentString(Version.getLatest().toString());
            latest.getStyle().setColor(TextFormatting.YELLOW);
            message = new TextComponentTranslation("cavern.version.message", name);
            message.appendText(" : ").appendSibling(latest);
            message.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, Cavern.metadata.url));
            mc.ingameGUI.getChatGUI().printChatMessage(message);
        }
        message = null;
        if (Version.DEV_DEBUG) {
            message = new TextComponentTranslation("cavern.version.message.dev", name);
        } else if (Version.isBeta()) {
            message = new TextComponentTranslation("cavern.version.message.beta", name);
        } else if (Version.isAlpha()) {
            message = new TextComponentTranslation("cavern.version.message.alpha", name);
        }
        if (message != null) {
            mc.ingameGUI.getChatGUI().printChatMessage(message);
        }
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) Minecraft(net.minecraft.client.Minecraft) TextComponentString(net.minecraft.util.text.TextComponentString) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 28 with ClickEvent

use of net.minecraft.util.text.event.ClickEvent in project HorsePower by GoryMoon.

the class Utils method sendSavedErrors.

public static void sendSavedErrors() {
    if (FMLCommonHandler.instance().getSide().isClient() && FMLClientHandler.instance().getClientPlayerEntity() != null && HPRecipes.ERRORS.size() > 0) {
        FMLClientHandler.instance().getClientPlayerEntity().sendMessage(new TextComponentString(TextFormatting.RED + "" + TextFormatting.BOLD + "HorsePower config errors"));
        FMLClientHandler.instance().getClientPlayerEntity().sendMessage(new TextComponentString(TextFormatting.RED + "" + TextFormatting.BOLD + "-----------------------------------------"));
        HPRecipes.ERRORS.forEach(s -> FMLClientHandler.instance().getClientPlayerEntity().sendMessage(new TextComponentString(TextFormatting.RED + s).setStyle(new Style().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, Loader.instance().getConfigDir() + "/horsepower.cfg")).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Changed in in-game config or click to open the config file to fix this"))))));
        FMLClientHandler.instance().getClientPlayerEntity().sendMessage(new TextComponentString(TextFormatting.RED + "" + TextFormatting.BOLD + "-----------------------------------------"));
        HPRecipes.ERRORS.clear();
    }
}
Also used : HoverEvent(net.minecraft.util.text.event.HoverEvent) ClickEvent(net.minecraft.util.text.event.ClickEvent) Style(net.minecraft.util.text.Style) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 29 with ClickEvent

use of net.minecraft.util.text.event.ClickEvent in project GregTech by GregTechCE.

the class AdvancedTextWidget method handleCustomComponentClick.

@SideOnly(Side.CLIENT)
private boolean handleCustomComponentClick(ITextComponent textComponent) {
    Style style = textComponent.getStyle();
    if (style.getClickEvent() != null) {
        ClickEvent clickEvent = style.getClickEvent();
        String componentText = clickEvent.getValue();
        if (clickEvent.getAction() == Action.OPEN_URL && componentText.startsWith("@!")) {
            String rawText = componentText.substring(2);
            ClickData clickData = new ClickData(Mouse.getEventButton(), isShiftDown(), isCtrlDown());
            writeClientAction(1, buf -> {
                clickData.writeToBuf(buf);
                buf.writeString(rawText);
            });
            return true;
        }
    }
    return false;
}
Also used : ClickEvent(net.minecraft.util.text.event.ClickEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 30 with ClickEvent

use of net.minecraft.util.text.event.ClickEvent in project minecolonies by Minecolonies.

the class WindowTownHall method teleportToColony.

/**
 * On Button click teleport to the colony..
 *
 * @param button the clicked button.
 */
private void teleportToColony(@NotNull final Button button) {
    final int row = alliesList.getListElementIndexByPane(button);
    final ColonyView ally = allies.get(row);
    final ITextComponent teleport = new TextComponentString(LanguageHandler.format(DO_REALLY_WANNA_TP, ally.getName())).setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, TELEPORT_COMMAND + ally.getID())));
    Minecraft.getMinecraft().player.sendMessage(teleport);
}
Also used : ColonyView(com.minecolonies.coremod.colony.ColonyView) ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) Style(net.minecraft.util.text.Style) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

ClickEvent (net.minecraft.util.text.event.ClickEvent)41 HoverEvent (net.minecraft.util.text.event.HoverEvent)21 TextComponentString (net.minecraft.util.text.TextComponentString)19 ITextComponent (net.minecraft.util.text.ITextComponent)16 Style (net.minecraft.util.text.Style)10 Nonnull (javax.annotation.Nonnull)8 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)6 BlockPos (net.minecraft.util.math.BlockPos)4 JsonObject (com.google.gson.JsonObject)3 Colony (com.minecolonies.coremod.colony.Colony)3 Minecraft (net.minecraft.client.Minecraft)3 JsonArray (com.google.gson.JsonArray)2 IOException (java.io.IOException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 Matcher (java.util.regex.Matcher)2 CommandException (net.minecraft.command.CommandException)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 JsonElement (com.google.gson.JsonElement)1