Updates code to account for KnarLib changes

This commit is contained in:
Kristian Knarvik 2022-11-07 22:26:22 +01:00
parent a9c97f71f9
commit 5c095e79f6
11 changed files with 60 additions and 80 deletions

View File

@ -1,6 +1,6 @@
package net.knarcraft.paidsigns; package net.knarcraft.paidsigns;
import net.knarcraft.knarlib.KnarLib; import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.knarlib.formatting.Translator; import net.knarcraft.knarlib.formatting.Translator;
import net.knarcraft.knarlib.util.UpdateChecker; import net.knarcraft.knarlib.util.UpdateChecker;
import net.knarcraft.paidsigns.command.AddCommand; import net.knarcraft.paidsigns.command.AddCommand;
@ -40,6 +40,7 @@ public final class PaidSigns extends JavaPlugin {
private static PaidSigns paidSigns; private static PaidSigns paidSigns;
private static Translator translator; private static Translator translator;
private static StringFormatter stringFormatter;
private PaidSignManager signManager; private PaidSignManager signManager;
private String language; private String language;
private boolean ignoreCase; private boolean ignoreCase;
@ -74,17 +75,25 @@ public final class PaidSigns extends JavaPlugin {
return translator; return translator;
} }
/**
* Gets the string formatter to use for this plugin
*
* @return <p>The string formatter to use for this plugin</p>
*/
public static StringFormatter getStringFormatter() {
return stringFormatter;
}
@Override @Override
public void onEnable() { public void onEnable() {
KnarLib.setPlugin(this);
setupVault(); setupVault();
loadConfig(); loadConfig();
//Initialize translator //Initialize translator
translator = new Translator(); translator = new Translator();
translator.registerMessageCategory(PaidSignsTranslatableMessage.BOOLEAN_TRUE); translator.registerMessageCategory(PaidSignsTranslatableMessage.BOOLEAN_TRUE);
translator.loadLanguages(language); translator.loadLanguages(this.getDataFolder(), language);
stringFormatter = new StringFormatter(this.getDescription().getPrefix(), translator);
signManager = new PaidSignManager(PaidSignManager.loadSigns()); signManager = new PaidSignManager(PaidSignManager.loadSigns());
TrackedSignManager.loadTrackedSigns(); TrackedSignManager.loadTrackedSigns();
@ -109,7 +118,7 @@ public final class PaidSigns extends JavaPlugin {
public void reload() { public void reload() {
this.reloadConfig(); this.reloadConfig();
loadConfig(); loadConfig();
translator.loadLanguages(language); translator.loadLanguages(this.getDataFolder(), language);
signManager = new PaidSignManager(PaidSignManager.loadSigns()); signManager = new PaidSignManager(PaidSignManager.loadSigns());
TrackedSignManager.loadTrackedSigns(); TrackedSignManager.loadTrackedSigns();
} }

View File

@ -1,6 +1,5 @@
package net.knarcraft.paidsigns.command; package net.knarcraft.paidsigns.command;
import net.knarcraft.knarlib.formatting.StringFormatter;
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.PaidSignsTranslatableMessage; import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage;
@ -30,8 +29,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) {
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
return false; return false;
} }
String permission = ""; String permission = "";
@ -72,20 +70,17 @@ public class AddCommand extends TokenizedCommand {
try { try {
PaidSign sign = new PaidSign(signName, cost, permission, ignoreCase, ignoreColor, matchAnyCondition); PaidSign sign = new PaidSign(signName, cost, permission, ignoreCase, ignoreColor, matchAnyCondition);
if (manager.getPaidSign(signName) != null) { if (manager.getPaidSign(signName) != null) {
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_NAME_DUPLICATE);
PaidSignsTranslatableMessage.ERROR_NAME_DUPLICATE);
return false; return false;
} }
manager.addPaidSign(sign); manager.addPaidSign(sign);
StringFormatter.displaySuccessMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displaySuccessMessage(sender, PaidSignsTranslatableMessage.SUCCESS_ADDED_PAID_SIGN);
PaidSignsTranslatableMessage.SUCCESS_ADDED_PAID_SIGN);
return true; return true;
} catch (IOException e) { } catch (IOException e) {
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED);
PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED);
return false; return false;
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
StringFormatter.displayErrorMessage(sender, StringFormatter.replacePlaceholder(PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSigns.getStringFormatter().replacePlaceholder(
PaidSignsTranslatableMessage.ERROR_INVALID_INPUT, "{input}", e.getMessage())); PaidSignsTranslatableMessage.ERROR_INVALID_INPUT, "{input}", e.getMessage()));
} }
return false; return false;

View File

@ -1,6 +1,5 @@
package net.knarcraft.paidsigns.command; package net.knarcraft.paidsigns.command;
import net.knarcraft.knarlib.formatting.StringFormatter;
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.PaidSignsTranslatableMessage; import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage;
@ -30,13 +29,11 @@ public class AddConditionCommand extends TokenizedCommand {
try { try {
lineNumber = (short) (Short.parseShort(arguments.get(1)) - 1); lineNumber = (short) (Short.parseShort(arguments.get(1)) - 1);
if (lineNumber < 0 || lineNumber > 3) { if (lineNumber < 0 || lineNumber > 3) {
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
return false; return false;
} }
} catch (NumberFormatException exception) { } catch (NumberFormatException exception) {
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
return false; return false;
} }
String stringToMatch = arguments.get(2); String stringToMatch = arguments.get(2);
@ -75,20 +72,17 @@ public class AddConditionCommand extends TokenizedCommand {
PaidSignManager signManager = PaidSigns.getInstance().getSignManager(); PaidSignManager signManager = PaidSigns.getInstance().getSignManager();
PaidSign sign = signManager.getPaidSign(name); PaidSign sign = signManager.getPaidSign(name);
if (sign == null) { if (sign == null) {
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND);
PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND);
return false; return false;
} }
sign.addCondition(lineNumber, stringToMatch, executeRegEx, ignoreCase, ignoreColor); sign.addCondition(lineNumber, stringToMatch, executeRegEx, ignoreCase, ignoreColor);
try { try {
signManager.saveSigns(); signManager.saveSigns();
} catch (IOException e) { } catch (IOException e) {
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED);
PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED);
return false; return false;
} }
StringFormatter.displaySuccessMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displaySuccessMessage(sender, PaidSignsTranslatableMessage.SUCCESS_ADDED_PAID_SIGN_CONDITION);
PaidSignsTranslatableMessage.SUCCESS_ADDED_PAID_SIGN_CONDITION);
return true; return true;
} }

View File

@ -1,6 +1,5 @@
package net.knarcraft.paidsigns.command; package net.knarcraft.paidsigns.command;
import net.knarcraft.knarlib.formatting.StringFormatter;
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.container.PaidSignCondition; import net.knarcraft.paidsigns.container.PaidSignCondition;
@ -31,8 +30,7 @@ public class EditCommand extends TokenizedCommand {
PaidSign sign = PaidSigns.getInstance().getSignManager().getPaidSign(arguments.get(0)); PaidSign sign = PaidSigns.getInstance().getSignManager().getPaidSign(arguments.get(0));
if (sign == null) { if (sign == null) {
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND);
PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND);
return false; return false;
} }
@ -45,8 +43,7 @@ public class EditCommand extends TokenizedCommand {
return parseGivenProperty(sign, sender); return parseGivenProperty(sign, sender);
} }
} catch (IOException e) { } catch (IOException e) {
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED);
PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED);
return false; return false;
} }
} }
@ -63,8 +60,7 @@ public class EditCommand extends TokenizedCommand {
@NotNull CommandSender sender) throws NumberFormatException { @NotNull CommandSender sender) throws NumberFormatException {
short signLine = (short) (Short.parseShort(arguments.get(1)) - 1); short signLine = (short) (Short.parseShort(arguments.get(1)) - 1);
if (signLine < 0 || signLine > 3 || sign.getConditions().get(signLine) == null) { if (signLine < 0 || signLine > 3 || sign.getConditions().get(signLine) == null) {
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_NO_SUCH_CONDITION);
PaidSignsTranslatableMessage.ERROR_NO_SUCH_CONDITION);
return false; return false;
} }
if (argumentSize < 4) { if (argumentSize < 4) {
@ -73,8 +69,7 @@ public class EditCommand extends TokenizedCommand {
PaidSignConditionProperty conditionProperty = PaidSignConditionProperty.getFromString(arguments.get(2)); PaidSignConditionProperty conditionProperty = PaidSignConditionProperty.getFromString(arguments.get(2));
if (conditionProperty == null) { if (conditionProperty == null) {
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_PROPERTY_NOT_RECOGNIZED);
PaidSignsTranslatableMessage.ERROR_PROPERTY_NOT_RECOGNIZED);
return false; return false;
} }
String value = arguments.get(3); String value = arguments.get(3);
@ -93,8 +88,7 @@ public class EditCommand extends TokenizedCommand {
@NotNull CommandSender sender) throws IOException { @NotNull CommandSender sender) throws IOException {
PaidSignProperty property = PaidSignProperty.getFromString(arguments.get(1)); PaidSignProperty property = PaidSignProperty.getFromString(arguments.get(1));
if (property == null) { if (property == null) {
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_PROPERTY_NOT_RECOGNIZED);
PaidSignsTranslatableMessage.ERROR_PROPERTY_NOT_RECOGNIZED);
return false; return false;
} }
String value = arguments.get(2); String value = arguments.get(2);
@ -102,8 +96,7 @@ public class EditCommand extends TokenizedCommand {
updateProperty(sender, sign, property, value); updateProperty(sender, sign, property, value);
return true; return true;
} catch (NumberFormatException exception) { } catch (NumberFormatException exception) {
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
return false; return false;
} }
} }
@ -141,8 +134,7 @@ public class EditCommand extends TokenizedCommand {
manager.removePaidSign(sign.getName()); manager.removePaidSign(sign.getName());
manager.addPaidSign(updatedSign); manager.addPaidSign(updatedSign);
StringFormatter.displaySuccessMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displaySuccessMessage(sender, PaidSignsTranslatableMessage.SUCCESS_UPDATED_PAID_SIGN);
PaidSignsTranslatableMessage.SUCCESS_UPDATED_PAID_SIGN);
} }
/** /**
@ -178,13 +170,11 @@ public class EditCommand extends TokenizedCommand {
try { try {
PaidSigns.getInstance().getSignManager().saveSigns(); PaidSigns.getInstance().getSignManager().saveSigns();
} catch (IOException e) { } catch (IOException e) {
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED);
PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED);
return false; return false;
} }
StringFormatter.displaySuccessMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displaySuccessMessage(sender, PaidSignsTranslatableMessage.SUCCESS_UPDATED_PAID_SIGN_CONDITION);
PaidSignsTranslatableMessage.SUCCESS_UPDATED_PAID_SIGN_CONDITION);
return true; return true;
} }

View File

@ -15,7 +15,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static net.knarcraft.knarlib.formatting.StringFormatter.displayErrorMessage;
import static net.knarcraft.knarlib.formatting.StringFormatter.replacePlaceholder; import static net.knarcraft.knarlib.formatting.StringFormatter.replacePlaceholder;
import static net.knarcraft.knarlib.formatting.StringFormatter.replacePlaceholders; import static net.knarcraft.knarlib.formatting.StringFormatter.replacePlaceholders;
@ -89,7 +88,8 @@ public class ListCommand extends TokenizedCommand {
private boolean parsePaidSignSelection(CommandSender sender) { private boolean parsePaidSignSelection(CommandSender sender) {
PaidSign paidSign = PaidSigns.getInstance().getSignManager().getPaidSign(arguments.get(0)); PaidSign paidSign = PaidSigns.getInstance().getSignManager().getPaidSign(arguments.get(0));
if (paidSign == null) { if (paidSign == null) {
displayErrorMessage(sender, PaidSigns.getTranslator(), PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND); PaidSigns.getStringFormatter().displayErrorMessage(sender,
PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND);
return false; return false;
} }
if (argumentSize < 2) { if (argumentSize < 2) {
@ -99,18 +99,20 @@ public class ListCommand extends TokenizedCommand {
try { try {
lineNumber = (short) (Short.parseShort(arguments.get(1)) - 1); lineNumber = (short) (Short.parseShort(arguments.get(1)) - 1);
if (lineNumber < 0 || lineNumber > 3) { if (lineNumber < 0 || lineNumber > 3) {
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displayErrorMessage(sender,
PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER); PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
return false; return false;
} }
} catch (NumberFormatException exception) { } catch (NumberFormatException exception) {
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displayErrorMessage(sender,
PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER); PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
return false; return false;
} }
if (!paidSign.getConditions().containsKey(lineNumber)) { if (!paidSign.getConditions().containsKey(lineNumber)) {
StringFormatter.displayErrorMessage(sender, replacePlaceholder(PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displayErrorMessage(sender,
PaidSignsTranslatableMessage.ERROR_NO_SUCH_CONDITION, "{line}", String.valueOf(lineNumber))); PaidSigns.getStringFormatter().replacePlaceholder(
PaidSignsTranslatableMessage.ERROR_NO_SUCH_CONDITION, "{line}",
String.valueOf(lineNumber)));
return false; return false;
} }
PaidSignCondition condition = paidSign.getConditions().get(lineNumber); PaidSignCondition condition = paidSign.getConditions().get(lineNumber);
@ -129,7 +131,7 @@ public class ListCommand extends TokenizedCommand {
*/ */
private void displayPaidSignCondition(CommandSender sender, String signName, short signLine, private void displayPaidSignCondition(CommandSender sender, String signName, short signLine,
PaidSignCondition condition) { PaidSignCondition condition) {
sender.sendMessage(StringFormatter.replacePlaceholders(PaidSigns.getTranslator(), sender.sendMessage(PaidSigns.getStringFormatter().replacePlaceholders(
PaidSignsTranslatableMessage.PAID_SIGN_CONDITION_INFO, new String[]{"{name}", "{line}", "{match}", PaidSignsTranslatableMessage.PAID_SIGN_CONDITION_INFO, new String[]{"{name}", "{line}", "{match}",
"{regex}", "{case}", "{color}"}, new String[]{signName, String.valueOf(signLine + 1), "{regex}", "{case}", "{color}"}, new String[]{signName, String.valueOf(signLine + 1),
condition.stringToMatch(), translateBoolean(condition.executeRegex()), condition.stringToMatch(), translateBoolean(condition.executeRegex()),

View File

@ -1,6 +1,5 @@
package net.knarcraft.paidsigns.command; package net.knarcraft.paidsigns.command;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.paidsigns.PaidSigns; import net.knarcraft.paidsigns.PaidSigns;
import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage; import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -20,8 +19,7 @@ public class ReloadTabCommand implements TabExecutor {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
@NotNull String[] args) { @NotNull String[] args) {
PaidSigns.getInstance().reload(); PaidSigns.getInstance().reload();
StringFormatter.displaySuccessMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displaySuccessMessage(sender, PaidSignsTranslatableMessage.SUCCESS_RELOADED);
PaidSignsTranslatableMessage.SUCCESS_RELOADED);
return true; return true;
} }

View File

@ -1,6 +1,5 @@
package net.knarcraft.paidsigns.command; package net.knarcraft.paidsigns.command;
import net.knarcraft.knarlib.formatting.StringFormatter;
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.PaidSignsTranslatableMessage; import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage;
@ -17,7 +16,8 @@ import java.io.IOException;
public class RemoveConditionCommand extends TokenizedCommand { public class RemoveConditionCommand extends TokenizedCommand {
@Override @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); super.onCommand(sender, command, label, args);
if (argumentSize < 2) { if (argumentSize < 2) {
return false; return false;
@ -28,25 +28,23 @@ public class RemoveConditionCommand extends TokenizedCommand {
try { try {
lineNumber = (short) (Short.parseShort(arguments.get(1)) - 1); lineNumber = (short) (Short.parseShort(arguments.get(1)) - 1);
if (lineNumber < 0 || lineNumber > 3) { if (lineNumber < 0 || lineNumber > 3) {
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
return false; return false;
} }
} catch (NumberFormatException exception) { } catch (NumberFormatException exception) {
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER);
return false; return false;
} }
PaidSignManager signManager = PaidSigns.getInstance().getSignManager(); PaidSignManager signManager = PaidSigns.getInstance().getSignManager();
PaidSign sign = signManager.getPaidSign(name); PaidSign sign = signManager.getPaidSign(name);
if (sign == null) { if (sign == null) {
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displayErrorMessage(sender,
PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND); PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND);
return false; return false;
} }
if (!sign.getConditions().containsKey(lineNumber)) { if (!sign.getConditions().containsKey(lineNumber)) {
StringFormatter.displayErrorMessage(sender, StringFormatter.replacePlaceholder(PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSigns.getStringFormatter().replacePlaceholder(
PaidSignsTranslatableMessage.ERROR_NO_SUCH_CONDITION, "{line}", PaidSignsTranslatableMessage.ERROR_NO_SUCH_CONDITION, "{line}",
String.valueOf((lineNumber + 1)))); String.valueOf((lineNumber + 1))));
return false; return false;
@ -56,12 +54,10 @@ public class RemoveConditionCommand extends TokenizedCommand {
try { try {
signManager.saveSigns(); signManager.saveSigns();
} catch (IOException e) { } catch (IOException e) {
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED);
PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED);
return false; return false;
} }
StringFormatter.displaySuccessMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displaySuccessMessage(sender, PaidSignsTranslatableMessage.SUCCESS_REMOVED_CONDITION);
PaidSignsTranslatableMessage.SUCCESS_REMOVED_CONDITION);
return true; return true;
} }

View File

@ -1,6 +1,5 @@
package net.knarcraft.paidsigns.command; package net.knarcraft.paidsigns.command;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.paidsigns.PaidSigns; import net.knarcraft.paidsigns.PaidSigns;
import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage; import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage;
import net.knarcraft.paidsigns.utility.PaidSignsTabCompleteHelper; import net.knarcraft.paidsigns.utility.PaidSignsTabCompleteHelper;
@ -31,15 +30,15 @@ public class RemoveTabCommand implements TabExecutor {
try { try {
if (PaidSigns.getInstance().getSignManager().removePaidSign(name)) { if (PaidSigns.getInstance().getSignManager().removePaidSign(name)) {
StringFormatter.displaySuccessMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displaySuccessMessage(sender,
PaidSignsTranslatableMessage.SUCCESS_REMOVED_PAID_SIGN); PaidSignsTranslatableMessage.SUCCESS_REMOVED_PAID_SIGN);
} else { } else {
StringFormatter.displaySuccessMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displaySuccessMessage(sender,
PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND); PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND);
} }
return true; return true;
} catch (IOException e) { } catch (IOException e) {
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displayErrorMessage(sender,
PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED); PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED);
} }
return false; return false;

View File

@ -1,6 +1,5 @@
package net.knarcraft.paidsigns.command; package net.knarcraft.paidsigns.command;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.paidsigns.PaidSigns; import net.knarcraft.paidsigns.PaidSigns;
import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage; import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage;
import net.knarcraft.paidsigns.utility.Tokenizer; import net.knarcraft.paidsigns.utility.Tokenizer;
@ -40,7 +39,7 @@ public class TokenizedCommand implements CommandExecutor {
Pattern.compile(regularExpression); Pattern.compile(regularExpression);
return false; return false;
} catch (PatternSyntaxException exception) { } catch (PatternSyntaxException exception) {
StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), PaidSigns.getStringFormatter().displayErrorMessage(sender,
PaidSignsTranslatableMessage.ERROR_INVALID_REGULAR_EXPRESSION); PaidSignsTranslatableMessage.ERROR_INVALID_REGULAR_EXPRESSION);
return true; return true;
} }

View File

@ -1,6 +1,5 @@
package net.knarcraft.paidsigns.listener; package net.knarcraft.paidsigns.listener;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.knarlib.formatting.TranslatableMessage; import net.knarcraft.knarlib.formatting.TranslatableMessage;
import net.knarcraft.paidsigns.PaidSigns; import net.knarcraft.paidsigns.PaidSigns;
import net.knarcraft.paidsigns.container.PaidSign; import net.knarcraft.paidsigns.container.PaidSign;
@ -130,11 +129,11 @@ public class SignListener implements Listener {
double cost = paidSign.getCost(); double cost = paidSign.getCost();
boolean canAfford = EconomyManager.canAfford(player, cost); boolean canAfford = EconomyManager.canAfford(player, cost);
if (!canAfford) { if (!canAfford) {
StringFormatter.displayErrorMessage(player, replaceCost(cost, PaidSignsTranslatableMessage.ERROR_CANNOT_AFFORD)); PaidSigns.getStringFormatter().displayErrorMessage(player, replaceCost(cost, PaidSignsTranslatableMessage.ERROR_CANNOT_AFFORD));
event.setCancelled(true); event.setCancelled(true);
} else { } else {
EconomyManager.withdraw(player, cost); EconomyManager.withdraw(player, cost);
StringFormatter.displaySuccessMessage(player, replaceCost(cost, PaidSignsTranslatableMessage.SUCCESS_PAID_FOR_SIGN)); PaidSigns.getStringFormatter().displaySuccessMessage(player, replaceCost(cost, PaidSignsTranslatableMessage.SUCCESS_PAID_FOR_SIGN));
try { try {
TrackedSignManager.addTrackedSign(event.getBlock().getLocation(), player.getUniqueId(), cost); TrackedSignManager.addTrackedSign(event.getBlock().getLocation(), player.getUniqueId(), cost);
} catch (IOException ignored) { } catch (IOException ignored) {
@ -151,7 +150,7 @@ public class SignListener implements Listener {
*/ */
private String replaceCost(double cost, TranslatableMessage message) { private String replaceCost(double cost, TranslatableMessage message) {
String unit = EconomyManager.getCurrency(cost != 1); String unit = EconomyManager.getCurrency(cost != 1);
return String.format(StringFormatter.replacePlaceholders(PaidSigns.getTranslator(), message, return String.format(PaidSigns.getStringFormatter().replacePlaceholders(message,
new String[]{"{cost}", "{unit}"}, new String[]{"%.2f", "%s"}), cost, unit); new String[]{"{cost}", "{unit}"}, new String[]{"%.2f", "%s"}), cost, unit);
} }

View File

@ -1,6 +1,5 @@
package net.knarcraft.paidsigns.manager; package net.knarcraft.paidsigns.manager;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.paidsigns.PaidSigns; import net.knarcraft.paidsigns.PaidSigns;
import net.knarcraft.paidsigns.container.TrackedSign; import net.knarcraft.paidsigns.container.TrackedSign;
import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage; import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage;
@ -155,8 +154,8 @@ public final class TrackedSignManager {
double refundSum = trackedSign.cost() / 100 * PaidSigns.getInstance().getRefundPercentage(); double refundSum = trackedSign.cost() / 100 * PaidSigns.getInstance().getRefundPercentage();
EconomyManager.deposit(offlinePlayer, refundSum); EconomyManager.deposit(offlinePlayer, refundSum);
if (offlinePlayer instanceof Player player) { if (offlinePlayer instanceof Player player) {
StringFormatter.displaySuccessMessage(player, String.format(StringFormatter.replacePlaceholders( PaidSigns.getStringFormatter().displaySuccessMessage(player, String.format(
PaidSigns.getTranslator(), PaidSignsTranslatableMessage.SUCCESS_REFUNDED, PaidSigns.getStringFormatter().replacePlaceholders(PaidSignsTranslatableMessage.SUCCESS_REFUNDED,
new String[]{"{cost}", "{unit}"}, new String[]{"%.2f", "%s"}), refundSum, new String[]{"{cost}", "{unit}"}, new String[]{"%.2f", "%s"}), refundSum,
EconomyManager.getCurrency(refundSum != 1))); EconomyManager.getCurrency(refundSum != 1)));
} }