/dynmapexp tabcompletions

This commit is contained in:
James Lyne 2021-12-20 00:31:03 +00:00
parent 2b2735516b
commit 742e289d56
2 changed files with 57 additions and 0 deletions

View File

@ -1881,6 +1881,10 @@ public class DynmapCore implements DynmapCommonAPI {
return markerapi.getTabCompletions(sender, args, this);
}
if (cmd.equalsIgnoreCase("dynmapexp")) {
return dynmapexpcmds.getTabCompletions(sender, args, this);
}
if (!cmd.equalsIgnoreCase("dynmap")) {
return Collections.emptyList();
}

View File

@ -1,7 +1,13 @@
package org.dynmap.exporter;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.dynmap.DynmapCore;
import org.dynmap.DynmapLocation;
@ -91,6 +97,53 @@ public class DynmapExpCommands {
return rslt;
}
public List<String> getTabCompletions(DynmapCommandSender sender, String[] args, DynmapCore core) {
/* Re-parse args - handle doublequotes */
args = DynmapCore.parseArgs(args, sender);
if (args == null || args.length <= 1) {
return Collections.emptyList();
}
String cmd = args[0];
if(cmd.equalsIgnoreCase("set")) {
List<String> keys = new ArrayList<>(
Arrays.asList("x0", "x1", "y0", "y1", "z0", "z1", "world", "shader", "byChunk",
"byBlockID", "byBlockIDData", "byTexture"));
if (args.length % 2 == 0) { // Args contain only complete key value argument pairs (plus subcommand)
// Remove previous used keys
for (int i = 1; i < args.length; i += 2) {
keys.remove(args[i]);
}
return keys;
} else { // Incomplete key value argument pair, suggest values
final String lastKey = args[args.length - 2];
final String lastValue = args[args.length - 1];
switch(lastKey) {
case "world":
return core.getWorldSuggestions(lastValue);
case "shader":
return MapManager.mapman.hdmapman.shaders.keySet().stream()
.filter(value -> value.startsWith(lastValue))
.collect(Collectors.toList());
case "byChunk":
case "byBlockID":
case "byBlockIDData":
case "byTexture":
return Stream.of("true", "false")
.filter(value -> value.startsWith(lastValue))
.collect(Collectors.toList());
}
}
}
return Collections.emptyList();
}
private boolean handleInfo(DynmapCommandSender sender, String[] args, ExportContext ctx, DynmapCore core) {
sender.sendMessage(String.format("Bounds: <%s,%s,%s> - <%s,%s,%s> on world '%s'", val(ctx.xmin), val(ctx.ymin), val(ctx.zmin),
val(ctx.xmax), val(ctx.ymax), val(ctx.zmax), ctx.world));