Search in sources :

Example 1 with ChatStyle

use of net.minecraft.util.ChatStyle in project Galacticraft by micdoodle8.

the class SpaceRaceManager method onPlayerRemoval.

public static void onPlayerRemoval(MinecraftServer server, String player, SpaceRace race) {
    for (String member : race.getPlayerNames()) {
        EntityPlayerMP memberObj = PlayerUtil.getPlayerForUsernameVanilla(server, member);
        if (memberObj != null) {
            memberObj.addChatMessage(new ChatComponentText(EnumColor.DARK_AQUA + GCCoreUtil.translateWithFormat("gui.space_race.chat.remove_success", EnumColor.RED + player + EnumColor.DARK_AQUA)).setChatStyle(new ChatStyle().setColor(EnumChatFormatting.DARK_AQUA)));
        }
    }
    List<String> playerList = new ArrayList<String>();
    playerList.add(player);
    SpaceRace newRace = SpaceRaceManager.addSpaceRace(new SpaceRace(playerList, SpaceRace.DEFAULT_NAME, new FlagData(48, 32), new Vector3(1, 1, 1)));
    EntityPlayerMP playerToRemove = PlayerUtil.getPlayerBaseServerFromPlayerUsername(server, player, true);
    if (playerToRemove != null) {
        SpaceRaceManager.sendSpaceRaceData(server, playerToRemove, newRace);
        SpaceRaceManager.sendSpaceRaceData(server, playerToRemove, race);
    }
}
Also used : ChatStyle(net.minecraft.util.ChatStyle) FlagData(micdoodle8.mods.galacticraft.core.wrappers.FlagData) ArrayList(java.util.ArrayList) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 2 with ChatStyle

use of net.minecraft.util.ChatStyle 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 ChatStyle

use of net.minecraft.util.ChatStyle in project Hyperium by HyperiumClient.

the class UniversalUtil method newComponent.

private static IChatComponent newComponent(String text, String url, String hoverText) {
    ChatStyle chatStyle = new ChatStyle();
    ClickEvent clickEvent;
    HoverEvent hoverEvent;
    if (url != null && !url.equals("")) {
        clickEvent = new ClickEvent(ClickEvent.Action.OPEN_URL, url);
        chatStyle.setChatClickEvent(clickEvent);
    }
    if (hoverText != null && !hoverText.equals("")) {
        hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, newComponent(hoverText));
        chatStyle.setChatHoverEvent(hoverEvent);
    }
    IChatComponent chatComponent = newComponent(text);
    chatComponent.setChatStyle(chatStyle);
    return chatComponent;
}
Also used : HoverEvent(net.minecraft.event.HoverEvent) ChatStyle(net.minecraft.util.ChatStyle) ClickEvent(net.minecraft.event.ClickEvent) IChatComponent(net.minecraft.util.IChatComponent)

Example 4 with ChatStyle

use of net.minecraft.util.ChatStyle in project Hyperium by HyperiumClient.

the class LevelheadChatRenderer method chat.

@InvokeEvent
public void chat(ServerChatEvent event) {
    if (!levelhead.getDisplayManager().getMasterConfig().isEnabled())
        return;
    LevelheadDisplay chat = Levelhead.getInstance().getDisplayManager().getChat();
    if (chat == null || !levelhead.getLevelheadPurchaseStates().isChat() || !chat.getConfig().isEnabled())
        return;
    List<IChatComponent> siblings = event.getChat().getSiblings();
    if (siblings.size() == 0)
        return;
    IChatComponent chatComponent = siblings.get(0);
    if (chatComponent instanceof ChatComponentText) {
        ChatStyle style = chatComponent.getChatStyle();
        ClickEvent clickEvent = style.getChatClickEvent();
        if (clickEvent != null && clickEvent.getAction() == ClickEvent.Action.RUN_COMMAND) {
            String value = clickEvent.getValue();
            HoverEvent hoverEvent = style.getChatHoverEvent();
            if (hoverEvent != null && hoverEvent.getAction() == HoverEvent.Action.SHOW_TEXT) {
                String[] split = value.split(" ");
                if (split.length == 2) {
                    String uuid = split[1];
                    UUID key = UUID.fromString(uuid);
                    String tag = chat.getTrueValueCache().get(key);
                    if (tag != null) {
                        event.setChat(modifyChat(event.getChat(), tag, chat.getConfig()));
                    } else if (!(chat.getCache().get(key) instanceof NullLevelheadTag)) {
                        levelhead.fetch(key, chat, false);
                    }
                }
            }
        }
    }
}
Also used : HoverEvent(net.minecraft.event.HoverEvent) ChatStyle(net.minecraft.util.ChatStyle) ClickEvent(net.minecraft.event.ClickEvent) IChatComponent(net.minecraft.util.IChatComponent) UUID(java.util.UUID) ChatComponentText(net.minecraft.util.ChatComponentText) LevelheadDisplay(cc.hyperium.mods.levelhead.display.LevelheadDisplay) InvokeEvent(cc.hyperium.event.InvokeEvent)

Example 5 with ChatStyle

use of net.minecraft.util.ChatStyle in project Hyperium by HyperiumClient.

the class ToggleChatEvents method onChatReceive.

// We use the high priority to grab things first
@InvokeEvent(priority = Priority.HIGH)
public void onChatReceive(ServerChatEvent event) {
    // Strip the message of any colors for improved detectability
    String unformattedText = ChatColor.stripColor(event.getChat().getUnformattedText());
    // The formatted message for a few of the custom toggles
    String formattedText = event.getChat().getFormattedText();
    try {
        // Loop through all the toggles
        for (ToggleBase type : mod.getToggleHandler().getToggles().values()) {
            // The chat its looking for shouldn't be toggled, move to next one!
            if (type.isEnabled())
                continue;
            // the whole toggle system crashing down in flames.
            try {
                // The text we want to input into the shouldToggle method.
                String input = type.useFormattedMessage() ? formattedText : unformattedText;
                // don't send the message to the player & stop looping
                if (type.shouldToggle(input)) {
                    if (type instanceof TypeMessageSeparator) {
                        // Attempt to keep the formatting
                        ChatStyle style = event.getChat().getChatStyle();
                        String edited = ((TypeMessageSeparator) type).editMessage(formattedText);
                        // Don't bother sending the message if its empty
                        if (!input.equals(edited) && edited.isEmpty()) {
                            event.setCancelled(true);
                        } else {
                            event.setChat(new ChatComponentText(edited).setChatStyle(style));
                        }
                    } else {
                        event.setCancelled(true);
                    }
                    break;
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    } catch (Exception e1) {
        e1.printStackTrace();
    }
}
Also used : ChatStyle(net.minecraft.util.ChatStyle) TypeMessageSeparator(cc.hyperium.mods.togglechat.toggles.defaults.TypeMessageSeparator) ChatComponentText(net.minecraft.util.ChatComponentText) ToggleBase(cc.hyperium.mods.togglechat.toggles.ToggleBase) InvokeEvent(cc.hyperium.event.InvokeEvent)

Aggregations

ChatStyle (net.minecraft.util.ChatStyle)10 ChatComponentText (net.minecraft.util.ChatComponentText)9 IChatComponent (net.minecraft.util.IChatComponent)5 ClickEvent (net.minecraft.event.ClickEvent)4 InvokeEvent (cc.hyperium.event.InvokeEvent)2 ArrayList (java.util.ArrayList)2 HoverEvent (net.minecraft.event.HoverEvent)2 LevelheadDisplay (cc.hyperium.mods.levelhead.display.LevelheadDisplay)1 ToggleBase (cc.hyperium.mods.togglechat.toggles.ToggleBase)1 TypeMessageSeparator (cc.hyperium.mods.togglechat.toggles.defaults.TypeMessageSeparator)1 UUID (java.util.UUID)1 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)1 FlagData (micdoodle8.mods.galacticraft.core.wrappers.FlagData)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 EnumChatFormatting (net.minecraft.util.EnumChatFormatting)1