Package net.gcnt.additionsplus.api.utils
Interface AdditionsUtils
public interface AdditionsUtils
General Utils class that holds general utility methods.
-
Method Summary
Modifier and TypeMethodDescriptionColor a string.Color a list of strings.boolean
calculateChance
(double chance) Calculate if a random number between 0-100 is lower than the given chance.boolean
calculateIfChances
(String value) Execute the [IF] action parameters and check if they are true.determinePlayerTablist
(org.bukkit.entity.Player player) Get the header and footer of the tablist group of the player.double
Resolve a mathematical expression with JavaScript.executeScript
(String script) Execute a JavaScript script.getArrayFrom
(String[] array, int start) Get a sublist of an array as a string, joined by a space.getArrayFrom
(String[] array, int start, int end) Get a sublist of an array as a string, joined by a space.org.bukkit.command.CommandMap
Get the Bukkit command map used for registering commands.int
getExpAtLevel
(int level) Get the Bukkit experience required for one level.org.bukkit.GameMode
getGameMode
(String input) Get theGameMode
from a string.org.bukkit.Color
getHEXColor
(String message) Get the HEX color from a string.getLanguage
(ActionSender sender) Get the Vault language of a sender.getLanguage
(org.bukkit.entity.Player player) Get the Vault language of a player.boolean
Check if a string is a boolean.boolean
Check if a string is a double.boolean
Check if a string is a float.boolean
Check if a string is an integer.boolean
Check if a string is a long.void
logToConsole
(String message, boolean severe) Log a message to the console.parseStatics
(String message, ActionSender sender) Parse all placeholders of a player to the message.parseStatics
(String message, org.bukkit.entity.Player player) Parse all placeholders of a player to the message.parseStatics
(List<String> messages, ActionSender sender) Parse all placeholders of a player to the messages.void
registerCommand
(String plugin, org.bukkit.command.Command command) Register a command to Bukkit.replaceHEXColors
(String message) Replace all HEX colors with bukkit encoding in a string.void
sendCenteredMessage
(ActionSender player, String message) Send a horizontally centered message to the player.void
sendCooldownMessage
(org.bukkit.entity.Player player, String message, long cooldown) Send the cooldown message to a player.void
setTotalExperience
(org.bukkit.entity.Player player, int experience) Set the total experience of a player.
-
Method Details
-
getLanguage
Get the Vault language of a sender.- Parameters:
sender
- Sender to check.- Returns:
- Vault language when found, null otherwise.
-
getLanguage
Get the Vault language of a player.- Parameters:
player
- Player to check.- Returns:
- Vault language when found, null otherwise.
-
sendCenteredMessage
Send a horizontally centered message to the player.- Parameters:
player
- Player to send the message to.message
- Message to send.
-
getGameMode
Get theGameMode
from a string.- Parameters:
input
- String to check.- Returns:
GameMode
when found, null otherwise.
-
evaluate
Resolve a mathematical expression with JavaScript.- Parameters:
input
- Expression to resolve.- Returns:
- Result of the expression.
-
c
Color a string. -
logToConsole
Log a message to the console.- Parameters:
message
- Message to log.severe
- Whether it should be sent as an error.
-
calculateChance
boolean calculateChance(double chance) Calculate if a random number between 0-100 is lower than the given chance.- Parameters:
chance
- Chance to check.- Returns:
- true when validated, false otherwise.
-
executeScript
Execute a JavaScript script.- Parameters:
script
- Piece of code to execute.- Returns:
- The result of the script.
-
calculateIfChances
Execute the [IF] action parameters and check if they are true.- Parameters:
value
- Value of the IF action to check.- Returns:
- true when script equals true, false otherwise.
-
parseStatics
Parse all placeholders of a player to the message. Supports PAPI and MvdW PAPI.- Parameters:
message
- Message to parse.sender
- Placeholder owner.- Returns:
- String with parsed placeholders.
-
parseStatics
Parse all placeholders of a player to the messages. Supports PAPI and MvdW PAPI. -
parseStatics
Parse all placeholders of a player to the message. Supports PAPI and MvdW PAPI.- Parameters:
message
- Message to parse.player
- Placeholder owner.- Returns:
- String with parsed placeholders.
-
c
Color a list of strings. -
sendCooldownMessage
Send the cooldown message to a player. Replaces %time% with the formatted cooldown time.- Parameters:
player
- Player to send message to.message
- Message to send.cooldown
- Cooldown in ticks.
-
isInt
Check if a string is an integer.- Parameters:
string
- String to check.- Returns:
- true when integer, false otherwise.
-
isLong
Check if a string is a long.- Parameters:
string
- String to check.- Returns:
- true when long, false otherwise.
-
isDouble
Check if a string is a double.- Parameters:
string
- String to check.- Returns:
- true when double, false otherwise.
-
isFloat
Check if a string is a float.- Parameters:
string
- String to check.- Returns:
- true when float, false otherwise.
-
isBoolean
Check if a string is a boolean.- Parameters:
string
- String to check.- Returns:
- true when boolean, false otherwise.
-
replaceHEXColors
Replace all HEX colors with bukkit encoding in a string.- Parameters:
message
- String to replace HEX colors of.- Returns:
- Same string with bukkit encoded colors instead of raw HEXes.
-
getHEXColor
Get the HEX color from a string. Could start with or without #, in format of RGB or RRGGBB.- Parameters:
message
- String to get the hex color of.- Returns:
Color
when found, null otherwise.
-
getCommandMap
org.bukkit.command.CommandMap getCommandMap()Get the Bukkit command map used for registering commands.- Returns:
- Bukkit CommandMap.
-
registerCommand
Register a command to Bukkit.- Parameters:
plugin
- Name of the plugin that the command belongs to.command
-Command
to register.
-
setTotalExperience
void setTotalExperience(org.bukkit.entity.Player player, int experience) Set the total experience of a player.- Parameters:
player
- Player to update.experience
- Number of experience to set.
-
getExpAtLevel
int getExpAtLevel(int level) Get the Bukkit experience required for one level.- Parameters:
level
- Level to get the experience of.- Returns:
- number of experience needed for that level.
-
determinePlayerTablist
Get the header and footer of the tablist group of the player.- Parameters:
player
- Player to check.- Returns:
- Array of
StringBuilder
with the Header and Footer, null when not found.
-
getArrayFrom
Get a sublist of an array as a string, joined by a space.- Parameters:
array
- String array to join.start
- Start index to start joining from (inclusive).end
- End index to stop joining at (exlusive).- Returns:
- All array sublist items joined by a space.
-
getArrayFrom
Get a sublist of an array as a string, joined by a space.- Parameters:
array
- String array to join.start
- Start index to start joining from (inclusive).- Returns:
- All array sublist items joined by a space.
-