Finishes the implementation of the list command
This commit is contained in:
		| @@ -4,6 +4,7 @@ import net.knarcraft.paidsigns.command.AddCommand; | ||||
| 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.ReloadTabCommand; | ||||
| import net.knarcraft.paidsigns.command.RemoveConditionCommand; | ||||
| import net.knarcraft.paidsigns.command.RemoveConditionTabCompleter; | ||||
| @@ -109,6 +110,12 @@ public final class PaidSigns extends JavaPlugin { | ||||
|             addCommand.setTabCompleter(new AddTabCompleter()); | ||||
|         } | ||||
|  | ||||
|         PluginCommand listCommand = this.getCommand("listPaidSigns"); | ||||
|         if (listCommand != null) { | ||||
|             listCommand.setExecutor(new ListCommand()); | ||||
|             //TODO: Add tab completer | ||||
|         } | ||||
|  | ||||
|         PluginCommand addConditionCommand = this.getCommand("addPaidSignCondition"); | ||||
|         if (addConditionCommand != null) { | ||||
|             addConditionCommand.setExecutor(new AddConditionCommand()); | ||||
|   | ||||
| @@ -1,17 +1,101 @@ | ||||
| package net.knarcraft.paidsigns.command; | ||||
|  | ||||
| import net.knarcraft.paidsigns.PaidSigns; | ||||
| import net.knarcraft.paidsigns.container.PaidSign; | ||||
| import net.knarcraft.paidsigns.container.PaidSignCondition; | ||||
| import org.bukkit.command.Command; | ||||
| import org.bukkit.command.CommandSender; | ||||
| import org.jetbrains.annotations.NotNull; | ||||
|  | ||||
| import java.util.Map; | ||||
|  | ||||
| /** | ||||
|  * A representation of the command for listing information about paid signs | ||||
|  */ | ||||
| public class ListCommand extends TokenizedCommand { | ||||
|  | ||||
|     @Override | ||||
|     public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { | ||||
|     public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, | ||||
|                              @NotNull String[] args) { | ||||
|         super.onCommand(sender, command, label, args); | ||||
|         //TODO: If no argument is given, list all paid sign names | ||||
|         //TODO: If an argument is given, output extensive information about the sign | ||||
|         if (argumentSize < 1) { | ||||
|             sender.sendMessage("Paid signs:"); | ||||
|             for (String signName : PaidSigns.getInstance().getSignManager().getAllPaidSigns().keySet()) { | ||||
|                 sender.sendMessage(" | " + signName); | ||||
|             } | ||||
|             return true; | ||||
|         } else if (argumentSize < 3) { | ||||
|             return parsePaidSignSelection(sender); | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Parses the given input and displays the wanted paid-sign information | ||||
|      * | ||||
|      * @param sender <p>The command sender to display the information to</p> | ||||
|      * @return <p>True if successful. False if the input contained errors</p> | ||||
|      */ | ||||
|     private boolean parsePaidSignSelection(CommandSender sender) { | ||||
|         PaidSign paidSign = PaidSigns.getInstance().getSignManager().getPaidSign(arguments.get(0)); | ||||
|         if (paidSign == null) { | ||||
|             sender.sendMessage("No such paid sign"); | ||||
|             return false; | ||||
|         } | ||||
|         if (argumentSize < 2) { | ||||
|             displayPaidSign(sender, paidSign); | ||||
|         } else { | ||||
|             short signLine; | ||||
|             try { | ||||
|                 signLine = Short.parseShort(arguments.get(1)); | ||||
|             } catch (NumberFormatException exception) { | ||||
|                 sender.sendMessage("Invalid number given"); | ||||
|                 return false; | ||||
|             } | ||||
|             if (!paidSign.getConditions().containsKey(signLine)) { | ||||
|                 sender.sendMessage("The paid sign you specified has no condition for line " + signLine); | ||||
|                 return false; | ||||
|             } | ||||
|             PaidSignCondition condition = paidSign.getConditions().get(signLine); | ||||
|             displayPaidSignCondition(sender, paidSign.getName(), condition); | ||||
|         } | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Displays information about a paid sign condition | ||||
|      * | ||||
|      * @param sender    <p>The command sender to display the information to</p> | ||||
|      * @param signName  <p>The name of the sign to display the condition for</p> | ||||
|      * @param condition <p>The condition to display information about</p> | ||||
|      */ | ||||
|     private void displayPaidSignCondition(CommandSender sender, String signName, PaidSignCondition condition) { | ||||
|         sender.sendMessage("Paid sign condition info: "); | ||||
|         sender.sendMessage("Paid sign name: " + signName); | ||||
|         sender.sendMessage("Condition match string: " + condition.getStringToMatch()); | ||||
|         sender.sendMessage("Execute RegEx: " + condition.executeRegex()); | ||||
|         sender.sendMessage("Ignore case: " + condition.ignoreCase()); | ||||
|         sender.sendMessage("Ignore color: " + condition.ignoreColor()); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Displays information about a paid sign | ||||
|      * | ||||
|      * @param sender   <p>The command sender to display the information to</p> | ||||
|      * @param paidSign <p>The paid sign to display information about</p> | ||||
|      */ | ||||
|     private void displayPaidSign(CommandSender sender, PaidSign paidSign) { | ||||
|         sender.sendMessage("Paid sign info:"); | ||||
|         sender.sendMessage("Name: " + paidSign.getName()); | ||||
|         sender.sendMessage("Cost: " + paidSign.getCost()); | ||||
|         sender.sendMessage("Permission: " + paidSign.getPermission()); | ||||
|         sender.sendMessage("Ignore case: " + paidSign.getIgnoreCase()); | ||||
|         sender.sendMessage("Ignore color: " + paidSign.getIgnoreColor()); | ||||
|         sender.sendMessage("Sign conditions: "); | ||||
|         Map<Short, PaidSignCondition> conditions = paidSign.getConditions(); | ||||
|         for (short lineIndex : conditions.keySet()) { | ||||
|             sender.sendMessage(" | " + lineIndex + ". " + conditions.get(lineIndex)); | ||||
|         } | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -1,17 +0,0 @@ | ||||
| package net.knarcraft.paidsigns.command; | ||||
|  | ||||
| import org.bukkit.command.Command; | ||||
| import org.bukkit.command.CommandSender; | ||||
| import org.jetbrains.annotations.NotNull; | ||||
|  | ||||
| public class ListConditionsCommand extends TokenizedCommand { | ||||
|  | ||||
|     @Override | ||||
|     public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { | ||||
|         super.onCommand(sender, command, label, args); | ||||
|         //TODO: If a paid sign name is given, print a short overview over the conditions | ||||
|         //TODO: If a paid sign name and a line is given, display everything about the condition | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -18,11 +18,7 @@ commands: | ||||
|     permission: paidsigns.manage | ||||
|   listpaidsigns: | ||||
|     description: Lists all previously added paid signs | ||||
|     usage: /<command> | ||||
|     permission: paidsigns.manage | ||||
|   listpaidsignconditions: | ||||
|     description: Lists all conditions added to the given paid sign | ||||
|     usage: /<command> <name (of a paid sign)> | ||||
|     usage: /<command> [sign name] [line number] | ||||
|     permission: paidsigns.manage | ||||
|   removepaidsigncondition: | ||||
|     description: Used to remove a match condition from a paid sign | ||||
|   | ||||
		Reference in New Issue
	
	Block a user