Search in sources :

Example 1 with IChatComponent

use of v1_8_9.net.minecraft.util.IChatComponent in project SecurityCraft by Geforce132.

the class SCEventHandler method onPlayerLoggedIn.

@SubscribeEvent
public void onPlayerLoggedIn(PlayerLoggedInEvent event) {
    String tipKey = getRandomTip();
    IChatComponent chatcomponenttext;
    if (tipsWithLink.containsKey(tipKey.split("\\.")[2]))
        chatcomponenttext = new ChatComponentText("[" + EnumChatFormatting.GOLD + "SecurityCraft" + EnumChatFormatting.WHITE + "] " + StatCollector.translateToLocal("messages.thanks").replace("#", SecurityCraft.getVersion()) + " " + StatCollector.translateToLocal("messages.tip") + " " + StatCollector.translateToLocal(tipKey) + " ").appendSibling(ForgeHooks.newChatWithLinks(tipsWithLink.get(tipKey.split("\\.")[2])));
    else
        chatcomponenttext = new ChatComponentText("[" + EnumChatFormatting.GOLD + "SecurityCraft" + EnumChatFormatting.WHITE + "] " + StatCollector.translateToLocal("messages.thanks").replace("#", SecurityCraft.getVersion()) + " " + StatCollector.translateToLocal("messages.tip") + " " + StatCollector.translateToLocal(tipKey));
    if (SecurityCraft.config.sayThanksMessage)
        event.player.addChatComponentMessage(chatcomponenttext);
}
Also used : IChatComponent(net.minecraft.util.IChatComponent) ChatComponentText(net.minecraft.util.ChatComponentText) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with IChatComponent

use of v1_8_9.net.minecraft.util.IChatComponent in project watson by totemo.

the class Text method toChatComponent.

// --------------------------------------------------------------------------
/**
 * Return the IChatComponent representation of the Text.
 *
 * @return the IChatComponent representation of the Text.
 */
public IChatComponent toChatComponent() {
    ArrayList<IChatComponent> result = new ArrayList<IChatComponent>();
    StringBuilder text = new StringBuilder();
    // Sentinel:
    char colourStyle = Colour.white.getCode();
    ChatStyle style = new ChatStyle();
    for (int i = 0; i < _unformatted.length(); ++i) {
        // Detect a change in colour or style and add new component to result.
        if (_colourStyles.charAt(i) != colourStyle) {
            // Set the new colour. This also clears the current style.
            char newColourStyle = _colourStyles.charAt(i);
            char colour = (char) (newColourStyle & Format.COLOUR_MASK);
            // Put all of the characters accumulated so far in ChatComponentText.
            IChatComponent sibling = new ChatComponentText(text.toString());
            sibling.setChatStyle(style);
            result.add(sibling);
            // Reuse StringBuilder to accumulate characters for the next sibling.
            text.setLength(0);
            // Configure the style of the next sibling to be appended to result.
            style = new ChatStyle();
            EnumChatFormatting chatFormatting = _TO_ENUM_CHAT_FORMATTING.get(colour);
            style.setColor(chatFormatting);
            if ((newColourStyle & Format.BOLD) != 0) {
                style.setBold(true);
            }
            if ((newColourStyle & Format.ITALIC) != 0) {
                style.setItalic(true);
            }
            if ((newColourStyle & Format.UNDERLINE) != 0) {
                style.setUnderlined(true);
            }
            if ((newColourStyle & Format.STRIKE) != 0) {
                style.setStrikethrough(true);
            }
            if ((newColourStyle & Format.RANDOM) != 0) {
                style.setObfuscated(true);
            }
            colourStyle = newColourStyle;
        }
        // colour or style changed
        text.append(_unformatted.charAt(i));
    }
    // for
    IChatComponent sibling = new ChatComponentText(text.toString());
    sibling.setChatStyle(style);
    result.add(sibling);
    return ChatComponents.toChatComponent(result);
}
Also used : ChatStyle(net.minecraft.util.ChatStyle) EnumChatFormatting(net.minecraft.util.EnumChatFormatting) IChatComponent(net.minecraft.util.IChatComponent) ArrayList(java.util.ArrayList) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 3 with IChatComponent

use of v1_8_9.net.minecraft.util.IChatComponent in project watson by totemo.

the class Chat method localChat.

// --------------------------------------------------------------------------
/**
 * Display the chat locally.
 *
 * @param chat the chat component.
 */
public static void localChat(IChatComponent chat) {
    if (isChatGuiReady()) {
        IChatComponent highlighted = getChatHighlighter().highlight(chat);
        Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(highlighted);
    }
}
Also used : IChatComponent(net.minecraft.util.IChatComponent)

Example 4 with IChatComponent

use of v1_8_9.net.minecraft.util.IChatComponent in project watson by totemo.

the class ChatComponents method getComponents.

// --------------------------------------------------------------------------
/**
 * Return an array containing the specified IChatComponent and all its
 * siblings.
 *
 * @return an array containing the specified IChatComponent and all its
 *         siblings.
 */
@SuppressWarnings("unchecked")
public static ArrayList<IChatComponent> getComponents(IChatComponent chat) {
    ArrayList<IChatComponent> components = new ArrayList<IChatComponent>();
    for (Object o : chat) {
        IChatComponent component = (IChatComponent) o;
        IChatComponent copy = new ChatComponentText(component.getUnformattedTextForChat());
        copy.setChatStyle(component.getChatStyle().createDeepCopy());
        components.add(copy);
    }
    return components;
}
Also used : IChatComponent(net.minecraft.util.IChatComponent) ArrayList(java.util.ArrayList) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 5 with IChatComponent

use of v1_8_9.net.minecraft.util.IChatComponent in project Hyperium by HyperiumClient.

the class NetworkHandler method handleChat.

@Override
public void handleChat(String s) {
    if (s.toLowerCase().contains("reconnecting hyperium connection"))
        return;
    Hyperium.LOGGER.debug("Chat: {}", s);
    s = s.replace("&", C.COLOR_CODE_SYMBOL);
    IChatComponent chatComponent = new ChatComponentText("");
    Arrays.stream(s.split(" ")).forEach(s1 -> {
        ChatComponentText iChatComponents = new ChatComponentText(s1 + " ");
        if (s1.contains(".") && !s1.startsWith(".") && !s1.endsWith(".")) {
            ChatStyle chatStyle = new ChatStyle();
            chatStyle.setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, s1.startsWith("http") ? s1 : "http://" + s1));
            iChatComponents.setChatStyle(chatStyle);
        }
        chatComponent.appendSibling(iChatComponents);
    });
    GeneralChatHandler.instance().sendMessage(chatComponent);
}
Also used : ChatStyle(net.minecraft.util.ChatStyle) ClickEvent(net.minecraft.event.ClickEvent) IChatComponent(net.minecraft.util.IChatComponent) ChatComponentText(net.minecraft.util.ChatComponentText)

Aggregations

IChatComponent (net.minecraft.util.IChatComponent)101 ChatComponentText (net.minecraft.util.ChatComponentText)55 ClickEvent (net.minecraft.event.ClickEvent)20 HoverEvent (net.minecraft.event.HoverEvent)18 ChatStyle (net.minecraft.util.ChatStyle)18 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)14 ArrayList (java.util.ArrayList)12 Matcher (java.util.regex.Matcher)9 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)5 Overwrite (org.spongepowered.asm.mixin.Overwrite)5 ChatLine (net.minecraft.client.gui.ChatLine)4 GameProfile (com.mojang.authlib.GameProfile)3 BufferedImage (java.awt.image.BufferedImage)3 File (java.io.File)3 ActiveCosmetic (kr.syeyoung.dungeonsguide.cosmetics.ActiveCosmetic)3 CosmeticData (kr.syeyoung.dungeonsguide.cosmetics.CosmeticData)3 GuiNewChat (net.minecraft.client.gui.GuiNewChat)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 NetworkManager (net.minecraft.network.NetworkManager)3