From c6d3a771c36cb222df708256b8a0bf4ed6d7ccb2 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Mon, 14 Mar 2022 20:20:04 +0100 Subject: [PATCH] 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 --- .../net/knarcraft/paidsigns/command/EditCommand.java | 9 +++++++++ .../knarcraft/paidsigns/command/EditTabCompleter.java | 3 ++- .../knarcraft/paidsigns/command/RemoveTabCommand.java | 10 ++-------- src/main/resources/plugin.yml | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/knarcraft/paidsigns/command/EditCommand.java b/src/main/java/net/knarcraft/paidsigns/command/EditCommand.java index 7897681..dd8250c 100644 --- a/src/main/java/net/knarcraft/paidsigns/command/EditCommand.java +++ b/src/main/java/net/knarcraft/paidsigns/command/EditCommand.java @@ -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 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); diff --git a/src/main/java/net/knarcraft/paidsigns/command/EditTabCompleter.java b/src/main/java/net/knarcraft/paidsigns/command/EditTabCompleter.java index b59533b..2c67f6e 100644 --- a/src/main/java/net/knarcraft/paidsigns/command/EditTabCompleter.java +++ b/src/main/java/net/knarcraft/paidsigns/command/EditTabCompleter.java @@ -27,6 +27,7 @@ public class EditTabCompleter extends TokenizedTabCompleter { @Override public List 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

The tab complete options to give to users

*/ private List 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<>(); diff --git a/src/main/java/net/knarcraft/paidsigns/command/RemoveTabCommand.java b/src/main/java/net/knarcraft/paidsigns/command/RemoveTabCommand.java index d74f0c7..0d08fe4 100644 --- a/src/main/java/net/knarcraft/paidsigns/command/RemoveTabCommand.java +++ b/src/main/java/net/knarcraft/paidsigns/command/RemoveTabCommand.java @@ -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 allPaidSigns = PaidSigns.getInstance().getSignManager().getAllPaidSigns(); - List signNames = new ArrayList<>(); - for (String name : allPaidSigns.keySet()) { - signNames.add("\"" + name + "\""); - } - return signNames; + return TabCompleteHelper.getPaidSignNames(); } else { return new ArrayList<>(); } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index caa2780..cab4000 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -30,7 +30,7 @@ commands: aliases: - eps description: Edits a property of a paid sign or a paid sign condition - usage: / / [new value]/ [new value] + usage: / / [new value]/ [new value] permission: paidsigns.manage removepaidsigncondition: aliases: