Search in sources :

Example 16 with IChatBaseComponent

use of net.minecraft.network.chat.IChatBaseComponent in project TheAPI by TheDevTec.

the class v1_17_R1 method toIChatBaseComponent.

@Override
public Object toIChatBaseComponent(List<Component> cc) {
    ChatComponentText main = new ChatComponentText("");
    for (Component c : cc) {
        if (c.getText() == null || c.getText().isEmpty()) {
            c = c.getExtra();
            continue;
        }
        ChatComponentText current = new ChatComponentText(c.getText());
        main.addSibling(current);
        ChatModifier modif = current.getChatModifier();
        if (c.getColor() != null && !c.getColor().isEmpty()) {
            if (c.getColor().startsWith("#"))
                modif = modif.setColor(ChatHexColor.a(c.getColor()));
            else
                modif = modif.setColor(EnumChatFormat.a(c.getColor().charAt(0)));
        }
        if (c.getClickEvent() != null)
            modif = modif.setChatClickable(new ChatClickable(EnumClickAction.a(c.getClickEvent().getAction().name().toLowerCase()), c.getClickEvent().getValue()));
        if (c.getHoverEvent() != null)
            modif = modif.setChatHoverable(EnumHoverAction.a(c.getHoverEvent().getAction().name().toLowerCase()).a((IChatBaseComponent) toIChatBaseComponent(c.getHoverEvent().getValue())));
        modif = modif.setBold(c.isBold());
        modif = modif.setItalic(c.isItalic());
        modif = modif.setRandom(c.isObfuscated());
        modif = modif.setUnderline(c.isUnderlined());
        modif = modif.setStrikethrough(c.isStrikethrough());
        current.setChatModifier(modif);
    }
    return main.getSiblings().isEmpty() ? ChatComponentText.d : main;
}
Also used : ChatClickable(net.minecraft.network.chat.ChatClickable) ChatModifier(net.minecraft.network.chat.ChatModifier) IChatBaseComponent(net.minecraft.network.chat.IChatBaseComponent) Component(me.devtec.shared.components.Component) IChatBaseComponent(net.minecraft.network.chat.IChatBaseComponent) ChatComponentText(net.minecraft.network.chat.ChatComponentText)

Example 17 with IChatBaseComponent

use of net.minecraft.network.chat.IChatBaseComponent in project TheAPI by TheDevTec.

the class v1_17_R1 method toIChatBaseComponents.

@Override
public Object toIChatBaseComponents(Component c) {
    List<IChatBaseComponent> chat = new ArrayList<>();
    chat.add(new ChatComponentText(""));
    while (c != null) {
        if (c.getText() == null || c.getText().isEmpty()) {
            c = c.getExtra();
            continue;
        }
        ChatComponentText current = new ChatComponentText(c.getText());
        chat.add(current);
        ChatModifier modif = current.getChatModifier();
        if (c.getColor() != null && !c.getColor().isEmpty()) {
            if (c.getColor().startsWith("#"))
                modif = modif.setColor(ChatHexColor.a(c.getColor()));
            else
                modif = modif.setColor(EnumChatFormat.a(c.getColor().charAt(0)));
        }
        if (c.getClickEvent() != null)
            modif = modif.setChatClickable(new ChatClickable(EnumClickAction.valueOf(c.getClickEvent().getAction().name()), c.getClickEvent().getValue()));
        if (c.getHoverEvent() != null)
            modif = modif.setChatHoverable(EnumHoverAction.a(c.getHoverEvent().getAction().name().toLowerCase()).a((IChatBaseComponent) toIChatBaseComponent(c.getHoverEvent().getValue())));
        modif = modif.setBold(c.isBold());
        modif = modif.setItalic(c.isItalic());
        modif = modif.setRandom(c.isObfuscated());
        modif = modif.setUnderline(c.isUnderlined());
        modif = modif.setStrikethrough(c.isStrikethrough());
        current.setChatModifier(modif);
        c = c.getExtra();
    }
    return chat.toArray(new IChatBaseComponent[0]);
}
Also used : ChatClickable(net.minecraft.network.chat.ChatClickable) ArrayList(java.util.ArrayList) ChatModifier(net.minecraft.network.chat.ChatModifier) IChatBaseComponent(net.minecraft.network.chat.IChatBaseComponent) ChatComponentText(net.minecraft.network.chat.ChatComponentText)

Example 18 with IChatBaseComponent

use of net.minecraft.network.chat.IChatBaseComponent in project TheAPI by TheDevTec.

the class v1_18_R1 method toIChatBaseComponent.

@Override
public Object toIChatBaseComponent(List<Component> cc) {
    ChatComponentText main = new ChatComponentText("");
    for (Component c : cc) {
        if (c.getText() == null || c.getText().isEmpty()) {
            c = c.getExtra();
            continue;
        }
        ChatComponentText current = new ChatComponentText(c.getText());
        main.a(current);
        ChatModifier modif = current.c();
        if (c.getColor() != null && !c.getColor().isEmpty()) {
            if (c.getColor().startsWith("#"))
                modif = modif.a(ChatHexColor.a(c.getColor()));
            else
                modif = modif.a(EnumChatFormat.a(c.getColor().charAt(0)));
        }
        if (c.getClickEvent() != null) {
            modif = modif.a(new ChatClickable(EnumClickAction.a(c.getClickEvent().getAction().name().toLowerCase()), c.getClickEvent().getValue()));
        }
        if (c.getHoverEvent() != null)
            modif = modif.a(EnumHoverAction.a(c.getHoverEvent().getAction().name().toLowerCase()).a((IChatBaseComponent) toIChatBaseComponent(c.getHoverEvent().getValue())));
        modif = modif.a(c.isBold());
        modif = modif.b(c.isItalic());
        modif = modif.e(c.isObfuscated());
        modif = modif.c(c.isUnderlined());
        modif = modif.d(c.isStrikethrough());
        current.a(modif);
    }
    return main.b().isEmpty() ? ChatComponentText.d : main;
}
Also used : ChatClickable(net.minecraft.network.chat.ChatClickable) ChatModifier(net.minecraft.network.chat.ChatModifier) IChatBaseComponent(net.minecraft.network.chat.IChatBaseComponent) Component(me.devtec.shared.components.Component) IChatBaseComponent(net.minecraft.network.chat.IChatBaseComponent) ChatComponentText(net.minecraft.network.chat.ChatComponentText)

Example 19 with IChatBaseComponent

use of net.minecraft.network.chat.IChatBaseComponent in project TheAPI by TheDevTec.

the class v1_18_R2 method toIChatBaseComponent.

@Override
public Object toIChatBaseComponent(Component c) {
    ChatComponentText main = new ChatComponentText("");
    while (c != null) {
        if (c.getText() == null || c.getText().isEmpty()) {
            c = c.getExtra();
            continue;
        }
        ChatComponentText current = new ChatComponentText(c.getText());
        main.a(current);
        ChatModifier modif = current.c();
        if (c.getColor() != null && !c.getColor().isEmpty()) {
            if (c.getColor().startsWith("#"))
                modif = modif.a(ChatHexColor.a(c.getColor()));
            else
                modif = modif.a(EnumChatFormat.a(c.getColor().charAt(0)));
        }
        if (c.getClickEvent() != null)
            modif = modif.a(new ChatClickable(EnumClickAction.a(c.getClickEvent().getAction().name().toLowerCase()), c.getClickEvent().getValue()));
        if (c.getHoverEvent() != null)
            modif = modif.a(EnumHoverAction.a(c.getHoverEvent().getAction().name().toLowerCase()).a((IChatBaseComponent) toIChatBaseComponent(c.getHoverEvent().getValue())));
        modif = modif.a(c.isBold());
        modif = modif.b(c.isItalic());
        modif = modif.e(c.isObfuscated());
        modif = modif.c(c.isUnderlined());
        modif = modif.d(c.isStrikethrough());
        current.a(modif);
        c = c.getExtra();
    }
    return main.b().isEmpty() ? ChatComponentText.d : main;
}
Also used : ChatClickable(net.minecraft.network.chat.ChatClickable) ChatModifier(net.minecraft.network.chat.ChatModifier) IChatBaseComponent(net.minecraft.network.chat.IChatBaseComponent) ChatComponentText(net.minecraft.network.chat.ChatComponentText)

Example 20 with IChatBaseComponent

use of net.minecraft.network.chat.IChatBaseComponent in project TheAPI by TheDevTec.

the class v1_18_R2 method toIChatBaseComponent.

@Override
public Object toIChatBaseComponent(List<Component> cc) {
    ChatComponentText main = new ChatComponentText("");
    for (Component c : cc) {
        if (c.getText() == null || c.getText().isEmpty()) {
            c = c.getExtra();
            continue;
        }
        ChatComponentText current = new ChatComponentText(c.getText());
        main.a(current);
        ChatModifier modif = current.c();
        if (c.getColor() != null && !c.getColor().isEmpty()) {
            if (c.getColor().startsWith("#"))
                modif = modif.a(ChatHexColor.a(c.getColor()));
            else
                modif = modif.a(EnumChatFormat.a(c.getColor().charAt(0)));
        }
        if (c.getClickEvent() != null) {
            modif = modif.a(new ChatClickable(EnumClickAction.a(c.getClickEvent().getAction().name().toLowerCase()), c.getClickEvent().getValue()));
        }
        if (c.getHoverEvent() != null)
            modif = modif.a(EnumHoverAction.a(c.getHoverEvent().getAction().name().toLowerCase()).a((IChatBaseComponent) toIChatBaseComponent(c.getHoverEvent().getValue())));
        modif = modif.a(c.isBold());
        modif = modif.b(c.isItalic());
        modif = modif.e(c.isObfuscated());
        modif = modif.c(c.isUnderlined());
        modif = modif.d(c.isStrikethrough());
        current.a(modif);
    }
    return main.b().isEmpty() ? ChatComponentText.d : main;
}
Also used : ChatClickable(net.minecraft.network.chat.ChatClickable) ChatModifier(net.minecraft.network.chat.ChatModifier) IChatBaseComponent(net.minecraft.network.chat.IChatBaseComponent) Component(me.devtec.shared.components.Component) IChatBaseComponent(net.minecraft.network.chat.IChatBaseComponent) ChatComponentText(net.minecraft.network.chat.ChatComponentText)

Aggregations

IChatBaseComponent (net.minecraft.network.chat.IChatBaseComponent)20 ChatClickable (net.minecraft.network.chat.ChatClickable)12 ChatComponentText (net.minecraft.network.chat.ChatComponentText)12 ChatModifier (net.minecraft.network.chat.ChatModifier)12 ArrayList (java.util.ArrayList)9 Component (me.devtec.shared.components.Component)6 GameProfile (com.mojang.authlib.GameProfile)5 Channel (io.netty.channel.Channel)3 ServerListPingEvent (me.devtec.theapi.bukkit.events.ServerListPingEvent)3 PlayerProfile (me.devtec.theapi.bukkit.events.ServerListPingEvent.PlayerProfile)3 PacketStatusOutServerInfo (net.minecraft.network.protocol.status.PacketStatusOutServerInfo)3 ServerPing (net.minecraft.network.protocol.status.ServerPing)3 ServerData (net.minecraft.network.protocol.status.ServerPing.ServerData)3 ServerPingPlayerSample (net.minecraft.network.protocol.status.ServerPing.ServerPingPlayerSample)3 EntityPlayer (net.minecraft.server.level.EntityPlayer)3 CraftPlayer (org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)3 CraftPlayer (org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer)3 Player (org.bukkit.entity.Player)3 Packet (net.minecraft.network.protocol.Packet)2 PacketPlayOutPlayerInfo (net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo)2