|
25 | 25 | import net.minecraft.nbt.CompoundTag; |
26 | 26 | import net.minecraft.nbt.ListTag; |
27 | 27 | import net.minecraft.nbt.StringTag; |
28 | | -import net.minecraft.nbt.Tag; |
29 | 28 | import net.minecraft.network.chat.Component; |
30 | 29 | import net.minecraft.server.MinecraftServer; |
31 | 30 | import net.minecraft.server.level.ServerPlayer; |
@@ -140,46 +139,45 @@ public boolean arePlayersInSameTeam(UUID id1, UUID id2) { |
140 | 139 | .orElse(false); |
141 | 140 | } |
142 | 141 |
|
143 | | - public void load() { |
| 142 | + public void load() throws IOException { |
144 | 143 | id = null; |
145 | 144 | Path directory = server.getWorldPath(FOLDER_NAME); |
146 | 145 |
|
147 | 146 | if (Files.notExists(directory) || !Files.isDirectory(directory)) { |
148 | 147 | return; |
149 | 148 | } |
150 | 149 |
|
151 | | - CompoundTag dataFileTag = SNBT.read(directory.resolve("ftbteams.snbt")); |
152 | | - |
153 | | - if (dataFileTag != null) { |
154 | | - if (dataFileTag.contains("id")) { |
155 | | - id = dataFileTag.read("id", UUIDUtil.CODEC).orElseThrow(); |
156 | | - } |
| 150 | + CompoundTag dataFileTag = SNBT.tryRead(directory.resolve("ftbteams.snbt")); |
| 151 | + if (dataFileTag.contains("id")) { |
| 152 | + id = dataFileTag.read("id", UUIDUtil.CODEC).orElseThrow(); |
| 153 | + } |
157 | 154 |
|
158 | | - extraData = dataFileTag.getCompoundOrEmpty("extra"); |
159 | | - TeamManagerEvent.LOADED.invoker().accept(new TeamManagerEvent(this)); |
| 155 | + extraData = dataFileTag.getCompoundOrEmpty("extra"); |
| 156 | + TeamManagerEvent.LOADED.invoker().accept(new TeamManagerEvent(this)); |
160 | 157 |
|
161 | | - chatRedirected.clear(); |
162 | | - dataFileTag.getList("chat_redirected", Tag.TAG_STRING).forEach(tag -> { |
163 | | - try { |
164 | | - chatRedirected.add(UUID.fromString(tag.getAsString())); |
165 | | - } catch (IllegalArgumentException e) { |
166 | | - FTBTeams.LOGGER.error("invalid uuid {} in 'chat_redirection', ignoring", tag.getAsString()); |
167 | | - } |
168 | | - }); |
169 | | - } |
| 158 | + chatRedirected.clear(); |
| 159 | + dataFileTag.getListOrEmpty("chat_redirected").forEach(tag -> { |
| 160 | + try { |
| 161 | + chatRedirected.add(UUID.fromString(tag.toString())); |
| 162 | + } catch (IllegalArgumentException e) { |
| 163 | + FTBTeams.LOGGER.error("invalid uuid {} in 'chat_redirection', ignoring", tag.toString()); |
| 164 | + } |
| 165 | + }); |
170 | 166 |
|
171 | 167 | for (TeamType type : TeamType.values()) { |
172 | 168 | Path dir = directory.resolve(type.getSerializedName()); |
173 | 169 |
|
174 | 170 | if (Files.exists(dir) && Files.isDirectory(dir)) { |
175 | 171 | try (Stream<Path> s = Files.list(dir)) { |
176 | 172 | s.filter(path -> path.getFileName().toString().endsWith(".snbt")).forEach(file -> { |
177 | | - CompoundTag nbt = SNBT.read(file); |
178 | | - if (nbt != null) { |
| 173 | + try { |
| 174 | + CompoundTag nbt = SNBT.tryRead(file); |
179 | 175 | AbstractTeam team = type.createTeam(this, nbt.read("id", UUIDUtil.CODEC).orElseThrow()); |
180 | 176 | teamMap.put(team.id, team); |
181 | 177 | team.deserializeNBT(nbt, server.registryAccess()); |
182 | | - } |
| 178 | + } catch (IOException e) { |
| 179 | + throw new RuntimeException(e); |
| 180 | + } |
183 | 181 | }); |
184 | 182 | } catch (Exception ex) { |
185 | 183 | FTBTeams.LOGGER.error("can't list directory {}: {}", dir, ex.getMessage()); |
|
0 commit comments