1818
1919import com .clubobsidian .dynamicgui .api .DynamicGui ;
2020import com .clubobsidian .dynamicgui .api .command .cloud .CloudArgument ;
21+ import com .clubobsidian .dynamicgui .api .entity .PlayerWrapper ;
2122import com .clubobsidian .dynamicgui .api .gui .GuiBuildType ;
2223import com .clubobsidian .dynamicgui .api .parser .function .tree .FunctionTree ;
2324import com .clubobsidian .dynamicgui .api .parser .gui .GuiToken ;
3031import com .clubobsidian .dynamicgui .parser .macro .SimpleMacroToken ;
3132import com .clubobsidian .dynamicgui .parser .slot .SimpleSlotToken ;
3233import com .clubobsidian .wrappy .ConfigurationSection ;
34+ import org .checkerframework .checker .nullness .qual .NonNull ;
3335import org .incendo .cloud .component .CommandComponent ;
36+ import org .incendo .cloud .context .CommandContext ;
37+ import org .incendo .cloud .context .CommandInput ;
38+ import org .incendo .cloud .suggestion .BlockingSuggestionProvider ;
3439
3540import java .util .*;
41+ import java .util .stream .Collectors ;
3642
3743public class SimpleGuiToken implements GuiToken {
3844
@@ -94,6 +100,7 @@ public SimpleGuiToken(ConfigurationSection section, List<MacroToken> macroTokens
94100 this .section = section ;
95101 }
96102
103+ @ SuppressWarnings ({"rawtypes" })
97104 private List <CommandComponent > loadCommandArguments (ConfigurationSection section ) {
98105 List <CommandComponent > args = new ArrayList <>();
99106 for (Object key : section .getKeys ()) {
@@ -105,7 +112,26 @@ private List<CommandComponent> loadCommandArguments(ConfigurationSection section
105112 Optional <CloudArgument > opt = CloudArgument .fromType (type );
106113 if (opt .isPresent ()) {
107114 CloudArgument arg = opt .get ();
108- args .add (arg .argument (keyName , optional , greedy ));
115+ CommandComponent .Builder commandBuilder = arg .argument (keyName , optional , greedy );
116+ ConfigurationSection tabComplete = keySec .getConfigurationSection ("tab-complete" );
117+ String completeType = tabComplete .getString ("type" );
118+ if (completeType == null ) {
119+ DynamicGui .get ().getLogger ().error ("No tab complete type found for arg %s" , keyName );
120+ } else {
121+ if (completeType .equals ("player" )) {
122+ commandBuilder = commandBuilder .suggestionProvider (new BlockingSuggestionProvider .Strings () {
123+ @ Override
124+ public @ NonNull Iterable <@ NonNull String > stringSuggestions (@ NonNull CommandContext commandContext ,
125+ @ NonNull CommandInput input ) {
126+ return DynamicGui .get ().getPlatform ()
127+ .getOnlinePlayers ()
128+ .stream ()
129+ .map (PlayerWrapper ::getName ).collect (Collectors .toList ());
130+ }
131+ });
132+ }
133+ }
134+ args .add (commandBuilder .build ());
109135 } else {
110136 DynamicGui .get ().getLogger ().error ("Invalid argument type %s" , type );
111137 }
0 commit comments