Very basic single level spigot tabcomplete
This commit is contained in:
parent
46a1544efa
commit
814f952c22
2 changed files with 60 additions and 2 deletions
|
|
@ -1248,7 +1248,7 @@ public class DynmapCore implements DynmapCommonAPI {
|
||||||
new CommandInfo("dmarker", "movehere", "id:<id>", "Move marker with ID <id> to current location."),
|
new CommandInfo("dmarker", "movehere", "id:<id>", "Move marker with ID <id> to current location."),
|
||||||
new CommandInfo("dmarker", "update", "<label> icon:<icon> newlabel:<newlabel>", "Update marker with ID <id> with new label <newlabel> and new icon <icon>."),
|
new CommandInfo("dmarker", "update", "<label> icon:<icon> newlabel:<newlabel>", "Update marker with ID <id> with new label <newlabel> and new icon <icon>."),
|
||||||
new CommandInfo("dmarker", "delete", "<label>", "Delete marker with label of <label>."),
|
new CommandInfo("dmarker", "delete", "<label>", "Delete marker with label of <label>."),
|
||||||
new CommandInfo("dmarker", "delete ", "id:<id>", "Delete marker with ID of <id>."),
|
new CommandInfo("dmarker", "delete", "id:<id>", "Delete marker with ID of <id>."),
|
||||||
new CommandInfo("dmarker", "list", "List details of all markers."),
|
new CommandInfo("dmarker", "list", "List details of all markers."),
|
||||||
new CommandInfo("dmarker", "icons", "List details of all icons."),
|
new CommandInfo("dmarker", "icons", "List details of all icons."),
|
||||||
new CommandInfo("dmarker", "addset", "<label>", "Add marker set with label <label>."),
|
new CommandInfo("dmarker", "addset", "<label>", "Add marker set with label <label>."),
|
||||||
|
|
@ -1349,6 +1349,27 @@ public class DynmapCore implements DynmapCommonAPI {
|
||||||
sender.sendMessage(subcmdlist);
|
sender.sendMessage(subcmdlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns tab completion suggestions for subcommands
|
||||||
|
*
|
||||||
|
* @param sender - The command sender requesting the tab completion suggestions
|
||||||
|
* @param cmd - The top level command to suggest for
|
||||||
|
* @param arg - Optional partial subcommand name to filter by
|
||||||
|
* @return List of tab completion suggestions
|
||||||
|
*/
|
||||||
|
List<String> getSubcommandSuggestions(DynmapCommandSender sender, String cmd, String arg) {
|
||||||
|
List<String> suggestions = new ArrayList<>();
|
||||||
|
|
||||||
|
for (CommandInfo ci : commandinfo) {
|
||||||
|
//TODO: Permission checks
|
||||||
|
if (ci.matches(cmd) && ci.subcmd.startsWith(arg) && !suggestions.contains(ci.subcmd)) {
|
||||||
|
suggestions.add(ci.subcmd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return suggestions;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean processCommand(DynmapCommandSender sender, String cmd, String commandLabel, String[] args) {
|
public boolean processCommand(DynmapCommandSender sender, String cmd, String commandLabel, String[] args) {
|
||||||
if (mapManager == null) { // Initialization faulure
|
if (mapManager == null) { // Initialization faulure
|
||||||
sender.sendMessage("Dynmap failed to initialize properly: commands not available");
|
sender.sendMessage("Dynmap failed to initialize properly: commands not available");
|
||||||
|
|
@ -1726,6 +1747,27 @@ public class DynmapCore implements DynmapCommonAPI {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of tab completion suggestions for the given sender, command and command arguments.
|
||||||
|
*
|
||||||
|
* @param sender - The sender of the tab completion, used for permission checks
|
||||||
|
* @param cmd - The top level command being tab completed
|
||||||
|
* @param args - Array of extra command arguments
|
||||||
|
* @return List of tab completion suggestions
|
||||||
|
*/
|
||||||
|
public List<String> getTabCompletions(DynmapCommandSender sender, String cmd, String[] args) {
|
||||||
|
if (mapManager == null) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length <= 1) {
|
||||||
|
return getSubcommandSuggestions(sender, cmd, args[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean checkPlayerPermission(DynmapCommandSender sender, String permission) {
|
public boolean checkPlayerPermission(DynmapCommandSender sender, String permission) {
|
||||||
if (!(sender instanceof DynmapPlayer) || sender.isOp()) {
|
if (!(sender instanceof DynmapPlayer) || sender.isOp()) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import java.io.File;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
@ -1103,6 +1104,21 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(CommandSender sender, Command cmd, String alias, String[] args) {
|
||||||
|
DynmapCommandSender dsender;
|
||||||
|
if(sender instanceof Player) {
|
||||||
|
dsender = new BukkitPlayer((Player)sender);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dsender = new BukkitCommandSender(sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (core != null)
|
||||||
|
return core.getTabCompletions(dsender, cmd.getName(), args);
|
||||||
|
else
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final MarkerAPI getMarkerAPI() {
|
public final MarkerAPI getMarkerAPI() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue