Translates the add command's messages

This commit is contained in:
Kristian Knarvik 2022-03-01 16:55:50 +01:00
parent 5cbde82fff
commit 81e62eb664

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;
@ -31,7 +33,7 @@ public class AddCommand extends TokenizedCommand {
try {
cost = Double.parseDouble(arguments.get(1));
} catch (NumberFormatException exception) {
sender.sendMessage("You provided an invalid number");
sender.sendMessage(StringFormatter.getTranslatedErrorMessage(TranslatableMessage.ERROR_INVALID_NUMBER));
return false;
}
String permission = "";
@ -67,21 +69,21 @@ public class AddCommand extends TokenizedCommand {
try {
PaidSign sign = new PaidSign(signName, cost, permission, ignoreCase, ignoreColor);
if (manager.getPaidSign(signName) != null) {
sender.sendMessage("A paid sign with the same name already exists");
sender.sendMessage(StringFormatter.getTranslatedErrorMessage(TranslatableMessage.ERROR_NAME_DUPLICATE));
return false;
}
manager.addPaidSign(sign);
sender.sendMessage("Successfully added new paid sign");
sender.sendMessage(StringFormatter.getTranslatedInfoMessage(TranslatableMessage.SUCCESS_ADDED_PAID_SIGN));
return true;
} catch (IOException e) {
Logger logger = PaidSigns.getInstance().getLogger();
logger.log(Level.SEVERE, "Exception encountered while trying to write " +
"to the data file");
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;
} catch (IllegalArgumentException e) {
sender.sendMessage("Invalid input: " + e.getMessage());
sender.sendMessage(StringFormatter.replacePlaceholder(StringFormatter.getTranslatedErrorMessage(
TranslatableMessage.ERROR_INVALID_INPUT), "{input}", e.getMessage()));
}
return false;
}