Translates the add condition command's messages

This commit is contained in:
Kristian Knarvik 2022-03-01 16:56:02 +01:00
parent 81e62eb664
commit 30bca7b8f1

View File

@ -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 <p>The name of the paid sign to add the condition to</p>
* @param lineNumber <p>The sign line the condition should check</p>
* @param stringToMatch <p>The string to look for on created signs</p>
* @param executeRegEx <p>Whether to treat the match string as a regular expression</p>
* @param ignoreCase <p>Whether to ignore case when matching</p>
* @param ignoreColor <p>Whether to ignore color when matching</p>
* @param sender <p>The command sender to notify when finished</p>
* @return <p>True if the condition was successfully added</p>
*/
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;
}