11package org .mvplugins .multiverse .inventories .commands ;
22
33import com .google .common .io .Files ;
4- import org .bukkit .Bukkit ;
4+ import org .bukkit .World ;
55import org .jvnet .hk2 .annotations .Service ;
66import org .mvplugins .multiverse .core .command .MVCommandIssuer ;
77import org .mvplugins .multiverse .external .acf .commands .annotation .CommandCompletion ;
@@ -41,18 +41,24 @@ final class PlayerDataImportCommand extends InventoriesCommand {
4141 @ Subcommand ("playerdata import" )
4242 @ Syntax ("<world>" )
4343 @ CommandPermission ("multiverse.inventories.importplayerdata" )
44- @ CommandCompletion ("" )
44+ @ CommandCompletion ("@worldwithplayerdata " )
4545 @ Description ("Import player data from the world's playerdata folder." )
46- void onCommand (MVCommandIssuer issuer , String world ) {
47- Path worldPath = Bukkit . getWorldContainer ().toPath (). resolve ( world );
46+ void onCommand (MVCommandIssuer issuer , World world ) {
47+ Path worldPath = world . getWorldFolder ().toPath ();
4848 File playerDataPath = worldPath .resolve ("playerdata" ).toFile ();
4949 if (!playerDataPath .isDirectory ()) {
50- issuer .sendMessage ("World's playerdata folder does not exist: " + world );
50+ issuer .sendMessage ("World's playerdata folder does not exist: " + world . getName () );
5151 return ;
5252 }
5353
5454 List <CompletableFuture <Void >> playerDataFutures = new ArrayList <>();
55- for (File playerDataFile : playerDataPath .listFiles ()) {
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 ) {
5662 if (!Files .getFileExtension (playerDataFile .getName ()).equals ("dat" )) {
5763 continue ;
5864 }
@@ -62,13 +68,13 @@ void onCommand(MVCommandIssuer issuer, String world) {
6268 .getGlobalProfile (GlobalProfileKey .of (playerUUID ))
6369 .thenCompose (profileDataSource ::updateGlobalProfile )
6470 .thenCompose (ignore -> profileDataSource .getPlayerProfile (
65- ProfileKey .of (ContainerType .WORLD , world , ProfileTypes .getDefault (), playerUUID )))
71+ ProfileKey .of (ContainerType .WORLD , world . getName () , ProfileTypes .getDefault (), playerUUID )))
6672 .thenCompose (playerProfile -> {
6773 playerProfile .update (profileData .get ());
6874 return profileDataSource .updatePlayerProfile (playerProfile );
6975 }));
7076 }
7177 CompletableFuture .allOf (playerDataFutures .toArray (new CompletableFuture [0 ]))
72- .thenRun (() -> issuer .sendMessage ("Successfully imported all player data from " + world + "." ));
78+ .thenRun (() -> issuer .sendMessage ("Successfully imported all player data from " + world . getName () + "." ));
7379 }
7480}
0 commit comments