From c64ecf76af49744fc8671aed68f8b54e1a337f5f Mon Sep 17 00:00:00 2001 From: tastybento Date: Thu, 12 Jul 2018 08:15:24 -0700 Subject: [PATCH] Fixed admin command tab complete for Ops Tab complete values are sorted now too. --- .../bskyblock/api/commands/CompositeCommand.java | 6 ++++-- src/test/java/bskyblock/TestBSkyBlock.java | 11 ++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/us/tastybento/bskyblock/api/commands/CompositeCommand.java b/src/main/java/us/tastybento/bskyblock/api/commands/CompositeCommand.java index 1a0768ac8..b94dc60d1 100644 --- a/src/main/java/us/tastybento/bskyblock/api/commands/CompositeCommand.java +++ b/src/main/java/us/tastybento/bskyblock/api/commands/CompositeCommand.java @@ -11,6 +11,7 @@ import java.util.Set; import java.util.UUID; import java.util.logging.Logger; +import java.util.stream.Collectors; import org.bukkit.Bukkit; import org.bukkit.World; @@ -438,6 +439,7 @@ public Command setUsage(String usage) { @Override public List tabComplete(final CommandSender sender, final String alias, final String[] args) { + Arrays.stream(args).forEach(plugin::log);// DEBUG List options = new ArrayList<>(); // Get command object based on args entered so far CompositeCommand cmd = getCommandFromArgs(args); @@ -445,7 +447,7 @@ public List tabComplete(final CommandSender sender, final String alias, if (cmd.onlyPlayer && !(sender instanceof Player)) { return options; } - if (!cmd.getPermission().isEmpty() && !sender.hasPermission(cmd.getPermission())) { + if (!cmd.getPermission().isEmpty() && !sender.hasPermission(cmd.getPermission()) && !sender.isOp()) { return options; } // Add any tab completion from the subcommand @@ -472,7 +474,7 @@ public List tabComplete(final CommandSender sender, final String alias, String lastArg = args.length != 0 ? args[args.length - 1] : ""; - return Util.tabLimit(options, lastArg); + return Util.tabLimit(options, lastArg).stream().sorted().collect(Collectors.toList()); } /** diff --git a/src/test/java/bskyblock/TestBSkyBlock.java b/src/test/java/bskyblock/TestBSkyBlock.java index 5c7c4f60e..30a9c5ecf 100644 --- a/src/test/java/bskyblock/TestBSkyBlock.java +++ b/src/test/java/bskyblock/TestBSkyBlock.java @@ -208,8 +208,9 @@ public void testCommandAPI() { } } String[] args = {""}; - assertEquals(Arrays.asList("sub1","sub2", "help"), testCommand.tabComplete(player, "test", args)); - assertNotSame(Arrays.asList("sub1","sub2", "help"), testCommand.tabComplete(sender, "test", args)); + // Results are alphabetically sorted + assertEquals(Arrays.asList("help", "sub1","sub2"), testCommand.tabComplete(player, "test", args)); + assertNotSame(Arrays.asList("help", "sub1","sub2"), testCommand.tabComplete(sender, "test", args)); args[0] = "su"; assertEquals(Arrays.asList("sub1","sub2"), testCommand.tabComplete(player, "test", args)); args[0] = "d"; @@ -217,13 +218,13 @@ public void testCommandAPI() { args[0] = "sub1"; assertEquals(Collections.emptyList(), testCommand.tabComplete(player, "test", args)); String[] args2 = {"sub2",""}; - assertEquals(Arrays.asList("subsub", "help"), testCommand.tabComplete(player, "test", args2)); + assertEquals(Arrays.asList("help", "subsub"), testCommand.tabComplete(player, "test", args2)); args2[1] = "s"; assertEquals(Collections.singletonList("subsub"), testCommand.tabComplete(player, "test", args2)); String[] args3 = {"sub2","subsub", ""}; - assertEquals(Arrays.asList("subsubsub", "help"), testCommand.tabComplete(player, "test", args3)); + assertEquals(Arrays.asList("help", "subsubsub"), testCommand.tabComplete(player, "test", args3)); // Test for overridden tabcomplete - assertEquals(Arrays.asList("Florian", "Ben", "Bill", "Ted", "help"), + assertEquals(Arrays.asList("Ben", "Bill", "Florian", "Ted", "help"), testCommand.tabComplete(player, "test", new String[] {"sub2", "subsub", "subsubsub", ""})); // Test for partial word assertEquals(Arrays.asList("Ben", "Bill"),