ScoreboardSaveData .java

net.minecraft.scoreboard.ScoreboardSaveData (class): members: readDisplayConfig, objectivesToNbt, delayedInitNbt, readObjectives, setScoreboard, readTeams.

net.minecraft.scoreboardclass309 linescommonextends WorldSavedData10.4 KB

API Surface (12)

void setScoreboard(Scoreboard scoreboardIn)
void readFromNBT(NBTTagCompound nbt)
void readTeams(NBTTagList p_96498_1_)
void func_96502_a(ScorePlayerTeam p_96502_1_, NBTTagList p_96502_2_)
void readDisplayConfig(NBTTagCompound p_96504_1_)
void readObjectives(NBTTagList nbt)
void readScores(NBTTagList nbt)
void writeToNBT(NBTTagCompound nbt)
NBTTagList func_96496_a()
void func_96497_d(NBTTagCompound p_96497_1_)
NBTTagList objectivesToNbt()
NBTTagList scoresToNbt()

Fields & Constants (3)

logger
theScoreboard
delayedInitNbt

String literals (20)

"scoreboard"
"Objectives"
"PlayerScores"
"DisplaySlots"
"Teams"
"DisplayName"
"TeamColor"
"Prefix"
"Suffix"
"AllowFriendlyFire"
"SeeFriendlyInvisibles"
"NameTagVisibility"
"DeathMessageVisibility"
"Players"
"slot_"
"CriteriaName"
"RenderType"
"Objective"
"Score"
"Locked"

Full Source

ScoreboardSaveData.java309 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.scoreboard;
2
3
import net.minecraft.nbt.NBTTagCompound;
4
import net.minecraft.nbt.NBTTagList;
5
import net.minecraft.nbt.NBTTagString;
6
import net.minecraft.util.EnumChatFormatting;
7
import net.minecraft.world.WorldSavedData;
8
import org.apache.logging.log4j.LogManager;
9
import org.apache.logging.log4j.Logger;
10
11
public class ScoreboardSaveData extends WorldSavedData
12
{
13
    private static final Logger logger = LogManager.getLogger();
14
    private Scoreboard theScoreboard;
15
    private NBTTagCompound delayedInitNbt;
16
17
    public ScoreboardSaveData()
18
    {
19
        this("scoreboard");
20
    }
21
22
    public ScoreboardSaveData(String name)
23
    {
24
        super(name);
25
    }
26
27
    public void setScoreboard(Scoreboard scoreboardIn)
28
    {
29
        this.theScoreboard = scoreboardIn;
30
31
        if (this.delayedInitNbt != null)
32
        {
33
            this.readFromNBT(this.delayedInitNbt);
34
        }
35
    }
36
37
    /**
38
     * reads in data from the NBTTagCompound into this MapDataBase
39
     */
40
    public void readFromNBT(NBTTagCompound nbt)
41
    {
42
        if (this.theScoreboard == null)
43
        {
44
            this.delayedInitNbt = nbt;
45
        }
46
        else
47
        {
48
            this.readObjectives(nbt.getTagList("Objectives", 10));
49
            this.readScores(nbt.getTagList("PlayerScores", 10));
50
51
            if (nbt.hasKey("DisplaySlots", 10))
52
            {
53
                this.readDisplayConfig(nbt.getCompoundTag("DisplaySlots"));
54
            }
55
56
            if (nbt.hasKey("Teams", 9))
57
            {
58
                this.readTeams(nbt.getTagList("Teams", 10));
59
            }
60
        }
61
    }
62
63
    protected void readTeams(NBTTagList p_96498_1_)
64
    {
65
        for (int i = 0; i < p_96498_1_.tagCount(); ++i)
66
        {
67
            NBTTagCompound nbttagcompound = p_96498_1_.getCompoundTagAt(i);
68
            String s = nbttagcompound.getString("Name");
69
70
            if (s.length() > 16)
71
            {
72
                s = s.substring(0, 16);
73
            }
74
75
            ScorePlayerTeam scoreplayerteam = this.theScoreboard.createTeam(s);
76
            String s1 = nbttagcompound.getString("DisplayName");
77
78
            if (s1.length() > 32)
79
            {
80
                s1 = s1.substring(0, 32);
81
            }
82
83
            scoreplayerteam.setTeamName(s1);
84
85
            if (nbttagcompound.hasKey("TeamColor", 8))
86
            {
87
                scoreplayerteam.setChatFormat(EnumChatFormatting.getValueByName(nbttagcompound.getString("TeamColor")));
88
            }
89
90
            scoreplayerteam.setNamePrefix(nbttagcompound.getString("Prefix"));
91
            scoreplayerteam.setNameSuffix(nbttagcompound.getString("Suffix"));
92
93
            if (nbttagcompound.hasKey("AllowFriendlyFire", 99))
94
            {
95
                scoreplayerteam.setAllowFriendlyFire(nbttagcompound.getBoolean("AllowFriendlyFire"));
96
            }
97
98
            if (nbttagcompound.hasKey("SeeFriendlyInvisibles", 99))
99
            {
100
                scoreplayerteam.setSeeFriendlyInvisiblesEnabled(nbttagcompound.getBoolean("SeeFriendlyInvisibles"));
101
            }
102
103
            if (nbttagcompound.hasKey("NameTagVisibility", 8))
104
            {
105
                Team.EnumVisible team$enumvisible = Team.EnumVisible.func_178824_a(nbttagcompound.getString("NameTagVisibility"));
106
107
                if (team$enumvisible != null)
108
                {
109
                    scoreplayerteam.setNameTagVisibility(team$enumvisible);
110
                }
111
            }
112
113
            if (nbttagcompound.hasKey("DeathMessageVisibility", 8))
114
            {
115
                Team.EnumVisible team$enumvisible1 = Team.EnumVisible.func_178824_a(nbttagcompound.getString("DeathMessageVisibility"));
116
117
                if (team$enumvisible1 != null)
118
                {
119
                    scoreplayerteam.setDeathMessageVisibility(team$enumvisible1);
120
                }
121
            }
122
123
            this.func_96502_a(scoreplayerteam, nbttagcompound.getTagList("Players", 8));
124
        }
125
    }
126
127
    protected void func_96502_a(ScorePlayerTeam p_96502_1_, NBTTagList p_96502_2_)
128
    {
129
        for (int i = 0; i < p_96502_2_.tagCount(); ++i)
130
        {
131
            this.theScoreboard.addPlayerToTeam(p_96502_2_.getStringTagAt(i), p_96502_1_.getRegisteredName());
132
        }
133
    }
134
135
    protected void readDisplayConfig(NBTTagCompound p_96504_1_)
136
    {
137
        for (int i = 0; i < 19; ++i)
138
        {
139
            if (p_96504_1_.hasKey("slot_" + i, 8))
140
            {
141
                String s = p_96504_1_.getString("slot_" + i);
142
                ScoreObjective scoreobjective = this.theScoreboard.getObjective(s);
143
                this.theScoreboard.setObjectiveInDisplaySlot(i, scoreobjective);
144
            }
145
        }
146
    }
147
148
    protected void readObjectives(NBTTagList nbt)
149
    {
150
        for (int i = 0; i < nbt.tagCount(); ++i)
151
        {
152
            NBTTagCompound nbttagcompound = nbt.getCompoundTagAt(i);
153
            IScoreObjectiveCriteria iscoreobjectivecriteria = (IScoreObjectiveCriteria)IScoreObjectiveCriteria.INSTANCES.get(nbttagcompound.getString("CriteriaName"));
154
155
            if (iscoreobjectivecriteria != null)
156
            {
157
                String s = nbttagcompound.getString("Name");
158
159
                if (s.length() > 16)
160
                {
161
                    s = s.substring(0, 16);
162
                }
163
164
                ScoreObjective scoreobjective = this.theScoreboard.addScoreObjective(s, iscoreobjectivecriteria);
165
                scoreobjective.setDisplayName(nbttagcompound.getString("DisplayName"));
166
                scoreobjective.setRenderType(IScoreObjectiveCriteria.EnumRenderType.func_178795_a(nbttagcompound.getString("RenderType")));
167
            }
168
        }
169
    }
170
171
    protected void readScores(NBTTagList nbt)
172
    {
173
        for (int i = 0; i < nbt.tagCount(); ++i)
174
        {
175
            NBTTagCompound nbttagcompound = nbt.getCompoundTagAt(i);
176
            ScoreObjective scoreobjective = this.theScoreboard.getObjective(nbttagcompound.getString("Objective"));
177
            String s = nbttagcompound.getString("Name");
178
179
            if (s.length() > 40)
180
            {
181
                s = s.substring(0, 40);
182
            }
183
184
            Score score = this.theScoreboard.getValueFromObjective(s, scoreobjective);
185
            score.setScorePoints(nbttagcompound.getInteger("Score"));
186
187
            if (nbttagcompound.hasKey("Locked"))
188
            {
189
                score.setLocked(nbttagcompound.getBoolean("Locked"));
190
            }
191
        }
192
    }
193
194
    /**
195
     * write data to NBTTagCompound from this MapDataBase, similar to Entities and TileEntities
196
     */
197
    public void writeToNBT(NBTTagCompound nbt)
198
    {
199
        if (this.theScoreboard == null)
200
        {
201
            logger.warn("Tried to save scoreboard without having a scoreboard...");
202
        }
203
        else
204
        {
205
            nbt.setTag("Objectives", this.objectivesToNbt());
206
            nbt.setTag("PlayerScores", this.scoresToNbt());
207
            nbt.setTag("Teams", this.func_96496_a());
208
            this.func_96497_d(nbt);
209
        }
210
    }
211
212
    protected NBTTagList func_96496_a()
213
    {
214
        NBTTagList nbttaglist = new NBTTagList();
215
216
        for (ScorePlayerTeam scoreplayerteam : this.theScoreboard.getTeams())
217
        {
218
            NBTTagCompound nbttagcompound = new NBTTagCompound();
219
            nbttagcompound.setString("Name", scoreplayerteam.getRegisteredName());
220
            nbttagcompound.setString("DisplayName", scoreplayerteam.getTeamName());
221
222
            if (scoreplayerteam.getChatFormat().getColorIndex() >= 0)
223
            {
224
                nbttagcompound.setString("TeamColor", scoreplayerteam.getChatFormat().getFriendlyName());
225
            }
226
227
            nbttagcompound.setString("Prefix", scoreplayerteam.getColorPrefix());
228
            nbttagcompound.setString("Suffix", scoreplayerteam.getColorSuffix());
229
            nbttagcompound.setBoolean("AllowFriendlyFire", scoreplayerteam.getAllowFriendlyFire());
230
            nbttagcompound.setBoolean("SeeFriendlyInvisibles", scoreplayerteam.getSeeFriendlyInvisiblesEnabled());
231
            nbttagcompound.setString("NameTagVisibility", scoreplayerteam.getNameTagVisibility().internalName);
232
            nbttagcompound.setString("DeathMessageVisibility", scoreplayerteam.getDeathMessageVisibility().internalName);
233
            NBTTagList nbttaglist1 = new NBTTagList();
234
235
            for (String s : scoreplayerteam.getMembershipCollection())
236
            {
237
                nbttaglist1.appendTag(new NBTTagString(s));
238
            }
239
240
            nbttagcompound.setTag("Players", nbttaglist1);
241
            nbttaglist.appendTag(nbttagcompound);
242
        }
243
244
        return nbttaglist;
245
    }
246
247
    protected void func_96497_d(NBTTagCompound p_96497_1_)
248
    {
249
        NBTTagCompound nbttagcompound = new NBTTagCompound();
250
        boolean flag = false;
251
252
        for (int i = 0; i < 19; ++i)
253
        {
254
            ScoreObjective scoreobjective = this.theScoreboard.getObjectiveInDisplaySlot(i);
255
256
            if (scoreobjective != null)
257
            {
258
                nbttagcompound.setString("slot_" + i, scoreobjective.getName());
259
                flag = true;
260
            }
261
        }
262
263
        if (flag)
264
        {
265
            p_96497_1_.setTag("DisplaySlots", nbttagcompound);
266
        }
267
    }
268
269
    protected NBTTagList objectivesToNbt()
270
    {
271
        NBTTagList nbttaglist = new NBTTagList();
272
273
        for (ScoreObjective scoreobjective : this.theScoreboard.getScoreObjectives())
274
        {
275
            if (scoreobjective.getCriteria() != null)
276
            {
277
                NBTTagCompound nbttagcompound = new NBTTagCompound();
278
                nbttagcompound.setString("Name", scoreobjective.getName());
279
                nbttagcompound.setString("CriteriaName", scoreobjective.getCriteria().getName());
280
                nbttagcompound.setString("DisplayName", scoreobjective.getDisplayName());
281
                nbttagcompound.setString("RenderType", scoreobjective.getRenderType().func_178796_a());
282
                nbttaglist.appendTag(nbttagcompound);
283
            }
284
        }
285
286
        return nbttaglist;
287
    }
288
289
    protected NBTTagList scoresToNbt()
290
    {
291
        NBTTagList nbttaglist = new NBTTagList();
292
293
        for (Score score : this.theScoreboard.getScores())
294
        {
295
            if (score.getObjective() != null)
296
            {
297
                NBTTagCompound nbttagcompound = new NBTTagCompound();
298
                nbttagcompound.setString("Name", score.getPlayerName());
299
                nbttagcompound.setString("Objective", score.getObjective().getName());
300
                nbttagcompound.setInteger("Score", score.getScorePoints());
301
                nbttagcompound.setBoolean("Locked", score.isLocked());
302
                nbttaglist.appendTag(nbttagcompound);
303
            }
304
        }
305
306
        return nbttaglist;
307
    }
308
}
309

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