1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
#pragma once
// 4J Not converted
#if 0
class ScoreboardSaveData extends SavedData {
public static final String FILE_ID = "scoreboard";
private Scoreboard scoreboard;
private CompoundTag delayLoad;
public ScoreboardSaveData() {
this(FILE_ID);
}
public ScoreboardSaveData(String id) {
super(id);
}
public void setScoreboard(Scoreboard scoreboard) {
this.scoreboard = scoreboard;
if (delayLoad != null) {
load(delayLoad);
}
}
@Override
public void load(CompoundTag tag) {
if (scoreboard == null) {
delayLoad = tag;
return;
}
loadObjectives((ListTag<CompoundTag>) tag.getList("Objectives"));
loadPlayerScores((ListTag<CompoundTag>) tag.getList("PlayerScores"));
if (tag.contains("DisplaySlots")) {
loadDisplaySlots(tag.getCompound("DisplaySlots"));
}
if (tag.contains("Teams")) {
loadTeams((ListTag<CompoundTag>) tag.getList("Teams"));
}
}
protected void loadTeams(ListTag<CompoundTag> list) {
for (int i = 0; i < list.size(); i++) {
CompoundTag tag = list.get(i);
PlayerTeam team = scoreboard.addPlayerTeam(tag.getString("Name"));
team.setDisplayName(tag.getString("DisplayName"));
team.setPrefix(tag.getString("Prefix"));
team.setSuffix(tag.getString("Suffix"));
if (tag.contains("AllowFriendlyFire")) team.setAllowFriendlyFire(tag.getBoolean("AllowFriendlyFire"));
if (tag.contains("SeeFriendlyInvisibles")) team.setSeeFriendlyInvisibles(tag.getBoolean("SeeFriendlyInvisibles"));
loadTeamPlayers(team, (ListTag<StringTag>) tag.getList("Players"));
}
}
protected void loadTeamPlayers(PlayerTeam team, ListTag<StringTag> list) {
for (int i = 0; i < list.size(); i++) {
scoreboard.addPlayerToTeam(list.get(i).data, team);
}
}
protected void loadDisplaySlots(CompoundTag tag) {
for (int i = 0; i < Scoreboard.DISPLAY_SLOTS; i++) {
if (tag.contains("slot_" + i)) {
String name = tag.getString("slot_" + i);
Objective objective = scoreboard.getObjective(name);
scoreboard.setDisplayObjective(i, objective);
}
}
}
protected void loadObjectives(ListTag<CompoundTag> list) {
for (int i = 0; i < list.size(); i++) {
CompoundTag tag = list.get(i);
ObjectiveCriteria criteria = ObjectiveCriteria.CRITERIA_BY_NAME.get(tag.getString("CriteriaName"));
Objective objective = scoreboard.addObjective(tag.getString("Name"), criteria);
objective.setDisplayName(tag.getString("DisplayName"));
}
}
protected void loadPlayerScores(ListTag<CompoundTag> list) {
for (int i = 0; i < list.size(); i++) {
CompoundTag tag = list.get(i);
Objective objective = scoreboard.getObjective(tag.getString("Objective"));
Score score = scoreboard.getPlayerScore(tag.getString("Name"), objective);
score.setScore(tag.getInt("Score"));
}
}
@Override
public void save(CompoundTag tag) {
if (scoreboard == null) {
MinecraftServer.getInstance().getLogger().warning("Tried to save scoreboard without having a scoreboard...");
return;
}
tag.put("Objectives", saveObjectives());
tag.put("PlayerScores", savePlayerScores());
tag.put("Teams", saveTeams());
saveDisplaySlots(tag);
}
protected ListTag<CompoundTag> saveTeams() {
ListTag<CompoundTag> list = new ListTag<CompoundTag>();
Collection<PlayerTeam> teams = scoreboard.getPlayerTeams();
for (PlayerTeam team : teams) {
CompoundTag tag = new CompoundTag();
tag.putString("Name", team.getName());
tag.putString("DisplayName", team.getDisplayName());
tag.putString("Prefix", team.getPrefix());
tag.putString("Suffix", team.getSuffix());
tag.putBoolean("AllowFriendlyFire", team.isAllowFriendlyFire());
tag.putBoolean("SeeFriendlyInvisibles", team.canSeeFriendlyInvisibles());
ListTag<StringTag> playerList = new ListTag<StringTag>();
for (String player : team.getPlayers()) {
playerList.add(new StringTag("", player));
}
tag.put("Players", playerList);
list.add(tag);
}
return list;
}
protected void saveDisplaySlots(CompoundTag tag) {
CompoundTag slots = new CompoundTag();
boolean hasDisplaySlot = false;
for (int i = 0; i < Scoreboard.DISPLAY_SLOTS; i++) {
Objective objective = scoreboard.getDisplayObjective(i);
if (objective != null) {
slots.putString("slot_" + i, objective.getName());
hasDisplaySlot = true;
}
}
if (hasDisplaySlot) tag.putCompound("DisplaySlots", slots);
}
protected ListTag<CompoundTag> saveObjectives() {
ListTag<CompoundTag> list = new ListTag<CompoundTag>();
Collection<Objective> objectives = scoreboard.getObjectives();
for (Objective objective : objectives) {
CompoundTag tag = new CompoundTag();
tag.putString("Name", objective.getName());
tag.putString("CriteriaName", objective.getCriteria().getName());
tag.putString("DisplayName", objective.getDisplayName());
list.add(tag);
}
return list;
}
protected ListTag<CompoundTag> savePlayerScores() {
ListTag<CompoundTag> list = new ListTag<CompoundTag>();
Collection<Score> scores = scoreboard.getScores();
for (Score score : scores) {
CompoundTag tag = new CompoundTag();
tag.putString("Name", score.getOwner());
tag.putString("Objective", score.getObjective().getName());
tag.putInt("Score", score.getScore());
list.add(tag);
}
return list;
}
};
#endif
|