Search in sources :

Example 1 with LevelheadDisplay

use of cc.hyperium.mods.levelhead.display.LevelheadDisplay 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)

Aggregations

InvokeEvent (cc.hyperium.event.InvokeEvent)1 LevelheadDisplay (cc.hyperium.mods.levelhead.display.LevelheadDisplay)1 UUID (java.util.UUID)1 ClickEvent (net.minecraft.event.ClickEvent)1 HoverEvent (net.minecraft.event.HoverEvent)1 ChatComponentText (net.minecraft.util.ChatComponentText)1 ChatStyle (net.minecraft.util.ChatStyle)1 IChatComponent (net.minecraft.util.IChatComponent)1