ChatComponentProcessor .java

net.minecraft.util.ChatComponentProcessor (class): members: processComponent. imports: EntityNotFoundException, PlayerSelector, CommandException, Entity.

net.minecraft.utilclass87 linescommon3.0 KB

API Surface (1)

IChatComponent processComponent(ICommandSender commandSender, IChatComponent component, Entity entityIn)

Full Source

ChatComponentProcessor.java87 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.util;
2
3
import java.util.List;
4
import net.minecraft.command.CommandException;
5
import net.minecraft.command.EntityNotFoundException;
6
import net.minecraft.command.ICommandSender;
7
import net.minecraft.command.PlayerSelector;
8
import net.minecraft.entity.Entity;
9
10
public class ChatComponentProcessor
11
{
12
    public static IChatComponent processComponent(ICommandSender commandSender, IChatComponent component, Entity entityIn) throws CommandException
13
    {
14
        IChatComponent ichatcomponent = null;
15
16
        if (component instanceof ChatComponentScore)
17
        {
18
            ChatComponentScore chatcomponentscore = (ChatComponentScore)component;
19
            String s = chatcomponentscore.getName();
20
21
            if (PlayerSelector.hasArguments(s))
22
            {
23
                List<Entity> list = PlayerSelector.<Entity>matchEntities(commandSender, s, Entity.class);
24
25
                if (list.size() != 1)
26
                {
27
                    throw new EntityNotFoundException();
28
                }
29
30
                s = ((Entity)list.get(0)).getName();
31
            }
32
33
            ichatcomponent = entityIn != null && s.equals("*") ? new ChatComponentScore(entityIn.getName(), chatcomponentscore.getObjective()) : new ChatComponentScore(s, chatcomponentscore.getObjective());
34
            ((ChatComponentScore)ichatcomponent).setValue(chatcomponentscore.getUnformattedTextForChat());
35
        }
36
        else if (component instanceof ChatComponentSelector)
37
        {
38
            String s1 = ((ChatComponentSelector)component).getSelector();
39
            ichatcomponent = PlayerSelector.matchEntitiesToChatComponent(commandSender, s1);
40
41
            if (ichatcomponent == null)
42
            {
43
                ichatcomponent = new ChatComponentText("");
44
            }
45
        }
46
        else if (component instanceof ChatComponentText)
47
        {
48
            ichatcomponent = new ChatComponentText(((ChatComponentText)component).getChatComponentText_TextValue());
49
        }
50
        else
51
        {
52
            if (!(component instanceof ChatComponentTranslation))
53
            {
54
                return component;
55
            }
56
57
            Object[] aobject = ((ChatComponentTranslation)component).getFormatArgs();
58
59
            for (int i = 0; i < aobject.length; ++i)
60
            {
61
                Object object = aobject[i];
62
63
                if (object instanceof IChatComponent)
64
                {
65
                    aobject[i] = processComponent(commandSender, (IChatComponent)object, entityIn);
66
                }
67
            }
68
69
            ichatcomponent = new ChatComponentTranslation(((ChatComponentTranslation)component).getKey(), aobject);
70
        }
71
72
        ChatStyle chatstyle = component.getChatStyle();
73
74
        if (chatstyle != null)
75
        {
76
            ichatcomponent.setChatStyle(chatstyle.createShallowCopy());
77
        }
78
79
        for (IChatComponent ichatcomponent1 : component.getSiblings())
80
        {
81
            ichatcomponent.appendSibling(processComponent(commandSender, ichatcomponent1, entityIn));
82
        }
83
84
        return ichatcomponent;
85
    }
86
}
87

Deobfuscated MCP 1.8.9 source of ChatComponentProcessor from Marcelektro/MavenMCP-1.8.9 (net/minecraft/util/ChatComponentProcessor.java), stored verbatim.