diff --git a/README.md b/README.md index fd8d546..f111aa0 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,8 @@ As this plugin only listens to sign change events, there are some limitations: * /addpaidsign \[permission] \[ignore case] \[ignore color] * /addpaidsigncondition \[executeRegEx] \[ignoreCase] \[ignoreColor] -* /listpaidsigns -* /listpaidsignconditions +* /listpaidsigns \[name (of a paid sign)] \[line number] +* /listpaidsignconditions * /removepaidsigncondition * /removepaidsign * /reload \ No newline at end of file diff --git a/src/main/java/net/knarcraft/paidsigns/PaidSigns.java b/src/main/java/net/knarcraft/paidsigns/PaidSigns.java index 53a2ad8..9f9b1e5 100644 --- a/src/main/java/net/knarcraft/paidsigns/PaidSigns.java +++ b/src/main/java/net/knarcraft/paidsigns/PaidSigns.java @@ -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()); diff --git a/src/main/java/net/knarcraft/paidsigns/command/ListCommand.java b/src/main/java/net/knarcraft/paidsigns/command/ListCommand.java index d950d72..b3bef85 100644 --- a/src/main/java/net/knarcraft/paidsigns/command/ListCommand.java +++ b/src/main/java/net/knarcraft/paidsigns/command/ListCommand.java @@ -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

The command sender to display the information to

+ * @return

True if successful. False if the input contained errors

+ */ + 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

The command sender to display the information to

+ * @param signName

The name of the sign to display the condition for

+ * @param condition

The condition to display information about

+ */ + 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

The command sender to display the information to

+ * @param paidSign

The paid sign to display information about

+ */ + 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 conditions = paidSign.getConditions(); + for (short lineIndex : conditions.keySet()) { + sender.sendMessage(" | " + lineIndex + ". " + conditions.get(lineIndex)); + } + } + } diff --git a/src/main/java/net/knarcraft/paidsigns/command/ListConditionsCommand.java b/src/main/java/net/knarcraft/paidsigns/command/ListConditionsCommand.java deleted file mode 100644 index e416ed6..0000000 --- a/src/main/java/net/knarcraft/paidsigns/command/ListConditionsCommand.java +++ /dev/null @@ -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; - } - -} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 324607d..88afa1e 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -18,11 +18,7 @@ commands: permission: paidsigns.manage listpaidsigns: description: Lists all previously added paid signs - usage: / - permission: paidsigns.manage - listpaidsignconditions: - description: Lists all conditions added to the given paid sign - usage: / + usage: / [sign name] [line number] permission: paidsigns.manage removepaidsigncondition: description: Used to remove a match condition from a paid sign