From 5c095e79f62c7f1372ac820b5eacaa8caa50b2ac Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Mon, 7 Nov 2022 22:26:22 +0100 Subject: [PATCH] Updates code to account for KnarLib changes --- .../net/knarcraft/paidsigns/PaidSigns.java | 19 +++++++++---- .../paidsigns/command/AddCommand.java | 15 ++++------ .../command/AddConditionCommand.java | 16 ++++------- .../paidsigns/command/EditCommand.java | 28 ++++++------------- .../paidsigns/command/ListCommand.java | 16 ++++++----- .../paidsigns/command/ReloadTabCommand.java | 4 +-- .../command/RemoveConditionCommand.java | 20 ++++++------- .../paidsigns/command/RemoveTabCommand.java | 7 ++--- .../paidsigns/command/TokenizedCommand.java | 3 +- .../paidsigns/listener/SignListener.java | 7 ++--- .../paidsigns/manager/TrackedSignManager.java | 5 ++-- 11 files changed, 60 insertions(+), 80 deletions(-) diff --git a/src/main/java/net/knarcraft/paidsigns/PaidSigns.java b/src/main/java/net/knarcraft/paidsigns/PaidSigns.java index e174617..514bca2 100644 --- a/src/main/java/net/knarcraft/paidsigns/PaidSigns.java +++ b/src/main/java/net/knarcraft/paidsigns/PaidSigns.java @@ -1,6 +1,6 @@ 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.util.UpdateChecker; import net.knarcraft.paidsigns.command.AddCommand; @@ -40,6 +40,7 @@ public final class PaidSigns extends JavaPlugin { private static PaidSigns paidSigns; private static Translator translator; + private static StringFormatter stringFormatter; private PaidSignManager signManager; private String language; private boolean ignoreCase; @@ -74,17 +75,25 @@ public final class PaidSigns extends JavaPlugin { return translator; } + /** + * Gets the string formatter to use for this plugin + * + * @return

The string formatter to use for this plugin

+ */ + public static StringFormatter getStringFormatter() { + return stringFormatter; + } + @Override public void onEnable() { - KnarLib.setPlugin(this); - setupVault(); loadConfig(); //Initialize translator translator = new Translator(); 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()); TrackedSignManager.loadTrackedSigns(); @@ -109,7 +118,7 @@ public final class PaidSigns extends JavaPlugin { public void reload() { this.reloadConfig(); loadConfig(); - translator.loadLanguages(language); + translator.loadLanguages(this.getDataFolder(), language); signManager = new PaidSignManager(PaidSignManager.loadSigns()); TrackedSignManager.loadTrackedSigns(); } diff --git a/src/main/java/net/knarcraft/paidsigns/command/AddCommand.java b/src/main/java/net/knarcraft/paidsigns/command/AddCommand.java index a38c4b2..10076b8 100644 --- a/src/main/java/net/knarcraft/paidsigns/command/AddCommand.java +++ b/src/main/java/net/knarcraft/paidsigns/command/AddCommand.java @@ -1,6 +1,5 @@ package net.knarcraft.paidsigns.command; -import net.knarcraft.knarlib.formatting.StringFormatter; import net.knarcraft.paidsigns.PaidSigns; import net.knarcraft.paidsigns.container.PaidSign; import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage; @@ -30,8 +29,7 @@ public class AddCommand extends TokenizedCommand { try { cost = Double.parseDouble(arguments.get(1)); } catch (NumberFormatException exception) { - StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), - PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER); + PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER); return false; } String permission = ""; @@ -72,20 +70,17 @@ public class AddCommand extends TokenizedCommand { try { PaidSign sign = new PaidSign(signName, cost, permission, ignoreCase, ignoreColor, matchAnyCondition); if (manager.getPaidSign(signName) != null) { - StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), - PaidSignsTranslatableMessage.ERROR_NAME_DUPLICATE); + PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_NAME_DUPLICATE); return false; } manager.addPaidSign(sign); - StringFormatter.displaySuccessMessage(sender, PaidSigns.getTranslator(), - PaidSignsTranslatableMessage.SUCCESS_ADDED_PAID_SIGN); + PaidSigns.getStringFormatter().displaySuccessMessage(sender, PaidSignsTranslatableMessage.SUCCESS_ADDED_PAID_SIGN); return true; } catch (IOException e) { - StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), - PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED); + PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED); return false; } catch (IllegalArgumentException e) { - StringFormatter.displayErrorMessage(sender, StringFormatter.replacePlaceholder(PaidSigns.getTranslator(), + PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSigns.getStringFormatter().replacePlaceholder( PaidSignsTranslatableMessage.ERROR_INVALID_INPUT, "{input}", e.getMessage())); } return false; diff --git a/src/main/java/net/knarcraft/paidsigns/command/AddConditionCommand.java b/src/main/java/net/knarcraft/paidsigns/command/AddConditionCommand.java index 59bd251..cef6ad1 100644 --- a/src/main/java/net/knarcraft/paidsigns/command/AddConditionCommand.java +++ b/src/main/java/net/knarcraft/paidsigns/command/AddConditionCommand.java @@ -1,6 +1,5 @@ package net.knarcraft.paidsigns.command; -import net.knarcraft.knarlib.formatting.StringFormatter; import net.knarcraft.paidsigns.PaidSigns; import net.knarcraft.paidsigns.container.PaidSign; import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage; @@ -30,13 +29,11 @@ public class AddConditionCommand extends TokenizedCommand { try { lineNumber = (short) (Short.parseShort(arguments.get(1)) - 1); if (lineNumber < 0 || lineNumber > 3) { - StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), - PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER); + PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER); return false; } } catch (NumberFormatException exception) { - StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), - PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER); + PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER); return false; } String stringToMatch = arguments.get(2); @@ -75,20 +72,17 @@ public class AddConditionCommand extends TokenizedCommand { PaidSignManager signManager = PaidSigns.getInstance().getSignManager(); PaidSign sign = signManager.getPaidSign(name); if (sign == null) { - StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), - PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND); + PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND); return false; } sign.addCondition(lineNumber, stringToMatch, executeRegEx, ignoreCase, ignoreColor); try { signManager.saveSigns(); } catch (IOException e) { - StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), - PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED); + PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED); return false; } - StringFormatter.displaySuccessMessage(sender, PaidSigns.getTranslator(), - PaidSignsTranslatableMessage.SUCCESS_ADDED_PAID_SIGN_CONDITION); + PaidSigns.getStringFormatter().displaySuccessMessage(sender, PaidSignsTranslatableMessage.SUCCESS_ADDED_PAID_SIGN_CONDITION); return true; } diff --git a/src/main/java/net/knarcraft/paidsigns/command/EditCommand.java b/src/main/java/net/knarcraft/paidsigns/command/EditCommand.java index 398440d..b08e01a 100644 --- a/src/main/java/net/knarcraft/paidsigns/command/EditCommand.java +++ b/src/main/java/net/knarcraft/paidsigns/command/EditCommand.java @@ -1,6 +1,5 @@ package net.knarcraft.paidsigns.command; -import net.knarcraft.knarlib.formatting.StringFormatter; import net.knarcraft.paidsigns.PaidSigns; import net.knarcraft.paidsigns.container.PaidSign; import net.knarcraft.paidsigns.container.PaidSignCondition; @@ -31,8 +30,7 @@ public class EditCommand extends TokenizedCommand { PaidSign sign = PaidSigns.getInstance().getSignManager().getPaidSign(arguments.get(0)); if (sign == null) { - StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), - PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND); + PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND); return false; } @@ -45,8 +43,7 @@ public class EditCommand extends TokenizedCommand { return parseGivenProperty(sign, sender); } } catch (IOException e) { - StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), - PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED); + PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED); return false; } } @@ -63,8 +60,7 @@ public class EditCommand extends TokenizedCommand { @NotNull CommandSender sender) throws NumberFormatException { short signLine = (short) (Short.parseShort(arguments.get(1)) - 1); if (signLine < 0 || signLine > 3 || sign.getConditions().get(signLine) == null) { - StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), - PaidSignsTranslatableMessage.ERROR_NO_SUCH_CONDITION); + PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_NO_SUCH_CONDITION); return false; } if (argumentSize < 4) { @@ -73,8 +69,7 @@ public class EditCommand extends TokenizedCommand { PaidSignConditionProperty conditionProperty = PaidSignConditionProperty.getFromString(arguments.get(2)); if (conditionProperty == null) { - StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), - PaidSignsTranslatableMessage.ERROR_PROPERTY_NOT_RECOGNIZED); + PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_PROPERTY_NOT_RECOGNIZED); return false; } String value = arguments.get(3); @@ -93,8 +88,7 @@ public class EditCommand extends TokenizedCommand { @NotNull CommandSender sender) throws IOException { PaidSignProperty property = PaidSignProperty.getFromString(arguments.get(1)); if (property == null) { - StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), - PaidSignsTranslatableMessage.ERROR_PROPERTY_NOT_RECOGNIZED); + PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_PROPERTY_NOT_RECOGNIZED); return false; } String value = arguments.get(2); @@ -102,8 +96,7 @@ public class EditCommand extends TokenizedCommand { updateProperty(sender, sign, property, value); return true; } catch (NumberFormatException exception) { - StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), - PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER); + PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER); return false; } } @@ -141,8 +134,7 @@ public class EditCommand extends TokenizedCommand { manager.removePaidSign(sign.getName()); manager.addPaidSign(updatedSign); - StringFormatter.displaySuccessMessage(sender, PaidSigns.getTranslator(), - PaidSignsTranslatableMessage.SUCCESS_UPDATED_PAID_SIGN); + PaidSigns.getStringFormatter().displaySuccessMessage(sender, PaidSignsTranslatableMessage.SUCCESS_UPDATED_PAID_SIGN); } /** @@ -178,13 +170,11 @@ public class EditCommand extends TokenizedCommand { try { PaidSigns.getInstance().getSignManager().saveSigns(); } catch (IOException e) { - StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), - PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED); + PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED); return false; } - StringFormatter.displaySuccessMessage(sender, PaidSigns.getTranslator(), - PaidSignsTranslatableMessage.SUCCESS_UPDATED_PAID_SIGN_CONDITION); + PaidSigns.getStringFormatter().displaySuccessMessage(sender, PaidSignsTranslatableMessage.SUCCESS_UPDATED_PAID_SIGN_CONDITION); return true; } diff --git a/src/main/java/net/knarcraft/paidsigns/command/ListCommand.java b/src/main/java/net/knarcraft/paidsigns/command/ListCommand.java index afe0e73..2071cef 100644 --- a/src/main/java/net/knarcraft/paidsigns/command/ListCommand.java +++ b/src/main/java/net/knarcraft/paidsigns/command/ListCommand.java @@ -15,7 +15,6 @@ import java.util.List; import java.util.Map; 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.replacePlaceholders; @@ -89,7 +88,8 @@ public class ListCommand extends TokenizedCommand { private boolean parsePaidSignSelection(CommandSender sender) { PaidSign paidSign = PaidSigns.getInstance().getSignManager().getPaidSign(arguments.get(0)); 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; } if (argumentSize < 2) { @@ -99,18 +99,20 @@ public class ListCommand extends TokenizedCommand { try { lineNumber = (short) (Short.parseShort(arguments.get(1)) - 1); if (lineNumber < 0 || lineNumber > 3) { - StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), + PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER); return false; } } catch (NumberFormatException exception) { - StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), + PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER); return false; } if (!paidSign.getConditions().containsKey(lineNumber)) { - StringFormatter.displayErrorMessage(sender, replacePlaceholder(PaidSigns.getTranslator(), - PaidSignsTranslatableMessage.ERROR_NO_SUCH_CONDITION, "{line}", String.valueOf(lineNumber))); + PaidSigns.getStringFormatter().displayErrorMessage(sender, + PaidSigns.getStringFormatter().replacePlaceholder( + PaidSignsTranslatableMessage.ERROR_NO_SUCH_CONDITION, "{line}", + String.valueOf(lineNumber))); return false; } PaidSignCondition condition = paidSign.getConditions().get(lineNumber); @@ -129,7 +131,7 @@ public class ListCommand extends TokenizedCommand { */ private void displayPaidSignCondition(CommandSender sender, String signName, short signLine, PaidSignCondition condition) { - sender.sendMessage(StringFormatter.replacePlaceholders(PaidSigns.getTranslator(), + sender.sendMessage(PaidSigns.getStringFormatter().replacePlaceholders( PaidSignsTranslatableMessage.PAID_SIGN_CONDITION_INFO, new String[]{"{name}", "{line}", "{match}", "{regex}", "{case}", "{color}"}, new String[]{signName, String.valueOf(signLine + 1), condition.stringToMatch(), translateBoolean(condition.executeRegex()), diff --git a/src/main/java/net/knarcraft/paidsigns/command/ReloadTabCommand.java b/src/main/java/net/knarcraft/paidsigns/command/ReloadTabCommand.java index 9bdf771..401f461 100644 --- a/src/main/java/net/knarcraft/paidsigns/command/ReloadTabCommand.java +++ b/src/main/java/net/knarcraft/paidsigns/command/ReloadTabCommand.java @@ -1,6 +1,5 @@ package net.knarcraft.paidsigns.command; -import net.knarcraft.knarlib.formatting.StringFormatter; import net.knarcraft.paidsigns.PaidSigns; import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage; 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, @NotNull String[] args) { PaidSigns.getInstance().reload(); - StringFormatter.displaySuccessMessage(sender, PaidSigns.getTranslator(), - PaidSignsTranslatableMessage.SUCCESS_RELOADED); + PaidSigns.getStringFormatter().displaySuccessMessage(sender, PaidSignsTranslatableMessage.SUCCESS_RELOADED); return true; } diff --git a/src/main/java/net/knarcraft/paidsigns/command/RemoveConditionCommand.java b/src/main/java/net/knarcraft/paidsigns/command/RemoveConditionCommand.java index 9d39bc5..b594f4b 100644 --- a/src/main/java/net/knarcraft/paidsigns/command/RemoveConditionCommand.java +++ b/src/main/java/net/knarcraft/paidsigns/command/RemoveConditionCommand.java @@ -1,6 +1,5 @@ package net.knarcraft.paidsigns.command; -import net.knarcraft.knarlib.formatting.StringFormatter; import net.knarcraft.paidsigns.PaidSigns; import net.knarcraft.paidsigns.container.PaidSign; import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage; @@ -17,7 +16,8 @@ import java.io.IOException; public class RemoveConditionCommand 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 < 2) { return false; @@ -28,25 +28,23 @@ public class RemoveConditionCommand extends TokenizedCommand { try { lineNumber = (short) (Short.parseShort(arguments.get(1)) - 1); if (lineNumber < 0 || lineNumber > 3) { - StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), - PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER); + PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER); return false; } } catch (NumberFormatException exception) { - StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), - PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER); + PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER); return false; } PaidSignManager signManager = PaidSigns.getInstance().getSignManager(); PaidSign sign = signManager.getPaidSign(name); if (sign == null) { - StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), + PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND); return false; } 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}", String.valueOf((lineNumber + 1)))); return false; @@ -56,12 +54,10 @@ public class RemoveConditionCommand extends TokenizedCommand { try { signManager.saveSigns(); } catch (IOException e) { - StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), - PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED); + PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED); return false; } - StringFormatter.displaySuccessMessage(sender, PaidSigns.getTranslator(), - PaidSignsTranslatableMessage.SUCCESS_REMOVED_CONDITION); + PaidSigns.getStringFormatter().displaySuccessMessage(sender, PaidSignsTranslatableMessage.SUCCESS_REMOVED_CONDITION); return true; } diff --git a/src/main/java/net/knarcraft/paidsigns/command/RemoveTabCommand.java b/src/main/java/net/knarcraft/paidsigns/command/RemoveTabCommand.java index 08ae9c4..b6fe30d 100644 --- a/src/main/java/net/knarcraft/paidsigns/command/RemoveTabCommand.java +++ b/src/main/java/net/knarcraft/paidsigns/command/RemoveTabCommand.java @@ -1,6 +1,5 @@ package net.knarcraft.paidsigns.command; -import net.knarcraft.knarlib.formatting.StringFormatter; import net.knarcraft.paidsigns.PaidSigns; import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage; import net.knarcraft.paidsigns.utility.PaidSignsTabCompleteHelper; @@ -31,15 +30,15 @@ public class RemoveTabCommand implements TabExecutor { try { if (PaidSigns.getInstance().getSignManager().removePaidSign(name)) { - StringFormatter.displaySuccessMessage(sender, PaidSigns.getTranslator(), + PaidSigns.getStringFormatter().displaySuccessMessage(sender, PaidSignsTranslatableMessage.SUCCESS_REMOVED_PAID_SIGN); } else { - StringFormatter.displaySuccessMessage(sender, PaidSigns.getTranslator(), + PaidSigns.getStringFormatter().displaySuccessMessage(sender, PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND); } return true; } catch (IOException e) { - StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), + PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED); } return false; diff --git a/src/main/java/net/knarcraft/paidsigns/command/TokenizedCommand.java b/src/main/java/net/knarcraft/paidsigns/command/TokenizedCommand.java index 8617534..4a59e85 100644 --- a/src/main/java/net/knarcraft/paidsigns/command/TokenizedCommand.java +++ b/src/main/java/net/knarcraft/paidsigns/command/TokenizedCommand.java @@ -1,6 +1,5 @@ package net.knarcraft.paidsigns.command; -import net.knarcraft.knarlib.formatting.StringFormatter; import net.knarcraft.paidsigns.PaidSigns; import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage; import net.knarcraft.paidsigns.utility.Tokenizer; @@ -40,7 +39,7 @@ public class TokenizedCommand implements CommandExecutor { Pattern.compile(regularExpression); return false; } catch (PatternSyntaxException exception) { - StringFormatter.displayErrorMessage(sender, PaidSigns.getTranslator(), + PaidSigns.getStringFormatter().displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_REGULAR_EXPRESSION); return true; } diff --git a/src/main/java/net/knarcraft/paidsigns/listener/SignListener.java b/src/main/java/net/knarcraft/paidsigns/listener/SignListener.java index 578ec1c..b7b179e 100644 --- a/src/main/java/net/knarcraft/paidsigns/listener/SignListener.java +++ b/src/main/java/net/knarcraft/paidsigns/listener/SignListener.java @@ -1,6 +1,5 @@ package net.knarcraft.paidsigns.listener; -import net.knarcraft.knarlib.formatting.StringFormatter; import net.knarcraft.knarlib.formatting.TranslatableMessage; import net.knarcraft.paidsigns.PaidSigns; import net.knarcraft.paidsigns.container.PaidSign; @@ -130,11 +129,11 @@ public class SignListener implements Listener { double cost = paidSign.getCost(); boolean canAfford = EconomyManager.canAfford(player, cost); if (!canAfford) { - StringFormatter.displayErrorMessage(player, replaceCost(cost, PaidSignsTranslatableMessage.ERROR_CANNOT_AFFORD)); + PaidSigns.getStringFormatter().displayErrorMessage(player, replaceCost(cost, PaidSignsTranslatableMessage.ERROR_CANNOT_AFFORD)); event.setCancelled(true); } else { 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 { TrackedSignManager.addTrackedSign(event.getBlock().getLocation(), player.getUniqueId(), cost); } catch (IOException ignored) { @@ -151,7 +150,7 @@ public class SignListener implements Listener { */ private String replaceCost(double cost, TranslatableMessage message) { 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); } diff --git a/src/main/java/net/knarcraft/paidsigns/manager/TrackedSignManager.java b/src/main/java/net/knarcraft/paidsigns/manager/TrackedSignManager.java index 586a13d..96da46d 100644 --- a/src/main/java/net/knarcraft/paidsigns/manager/TrackedSignManager.java +++ b/src/main/java/net/knarcraft/paidsigns/manager/TrackedSignManager.java @@ -1,6 +1,5 @@ package net.knarcraft.paidsigns.manager; -import net.knarcraft.knarlib.formatting.StringFormatter; import net.knarcraft.paidsigns.PaidSigns; import net.knarcraft.paidsigns.container.TrackedSign; import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage; @@ -155,8 +154,8 @@ public final class TrackedSignManager { double refundSum = trackedSign.cost() / 100 * PaidSigns.getInstance().getRefundPercentage(); EconomyManager.deposit(offlinePlayer, refundSum); if (offlinePlayer instanceof Player player) { - StringFormatter.displaySuccessMessage(player, String.format(StringFormatter.replacePlaceholders( - PaidSigns.getTranslator(), PaidSignsTranslatableMessage.SUCCESS_REFUNDED, + PaidSigns.getStringFormatter().displaySuccessMessage(player, String.format( + PaidSigns.getStringFormatter().replacePlaceholders(PaidSignsTranslatableMessage.SUCCESS_REFUNDED, new String[]{"{cost}", "{unit}"}, new String[]{"%.2f", "%s"}), refundSum, EconomyManager.getCurrency(refundSum != 1))); }