The boolean value to translate
+ * @returnThe translation of the boolean value
+ */ + public static String translateBoolean(boolean booleanValue) { + if (booleanValue) { + return Translator.getTranslatedMessage(PaidSignsTranslatableMessage.BOOLEAN_TRUE); + } else { + return Translator.getTranslatedMessage(PaidSignsTranslatableMessage.BOOLEAN_FALSE); + } + } + } diff --git a/src/main/java/net/knarcraft/paidsigns/command/ListTabCompleter.java b/src/main/java/net/knarcraft/paidsigns/command/ListTabCompleter.java index ddeeb3b..7ad6f34 100644 --- a/src/main/java/net/knarcraft/paidsigns/command/ListTabCompleter.java +++ b/src/main/java/net/knarcraft/paidsigns/command/ListTabCompleter.java @@ -1,8 +1,9 @@ package net.knarcraft.paidsigns.command; +import net.knarcraft.knarlib.util.TabCompletionHelper; import net.knarcraft.paidsigns.PaidSigns; import net.knarcraft.paidsigns.container.PaidSign; -import net.knarcraft.paidsigns.utility.TabCompleteHelper; +import net.knarcraft.paidsigns.utility.PaidSignsTabCompleteHelper; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; @@ -22,7 +23,7 @@ public class ListTabCompleter extends TokenizedTabCompleter { @NotNull String[] args) { super.onTabComplete(sender, command, alias, args); if (argumentSize == 1) { - return TabCompleteHelper.filterMatchingStartsWith(TabCompleteHelper.getPaidSignNames(), arguments.get(0)); + return TabCompletionHelper.filterMatchingStartsWith(PaidSignsTabCompleteHelper.getPaidSignNames(), arguments.get(0)); } else if (argumentSize == 2) { PaidSign sign = PaidSigns.getInstance().getSignManager().getPaidSign(arguments.get(0)); if (sign != null) { @@ -30,7 +31,7 @@ public class ListTabCompleter extends TokenizedTabCompleter { for (Short signLine : sign.getConditions().keySet()) { availableConditions.add(String.valueOf(signLine + 1)); } - return TabCompleteHelper.filterMatchingStartsWith(availableConditions, arguments.get(1)); + return TabCompletionHelper.filterMatchingStartsWith(availableConditions, arguments.get(1)); } } return new ArrayList<>(); diff --git a/src/main/java/net/knarcraft/paidsigns/command/ReloadTabCommand.java b/src/main/java/net/knarcraft/paidsigns/command/ReloadTabCommand.java index 9ed786a..ac630d0 100644 --- a/src/main/java/net/knarcraft/paidsigns/command/ReloadTabCommand.java +++ b/src/main/java/net/knarcraft/paidsigns/command/ReloadTabCommand.java @@ -1,8 +1,8 @@ package net.knarcraft.paidsigns.command; +import net.knarcraft.knarlib.formatting.StringFormatter; import net.knarcraft.paidsigns.PaidSigns; -import net.knarcraft.paidsigns.formatting.StringFormatter; -import net.knarcraft.paidsigns.formatting.TranslatableMessage; +import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; @@ -20,7 +20,7 @@ public class ReloadTabCommand implements TabExecutor { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { PaidSigns.getInstance().reload(); - sender.sendMessage(StringFormatter.getTranslatedInfoMessage(TranslatableMessage.SUCCESS_RELOADED)); + StringFormatter.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 133ebb5..3c21e7e 100644 --- a/src/main/java/net/knarcraft/paidsigns/command/RemoveConditionCommand.java +++ b/src/main/java/net/knarcraft/paidsigns/command/RemoveConditionCommand.java @@ -1,9 +1,9 @@ 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.StringFormatter; -import net.knarcraft.paidsigns.formatting.TranslatableMessage; +import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage; import net.knarcraft.paidsigns.manager.PaidSignManager; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -28,23 +28,24 @@ public class RemoveConditionCommand extends TokenizedCommand { try { lineNumber = (short) (Short.parseShort(arguments.get(1)) - 1); if (lineNumber < 0 || lineNumber > 3) { - sender.sendMessage(StringFormatter.getTranslatedErrorMessage(TranslatableMessage.ERROR_INVALID_NUMBER)); + StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER); return false; } } catch (NumberFormatException exception) { - sender.sendMessage(StringFormatter.getTranslatedErrorMessage(TranslatableMessage.ERROR_INVALID_NUMBER)); + StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_NUMBER); return false; } PaidSignManager signManager = PaidSigns.getInstance().getSignManager(); PaidSign sign = signManager.getPaidSign(name); if (sign == null) { - sender.sendMessage(StringFormatter.getTranslatedErrorMessage(TranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND)); + StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND); return false; } if (!sign.getConditions().containsKey(lineNumber)) { - sender.sendMessage(StringFormatter.replacePlaceholder(StringFormatter.getTranslatedErrorMessage( - TranslatableMessage.ERROR_NO_SUCH_CONDITION), "{line}", String.valueOf((lineNumber + 1)))); + StringFormatter.displayErrorMessage(sender, StringFormatter.replacePlaceholder( + PaidSignsTranslatableMessage.ERROR_NO_SUCH_CONDITION, "{line}", + String.valueOf((lineNumber + 1)))); return false; } @@ -52,10 +53,10 @@ public class RemoveConditionCommand extends TokenizedCommand { try { signManager.saveSigns(); } catch (IOException e) { - sender.sendMessage(StringFormatter.getTranslatedErrorMessage(TranslatableMessage.ERROR_EXCEPTION_OCCURRED)); + StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED); return false; } - sender.sendMessage(StringFormatter.getTranslatedInfoMessage(TranslatableMessage.SUCCESS_REMOVED_CONDITION)); + StringFormatter.displaySuccessMessage(sender, PaidSignsTranslatableMessage.SUCCESS_REMOVED_CONDITION); return true; } diff --git a/src/main/java/net/knarcraft/paidsigns/command/RemoveConditionTabCompleter.java b/src/main/java/net/knarcraft/paidsigns/command/RemoveConditionTabCompleter.java index 55161cf..5f2c4fe 100644 --- a/src/main/java/net/knarcraft/paidsigns/command/RemoveConditionTabCompleter.java +++ b/src/main/java/net/knarcraft/paidsigns/command/RemoveConditionTabCompleter.java @@ -1,8 +1,9 @@ package net.knarcraft.paidsigns.command; +import net.knarcraft.knarlib.util.TabCompletionHelper; import net.knarcraft.paidsigns.PaidSigns; import net.knarcraft.paidsigns.container.PaidSign; -import net.knarcraft.paidsigns.utility.TabCompleteHelper; +import net.knarcraft.paidsigns.utility.PaidSignsTabCompleteHelper; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; @@ -28,7 +29,7 @@ public class RemoveConditionTabCompleter extends TokenizedTabCompleter { } if (argumentSize == 1) { - return TabCompleteHelper.filterMatchingStartsWith(TabCompleteHelper.getPaidSignNames(), arguments.get(0)); + return TabCompletionHelper.filterMatchingStartsWith(PaidSignsTabCompleteHelper.getPaidSignNames(), arguments.get(0)); } else if (argumentSize == 2) { PaidSign sign = PaidSigns.getInstance().getSignManager().getPaidSign(arguments.get(0)); if (sign != null) { @@ -36,7 +37,7 @@ public class RemoveConditionTabCompleter extends TokenizedTabCompleter { for (Short signLine : sign.getConditions().keySet()) { availableConditions.add(String.valueOf(signLine + 1)); } - return TabCompleteHelper.filterMatchingStartsWith(availableConditions, arguments.get(1)); + return TabCompletionHelper.filterMatchingStartsWith(availableConditions, arguments.get(1)); } } return new ArrayList<>(); @@ -46,7 +47,7 @@ public class RemoveConditionTabCompleter extends TokenizedTabCompleter { * Initializes the values available for tab completion */ private void initializeValues() { - lineIndices = TabCompleteHelper.getSignLines(); + lineIndices = PaidSignsTabCompleteHelper.getSignLines(); } } diff --git a/src/main/java/net/knarcraft/paidsigns/command/RemoveTabCommand.java b/src/main/java/net/knarcraft/paidsigns/command/RemoveTabCommand.java index 0d08fe4..22801e6 100644 --- a/src/main/java/net/knarcraft/paidsigns/command/RemoveTabCommand.java +++ b/src/main/java/net/knarcraft/paidsigns/command/RemoveTabCommand.java @@ -1,9 +1,9 @@ package net.knarcraft.paidsigns.command; +import net.knarcraft.knarlib.formatting.StringFormatter; import net.knarcraft.paidsigns.PaidSigns; -import net.knarcraft.paidsigns.formatting.StringFormatter; -import net.knarcraft.paidsigns.formatting.TranslatableMessage; -import net.knarcraft.paidsigns.utility.TabCompleteHelper; +import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage; +import net.knarcraft.paidsigns.utility.PaidSignsTabCompleteHelper; import net.knarcraft.paidsigns.utility.Tokenizer; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -31,15 +31,13 @@ public class RemoveTabCommand implements TabExecutor { try { if (PaidSigns.getInstance().getSignManager().removePaidSign(name)) { - sender.sendMessage(StringFormatter.getTranslatedInfoMessage( - TranslatableMessage.SUCCESS_REMOVED_PAID_SIGN)); + StringFormatter.displaySuccessMessage(sender, PaidSignsTranslatableMessage.SUCCESS_REMOVED_PAID_SIGN); } else { - sender.sendMessage(StringFormatter.getTranslatedErrorMessage( - TranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND)); + StringFormatter.displaySuccessMessage(sender, PaidSignsTranslatableMessage.ERROR_PAID_SIGN_NOT_FOUND); } return true; } catch (IOException e) { - sender.sendMessage(StringFormatter.getTranslatedErrorMessage(TranslatableMessage.ERROR_EXCEPTION_OCCURRED)); + StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_EXCEPTION_OCCURRED); } return false; } @@ -52,7 +50,7 @@ public class RemoveTabCommand implements TabExecutor { int argumentSize = args[args.length - 1].isEmpty() ? arguments.size() : arguments.size() - 1; if (argumentSize < 1) { - return TabCompleteHelper.getPaidSignNames(); + return PaidSignsTabCompleteHelper.getPaidSignNames(); } else { return new ArrayList<>(); } diff --git a/src/main/java/net/knarcraft/paidsigns/command/TokenizedCommand.java b/src/main/java/net/knarcraft/paidsigns/command/TokenizedCommand.java index a76ac78..dfb440d 100644 --- a/src/main/java/net/knarcraft/paidsigns/command/TokenizedCommand.java +++ b/src/main/java/net/knarcraft/paidsigns/command/TokenizedCommand.java @@ -1,7 +1,7 @@ package net.knarcraft.paidsigns.command; -import net.knarcraft.paidsigns.formatting.StringFormatter; -import net.knarcraft.paidsigns.formatting.TranslatableMessage; +import net.knarcraft.knarlib.formatting.StringFormatter; +import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage; import net.knarcraft.paidsigns.utility.Tokenizer; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -39,8 +39,7 @@ public class TokenizedCommand implements CommandExecutor { Pattern.compile(regularExpression); return false; } catch (PatternSyntaxException exception) { - sender.sendMessage(StringFormatter.getTranslatedErrorMessage( - TranslatableMessage.ERROR_INVALID_REGULAR_EXPRESSION)); + StringFormatter.displayErrorMessage(sender, PaidSignsTranslatableMessage.ERROR_INVALID_REGULAR_EXPRESSION); return true; } } diff --git a/src/main/java/net/knarcraft/paidsigns/container/PaidSignCondition.java b/src/main/java/net/knarcraft/paidsigns/container/PaidSignCondition.java index 9ac4b7b..65cc78a 100644 --- a/src/main/java/net/knarcraft/paidsigns/container/PaidSignCondition.java +++ b/src/main/java/net/knarcraft/paidsigns/container/PaidSignCondition.java @@ -1,6 +1,7 @@ package net.knarcraft.paidsigns.container; -import net.knarcraft.paidsigns.utility.ColorHelper; +import net.knarcraft.knarlib.property.ColorConversion; +import net.knarcraft.knarlib.util.ColorHelper; /** * A condition for deciding if a paid sign matches a sign line @@ -23,8 +24,8 @@ public record PaidSignCondition(String stringToMatch, boolean executeRegex, bool String stringToMatch = this.stringToMatch; //Strip color codes if they shouldn't matter if (this.ignoreColor) { - stringToMatch = ColorHelper.stripColorCodes(stringToMatch); - line = ColorHelper.stripColorCodes(line); + stringToMatch = ColorHelper.stripColorCodes(stringToMatch, ColorConversion.NORMAL); + line = ColorHelper.stripColorCodes(line, ColorConversion.NORMAL); } if (this.executeRegex) { //Match using RegEx diff --git a/src/main/java/net/knarcraft/paidsigns/formatting/TranslatableMessage.java b/src/main/java/net/knarcraft/paidsigns/formatting/PaidSignsTranslatableMessage.java similarity index 92% rename from src/main/java/net/knarcraft/paidsigns/formatting/TranslatableMessage.java rename to src/main/java/net/knarcraft/paidsigns/formatting/PaidSignsTranslatableMessage.java index 21224ad..3ccae16 100644 --- a/src/main/java/net/knarcraft/paidsigns/formatting/TranslatableMessage.java +++ b/src/main/java/net/knarcraft/paidsigns/formatting/PaidSignsTranslatableMessage.java @@ -1,14 +1,11 @@ package net.knarcraft.paidsigns.formatting; +import net.knarcraft.knarlib.formatting.TranslatableMessage; + /** * An enum representing all translatable messages */ -public enum TranslatableMessage { - - /** - * The prefix to display in messages - */ - PREFIX, +public enum PaidSignsTranslatableMessage implements TranslatableMessage { /** * The message to display when a paid sign is successfully added @@ -139,5 +136,10 @@ public enum TranslatableMessage { * The error to display if an invalid property is given to the edit command */ ERROR_PROPERTY_NOT_RECOGNIZED, + ; + @Override + public TranslatableMessage[] getAllMessages() { + return PaidSignsTranslatableMessage.values(); + } } diff --git a/src/main/java/net/knarcraft/paidsigns/formatting/StringFormatter.java b/src/main/java/net/knarcraft/paidsigns/formatting/StringFormatter.java deleted file mode 100644 index 89bcecc..0000000 --- a/src/main/java/net/knarcraft/paidsigns/formatting/StringFormatter.java +++ /dev/null @@ -1,125 +0,0 @@ -package net.knarcraft.paidsigns.formatting; - -import net.md_5.bungee.api.ChatColor; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * A formatter for formatting displayed messages - */ -public final class StringFormatter { - - private StringFormatter() { - - } - - /** - * Translates the given boolean value - * - * @param booleanValueThe boolean value to translate
- * @returnThe translation of the boolean value
- */ - public static String translateBoolean(boolean booleanValue) { - if (booleanValue) { - return Translator.getTranslatedMessage(TranslatableMessage.BOOLEAN_TRUE); - } else { - return Translator.getTranslatedMessage(TranslatableMessage.BOOLEAN_FALSE); - } - } - - /** - * Replaces a placeholder in a string - * - * @param inputThe input string to replace in
- * @param placeholderThe placeholder to replace
- * @param replacementThe replacement value
- * @returnThe input string with the placeholder replaced
- */ - public static String replacePlaceholder(String input, String placeholder, String replacement) { - return input.replace(placeholder, replacement); - } - - /** - * Replaces placeholders in a string - * - * @param inputThe input string to replace in
- * @param placeholdersThe placeholders to replace
- * @param replacementsThe replacement values
- * @returnThe input string with placeholders replaced
- */ - public static String replacePlaceholders(String input, String[] placeholders, String[] replacements) { - for (int i = 0; i < Math.min(placeholders.length, replacements.length); i++) { - input = replacePlaceholder(input, placeholders[i], replacements[i]); - } - return input; - } - - /** - * Gets a translated and formatted info message - * - * @param translatableMessageThe translatable message to translate and format
- * @returnThe translated and formatted message
- */ - public static String getTranslatedInfoMessage(TranslatableMessage translatableMessage) { - return formatInfoMessage(Translator.getTranslatedMessage(translatableMessage)); - } - - /** - * Gets a translated and formatted error message - * - * @param translatableMessageThe translatable message to translate and format
- * @returnThe translated and formatted message
- */ - public static String getTranslatedErrorMessage(TranslatableMessage translatableMessage) { - return formatErrorMessage(Translator.getTranslatedMessage(translatableMessage)); - } - - /** - * Formats an information message by adding the prefix and text color - * - * @param messageThe message to format
- * @returnThe formatted message
- */ - public static String formatInfoMessage(String message) { - return ChatColor.DARK_GREEN + formatMessage(message); - } - - /** - * Formats an error message by adding the prefix and text color - * - * @param messageThe message to format
- * @returnThe formatted message
- */ - public static String formatErrorMessage(String message) { - return ChatColor.DARK_RED + formatMessage(message); - } - - /** - * Translates all found color codes to formatting in a string - * - * @param messageThe string to search for color codes
- * @returnThe message with color codes translated
- */ - public static String translateAllColorCodes(String message) { - message = ChatColor.translateAlternateColorCodes('&', message); - Pattern pattern = Pattern.compile("(#[a-fA-F0-9]{6})"); - Matcher matcher = pattern.matcher(message); - while (matcher.find()) { - message = message.replace(matcher.group(), "" + ChatColor.of(matcher.group())); - } - return message; - } - - /** - * Formats a message by adding the prefix and text color - * - * @param messageThe message to format
- * @returnThe formatted message
- */ - private static String formatMessage(String message) { - return Translator.getTranslatedMessage(TranslatableMessage.PREFIX) + " " + - ChatColor.RESET + message; - } - -} diff --git a/src/main/java/net/knarcraft/paidsigns/formatting/Translator.java b/src/main/java/net/knarcraft/paidsigns/formatting/Translator.java deleted file mode 100644 index 5070282..0000000 --- a/src/main/java/net/knarcraft/paidsigns/formatting/Translator.java +++ /dev/null @@ -1,118 +0,0 @@ -package net.knarcraft.paidsigns.formatting; - -import net.knarcraft.paidsigns.PaidSigns; -import net.knarcraft.paidsigns.utility.FileHelper; -import org.bukkit.configuration.file.YamlConfiguration; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.InputStreamReader; -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Level; - -/** - * A tool to get strings translated to the correct language - */ -public final class Translator { - - private static MapThe message to translate
- * @returnThe translated message
- */ - public static String getTranslatedMessage(TranslatableMessage translatableMessage) { - if (translatedMessages == null) { - return "Translated strings not loaded"; - } - String translatedMessage; - if (translatedMessages.containsKey(translatableMessage)) { - translatedMessage = translatedMessages.get(translatableMessage); - } else if (backupTranslatedMessages.containsKey(translatableMessage)) { - translatedMessage = backupTranslatedMessages.get(translatableMessage); - } else { - translatedMessage = translatableMessage.toString(); - } - return StringFormatter.translateAllColorCodes(translatedMessage); - } - - /** - * Loads all translated messages for the given language - * - * @param languageThe language chosen by the user
- * @returnA mapping of all strings for the given language
- */ - public static MapThe selected language
- * @returnThe loaded translated strings, or null if no custom language file exists
- */ - public static MapThe selected language
- * @param readerThe buffered reader to read from
- * @returnThe loaded translated strings
- */ - private static MapThe original message to replace the cost placeholder for
* @returnThe message with the cost instead of the cost placeholder
*/ - private String replaceCost(double cost, String message) { + private String replaceCost(double cost, TranslatableMessage message) { String unit = EconomyManager.getCurrency(cost != 1); return String.format(StringFormatter.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 da97300..ffea755 100644 --- a/src/main/java/net/knarcraft/paidsigns/manager/TrackedSignManager.java +++ b/src/main/java/net/knarcraft/paidsigns/manager/TrackedSignManager.java @@ -1,9 +1,9 @@ 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.StringFormatter; -import net.knarcraft.paidsigns.formatting.TranslatableMessage; +import net.knarcraft.paidsigns.formatting.PaidSignsTranslatableMessage; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.OfflinePlayer; @@ -155,10 +155,9 @@ public final class TrackedSignManager { double refundSum = trackedSign.cost() / 100 * PaidSigns.getInstance().getRefundPercentage(); EconomyManager.deposit(offlinePlayer, refundSum); if (offlinePlayer instanceof Player player) { - player.sendMessage(String.format(StringFormatter.replacePlaceholders( - StringFormatter.getTranslatedInfoMessage(TranslatableMessage.SUCCESS_REFUNDED), - new String[]{"{cost}", "{unit}"}, new String[]{"%.2f", "%s"}), refundSum, - EconomyManager.getCurrency(refundSum != 1))); + StringFormatter.displaySuccessMessage(player, String.format(StringFormatter.replacePlaceholders( + PaidSignsTranslatableMessage.SUCCESS_REFUNDED, new String[]{"{cost}", "{unit}"}, + new String[]{"%.2f", "%s"}), refundSum, EconomyManager.getCurrency(refundSum != 1))); } } diff --git a/src/main/java/net/knarcraft/paidsigns/utility/ColorHelper.java b/src/main/java/net/knarcraft/paidsigns/utility/ColorHelper.java deleted file mode 100644 index 24b2c76..0000000 --- a/src/main/java/net/knarcraft/paidsigns/utility/ColorHelper.java +++ /dev/null @@ -1,43 +0,0 @@ -package net.knarcraft.paidsigns.utility; - -import net.md_5.bungee.api.ChatColor; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * A helper class for dealing with colors - */ -public final class ColorHelper { - - private ColorHelper() { - - } - - /** - * Strips all color codes from the given message - * - * @param messageThe message to strip color codes from
- * @returnThe message without color codes
- */ - public static String stripColorCodes(String message) { - return ChatColor.stripColor(translateAllColorCodes(message)); - } - - /** - * Translates all found color codes to formatting in a string - * - * @param messageThe string to search for color codes
- * @returnThe message with color codes translated
- */ - public static String translateAllColorCodes(String message) { - message = ChatColor.translateAlternateColorCodes('&', message); - Pattern pattern = Pattern.compile("(#[a-fA-F0-9]{6})"); - Matcher matcher = pattern.matcher(message); - while (matcher.find()) { - message = message.replace(matcher.group(), "" + ChatColor.of(matcher.group())); - } - return message; - } - -} diff --git a/src/main/java/net/knarcraft/paidsigns/utility/FileHelper.java b/src/main/java/net/knarcraft/paidsigns/utility/FileHelper.java deleted file mode 100644 index ece2d2c..0000000 --- a/src/main/java/net/knarcraft/paidsigns/utility/FileHelper.java +++ /dev/null @@ -1,32 +0,0 @@ -package net.knarcraft.paidsigns.utility; - -import java.io.BufferedReader; -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; - -/** - * A helper class for dealing with files - */ -public final class FileHelper { - - private FileHelper() { - - } - - /** - * Gets a buffered reader for - * - * @returnA buffered read for reading the file
- * @throws FileNotFoundExceptionIf unable to get an input stream for the given file
- */ - public static BufferedReader getBufferedReaderForInternalFile(String file) throws FileNotFoundException { - InputStream inputStream = FileHelper.class.getResourceAsStream(file); - if (inputStream == null) { - throw new FileNotFoundException("Unable to read the given file"); - } - return new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); - } - -} diff --git a/src/main/java/net/knarcraft/paidsigns/utility/TabCompleteHelper.java b/src/main/java/net/knarcraft/paidsigns/utility/PaidSignsTabCompleteHelper.java similarity index 82% rename from src/main/java/net/knarcraft/paidsigns/utility/TabCompleteHelper.java rename to src/main/java/net/knarcraft/paidsigns/utility/PaidSignsTabCompleteHelper.java index a294d80..d9cbb95 100644 --- a/src/main/java/net/knarcraft/paidsigns/utility/TabCompleteHelper.java +++ b/src/main/java/net/knarcraft/paidsigns/utility/PaidSignsTabCompleteHelper.java @@ -1,9 +1,9 @@ package net.knarcraft.paidsigns.utility; +import net.knarcraft.knarlib.util.TabCompletionHelper; import net.knarcraft.paidsigns.PaidSigns; import org.bukkit.Bukkit; import org.bukkit.permissions.Permission; -import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.HashMap; @@ -15,36 +15,15 @@ import java.util.StringJoiner; /** * A helper class for providing common tab complete options */ -public final class TabCompleteHelper { +public final class PaidSignsTabCompleteHelper { private static ListThe values to filter
- * @param typedTextThe text the player has started typing
- * @returnThe given string values that start with the player's typed text
- */ - public static List