Implements the add condition command and its tab completion

This commit is contained in:
2022-02-19 17:51:27 +01:00
parent d76d5cdf93
commit 90b5ff7304
9 changed files with 247 additions and 46 deletions

View File

@ -29,6 +29,7 @@ public class AddCommand implements CommandExecutor {
}
PaidSignManager manager = PaidSigns.getInstance().getSignManager();
List<String> arguments = Tokenizer.tokenize(String.join(" ", args));
int argumentSize = args[args.length - 1].isEmpty() ? arguments.size() : arguments.size() - 1;
String signName = arguments.get(0);
double cost;
@ -41,20 +42,18 @@ public class AddCommand implements CommandExecutor {
String permission = arguments.get(2);
OptionState ignoreCase = OptionState.DEFAULT;
OptionState ignoreColor = OptionState.DEFAULT;
if (arguments.size() > 3) {
if (argumentSize > 3) {
ignoreCase = OptionState.fromString(arguments.get(3));
}
if (arguments.size() > 4) {
if (argumentSize > 4) {
ignoreColor = OptionState.fromString(arguments.get(4));
}
try {
PaidSign sign = new PaidSign(signName, cost, permission, ignoreCase, ignoreColor);
for (PaidSign otherSign : manager.getAllPaidSigns()) {
if (sign.getName().equals(otherSign.getName())) {
sender.sendMessage("A paid sign with the same name already exists");
return false;
}
if (manager.getPaidSign(signName) != null) {
sender.sendMessage("A paid sign with the same name already exists");
return false;
}
manager.addPaidSign(sign);
sender.sendMessage("Successfully added new paid sign");