package net.knarcraft.paidsigns.command; import net.knarcraft.paidsigns.PaidSigns; import net.knarcraft.paidsigns.container.PaidSign; import net.knarcraft.paidsigns.utility.Tokenizer; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; import java.util.List; /** * A representation of the command for removing a condition from a sign */ public class RemoveConditionCommand implements CommandExecutor { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { List arguments = Tokenizer.tokenize(String.join(" ", args)); int argumentSize = args[args.length - 1].isEmpty() ? arguments.size() : arguments.size() - 1; if (argumentSize < 2) { return false; } String name = arguments.get(0); short line; try { line = Short.parseShort(arguments.get(1)); } catch (NumberFormatException exception) { sender.sendMessage("Invalid line number given"); return false; } PaidSign sign = PaidSigns.getInstance().getSignManager().getPaidSign(name); sign.removeCondition(line); sender.sendMessage("Condition removed"); return true; } }