|
3 | 3 | import net.thenextlvl.perworlds.PerWorldsPlugin; |
4 | 4 | import net.thenextlvl.perworlds.WorldGroup; |
5 | 5 | import net.thenextlvl.perworlds.data.PlayerData; |
6 | | -import org.bukkit.generator.WorldInfo; |
7 | 6 | import org.jspecify.annotations.NullMarked; |
8 | 7 |
|
9 | 8 | import java.io.IOException; |
10 | | -import java.nio.file.Files; |
11 | 9 | import java.nio.file.Path; |
12 | 10 | import java.util.HashSet; |
13 | 11 | import java.util.Map; |
@@ -60,22 +58,22 @@ public Set<WorldGroup> loadGroups() throws IOException { |
60 | 58 | } |
61 | 59 |
|
62 | 60 | public void loadPlayers(Set<WorldGroup> groups) throws IOException { |
63 | | - // todo: extract to readPlayer |
64 | | - readPlayers().forEach((uuid, name) -> { |
65 | | - groups.stream().forEach(group -> group.getWorlds().map(WorldInfo::getName) |
66 | | - .map(this.dataPath.resolve("worlds")::resolve) |
67 | | - .map(path -> path.resolve(name + ".json")) |
68 | | - .filter(Files::isRegularFile) |
69 | | - .findAny().ifPresent(path -> { |
70 | | - // todo: load player data from path into the current group |
71 | | - }) |
72 | | - ); |
73 | | - }); |
| 61 | + readPlayers().forEach((uuid, name) -> groups.forEach(group -> { |
| 62 | + var offlinePlayer = plugin.getServer().getOfflinePlayer(uuid); |
| 63 | + group.persistPlayerData(offlinePlayer, playerData -> { |
| 64 | + try { |
| 65 | + readPlayer(uuid, name, group, playerData); |
| 66 | + } catch (IOException e) { |
| 67 | + plugin.getComponentLogger().error("Failed to import player data for {} ({}) in group {}", |
| 68 | + name, uuid, group.getName(), e); |
| 69 | + } |
| 70 | + }); |
| 71 | + })); |
74 | 72 | } |
75 | 73 |
|
76 | 74 | public abstract Map<String, Set<String>> readGroups() throws IOException; |
77 | 75 |
|
78 | 76 | public abstract Map<UUID, String> readPlayers() throws IOException; |
79 | 77 |
|
80 | | - public abstract PlayerData readPlayer(UUID uuid, String name, WorldGroup group) throws IOException; |
| 78 | + public abstract void readPlayer(UUID uuid, String name, WorldGroup group, PlayerData data) throws IOException; |
81 | 79 | } |
0 commit comments