From d3ea12435134b10bc400148c321155252fdce125 Mon Sep 17 00:00:00 2001 From: ME1312 Date: Sun, 21 Oct 2018 00:46:14 -0400 Subject: [PATCH] Fix tab completes for commands using the /sub alias --- .../ME1312/SubServers/Host/SubCommand.java | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/SubCommand.java b/SubServers.Host/src/net/ME1312/SubServers/Host/SubCommand.java index 9ddd530b..323801d6 100644 --- a/SubServers.Host/src/net/ME1312/SubServers/Host/SubCommand.java +++ b/SubServers.Host/src/net/ME1312/SubServers/Host/SubCommand.java @@ -6,6 +6,7 @@ import net.ME1312.Galaxi.Library.Util; import net.ME1312.Galaxi.Library.Version.Version; import net.ME1312.Galaxi.Plugin.Command.Command; import net.ME1312.Galaxi.Plugin.Command.CommandSender; +import net.ME1312.Galaxi.Plugin.Command.CompletionHandler; import net.ME1312.SubServers.Host.Library.TextColor; import net.ME1312.SubServers.Host.Network.API.*; import net.ME1312.SubServers.Host.Network.Packet.*; @@ -36,18 +37,18 @@ public class SubCommand { } } }.autocomplete((sender, handle, args) -> { + String last = (args.length > 0)?args[args.length - 1].toLowerCase():""; + TreeMap commands; + try { + Field f = PluginManager.class.getDeclaredField("commands"); + f.setAccessible(true); + commands = (TreeMap) f.get(GalaxiEngine.getInstance().getPluginManager()); + f.setAccessible(false); + } catch (Exception e) { + e.printStackTrace(); + commands = new TreeMap(); + } if (args.length <= 1) { - String last = (args.length > 0)?args[args.length - 1].toLowerCase():""; - TreeMap commands; - try { - Field f = PluginManager.class.getDeclaredField("commands"); - f.setAccessible(true); - commands = (TreeMap) f.get(GalaxiEngine.getInstance().getPluginManager()); - f.setAccessible(false); - } catch (Exception e) { - e.printStackTrace(); - commands = new TreeMap(); - } if (last.length() == 0) { return commands.keySet().toArray(new String[0]); } else { @@ -57,6 +58,14 @@ public class SubCommand { } return list.toArray(new String[0]); } + } else if (commands.keySet().contains(args[0].toLowerCase())) { + CompletionHandler autocompletor = commands.get(args[0].toLowerCase()).autocomplete(); + if (autocompletor != null) { + LinkedList arguments = new LinkedList(); + arguments.addAll(Arrays.asList(args)); + arguments.removeFirst(); + return autocompletor.complete(sender, args[0], arguments.toArray(new String[0])); + } else return new String[0]; } else { return new String[0]; }