diff --git a/src/main/java/com/gamingmesh/jobs/stuff/TabComplete.java b/src/main/java/com/gamingmesh/jobs/stuff/TabComplete.java index 0c1dfbd1..f186de76 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/TabComplete.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/TabComplete.java @@ -8,6 +8,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; +import org.bukkit.util.StringUtil; import com.gamingmesh.jobs.ItemBoostManager; import com.gamingmesh.jobs.Jobs; @@ -19,15 +20,15 @@ import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.Quest; -public class TabComplete implements TabCompleter { +public final class TabComplete implements TabCompleter { @Override public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { - if (args.length == 1) { - return new ArrayList<>(Jobs.getCommandManager().getCommands(sender)); - } + List completionList = new ArrayList<>(); - if (args.length > 1) { + if (args.length == 1) { + StringUtil.copyPartialMatches(args[0], Jobs.getCommandManager().getCommands(sender), completionList); + } else if (args.length > 1) { String first = args[0].toLowerCase(); for (int i = 1; i <= args.length; i++) { @@ -43,8 +44,9 @@ public class TabComplete implements TabCompleter { String arg = argsList.get(i - 1); List t2 = new ArrayList<>(); - if (arg.contains("%%")) - for (String one : arg.split("%%")) { + String[] split = arg.split("%%"); + if (split.length > 0) + for (String one : split) { t2.add(one); } else @@ -144,11 +146,12 @@ public class TabComplete implements TabCompleter { } } - return temp; + StringUtil.copyPartialMatches(args[i], temp, completionList); } } } - return null; + java.util.Collections.sort(completionList); + return completionList; } }