Package org.kingdoms.locale
Class MessageHandler
java.lang.Object
org.kingdoms.locale.MessageHandler
Simplified yet heavily optimized message supplier services for colored messages
for players and console. And the ability to break lines simply by using
All the parameters should be non-null.
\nAll the parameters should be non-null.
Normal color format: &X where X can be [0-9] & [abcdefg] & [klmnor] -> §X
Hex color format: � which accepts a hexadecimal with the 0x prefix replaced with &x -> §x§0§0§0§0§0§0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final charprotected static final charprotected static final charprotected static final charprotected static final char[]protected static final booleanSupport for hex colors. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringTranslates color codes for the given string using & character.static voidSends a debug message to console and all the online players with the "pluginName.debug" permission.static Stringstatic booleanisColorCode(char ch) Checks if this character can be a color code.protected static booleanisFormattingCode(char ch) Checks if this character can be a special color code.protected static booleanisHexOrDigit(char ch) Checks if this character can be a part of hex color.static Stringstatic StringremovePattern(String str, Pattern pattern) static StringReplaces a variable in a string in the most efficient way possible that is the most compatible withreplaceVariables(String, Object...)andreplaceVariables(String, List)static StringreplaceVariables(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.static StringreplaceVariables(String str, List<Object> edits) A version ofreplaceVariables(String, Object...)without needing to convert the list to an array.static StringrgbToHexString(int r, int g, int b) static voidsendConsoleMessage(String message) Sends a colored message to console.static voidsendConsolePluginMessage(String message) Sends a colored message using the plugin's prefix to console.static voidsendMessage(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.static voidsendMessage(org.bukkit.command.CommandSender receiver, String message, boolean prefix) static voidsendPlayerMessage(org.bukkit.entity.Player player, String message) Sends a colored message to a player.static voidsendPlayerPluginMessage(org.bukkit.entity.Player player, String message) Sends a colored message with the plugin's prefix to a player.static voidsendPlayersMessage(String message) Sends a colored message to all the online players on the server.static voidsendPlayersPluginMessage(String message) Sends a colored message with the plugin's prefix to all the online players on the server.static voidsendPluginMessage(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.static StringstripColors(String str, boolean strip) Strips all the color codes from the string and replacing the section character withCOLOR_CODEfor both hex colors and normal color codes.static Supplier<?>A version ofSupplierthat's more convenient to use.static String
-
Field Details
-
SIXTEEN
protected static final boolean SIXTEENSupport 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
-
hex
-
replaceVariables
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
A version ofreplaceVariables(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
Replaces a variable in a string in the most efficient way possible that is the most compatible withreplaceVariables(String, Object...)andreplaceVariables(String, List)Also supports
Supplieras 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
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 beisHexOrDigit(char)hex orisFormattingCode(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
Strips all the color codes from the string and replacing the section character withCOLOR_CODEfor 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
-
parseRGB
-
rgbToHexString
-
sendMessage
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
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
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
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
Sends a colored message to console.- Parameters:
message- the message that is going to be sent to console.- Since:
- 1.0.0
-
sendConsolePluginMessage
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
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
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
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
A version ofSupplierthat's more convenient to use.- Since:
- 3.0.0
-