Class MessageHandler

java.lang.Object
org.kingdoms.locale.MessageHandler

public final class MessageHandler extends Object
Simplified yet heavily optimized message supplier services for colored messages for players and console. And the ability to break lines simply by using \n
All the parameters should be non-null.

Normal color format: &X where X can be [0-9] & [abcdefg] & [klmnor] -> §X Hex color format: &#000000 which accepts a hexadecimal with the 0x prefix replaced with &x -> §x§0§0§0§0§0§0

  • Field Details

    • SIXTEEN

      protected static final boolean SIXTEEN
      Support for hex colors.
    • HEX_CHAR

      protected static final char HEX_CHAR
      See Also:
    • HEX_CODE

      protected static final char HEX_CODE
      See Also:
    • COLOR_CHAR

      protected static final char COLOR_CHAR
      See Also:
    • COLOR_CODE

      protected static final char COLOR_CODE
      See Also:
    • HEXADECIMAL

      protected static final char[] HEXADECIMAL
  • Constructor Details

    • MessageHandler

      public MessageHandler()
  • Method Details

    • translateComplexColor

      public static String translateComplexColor(String str)
    • hex

      public static String hex(String str)
    • replaceVariables

      public static String replaceVariables(String str, Object... edits)
      A simple method to simplify the process of replacing multiple strings for a single string.
      Should be used in your locale manager, not here.

      Example

      String test = ...;
      test = replaceAllLocalHolders(test, "%toaster%", ToasterUtils.getName(), "%capacity%", ToasterUtils.getCapacity());
      Parameters:
      str - the original string that is going to be checked.
      edits - the objects with their variables that are going to be replaced.
      Returns:
      a translated string with all the variables replaced.
      Since:
      1.0.0
    • replaceVariables

      public static String replaceVariables(String str, List<Object> edits)
      A version of replaceVariables(String, Object...) without needing to convert the list to an array.
      Parameters:
      str - the string to replace.
      edits - the edits to apply to the string.
      Returns:
      a replaced string.
      Since:
      3.0.0
    • replace

      public static String replace(String text, String variable, Object replace)
      Replaces a variable in a string in the most efficient way possible that is the most compatible with replaceVariables(String, Object...) and replaceVariables(String, List)

      Also supports Supplier as its replacement. Supllied replacements have the ability to not be evaluated if the specified string doesn't contain the variable.

      Parameters:
      text - the string to replace the variable in.
      variable - the variable to replace.
      replace - the replacement object. A supplier in special cases.
      Returns:
      the string with the variable replaced.
      Since:
      2.0.0
    • sendMessage

      public static void sendMessage(org.bukkit.command.CommandSender receiver, String message, boolean prefix)
    • colorize

      public static String colorize(String str)
      Translates color codes for the given string using & character.
      Parameters:
      str - the string to translate.
      Returns:
      Translated Alternate Color Codes of the string.
      Since:
      1.0.0
    • isColorCode

      public static boolean isColorCode(char ch)
      Checks if this character can be a color code. A part of color codes can be isHexOrDigit(char) hex or isFormattingCode(char) color code.
      Parameters:
      ch - the character.
      Returns:
      true if this character can color code, otherwise false.
      Since:
      3.0.0
    • isFormattingCode

      protected static boolean isFormattingCode(char ch)
      Checks if this character can be a special color code. Special color codes are bolds, italics, resets, underlines, strikethrough and obfuscated.
      Parameters:
      ch - the character.
      Returns:
      true if this character can color code, otherwise false.
      Since:
      3.0.0
    • isHexOrDigit

      protected static boolean isHexOrDigit(char ch)
      Checks if this character can be a part of hex color. https://simple.wikipedia.org/wiki/Hexadecimal
      Parameters:
      ch - the character.
      Returns:
      true if this character can be a hex color code, otherwise false.
      Since:
      3.0.0
    • stripColors

      public static String stripColors(String str, boolean strip)
      Strips all the color codes from the string and replacing the section character with COLOR_CODE for both hex colors and normal color codes.
      Parameters:
      str - the string to strip colors from.
      strip - whether the colors should be stripped only or removed completely.
      Returns:
      a string with visible colors.
      Since:
      3.0.0
    • removePattern

      public static String removePattern(String str, Pattern pattern)
    • parseRGB

      public static String parseRGB(String rgb)
    • rgbToHexString

      public static String rgbToHexString(int r, int g, int b)
    • sendMessage

      public static void sendMessage(org.bukkit.command.CommandSender receiver, String message)
      Sends a colored message to either console or the player depending on if the receiver is a player or console. Mostly useful for commnad handlers.
      Parameters:
      receiver - the sender who's going to receive the message.
      message - the message to send to the receiver.
      Since:
      1.0.0
      See Also:
    • sendPluginMessage

      public static void sendPluginMessage(org.bukkit.command.CommandSender receiver, String message)
      Sends a colored message with the plugin's prefix to either console or the player depending on if the receiver is a player or console.
      Parameters:
      receiver - the sender who's going to receive the message.
      message - the message to send to the receiver.
      Since:
      1.0.0
      See Also:
    • sendPlayerMessage

      public static void sendPlayerMessage(org.bukkit.entity.Player player, String message)
      Sends a colored message to a player.
      Parameters:
      player - the player who's going to receive the message.
      message - the message that is going to be sent to the player.
      Since:
      1.0.0
    • sendPlayerPluginMessage

      public static void sendPlayerPluginMessage(org.bukkit.entity.Player player, String message)
      Sends a colored message with the plugin's prefix to a player.
      Parameters:
      player - the player who's going to receive the message.
      message - the message that is going to be sent to the player.
      Since:
      1.0.0
    • sendConsoleMessage

      public static void sendConsoleMessage(String message)
      Sends a colored message to console.
      Parameters:
      message - the message that is going to be sent to console.
      Since:
      1.0.0
    • sendConsolePluginMessage

      public static void sendConsolePluginMessage(String message)
      Sends a colored message using the plugin's prefix to console.
      Parameters:
      message - the message that is going to be sent to console.
      Since:
      1.0.0
    • sendPlayersMessage

      public static void sendPlayersMessage(String message)
      Sends a colored message to all the online players on the server.
      Parameters:
      message - the message that is going to be sent to the players.
      Since:
      1.0.0
    • sendPlayersPluginMessage

      public static void sendPlayersPluginMessage(String message)
      Sends a colored message with the plugin's prefix to all the online players on the server.
      Parameters:
      message - the message that is going to be sent to the players.
      Since:
      1.0.0
    • debug

      public static void debug(String message)
      Sends a debug message to console and all the online players with the "pluginName.debug" permission. You need to replace the permission name inside the method yourself. You can also change the debug prefix yourself inside the method.
      Parameters:
      message - the message to send to console and the players.
      Since:
      1.0.0
    • supply

      public static Supplier<?> supply(Supplier<?> replacer)
      A version of Supplier that's more convenient to use.
      Since:
      3.0.0