55import org .mvplugins .multiverse .core .command .MVCommandCompletions ;
66import org .mvplugins .multiverse .core .command .MVCommandManager ;
77import org .mvplugins .multiverse .core .config .handle .PropertyModifyAction ;
8+ import org .mvplugins .multiverse .core .utils .StringFormatter ;
89import org .mvplugins .multiverse .external .acf .commands .BukkitCommandCompletionContext ;
910import org .mvplugins .multiverse .external .jakarta .inject .Inject ;
1011import org .mvplugins .multiverse .external .vavr .control .Try ;
1112import org .mvplugins .multiverse .inventories .config .InventoriesConfig ;
1213import org .mvplugins .multiverse .inventories .dataimport .DataImportManager ;
14+ import org .mvplugins .multiverse .inventories .profile .PlayerNamesMapper ;
1315import org .mvplugins .multiverse .inventories .profile .group .WorldGroup ;
1416import org .mvplugins .multiverse .inventories .profile .group .WorldGroupManager ;
17+ import org .mvplugins .multiverse .inventories .profile .key .GlobalProfileKey ;
1518import org .mvplugins .multiverse .inventories .share .Sharables ;
1619
1720import java .util .Arrays ;
1821import java .util .Collection ;
1922import java .util .Collections ;
23+ import java .util .List ;
24+ import java .util .Objects ;
2025import java .util .Set ;
2126import java .util .stream .Collectors ;
2227
@@ -28,21 +33,26 @@ public final class MVInvCommandCompletion {
2833 private final InventoriesConfig inventoriesConfig ;
2934 private final WorldGroupManager worldGroupManager ;
3035 private final DataImportManager dataImportManager ;
36+ private final PlayerNamesMapper playerNamesMapper ;
3137
3238 @ Inject
3339 private MVInvCommandCompletion (
3440 @ NotNull InventoriesConfig inventoriesConfig ,
3541 @ NotNull WorldGroupManager worldGroupManager ,
3642 @ NotNull DataImportManager dataImportManager ,
37- @ NotNull MVCommandManager mvCommandManager ) {
43+ @ NotNull MVCommandManager mvCommandManager ,
44+ @ NotNull PlayerNamesMapper playerNamesMapper
45+ ) {
3846 this .inventoriesConfig = inventoriesConfig ;
3947 this .worldGroupManager = worldGroupManager ;
4048 this .dataImportManager = dataImportManager ;
49+ this .playerNamesMapper = playerNamesMapper ;
4150
4251 MVCommandCompletions commandCompletions = mvCommandManager .getCommandCompletions ();
4352 commandCompletions .registerAsyncCompletion ("dataimporters" , this ::suggestDataImporters );
4453 commandCompletions .registerStaticCompletion ("mvinvconfigs" , inventoriesConfig .getStringPropertyHandle ().getAllPropertyNames ());
4554 commandCompletions .registerAsyncCompletion ("mvinvconfigvalues" , this ::suggestConfigValues );
55+ commandCompletions .registerAsyncCompletion ("mvinvplayernames" , this ::suggestPlayerNames );
4656 commandCompletions .registerAsyncCompletion ("sharables" , this ::suggestSharables );
4757 commandCompletions .registerAsyncCompletion ("shares" , this ::suggestShares );
4858 commandCompletions .registerAsyncCompletion ("worldGroups" , this ::suggestWorldGroups );
@@ -60,6 +70,25 @@ private Collection<String> suggestConfigValues(BukkitCommandCompletionContext co
6070 .getOrElse (Collections .emptyList ());
6171 }
6272
73+ private Collection <String > suggestPlayerNames (BukkitCommandCompletionContext context ) {
74+ if (Objects .equals (context .getInput (), "@all" )) {
75+ return Collections .emptyList ();
76+ }
77+ List <String > playerNames = getPlayerNames ();
78+ if (context .getInput ().indexOf (',' ) == -1 ) {
79+ playerNames .add ("@all" );
80+ return playerNames ;
81+ }
82+ return StringFormatter .addonToCommaSeperated (context .getInput (), playerNames );
83+ }
84+
85+ private List <String > getPlayerNames () {
86+ return playerNamesMapper .getKeys ()
87+ .stream ()
88+ .map (GlobalProfileKey ::getPlayerName )
89+ .collect (Collectors .toList ());
90+ }
91+
6392 private Collection <String > suggestSharables (BukkitCommandCompletionContext context ) {
6493 String scope = context .getConfig ("scope" , "enabled" );
6594
0 commit comments