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