Fixes some bugs in the edit command

Adds missing super call to EditTabCompleter
Adds missing super call to EditCommand
Fixes the index of an argument during tab completion
Fixes a bug that caused conditions to be lost when a paid sign is changed
This commit is contained in:
Kristian Knarvik 2022-03-14 20:20:04 +01:00
parent 3e31c8c648
commit c6d3a771c3
4 changed files with 14 additions and 10 deletions

View File

@ -14,6 +14,7 @@ import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.Map;
/**
* A representation of the command for editing a new paid sign
@ -23,6 +24,7 @@ public class EditCommand extends TokenizedCommand {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
@NotNull String[] args) {
super.onCommand(sender, command, label, args);
if (argumentSize < 3) {
return false;
}
@ -122,9 +124,16 @@ public class EditCommand extends TokenizedCommand {
sign.matchAnyCondition();
double cost = property == PaidSignProperty.COST ? Double.parseDouble(newValue) : sign.getCost();
String permission = property == PaidSignProperty.PERMISSION ? newValue : sign.getPermission();
Map<Short, PaidSignCondition> conditions = sign.getConditions();
PaidSignManager manager = PaidSigns.getInstance().getSignManager();
PaidSign updatedSign = new PaidSign(signName, cost, permission, ignoreCase, ignoreColor, matchAnyCondition);
for (short line : conditions.keySet()) {
PaidSignCondition condition = conditions.get(line);
updatedSign.addCondition(line, condition.getStringToMatch(), condition.executeRegex(),
OptionState.getFromBoolean(condition.ignoreCase()),
OptionState.getFromBoolean(condition.ignoreColor()));
}
manager.removePaidSign(sign.getName());
manager.addPaidSign(updatedSign);

View File

@ -27,6 +27,7 @@ public class EditTabCompleter extends TokenizedTabCompleter {
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
@NotNull String[] args) {
super.onTabComplete(sender, command, label, args);
if (propertyExampleValues == null) {
initializePropertyExampleValues();
initializeConditionPropertyExampleValues();
@ -73,7 +74,7 @@ public class EditTabCompleter extends TokenizedTabCompleter {
* @return <p>The tab complete options to give to users</p>
*/
private List<String> tabCompleteSignLine(@NotNull PaidSign sign) {
short signLine = (short) (Short.parseShort(arguments.get(2)) - 1);
short signLine = (short) (Short.parseShort(arguments.get(1)) - 1);
//Refuse to autocomplete if invalid input is given
if (signLine < 0 || signLine > 3 || sign.getConditions().get(signLine) == null) {
return new ArrayList<>();

View File

@ -1,9 +1,9 @@
package net.knarcraft.paidsigns.command;
import net.knarcraft.paidsigns.PaidSigns;
import net.knarcraft.paidsigns.container.PaidSign;
import net.knarcraft.paidsigns.formatting.StringFormatter;
import net.knarcraft.paidsigns.formatting.TranslatableMessage;
import net.knarcraft.paidsigns.utility.TabCompleteHelper;
import net.knarcraft.paidsigns.utility.Tokenizer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@ -14,7 +14,6 @@ import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* A representation of the command for removing a paid sign
@ -53,12 +52,7 @@ public class RemoveTabCommand implements TabExecutor {
int argumentSize = args[args.length - 1].isEmpty() ? arguments.size() : arguments.size() - 1;
if (argumentSize < 1) {
Map<String, PaidSign> allPaidSigns = PaidSigns.getInstance().getSignManager().getAllPaidSigns();
List<String> signNames = new ArrayList<>();
for (String name : allPaidSigns.keySet()) {
signNames.add("\"" + name + "\"");
}
return signNames;
return TabCompleteHelper.getPaidSignNames();
} else {
return new ArrayList<>();
}

View File

@ -30,7 +30,7 @@ commands:
aliases:
- eps
description: Edits a property of a paid sign or a paid sign condition
usage: /<ommand> <sign name> <property>/<line number> [new value]/<property> [new value]
usage: /<command> <sign name> <property>/<line number> [new value]/<property> [new value]
permission: paidsigns.manage
removepaidsigncondition:
aliases: