|
1 | 1 | package org.mvplugins.multiverse.inventories.commands; |
2 | 2 |
|
3 | | -import com.google.common.io.Files; |
4 | 3 | import org.bukkit.World; |
5 | 4 | import org.jvnet.hk2.annotations.Service; |
6 | 5 | import org.mvplugins.multiverse.core.command.MVCommandIssuer; |
|
9 | 8 | import org.mvplugins.multiverse.external.acf.commands.annotation.Description; |
10 | 9 | import org.mvplugins.multiverse.external.acf.commands.annotation.Subcommand; |
11 | 10 | import org.mvplugins.multiverse.external.acf.commands.annotation.Syntax; |
12 | | -import org.mvplugins.multiverse.external.jakarta.inject.Inject; |
13 | | -import org.mvplugins.multiverse.external.vavr.control.Try; |
14 | | -import org.mvplugins.multiverse.inventories.profile.ProfileDataSource; |
15 | | -import org.mvplugins.multiverse.inventories.profile.data.ProfileData; |
16 | | -import org.mvplugins.multiverse.inventories.profile.key.ContainerType; |
17 | | -import org.mvplugins.multiverse.inventories.profile.key.GlobalProfileKey; |
18 | | -import org.mvplugins.multiverse.inventories.profile.key.ProfileKey; |
19 | | -import org.mvplugins.multiverse.inventories.profile.key.ProfileTypes; |
20 | | -import org.mvplugins.multiverse.inventories.profile.nbt.PlayerDataExtractor; |
21 | | - |
22 | | -import java.io.File; |
23 | | -import java.nio.file.Path; |
24 | | -import java.util.ArrayList; |
25 | | -import java.util.List; |
26 | | -import java.util.UUID; |
27 | | -import java.util.concurrent.CompletableFuture; |
28 | 11 |
|
29 | 12 | @Service |
30 | 13 | final class PlayerDataImportCommand extends InventoriesCommand { |
31 | 14 |
|
32 | | - private final PlayerDataExtractor playerDataExtractor; |
33 | | - private final ProfileDataSource profileDataSource; |
34 | | - |
35 | | - @Inject |
36 | | - PlayerDataImportCommand(PlayerDataExtractor playerDataExtractor, ProfileDataSource profileDataSource) { |
37 | | - this.playerDataExtractor = playerDataExtractor; |
38 | | - this.profileDataSource = profileDataSource; |
39 | | - } |
40 | | - |
41 | 15 | @Subcommand("playerdata import") |
42 | 16 | @Syntax("<world>") |
43 | 17 | @CommandPermission("multiverse.inventories.importplayerdata") |
44 | 18 | @CommandCompletion("@worldwithplayerdata") |
45 | 19 | @Description("Import player data from the world's playerdata folder.") |
46 | 20 | void onCommand(MVCommandIssuer issuer, World world) { |
47 | | - Path worldPath = world.getWorldFolder().toPath(); |
48 | | - File playerDataPath = worldPath.resolve("playerdata").toFile(); |
49 | | - if (!playerDataPath.isDirectory()) { |
50 | | - issuer.sendMessage("World's playerdata folder does not exist: " + world.getName()); |
51 | | - return; |
52 | | - } |
53 | | - |
54 | | - List<CompletableFuture<Void>> playerDataFutures = new ArrayList<>(); |
55 | | - File[] files = playerDataPath.listFiles(); |
56 | | - if (files == null) { |
57 | | - issuer.sendMessage("No player data files found in the world's playerdata folder: " + world.getName()); |
58 | | - return; |
59 | | - } |
60 | | - |
61 | | - for (File playerDataFile : files) { |
62 | | - if (!Files.getFileExtension(playerDataFile.getName()).equals("dat")) { |
63 | | - continue; |
64 | | - } |
65 | | - UUID playerUUID = UUID.fromString(Files.getNameWithoutExtension(playerDataFile.getName())); |
66 | | - playerDataExtractor.extract(playerDataFile.toPath()) |
67 | | - .onSuccess(profileData -> playerDataFutures.add(profileDataSource |
68 | | - .getGlobalProfile(GlobalProfileKey.of(playerUUID)) |
69 | | - .thenCompose(profileDataSource::updateGlobalProfile) |
70 | | - .thenCompose(ignore -> profileDataSource.getPlayerProfile( |
71 | | - ProfileKey.of(ContainerType.WORLD, world.getName(), ProfileTypes.getDefault(), playerUUID))) |
72 | | - .thenCompose(playerProfile -> { |
73 | | - playerProfile.update(profileData); |
74 | | - return profileDataSource.updatePlayerProfile(playerProfile); |
75 | | - }))); |
76 | | - } |
77 | | - CompletableFuture.allOf(playerDataFutures.toArray(new CompletableFuture[0])) |
78 | | - .thenRun(() -> issuer.sendMessage("Successfully imported all player data from " + world.getName() + ".")); |
| 21 | + issuer.sendError("Please install Multiverse-InventoriesImporter plugin to use this command."); |
| 22 | + issuer.sendInfo("Download Link: https://modrinth.com/project/multiverse-inventoriesimporter/"); |
| 23 | + issuer.sendInfo("Learn More: https://mvplugins.org/inventories/how-to/import-playerdata/"); |
79 | 24 | } |
80 | 25 | } |
0 commit comments