1616import org .mvplugins .multiverse .external .jakarta .inject .Inject ;
1717import org .mvplugins .multiverse .external .jetbrains .annotations .NotNull ;
1818import org .mvplugins .multiverse .inventories .commands .InventoriesCommand ;
19+ import org .mvplugins .multiverse .inventories .commands .bulkedit .BulkEditCommand ;
1920import org .mvplugins .multiverse .inventories .profile .ProfileDataSource ;
21+ import org .mvplugins .multiverse .inventories .profile .bulkedit .BulkEditAction ;
22+ import org .mvplugins .multiverse .inventories .profile .bulkedit .BulkEditCreator ;
2023import org .mvplugins .multiverse .inventories .profile .key .GlobalProfileKey ;
2124
2225import java .util .Arrays ;
2326import java .util .concurrent .CompletableFuture ;
2427
2528@ Service
26- final class ClearCommand extends InventoriesCommand {
29+ final class ClearCommand extends BulkEditCommand {
2730
2831 private final CommandQueueManager commandQueueManager ;
29- private final ProfileDataSource profileDataSource ;
3032 private final Flags flags ;
3133
3234 @ Inject
3335 ClearCommand (
36+ @ NotNull BulkEditCreator bulkEditCreator ,
3437 @ NotNull CommandQueueManager commandQueueManager ,
35- @ NotNull ProfileDataSource profileDataSource ,
3638 @ NotNull Flags flags
3739 ) {
40+ super (bulkEditCreator );
3841 this .commandQueueManager = commandQueueManager ;
39- this .profileDataSource = profileDataSource ;
4042 this .flags = flags ;
4143 }
4244
4345 @ Subcommand ("bulkedit globalprofile clear" )
4446 @ CommandPermission ("multiverse.inventories.bulkedit" )
4547 @ CommandCompletion ("@mvinvplayernames @flags:groupName=" + Flags .NAME )
46- @ Syntax ("<players> [--clear-all-playerprofiles ]" )
48+ @ Syntax ("<players> [--clear-all-player-profiles ]" )
4749 void onCommand (
4850 MVCommandIssuer issuer ,
4951
@@ -55,19 +57,16 @@ void onCommand(
5557 ) {
5658 ParsedCommandFlags parsedFlags = flags .parse (flagArray );
5759
58- commandQueueManager . addToQueue ( CommandQueuePayload . issuer ( issuer )
59- . prompt ( Message . of ( "Are you sure you want to clear %d profiles?" . formatted ( globalProfileKeys . length )))
60- . action (() -> doClear ( issuer , globalProfileKeys , parsedFlags .hasFlag (flags .clearAllPlayerprofiles ))));
61- }
60+ BulkEditAction <?> bulkEditAction = bulkEditCreator . globalProfileClear (
61+ globalProfileKeys ,
62+ parsedFlags .hasFlag (flags .clearAllPlayerProfiles )
63+ );
6264
63- private void doClear (MVCommandIssuer issuer , GlobalProfileKey [] globalProfileKeys , boolean clearPlayerProfile ) {
64- //TODO: Check lastWorld and online
65- CompletableFuture [] futures = Arrays .stream (globalProfileKeys )
66- .map (globalProfileKey -> profileDataSource .deleteGlobalProfile (globalProfileKey , clearPlayerProfile ))
67- .toArray (CompletableFuture []::new );
65+ outputActionSummary (issuer , bulkEditAction );
6866
69- CompletableFuture .allOf (futures )
70- .thenRun (() -> issuer .sendMessage ("Successfully cleared %d profiles." .formatted (globalProfileKeys .length )));
67+ commandQueueManager .addToQueue (CommandQueuePayload .issuer (issuer )
68+ .prompt (Message .of ("Are you sure you want to clear the selected global profiles?" ))
69+ .action (() -> runBulkEditAction (issuer , bulkEditAction )));
7170 }
7271
7372 @ Service
@@ -79,7 +78,7 @@ private Flags(@NotNull CommandFlagsManager flagsManager) {
7978 super (NAME , flagsManager );
8079 }
8180
82- private final CommandFlag clearAllPlayerprofiles = flag (CommandFlag .builder ("--clear-all-playerprofiles " )
81+ private final CommandFlag clearAllPlayerProfiles = flag (CommandFlag .builder ("--clear-all-player-profiles " )
8382 .addAlias ("-a" )
8483 .build ());
8584 }
0 commit comments