Search in sources :

Example 1 with EnumChatFormat

use of net.minecraft.server.v1_16_R3.EnumChatFormat in project TheAPI by TheDevTec.

the class v1_16_R3 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 {
                for (EnumChatFormat e : EnumChatFormat.values()) if (e.character == c.getColor().charAt(0)) {
                    modif = modif.setColor(e);
                    break;
                }
            }
        }
        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 : EnumChatFormat(net.minecraft.server.v1_16_R3.EnumChatFormat) ChatClickable(net.minecraft.server.v1_16_R3.ChatClickable) ArrayList(java.util.ArrayList) ChatModifier(net.minecraft.server.v1_16_R3.ChatModifier) IChatBaseComponent(net.minecraft.server.v1_16_R3.IChatBaseComponent) ChatComponentText(net.minecraft.server.v1_16_R3.ChatComponentText)

Example 2 with EnumChatFormat

use of net.minecraft.server.v1_16_R3.EnumChatFormat in project TheAPI by TheDevTec.

the class v1_16_R3 method toIChatBaseComponents.

@Override
public Object toIChatBaseComponents(List<Component> components) {
    List<IChatBaseComponent> chat = new ArrayList<>();
    chat.add(new ChatComponentText(""));
    for (Component c : components) {
        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 {
                for (EnumChatFormat e : EnumChatFormat.values()) if (e.character == c.getColor().charAt(0)) {
                    modif = modif.setColor(e);
                    break;
                }
            }
        }
        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);
    }
    return chat.toArray(new IChatBaseComponent[0]);
}
Also used : EnumChatFormat(net.minecraft.server.v1_16_R3.EnumChatFormat) ChatClickable(net.minecraft.server.v1_16_R3.ChatClickable) ArrayList(java.util.ArrayList) ChatModifier(net.minecraft.server.v1_16_R3.ChatModifier) IChatBaseComponent(net.minecraft.server.v1_16_R3.IChatBaseComponent) Component(me.devtec.shared.components.Component) IChatBaseComponent(net.minecraft.server.v1_16_R3.IChatBaseComponent) ChatComponentText(net.minecraft.server.v1_16_R3.ChatComponentText)

Example 3 with EnumChatFormat

use of net.minecraft.server.v1_16_R3.EnumChatFormat in project TheAPI by TheDevTec.

the class v1_16_R3 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 {
                for (EnumChatFormat e : EnumChatFormat.values()) if (e.character == c.getColor().charAt(0)) {
                    modif = modif.setColor(e);
                    break;
                }
            }
        }
        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);
    }
    return main.getSiblings().isEmpty() ? ChatComponentText.d : main;
}
Also used : EnumChatFormat(net.minecraft.server.v1_16_R3.EnumChatFormat) ChatClickable(net.minecraft.server.v1_16_R3.ChatClickable) ChatModifier(net.minecraft.server.v1_16_R3.ChatModifier) IChatBaseComponent(net.minecraft.server.v1_16_R3.IChatBaseComponent) Component(me.devtec.shared.components.Component) IChatBaseComponent(net.minecraft.server.v1_16_R3.IChatBaseComponent) ChatComponentText(net.minecraft.server.v1_16_R3.ChatComponentText)

Example 4 with EnumChatFormat

use of net.minecraft.server.v1_16_R3.EnumChatFormat in project TheAPI by TheDevTec.

the class v1_16_R3 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.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 {
                for (EnumChatFormat e : EnumChatFormat.values()) if (e.character == c.getColor().charAt(0)) {
                    modif = modif.setColor(e);
                    break;
                }
            }
        }
        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 main.getSiblings().isEmpty() ? ChatComponentText.d : main;
}
Also used : EnumChatFormat(net.minecraft.server.v1_16_R3.EnumChatFormat) ChatClickable(net.minecraft.server.v1_16_R3.ChatClickable) ChatModifier(net.minecraft.server.v1_16_R3.ChatModifier) IChatBaseComponent(net.minecraft.server.v1_16_R3.IChatBaseComponent) ChatComponentText(net.minecraft.server.v1_16_R3.ChatComponentText)

Example 5 with EnumChatFormat

use of net.minecraft.server.v1_16_R3.EnumChatFormat in project PaperDev by Kamillaova.

the class ChatTest method testColors.

@Test
public void testColors() {
    for (ChatColor color : ChatColor.values()) {
        Assert.assertNotNull(CraftChatMessage.getColor(color));
        Assert.assertEquals(color, CraftChatMessage.getColor(CraftChatMessage.getColor(color)));
    }
    for (EnumChatFormat format : EnumChatFormat.values()) {
        Assert.assertNotNull(CraftChatMessage.getColor(format));
        Assert.assertEquals(format, CraftChatMessage.getColor(CraftChatMessage.getColor(format)));
    }
}
Also used : EnumChatFormat(net.minecraft.server.v1_12_R1.EnumChatFormat) Test(org.junit.Test)

Aggregations

ChatClickable (net.minecraft.server.v1_16_R3.ChatClickable)4 ChatComponentText (net.minecraft.server.v1_16_R3.ChatComponentText)4 ChatModifier (net.minecraft.server.v1_16_R3.ChatModifier)4 EnumChatFormat (net.minecraft.server.v1_16_R3.EnumChatFormat)4 IChatBaseComponent (net.minecraft.server.v1_16_R3.IChatBaseComponent)4 ArrayList (java.util.ArrayList)2 Component (me.devtec.shared.components.Component)2 EnumChatFormat (net.minecraft.server.v1_12_R1.EnumChatFormat)1 Test (org.junit.Test)1