ChatComponentScore .java

net.minecraft.util.ChatComponentScore (class): members: objective, setValue, getObjective, getUnformattedTextForChat, createCopy, value, name, equals.

net.minecraft.utilclass106 linescommonextends ChatComponentStyle3.1 KB

API Surface (7)

String getName()
String getObjective()
void setValue(String valueIn)
String getUnformattedTextForChat()
ChatComponentScore createCopy()
boolean equals(Object p_equals_1_)
String toString()

Fields & Constants (3)

name
objective
value

String literals (4)

"ScoreComponent{name=\'"
"objective=\'"
", siblings="
", style="

Code Graph: Dependencies (6)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

ChatComponentScore.java106 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.util;
2
3
import net.minecraft.scoreboard.Score;
4
import net.minecraft.scoreboard.ScoreObjective;
5
import net.minecraft.scoreboard.Scoreboard;
6
import net.minecraft.server.MinecraftServer;
7
8
public class ChatComponentScore extends ChatComponentStyle
9
{
10
    private final String name;
11
    private final String objective;
12
13
    /** The value displayed instead of the real score (may be null) */
14
    private String value = "";
15
16
    public ChatComponentScore(String nameIn, String objectiveIn)
17
    {
18
        this.name = nameIn;
19
        this.objective = objectiveIn;
20
    }
21
22
    public String getName()
23
    {
24
        return this.name;
25
    }
26
27
    public String getObjective()
28
    {
29
        return this.objective;
30
    }
31
32
    /**
33
     * Sets the value displayed instead of the real score.
34
     */
35
    public void setValue(String valueIn)
36
    {
37
        this.value = valueIn;
38
    }
39
40
    /**
41
     * Gets the text of this component, without any special formatting codes added, for chat.  TODO: why is this two
42
     * different methods?
43
     */
44
    public String getUnformattedTextForChat()
45
    {
46
        MinecraftServer minecraftserver = MinecraftServer.getServer();
47
48
        if (minecraftserver != null && minecraftserver.isAnvilFileSet() && StringUtils.isNullOrEmpty(this.value))
49
        {
50
            Scoreboard scoreboard = minecraftserver.worldServerForDimension(0).getScoreboard();
51
            ScoreObjective scoreobjective = scoreboard.getObjective(this.objective);
52
53
            if (scoreboard.entityHasObjective(this.name, scoreobjective))
54
            {
55
                Score score = scoreboard.getValueFromObjective(this.name, scoreobjective);
56
                this.setValue(String.format("%d", new Object[] {Integer.valueOf(score.getScorePoints())}));
57
            }
58
            else
59
            {
60
                this.value = "";
61
            }
62
        }
63
64
        return this.value;
65
    }
66
67
    /**
68
     * Creates a copy of this component.  Almost a deep copy, except the style is shallow-copied.
69
     */
70
    public ChatComponentScore createCopy()
71
    {
72
        ChatComponentScore chatcomponentscore = new ChatComponentScore(this.name, this.objective);
73
        chatcomponentscore.setValue(this.value);
74
        chatcomponentscore.setChatStyle(this.getChatStyle().createShallowCopy());
75
76
        for (IChatComponent ichatcomponent : this.getSiblings())
77
        {
78
            chatcomponentscore.appendSibling(ichatcomponent.createCopy());
79
        }
80
81
        return chatcomponentscore;
82
    }
83
84
    public boolean equals(Object p_equals_1_)
85
    {
86
        if (this == p_equals_1_)
87
        {
88
            return true;
89
        }
90
        else if (!(p_equals_1_ instanceof ChatComponentScore))
91
        {
92
            return false;
93
        }
94
        else
95
        {
96
            ChatComponentScore chatcomponentscore = (ChatComponentScore)p_equals_1_;
97
            return this.name.equals(chatcomponentscore.name) && this.objective.equals(chatcomponentscore.objective) && super.equals(p_equals_1_);
98
        }
99
    }
100
101
    public String toString()
102
    {
103
        return "ScoreComponent{name=\'" + this.name + '\'' + "objective=\'" + this.objective + '\'' + ", siblings=" + this.siblings + ", style=" + this.getChatStyle() + '}';
104
    }
105
}
106

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