From 77d0cd4b6a948a8136ad6c54cdb224aaa0bb7a49 Mon Sep 17 00:00:00 2001 From: StrangeOne101 Date: Sat, 9 Apr 2016 10:15:00 +1200 Subject: [PATCH] Command Tabbing moved to PKCommands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Every command now has its own tabbing method instead of having all tabbing in one file. This means custom PKCommands can now also be tabbed. --- .../projectkorra/command/AddCommand.java | 38 +++ .../command/BendingTabComplete.java | 306 +----------------- .../projectkorra/command/BindCommand.java | 25 ++ .../projectkorra/command/ChooseCommand.java | 24 ++ .../projectkorra/command/ClearCommand.java | 8 + .../projectkorra/command/CopyCommand.java | 11 + .../projectkorra/command/DisplayCommand.java | 40 +++ .../projectkorra/command/HelpCommand.java | 21 ++ .../projectkorra/command/PKCommand.java | 6 + .../command/PermaremoveCommand.java | 11 + .../projectkorra/command/PresetCommand.java | 31 ++ .../projectkorra/command/RemoveCommand.java | 38 +++ .../projectkorra/command/ToggleCommand.java | 22 ++ .../projectkorra/command/WhoCommand.java | 11 + 14 files changed, 301 insertions(+), 291 deletions(-) diff --git a/src/com/projectkorra/projectkorra/command/AddCommand.java b/src/com/projectkorra/projectkorra/command/AddCommand.java index 951cb1b6..80a621b1 100644 --- a/src/com/projectkorra/projectkorra/command/AddCommand.java +++ b/src/com/projectkorra/projectkorra/command/AddCommand.java @@ -14,6 +14,7 @@ import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -145,4 +146,41 @@ public class AddCommand extends PKCommand { public static boolean isVowel(char c) { return "AEIOUaeiou".indexOf(c) != -1; } + + @Override + protected List getTabCompletion(CommandSender sender, List args) { + if (args.size() >= 2 || !sender.hasPermission("bending.command.add")) return new ArrayList(); + List l = new ArrayList(); + if (args.size() == 0) { + + l.add("Air"); + l.add("Earth"); + l.add("Fire"); + l.add("Water"); + l.add("Chi"); + for (Element e : Element.getAddonElements()) { + l.add(e.getName()); + } + + l.add("Blood"); + l.add("Combustion"); + l.add("Flight"); + l.add("Healing"); + l.add("Ice"); + l.add("Lava"); + l.add("Lightning"); + l.add("Metal"); + l.add("Plant"); + l.add("Sand"); + l.add("Spiritual"); + for (SubElement e : Element.getAddonSubElements()) { + l.add(e.getName()); + } + } else { + for (Player p : Bukkit.getOnlinePlayers()) { + l.add(p.getName()); + } + } + return l; + } } diff --git a/src/com/projectkorra/projectkorra/command/BendingTabComplete.java b/src/com/projectkorra/projectkorra/command/BendingTabComplete.java index 031bbcac..5ba87cd6 100644 --- a/src/com/projectkorra/projectkorra/command/BendingTabComplete.java +++ b/src/com/projectkorra/projectkorra/command/BendingTabComplete.java @@ -1,18 +1,8 @@ package com.projectkorra.projectkorra.command; -import com.projectkorra.projectkorra.BendingPlayer; -import com.projectkorra.projectkorra.Element; -import com.projectkorra.projectkorra.Element.SubElement; -import com.projectkorra.projectkorra.GeneralMethods; -import com.projectkorra.projectkorra.ability.CoreAbility; -import com.projectkorra.projectkorra.object.Preset; -import com.projectkorra.rpg.commands.RPGCommand; - -import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; -import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.Arrays; @@ -25,290 +15,24 @@ import java.util.List; * @author StrangeOne101 * */ public class BendingTabComplete implements TabCompleter { + @Override public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { - if (args.length == 0 || args[0].equals("")) - return getPossibleCompletionsForGivenArgs(args, getCommandsForUser(sender)); - - if (args.length >= 2) { - BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(sender.getName()); - - if (args[0].equalsIgnoreCase("bind") || args[0].equalsIgnoreCase("b")) { - if (args.length > 3 || !sender.hasPermission("bending.command.bind") || !(sender instanceof Player)) - return new ArrayList(); - - List abilities = new ArrayList(); - if (args.length == 2) { - if (bPlayer != null) { - for (CoreAbility coreAbil : CoreAbility.getAbilities()) { - if (!coreAbil.isHiddenAbility() && bPlayer.canBind(coreAbil)) { - abilities.add(coreAbil.getName()); - } - } - } - } else { - for (int i = 1; i < 10; i++) { - abilities.add("" + i); - } - } - - Collections.sort(abilities); - return getPossibleCompletionsForGivenArgs(args, abilities); - } else if (args[0].equalsIgnoreCase("display") || args[0].equalsIgnoreCase("d")) { - if (args.length > 2 || !sender.hasPermission("bending.command.display")) - return new ArrayList(); - List list = new ArrayList(); - list.add("Air"); - list.add("Earth"); - list.add("Fire"); - list.add("Water"); - list.add("Chi"); - list.add("Bloodbending"); - list.add("Combustion"); - list.add("Flight"); - list.add("Healing"); - list.add("Ice"); - list.add("Lava"); - list.add("Lightning"); - list.add("Metal"); - list.add("Plantbending"); - list.add("Sand"); - list.add("SpiritualProjection"); - list.add("AirCombos"); - list.add("EarthCombos"); - list.add("FireCombos"); - list.add("WaterCombos"); - list.add("ChiCombos"); - list.add("Avatar"); - for (Element e : Element.getAddonElements()) { - list.add(e.getName()); - } - for (SubElement se : Element.getAddonSubElements()) { - list.add(se.getName()); - } - return getPossibleCompletionsForGivenArgs(args, list); - } else if (args[0].equalsIgnoreCase("add") || args[0].equalsIgnoreCase("a") || args[0].equalsIgnoreCase("choose") || args[0].equalsIgnoreCase("ch")) { - if (args.length > 3) return new ArrayList(); - if ((args[0].equalsIgnoreCase("add") || args[0].equalsIgnoreCase("a")) && !sender.hasPermission("bending.command.add")) return new ArrayList(); - if ((args[0].equalsIgnoreCase("choose") || args[0].equalsIgnoreCase("ch")) && !sender.hasPermission("bending.command.choose")) return new ArrayList(); - - List l = new ArrayList(); - if (args.length == 2) - { - l.add("Air"); - l.add("Earth"); - l.add("Fire"); - l.add("Water"); - l.add("Chi"); - for (Element e : Element.getAddonElements()) { - l.add(e.getName()); - } - - if (args[0].equalsIgnoreCase("add") || args[0].equalsIgnoreCase("a")) { - l.add("Blood"); - l.add("Combustion"); - l.add("Flight"); - l.add("Healing"); - l.add("Ice"); - l.add("Lava"); - l.add("Lightning"); - l.add("Metal"); - l.add("Plant"); - l.add("Sand"); - l.add("Spiritual"); - for (SubElement e : Element.getAddonSubElements()) { - l.add(e.getName()); - } - } - } - else - { - for (Player p : Bukkit.getOnlinePlayers()) { - l.add(p.getName()); - } - } - return getPossibleCompletionsForGivenArgs(args, l); - } else if (args[0].equalsIgnoreCase("clear") || args[0].equalsIgnoreCase("cl") || args[0].equalsIgnoreCase("c")) { - if (args.length > 2 || !sender.hasPermission("bending.command.clear")) - return new ArrayList(); - List l = new ArrayList(); - for (int i = 1; i < 10; i++) { - l.add("" + i); - } - return l; - } else if (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("h")) { - if (args.length > 2 || !sender.hasPermission("bending.command.help")) - return new ArrayList(); - List list = new ArrayList(); - for (Element e : Element.getElements()) { - list.add(e.getName()); - } - List abils = new ArrayList(); - for (CoreAbility coreAbil : CoreAbility.getAbilities()) { - if (bPlayer.canBind(coreAbil) && !coreAbil.getName().toLowerCase().contains("click")) { - abils.add(coreAbil.getName()); - } - } - - Collections.sort(abils); - list.addAll(abils); - return getPossibleCompletionsForGivenArgs(args, list); - } else if (args[0].equalsIgnoreCase("permaremove") || args[0].equalsIgnoreCase("pr") || args[0].equalsIgnoreCase("premove") || args[0].equalsIgnoreCase("permremove")) { - if (args.length > 2 || !sender.hasPermission("bending.command.permaremove")) - return new ArrayList(); - List players = new ArrayList(); - for (Player p : Bukkit.getOnlinePlayers()) { - players.add(p.getName()); - } - return getPossibleCompletionsForGivenArgs(args, players); - } else if (args[0].equalsIgnoreCase("preset") || args[0].equalsIgnoreCase("presets") || args[0].equalsIgnoreCase("pre") || args[0].equalsIgnoreCase("set") || args[0].equalsIgnoreCase("p")) { - if (args.length > 4 || !sender.hasPermission("bending.command.preset") || !(sender instanceof Player)) - return new ArrayList(); - List l = new ArrayList(); - if (args.length == 2) { - l.add("create"); - l.add("delete"); - l.add("list"); - l.add("bind"); - return getPossibleCompletionsForGivenArgs(args, l); - } else if (args.length == 3 && Arrays.asList(new String[] { "delete", "d", "del", "bind", "b" }).contains(args[1].toLowerCase())) { - List presets = Preset.presets.get(((Player) sender).getUniqueId()); - List presetNames = new ArrayList(); - if (presets != null && presets.size() != 0) { - for (Preset preset : presets) { - presetNames.add(preset.getName()); - } - } - if (sender.hasPermission("bending.command.preset.bind.external")) { - if (Preset.externalPresets.keySet().size() > 0) { - for (String externalPreset : Preset.externalPresets.keySet()) { - presetNames.add(externalPreset); - } - } - } - if (presetNames.size() == 0) - return new ArrayList(); - return getPossibleCompletionsForGivenArgs(args, presetNames); - } else if (args.length == 4 && Arrays.asList(new String[] {"bind", "b"}).contains(args[1].toLowerCase())) { - if (!sender.hasPermission("bending.command.preset.bind.assign") || (Preset.externalPresets.keySet().contains(args[2].toLowerCase())) && !sender.hasPermission("bending.command.preset.bind.external.other")) { - return new ArrayList(); - } - List players = new ArrayList(); - for (Player p : Bukkit.getOnlinePlayers()) { - players.add(p.getName()); - } - return getPossibleCompletionsForGivenArgs(args, players); - } - return new ArrayList(); - } else if (args[0].equalsIgnoreCase("remove") || args[0].equalsIgnoreCase("rm")) { - if (args.length > 3 || !sender.hasPermission("bending.command.remove")) - return new ArrayList(); - List l = new ArrayList(); - if (args.length == 2) { - for (Player p : Bukkit.getOnlinePlayers()) { - l.add(p.getName()); - } - } else { - l.add("Air"); - l.add("Earth"); - l.add("Fire"); - l.add("Water"); - l.add("Chi"); - for (Element e : Element.getAddonElements()) { - l.add(e.getName()); - } - - l.add("Blood"); - l.add("Combustion"); - l.add("Flight"); - l.add("Healing"); - l.add("Ice"); - l.add("Lava"); - l.add("Lightning"); - l.add("Metal"); - l.add("Plant"); - l.add("Sand"); - l.add("Spiritual"); - - for (SubElement e : Element.getAddonSubElements()) { - l.add(e.getName()); - } - } - return getPossibleCompletionsForGivenArgs(args, l); - } else if (args[0].equalsIgnoreCase("who") || args[0].equalsIgnoreCase("w")) { - if (args.length > 2 || !sender.hasPermission("bending.command.who")) - return new ArrayList(); - List l = new ArrayList(); - for (Player p : Bukkit.getOnlinePlayers()) { - l.add(p.getName()); - } - return getPossibleCompletionsForGivenArgs(args, l); - } else if (args[0].equalsIgnoreCase("copy") || args[0].equalsIgnoreCase("co")) { - //If they can't use the command, have over 3 args (copy ), or if have over 2 args and can't assign to other players - if (!sender.hasPermission("bending.command.copy") || args.length > 4 || (args.length > 3 && !sender.hasPermission("bending.command.copy.assign"))) - return new ArrayList(); //Return nothing - List l = new ArrayList(); - for (Player p : Bukkit.getOnlinePlayers()) { - l.add(p.getName()); - } - return getPossibleCompletionsForGivenArgs(args, l); - } else if (GeneralMethods.hasRPG()) { - if (args[0].equalsIgnoreCase("rpg")) { - if (sender.hasPermission("bending.command.rpg") && args.length <= 4) { - if (args.length == 2) { - List l = new ArrayList<>(); - l.addAll(RPGCommand.instances.keySet()); - Collections.sort(l); - return getPossibleCompletionsForGivenArgs(args, l); - } else if (args.length == 3) { - List l = new ArrayList<>(); - if (Arrays.asList(RPGCommand.instances.get("avatar").getAliases()).contains(args[1].toLowerCase()) && sender.hasPermission("bending.command.rpg.avatar")) { - for (Player p : Bukkit.getOnlinePlayers()) { - l.add(p.getName()); - } - } else if (Arrays.asList(RPGCommand.instances.get("worldevent").getAliases()).contains(args[1].toLowerCase()) && sender.hasPermission("bending.command.rpg.worldevent")) { - l.add("start"); - l.add("end"); - l.add("help"); - l.add("skip"); - l.add("current"); - } else if (Arrays.asList(RPGCommand.instances.get("help").getAliases()).contains(args[1].toLowerCase()) && sender.hasPermission("bending.command.rpg.help")) { - l.add("lunareclipse"); - l.add("solareclipse"); - l.add("sozinscomet"); - l.add("fullmoon"); - for (String rpg : RPGCommand.instances.keySet()) { - if (!rpg.equalsIgnoreCase("help")) { - l.add(rpg); - } - } - } - Collections.sort(l); - return getPossibleCompletionsForGivenArgs(args, l); - } else if (args.length == 4) { - List l = new ArrayList<>(); - String[] start = {"start", "st", "strt", "begin"}; - if (Arrays.asList(RPGCommand.instances.get("worldevent").getAliases()).contains(args[1].toLowerCase()) && sender.hasPermission("bending.command.rpg.worldevent")) { - if (Arrays.asList(start).contains(args[2].toLowerCase())) { - l.add("lunareclipse"); - l.add("solareclipse"); - l.add("sozinscomet"); - l.add("fullmoon"); - } - } - Collections.sort(l); - return getPossibleCompletionsForGivenArgs(args, l); - } + if (args.length == 0 || args.length == 1) + return getPossibleCompletions(args, getCommandsForUser(sender)); + else if (args.length > 1){ + for (PKCommand cmd : PKCommand.instances.values()) { + if (Arrays.asList(cmd.getAliases()).contains(args[0].toLowerCase()) && sender.hasPermission("bending.command." + cmd.getName())) { + List newargs = new ArrayList(); + for (int i = 1; i < args.length - 1; i++) { + if (!(args[i].equals("") || args[i].equals(" ")) && args.length >= 1) + newargs.add(args[i]); } + return getPossibleCompletions(args, cmd.getTabCompletion(sender, newargs)); } } - - else if (!PKCommand.instances.keySet().contains(args[0].toLowerCase())) { - return new ArrayList(); - } - } else { - return getPossibleCompletionsForGivenArgs(args, getCommandsForUser(sender)); } + return new ArrayList(); } @@ -324,7 +48,7 @@ public class BendingTabComplete implements TabCompleter { * @param args Args of the command. Provide all of them. * @param possibilitiesOfCompletion List of things that can be given */ - public static List getPossibleCompletionsForGivenArgs(String[] args, List possibilitiesOfCompletion) { + public static List getPossibleCompletions(String[] args, List possibilitiesOfCompletion) { String argumentToFindCompletionFor = args[args.length - 1]; List listOfPossibleCompletions = new ArrayList(); @@ -337,8 +61,8 @@ public class BendingTabComplete implements TabCompleter { return listOfPossibleCompletions; } - public static List getPossibleCompletionsForGivenArgs(String[] args, String[] possibilitiesOfCompletion) { - return getPossibleCompletionsForGivenArgs(args, Arrays.asList(possibilitiesOfCompletion)); + public static List getPossibleCompletions(String[] args, String[] possibilitiesOfCompletion) { + return getPossibleCompletions(args, Arrays.asList(possibilitiesOfCompletion)); } /** Returns a list of subcommands the sender can use. */ diff --git a/src/com/projectkorra/projectkorra/command/BindCommand.java b/src/com/projectkorra/projectkorra/command/BindCommand.java index 6b0b5118..2db85145 100644 --- a/src/com/projectkorra/projectkorra/command/BindCommand.java +++ b/src/com/projectkorra/projectkorra/command/BindCommand.java @@ -9,6 +9,9 @@ import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; /** @@ -76,4 +79,26 @@ public class BindCommand extends PKCommand { String name = coreAbil != null ? coreAbil.getName() : null; GeneralMethods.bindAbility((Player) sender, name, slot); } + + @Override + protected List getTabCompletion(CommandSender sender, List args) { + if (args.size() >= 2 || !sender.hasPermission("bending.command.bind") || !(sender instanceof Player)) return new ArrayList(); + + List abilities = new ArrayList(); + BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(sender.getName()); + if (args.size() == 0) { + if (bPlayer != null) { + for (CoreAbility coreAbil : CoreAbility.getAbilities()) { + if (!coreAbil.isHiddenAbility() && bPlayer.canBind(coreAbil)) { + abilities.add(coreAbil.getName()); + } + } + } + } else { + abilities = Arrays.asList("123456789".split("")); + } + + Collections.sort(abilities); + return abilities; + } } diff --git a/src/com/projectkorra/projectkorra/command/ChooseCommand.java b/src/com/projectkorra/projectkorra/command/ChooseCommand.java index 3b4c8599..ab180ecd 100644 --- a/src/com/projectkorra/projectkorra/command/ChooseCommand.java +++ b/src/com/projectkorra/projectkorra/command/ChooseCommand.java @@ -15,6 +15,7 @@ import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -151,4 +152,27 @@ public class ChooseCommand extends PKCommand { public static boolean isVowel(char c) { return "AEIOUaeiou".indexOf(c) != -1; } + + @Override + protected List getTabCompletion(CommandSender sender, List args) { + if (args.size() >= 2 || !sender.hasPermission("bending.command.choose")) return new ArrayList(); + + List l = new ArrayList(); + if (args.size() == 0) { + + l.add("Air"); + l.add("Earth"); + l.add("Fire"); + l.add("Water"); + l.add("Chi"); + for (Element e : Element.getAddonElements()) { + l.add(e.getName()); + } + } else { + for (Player p : Bukkit.getOnlinePlayers()) { + l.add(p.getName()); + } + } + return l; + } } diff --git a/src/com/projectkorra/projectkorra/command/ClearCommand.java b/src/com/projectkorra/projectkorra/command/ClearCommand.java index 2291caaa..40221e54 100644 --- a/src/com/projectkorra/projectkorra/command/ClearCommand.java +++ b/src/com/projectkorra/projectkorra/command/ClearCommand.java @@ -9,6 +9,8 @@ import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -70,5 +72,11 @@ public class ClearCommand extends PKCommand { } } } + + @Override + protected List getTabCompletion(CommandSender sender, List args) { + if (args.size() >= 1 || !sender.hasPermission("bending.command.clear")) return new ArrayList(); + return Arrays.asList("123456789".split("")); + } } diff --git a/src/com/projectkorra/projectkorra/command/CopyCommand.java b/src/com/projectkorra/projectkorra/command/CopyCommand.java index b04573fc..18e7350b 100644 --- a/src/com/projectkorra/projectkorra/command/CopyCommand.java +++ b/src/com/projectkorra/projectkorra/command/CopyCommand.java @@ -11,6 +11,7 @@ import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -110,5 +111,15 @@ public class CopyCommand extends PKCommand { target.setAbilities(abilities); return boundAll; } + + @Override + protected List getTabCompletion(CommandSender sender, List args) { + if (!sender.hasPermission("bending.command.copy") || args.size() >= 2 || (args.size() >= 1 && !sender.hasPermission("bending.command.copy.assign"))) return new ArrayList(); //Return nothing + List l = new ArrayList(); + for (Player p : Bukkit.getOnlinePlayers()) { + l.add(p.getName()); + } + return l; + } } \ No newline at end of file diff --git a/src/com/projectkorra/projectkorra/command/DisplayCommand.java b/src/com/projectkorra/projectkorra/command/DisplayCommand.java index c65012f0..2867633e 100644 --- a/src/com/projectkorra/projectkorra/command/DisplayCommand.java +++ b/src/com/projectkorra/projectkorra/command/DisplayCommand.java @@ -213,4 +213,44 @@ public class DisplayCommand extends PKCommand { sender.sendMessage(i + " - " + coreAbil.getElement().getColor() + ability); } } + + @Override + protected List getTabCompletion(CommandSender sender, List args) { + if (args.size() >= 1 || !sender.hasPermission("bending.command.display")) return new ArrayList(); + List list = new ArrayList(); + list.add("Air"); + list.add("Earth"); + list.add("Fire"); + list.add("Water"); + list.add("Chi"); + + for (Element e : Element.getAddonElements()) { + list.add(e.getName()); + } + + list.add("Bloodbending"); + list.add("Combustion"); + list.add("Flight"); + list.add("Healing"); + list.add("Ice"); + list.add("Lava"); + list.add("Lightning"); + list.add("Metal"); + list.add("Plantbending"); + list.add("Sand"); + list.add("SpiritualProjection"); + + for (SubElement se : Element.getAddonSubElements()) { + list.add(se.getName()); + } + + list.add("AirCombos"); + list.add("EarthCombos"); + list.add("FireCombos"); + list.add("WaterCombos"); + list.add("ChiCombos"); + list.add("Avatar"); + + return list; + } } diff --git a/src/com/projectkorra/projectkorra/command/HelpCommand.java b/src/com/projectkorra/projectkorra/command/HelpCommand.java index 6303ac7b..3745c7cc 100644 --- a/src/com/projectkorra/projectkorra/command/HelpCommand.java +++ b/src/com/projectkorra/projectkorra/command/HelpCommand.java @@ -1,6 +1,7 @@ package com.projectkorra.projectkorra.command; import com.projectkorra.items.command.PKICommand; +import com.projectkorra.projectkorra.BendingPlayer; import com.projectkorra.projectkorra.Element; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.ComboAbility; @@ -11,6 +12,7 @@ import com.projectkorra.rpg.commands.RPGCommand; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.Arrays; @@ -149,4 +151,23 @@ public class HelpCommand extends PKCommand { sender.sendMessage(ChatColor.RED + invalidTopic); } } + + @Override + protected List getTabCompletion(CommandSender sender, List args) { + if (args.size() >= 1 || !sender.hasPermission("bending.command.help")) return new ArrayList(); + List list = new ArrayList(); + for (Element e : Element.getAllElements()) { + list.add(e.getName()); + } + List abils = new ArrayList(); + for (CoreAbility coreAbil : CoreAbility.getAbilities()) { + if ((!(sender instanceof Player) || BendingPlayer.getBendingPlayer(sender.getName()).canBind(coreAbil)) && !coreAbil.getName().toLowerCase().contains("click")) { + abils.add(coreAbil.getName()); + } + } + + Collections.sort(abils); + list.addAll(abils); + return list; + } } diff --git a/src/com/projectkorra/projectkorra/command/PKCommand.java b/src/com/projectkorra/projectkorra/command/PKCommand.java index e2ceae7d..548a52a4 100644 --- a/src/com/projectkorra/projectkorra/command/PKCommand.java +++ b/src/com/projectkorra/projectkorra/command/PKCommand.java @@ -247,4 +247,10 @@ public abstract class PKCommand implements SubCommand { return strings; } + /**Gets a list of valid arguments that can be used in tabbing.*/ + protected List getTabCompletion(CommandSender sender, List args) + { + return new ArrayList(); + } + } diff --git a/src/com/projectkorra/projectkorra/command/PermaremoveCommand.java b/src/com/projectkorra/projectkorra/command/PermaremoveCommand.java index 3e0eebdf..c37956c0 100644 --- a/src/com/projectkorra/projectkorra/command/PermaremoveCommand.java +++ b/src/com/projectkorra/projectkorra/command/PermaremoveCommand.java @@ -11,6 +11,7 @@ import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.util.ArrayList; import java.util.List; /** @@ -98,4 +99,14 @@ public class PermaremoveCommand extends PKCommand { } return true; } + + @Override + protected List getTabCompletion(CommandSender sender, List args) { + if (args.size() >= 1 || !sender.hasPermission("bending.command.permaremove")) return new ArrayList(); + List players = new ArrayList(); + for (Player p : Bukkit.getOnlinePlayers()) { + players.add(p.getName()); + } + return players; + } } diff --git a/src/com/projectkorra/projectkorra/command/PresetCommand.java b/src/com/projectkorra/projectkorra/command/PresetCommand.java index 64801e42..631f9134 100644 --- a/src/com/projectkorra/projectkorra/command/PresetCommand.java +++ b/src/com/projectkorra/projectkorra/command/PresetCommand.java @@ -218,4 +218,35 @@ public class PresetCommand extends PKCommand { help(sender, false); } } + + @Override + protected List getTabCompletion(CommandSender sender, List args) { + if (args.size() >= 3 || !sender.hasPermission("bending.command.preset") || !(sender instanceof Player)) + return new ArrayList(); + List l = new ArrayList(); + if (args.size() == 0) { + l.add("create"); + l.add("delete"); + l.add("list"); + l.add("bind"); + return l; + } else if (args.size() == 2 && Arrays.asList(new String[] { "delete", "d", "del", "bind", "b" }).contains(args.get(0).toLowerCase())) { + List presets = Preset.presets.get(((Player) sender).getUniqueId()); + List presetNames = new ArrayList(); + if (presets != null && presets.size() != 0) { + for (Preset preset : presets) { + presetNames.add(preset.getName()); + } + } + if (sender.hasPermission("bending.command.preset.bind.external")) { + if (Preset.externalPresets.keySet().size() > 0) { + for (String externalPreset : Preset.externalPresets.keySet()) { + presetNames.add(externalPreset); + } + } + } + if (presetNames.size() == 0) return new ArrayList(); + } + return l; + } } \ No newline at end of file diff --git a/src/com/projectkorra/projectkorra/command/RemoveCommand.java b/src/com/projectkorra/projectkorra/command/RemoveCommand.java index 3b8bc4c1..adaaf7d7 100644 --- a/src/com/projectkorra/projectkorra/command/RemoveCommand.java +++ b/src/com/projectkorra/projectkorra/command/RemoveCommand.java @@ -15,6 +15,7 @@ import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.util.ArrayList; import java.util.List; /** @@ -134,4 +135,41 @@ public class RemoveCommand extends PKCommand { sender.sendMessage(super.noPermissionMessage); return false; } + + @Override + protected List getTabCompletion(CommandSender sender, List args) { + if (args.size() >= 2 || !sender.hasPermission("bending.command.remove")) return new ArrayList(); + List l = new ArrayList(); + if (args.size() == 1) { + for (Player p : Bukkit.getOnlinePlayers()) { + l.add(p.getName()); + } + } else { + l.add("Air"); + l.add("Earth"); + l.add("Fire"); + l.add("Water"); + l.add("Chi"); + for (Element e : Element.getAddonElements()) { + l.add(e.getName()); + } + + l.add("Blood"); + l.add("Combustion"); + l.add("Flight"); + l.add("Healing"); + l.add("Ice"); + l.add("Lava"); + l.add("Lightning"); + l.add("Metal"); + l.add("Plant"); + l.add("Sand"); + l.add("Spiritual"); + + for (SubElement e : Element.getAddonSubElements()) { + l.add(e.getName()); + } + } + return l; + } } diff --git a/src/com/projectkorra/projectkorra/command/ToggleCommand.java b/src/com/projectkorra/projectkorra/command/ToggleCommand.java index 71728d80..3c4aaf27 100644 --- a/src/com/projectkorra/projectkorra/command/ToggleCommand.java +++ b/src/com/projectkorra/projectkorra/command/ToggleCommand.java @@ -11,6 +11,8 @@ import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; /** @@ -142,4 +144,24 @@ public class ToggleCommand extends PKCommand { } return true; } + + @Override + protected List getTabCompletion(CommandSender sender, List args) { + if (args.size() >= 2 || !sender.hasPermission("bending.command.toggle.others")) return new ArrayList(); + List l = new ArrayList(); + if (args.size() == 0) { + List elements = new ArrayList(); + for (Element e : Element.getAllElements()) { + elements.add(e.getName()); + } + Collections.sort(elements); + l.add("All"); + l.addAll(elements); + } else { + for (Player p : Bukkit.getOnlinePlayers()) { + l.add(p.getName()); + } + } + return l; + } } diff --git a/src/com/projectkorra/projectkorra/command/WhoCommand.java b/src/com/projectkorra/projectkorra/command/WhoCommand.java index de2a0ba0..ad31624a 100644 --- a/src/com/projectkorra/projectkorra/command/WhoCommand.java +++ b/src/com/projectkorra/projectkorra/command/WhoCommand.java @@ -331,5 +331,16 @@ public class WhoCommand extends PKCommand { sender.sendMessage(staff.get(uuid.toString())); } } + + } + + @Override + protected List getTabCompletion(CommandSender sender, List args) { + if (args.size() >= 1 || !sender.hasPermission("bending.command.who")) return new ArrayList(); + List l = new ArrayList(); + for (Player p : Bukkit.getOnlinePlayers()) { + l.add(p.getName()); + } + return l; } }