Finishes the implementation of the list command

This commit is contained in:
Kristian Knarvik 2022-02-25 19:41:43 +01:00
parent 86cb1c0fed
commit 7e01d77723
5 changed files with 97 additions and 27 deletions

View File

@ -16,8 +16,8 @@ As this plugin only listens to sign change events, there are some limitations:
* /addpaidsign <name> <cost> \[permission] \[ignore case] \[ignore color] * /addpaidsign <name> <cost> \[permission] \[ignore case] \[ignore color]
* /addpaidsigncondition <name (of a paid sign)> <line number> <string to match> \[executeRegEx] \[ignoreCase] * /addpaidsigncondition <name (of a paid sign)> <line number> <string to match> \[executeRegEx] \[ignoreCase]
\[ignoreColor] \[ignoreColor]
* /listpaidsigns * /listpaidsigns \[name (of a paid sign)] \[line number]
* /listpaidsignconditions <name (of a paid sign)> * /listpaidsignconditions
* /removepaidsigncondition <name (of a paid sign)> <line number> * /removepaidsigncondition <name (of a paid sign)> <line number>
* /removepaidsign <name (of a paid sign)> * /removepaidsign <name (of a paid sign)>
* /reload * /reload

View File

@ -4,6 +4,7 @@ import net.knarcraft.paidsigns.command.AddCommand;
import net.knarcraft.paidsigns.command.AddConditionCommand; import net.knarcraft.paidsigns.command.AddConditionCommand;
import net.knarcraft.paidsigns.command.AddConditionTabCompleter; import net.knarcraft.paidsigns.command.AddConditionTabCompleter;
import net.knarcraft.paidsigns.command.AddTabCompleter; import net.knarcraft.paidsigns.command.AddTabCompleter;
import net.knarcraft.paidsigns.command.ListCommand;
import net.knarcraft.paidsigns.command.ReloadTabCommand; import net.knarcraft.paidsigns.command.ReloadTabCommand;
import net.knarcraft.paidsigns.command.RemoveConditionCommand; import net.knarcraft.paidsigns.command.RemoveConditionCommand;
import net.knarcraft.paidsigns.command.RemoveConditionTabCompleter; import net.knarcraft.paidsigns.command.RemoveConditionTabCompleter;
@ -109,6 +110,12 @@ public final class PaidSigns extends JavaPlugin {
addCommand.setTabCompleter(new AddTabCompleter()); 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"); PluginCommand addConditionCommand = this.getCommand("addPaidSignCondition");
if (addConditionCommand != null) { if (addConditionCommand != null) {
addConditionCommand.setExecutor(new AddConditionCommand()); addConditionCommand.setExecutor(new AddConditionCommand());

View File

@ -1,17 +1,101 @@
package net.knarcraft.paidsigns.command; 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.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull; 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 { public class ListCommand extends TokenizedCommand {
@Override @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); super.onCommand(sender, command, label, args);
//TODO: If no argument is given, list all paid sign names if (argumentSize < 1) {
//TODO: If an argument is given, output extensive information about the sign 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; 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));
}
}
} }

View File

@ -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;
}
}

View File

@ -18,11 +18,7 @@ commands:
permission: paidsigns.manage permission: paidsigns.manage
listpaidsigns: listpaidsigns:
description: Lists all previously added paid signs description: Lists all previously added paid signs
usage: /<command> usage: /<command> [sign name] [line number]
permission: paidsigns.manage
listpaidsignconditions:
description: Lists all conditions added to the given paid sign
usage: /<command> <name (of a paid sign)>
permission: paidsigns.manage permission: paidsigns.manage
removepaidsigncondition: removepaidsigncondition:
description: Used to remove a match condition from a paid sign description: Used to remove a match condition from a paid sign