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