Skip to content

Commit 1f4385f

Browse files
committed
Work in progress tab complete
1 parent 0488dc2 commit 1f4385f

2 files changed

Lines changed: 32 additions & 6 deletions

File tree

api/src/main/java/com/clubobsidian/dynamicgui/api/command/cloud/CloudArgument.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static CloudArgument create(@NotNull Function<String, CommandComponent.Bu
6666
if (d.isGreedy()) {
6767
builder.parser(StringParser.greedyStringParser());
6868
}
69-
return builder.build();
69+
return builder;
7070
});
7171
}
7272

@@ -92,17 +92,17 @@ public static Optional<CloudArgument> fromType(@NotNull String type) {
9292
return Optional.ofNullable(TYPES.get(type));
9393
}
9494

95-
private final Function<CloudData, CommandComponent> function;
95+
private final Function<CloudData, CommandComponent.Builder> function;
9696

97-
public CloudArgument(@NotNull Function<CloudData, CommandComponent> function) {
97+
public CloudArgument(@NotNull Function<CloudData, CommandComponent.Builder> function) {
9898
this.function = Objects.requireNonNull(function);
9999
}
100100

101-
public <T extends CommandComponent> T argument(@NotNull String argName) {
101+
public <T extends CommandComponent.Builder> T argument(@NotNull String argName) {
102102
return this.argument(argName, false, false);
103103
}
104104

105-
public <T extends CommandComponent> T argument(@NotNull String argName,
105+
public <T extends CommandComponent.Builder> T argument(@NotNull String argName,
106106
boolean optional,
107107
boolean greedy) {
108108
Objects.requireNonNull(argName);

parser/src/main/java/com/clubobsidian/dynamicgui/parser/gui/SimpleGuiToken.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.clubobsidian.dynamicgui.api.DynamicGui;
2020
import com.clubobsidian.dynamicgui.api.command.cloud.CloudArgument;
21+
import com.clubobsidian.dynamicgui.api.entity.PlayerWrapper;
2122
import com.clubobsidian.dynamicgui.api.gui.GuiBuildType;
2223
import com.clubobsidian.dynamicgui.api.parser.function.tree.FunctionTree;
2324
import com.clubobsidian.dynamicgui.api.parser.gui.GuiToken;
@@ -30,9 +31,14 @@
3031
import com.clubobsidian.dynamicgui.parser.macro.SimpleMacroToken;
3132
import com.clubobsidian.dynamicgui.parser.slot.SimpleSlotToken;
3233
import com.clubobsidian.wrappy.ConfigurationSection;
34+
import org.checkerframework.checker.nullness.qual.NonNull;
3335
import 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

3540
import java.util.*;
41+
import java.util.stream.Collectors;
3642

3743
public 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

Comments
 (0)