Adds a tab completer for the list command
This commit is contained in:
		| @@ -5,6 +5,7 @@ import net.knarcraft.paidsigns.command.AddConditionCommand; | ||||
| import net.knarcraft.paidsigns.command.AddConditionTabCompleter; | ||||
| import net.knarcraft.paidsigns.command.AddTabCompleter; | ||||
| import net.knarcraft.paidsigns.command.ListCommand; | ||||
| import net.knarcraft.paidsigns.command.ListTabCompleter; | ||||
| import net.knarcraft.paidsigns.command.ReloadTabCommand; | ||||
| import net.knarcraft.paidsigns.command.RemoveConditionCommand; | ||||
| import net.knarcraft.paidsigns.command.RemoveConditionTabCompleter; | ||||
| @@ -113,7 +114,7 @@ public final class PaidSigns extends JavaPlugin { | ||||
|         PluginCommand listCommand = this.getCommand("listPaidSigns"); | ||||
|         if (listCommand != null) { | ||||
|             listCommand.setExecutor(new ListCommand()); | ||||
|             //TODO: Add tab completer | ||||
|             listCommand.setTabCompleter(new ListTabCompleter()); | ||||
|         } | ||||
|  | ||||
|         PluginCommand addConditionCommand = this.getCommand("addPaidSignCondition"); | ||||
|   | ||||
| @@ -25,7 +25,6 @@ public class AddCommand extends TokenizedCommand { | ||||
|         if (args.length < 3) { | ||||
|             return false; | ||||
|         } | ||||
|         PaidSignManager manager = PaidSigns.getInstance().getSignManager(); | ||||
|  | ||||
|         String signName = arguments.get(0); | ||||
|         double cost; | ||||
| @@ -45,6 +44,23 @@ public class AddCommand extends TokenizedCommand { | ||||
|             ignoreColor = OptionState.fromString(arguments.get(4)); | ||||
|         } | ||||
|  | ||||
|         return createPaidSign(sender, signName, cost, permission, ignoreCase, ignoreColor); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new paid sign with the given user input | ||||
|      * | ||||
|      * @param sender      <p>The command sender that called the add command</p> | ||||
|      * @param signName    <p>The name of the new paid sign</p> | ||||
|      * @param cost        <p>The cost of the new paid sign</p> | ||||
|      * @param permission  <p>The permission required for creating the sign represented by the paid sign</p> | ||||
|      * @param ignoreCase  <p>Whether to ignore case for the paid sign's conditions</p> | ||||
|      * @param ignoreColor <p>Whether to ignore color for the paid sign's conditions</p> | ||||
|      * @return <p>True if the paid sign was successfully created and registered</p> | ||||
|      */ | ||||
|     private boolean createPaidSign(CommandSender sender, String signName, double cost, String permission, | ||||
|                                    OptionState ignoreCase, OptionState ignoreColor) { | ||||
|         PaidSignManager manager = PaidSigns.getInstance().getSignManager(); | ||||
|         try { | ||||
|             PaidSign sign = new PaidSign(signName, cost, permission, ignoreCase, ignoreColor); | ||||
|             if (manager.getPaidSign(signName) != null) { | ||||
|   | ||||
| @@ -0,0 +1,29 @@ | ||||
| package net.knarcraft.paidsigns.command; | ||||
|  | ||||
| import net.knarcraft.paidsigns.utility.TabCompleteHelper; | ||||
| import org.bukkit.command.Command; | ||||
| import org.bukkit.command.CommandSender; | ||||
| import org.jetbrains.annotations.NotNull; | ||||
| import org.jetbrains.annotations.Nullable; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * The tab completer for the list paid signs command | ||||
|  */ | ||||
| public class ListTabCompleter extends TokenizedTabCompleter { | ||||
|  | ||||
|     @Nullable | ||||
|     @Override | ||||
|     public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, | ||||
|                                       @NotNull String[] args) { | ||||
|         if (argumentSize < 1) { | ||||
|             return TabCompleteHelper.getPaidSignNames(); | ||||
|         } else if (argumentSize < 2) { | ||||
|             return TabCompleteHelper.getSignLines(); | ||||
|         } | ||||
|         return new ArrayList<>(); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -8,7 +8,11 @@ import java.util.List; | ||||
| /** | ||||
|  * A helper class for providing common tab complete options | ||||
|  */ | ||||
| public class TabCompleteHelper { | ||||
| public final class TabCompleteHelper { | ||||
|  | ||||
|     private TabCompleteHelper() { | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Gets the available boolean values for tab completion | ||||
|   | ||||
		Reference in New Issue
	
	Block a user