From 30bca7b8f15b6b4d852617570f8e44c72beaeb51 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Tue, 1 Mar 2022 16:56:02 +0100 Subject: [PATCH] Translates the add condition command's messages --- .../command/AddConditionCommand.java | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/knarcraft/paidsigns/command/AddConditionCommand.java b/src/main/java/net/knarcraft/paidsigns/command/AddConditionCommand.java index 9cce244..71c9c6b 100644 --- a/src/main/java/net/knarcraft/paidsigns/command/AddConditionCommand.java +++ b/src/main/java/net/knarcraft/paidsigns/command/AddConditionCommand.java @@ -2,6 +2,8 @@ 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.manager.PaidSignManager; import net.knarcraft.paidsigns.property.OptionState; import org.bukkit.command.Command; @@ -19,7 +21,8 @@ import java.util.logging.Logger; public class AddConditionCommand extends TokenizedCommand { @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); if (argumentSize < 3) { return false; @@ -30,7 +33,7 @@ public class AddConditionCommand extends TokenizedCommand { try { lineNumber = (short) (Short.parseShort(arguments.get(1)) - 1); } catch (NumberFormatException exception) { - sender.sendMessage("Invalid line number given"); + sender.sendMessage(StringFormatter.getTranslatedErrorMessage(TranslatableMessage.ERROR_INVALID_NUMBER)); return false; } String stringToMatch = arguments.get(2); @@ -46,10 +49,27 @@ public class AddConditionCommand extends TokenizedCommand { if (argumentSize > 5) { ignoreColor = OptionState.getFromBoolean(Boolean.parseBoolean(arguments.get(5))); } + return addCondition(name, lineNumber, stringToMatch, executeRegEx, ignoreCase, ignoreColor, sender); + } + + /** + * Uses the given input to add a paid sign condition + * + * @param name

The name of the paid sign to add the condition to

+ * @param lineNumber

The sign line the condition should check

+ * @param stringToMatch

The string to look for on created signs

+ * @param executeRegEx

Whether to treat the match string as a regular expression

+ * @param ignoreCase

Whether to ignore case when matching

+ * @param ignoreColor

Whether to ignore color when matching

+ * @param sender

The command sender to notify when finished

+ * @return

True if the condition was successfully added

+ */ + private boolean addCondition(String name, short lineNumber, String stringToMatch, boolean executeRegEx, + OptionState ignoreCase, OptionState ignoreColor, CommandSender sender) { PaidSignManager signManager = PaidSigns.getInstance().getSignManager(); PaidSign sign = signManager.getPaidSign(name); if (sign == null) { - sender.sendMessage("No such paid sign exists"); + sender.sendMessage(StringFormatter.getTranslatedErrorMessage(TranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND)); return false; } sign.addCondition(lineNumber, stringToMatch, executeRegEx, ignoreCase, ignoreColor); @@ -59,10 +79,11 @@ public class AddConditionCommand extends TokenizedCommand { Logger logger = PaidSigns.getInstance().getLogger(); logger.log(Level.SEVERE, "Exception encountered while trying to write to the data file"); logger.log(Level.SEVERE, Arrays.toString(e.getStackTrace())); - sender.sendMessage("An exception occurred. Please notify the server administrator or check the server log."); + sender.sendMessage(StringFormatter.getTranslatedErrorMessage(TranslatableMessage.ERROR_EXCEPTION_OCCURRED)); return false; } - sender.sendMessage("Condition added"); + sender.sendMessage(StringFormatter.getTranslatedInfoMessage( + TranslatableMessage.SUCCESS_ADDED_PAID_SIGN_CONDITION)); return true; }