Class Utils
java.lang.Object
me.remigio07.chatplugin.api.common.util.Utils
Common utils class.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PatternPattern representing the allowed IPv4s.static final FileFile that indicates the current drive's main folder.static final UUIDUUID representing the nil UUID.static final StringString containing the "not applicable" text indicator.static final intSeconds in a day.static final intSeconds in a minute.static final intSeconds in a month.static final intSeconds in a week.static final intSeconds in a year.static final intSeconds in an hour.static final StringString containing the "string not found" text indicator.static final StringChatPlugin's default user agent. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> List<T> addAndGet(Collection<T> input, Collection<T> args) Creates a copy of the input collection, adds the specified collection's elements and then returns it.static booleanarrayContains(String[] array, String string, boolean ignoreCase) Checks ifarrayIndexOf(String[], String, boolean)!= -1.static intarrayIndexOf(String[] array, String string, boolean ignoreCase) Gets the index of the specified string in the given array.static StringcapitalizeEveryWord(String input) Capitalizes every word in the specified string.static longGets the free storage available on/, in bytes.static InetAddressgetInetAddress(String ipv4) Evaluates an IP address usingInetAddress.getByAddress(byte[])to avoid pinging it, making this method faster thanInetAddress.getByName(String).getListFromString(String string) Creates a list from a string representation obtained usinggetStringFromList(List, boolean, boolean).static intGets the maximum online players' amount.static Class<? extends ChatPluginManager> getOriginalClass(ChatPluginManager manager) Gets the original (abstract, API) class of the specified manager's instance.static StringgetStringFromList(List<?> list, boolean translateColorCodes, boolean retainNewLines) Creates a string representation of the specified list like the following:
"[random string, 3, that was a number as a string]"static longgetTime(int years, int months, int weeks, int days, int hours, int minutes, int seconds, boolean addCurrent) Converts the specified years, months, weeks, days, hours, minutes and seconds to their milliseconds value.static longCalculates the time in milliseconds expressed by an input string.static longGets the total storage installed on/, in bytes.static booleanChecks if the specified input is a valid float usingFloat.parseFloat(String).static booleanChecks if the specified input is a valid integer usingInteger.parseInt(String).static booleanChecks if the specified input is a valid long usingLong.parseLong(String).static booleanChecks if the specified input is a valid number usingDouble.parseDouble(String).static booleanisPositiveInteger(String number) Checks if the specified input is a positive integer usingInteger.parseInt(String).static booleanisPositiveLong(String number) Checks if the specified input is a positive long usingLong.parseLong(String).static booleanisValidIPv4(String ipv4) Checks if the specified String is a valid IPv4.static longkilometersToMiles(long kilometers) Converts the specified kilometers to miles.static longkilometersToNauticalMiles(long kilometers) Converts the specified kilometers to nautical miles.static <T> List<T> removeAndGet(Collection<T> input, Collection<T> args) Creates a copy of the input collection, removes the specified collection's elements and then returns it.static String[]removeFromArray(String[] array, String string, boolean ignoreCase) Creates a copy of the specified array, removes the given string and then returns it.static StringreplaceCustomPlaceholders(String string, String[] placeholders, Object... args) Replaces custom placeholders in a string with the given arguments:placeholders[0]will be replaced withargs[0]placeholders[1]will be replaced withargs[1]placeholders[7]will be replaced withargs[7]...and so on.static StringreplaceNumericPlaceholders(String string, Object... args) Replaces numeric placeholders in a string with the given arguments:{0}will be replaced withargs[0]{1}will be replaced withargs[1]{7}will be replaced withargs[7]...and so on.static voidreverse(char[] array) Reverses the specified char array.static doubletruncate(double number, int decimalPlaces) Truncates the specified double to a certain approximation.
-
Field Details
-
STRING_NOT_FOUND
String containing the "string not found" text indicator.Content: "string_not_found"
- See Also:
-
NOT_APPLICABLE
String containing the "not applicable" text indicator.Content: "N/A"
- See Also:
-
USER_AGENT
ChatPlugin's default user agent.Content: "Mozilla/5.0 +https://remigio07.me/chatplugin ChatPlugin/" +
ChatPlugin.VERSION -
NIL_UUID
UUID representing the nil UUID.UUID: "00000000-0000-0000-0000-000000000000"
-
MAIN_FOLDER
File that indicates the current drive's main folder.Path:
File.separator -
IPV4_PATTERN
Pattern representing the allowed IPv4s.- See Also:
-
SECONDS_IN_A_YEAR
public static final int SECONDS_IN_A_YEARSeconds in a year.Value: 31536000 (0x1e13380)
- See Also:
-
SECONDS_IN_A_MONTH
public static final int SECONDS_IN_A_MONTHSeconds in a month.Value: 2592000 (0x278d00)
- See Also:
-
SECONDS_IN_A_WEEK
public static final int SECONDS_IN_A_WEEKSeconds in a week.Value: 604800 (0x93a80)
- See Also:
-
SECONDS_IN_A_DAY
public static final int SECONDS_IN_A_DAYSeconds in a day.Value: 86400 (0x15180)
- See Also:
-
SECONDS_IN_AN_HOUR
public static final int SECONDS_IN_AN_HOURSeconds in an hour.Value: 3600 (0xe10)
- See Also:
-
SECONDS_IN_A_MINUTE
public static final int SECONDS_IN_A_MINUTESeconds in a minute.Value: 60 (0x3c)
- See Also:
-
-
Constructor Details
-
Utils
public Utils()
-
-
Method Details
-
isNumber
Checks if the specified input is a valid number usingDouble.parseDouble(String).- Parameters:
number- Number to check- Returns:
- Whether input is a valid number
-
isFloat
Checks if the specified input is a valid float usingFloat.parseFloat(String).- Parameters:
number- Number to check- Returns:
- Whether input is a valid float
-
isInteger
Checks if the specified input is a valid integer usingInteger.parseInt(String).- Parameters:
number- Number to check- Returns:
- Whether input is a valid integer
-
isLong
Checks if the specified input is a valid long usingLong.parseLong(String).- Parameters:
number- Number to check- Returns:
- Whether input is a valid long
-
isPositiveInteger
Checks if the specified input is a positive integer usingInteger.parseInt(String).- Parameters:
number- Number to check- Returns:
- Whether input is a positive integer
-
isPositiveLong
Checks if the specified input is a positive long usingLong.parseLong(String).- Parameters:
number- Number to check- Returns:
- Whether input is a positive long
-
truncate
public static double truncate(double number, int decimalPlaces) Truncates the specified double to a certain approximation.- Parameters:
number- Number to truncatedecimalPlaces- Decimal places to keep- Returns:
- Truncated number
-
kilometersToMiles
public static long kilometersToMiles(long kilometers) Converts the specified kilometers to miles.1 mi = 1609.344 m
- Parameters:
kilometers- Kilometers to convert- Returns:
- Corresponding miles
-
kilometersToNauticalMiles
public static long kilometersToNauticalMiles(long kilometers) Converts the specified kilometers to nautical miles.1 km = 0.53995680345572 nm
- Parameters:
kilometers- Kilometers to convert- Returns:
- Corresponding nautical miles
-
getMaxPlayers
public static int getMaxPlayers()Gets the maximum online players' amount.- Returns:
- Max players' amount
-
isValidIPv4
Checks if the specified String is a valid IPv4.- Parameters:
ipv4- IPv4's raw representation (xxx.xxx.xxx.xxx)- Returns:
- Whether the specified IPv4 is valid
- See Also:
-
getInetAddress
Evaluates an IP address usingInetAddress.getByAddress(byte[])to avoid pinging it, making this method faster thanInetAddress.getByName(String).- Parameters:
ipv4- IPv4's representation- Returns:
- Corresponding IP address
- Throws:
IllegalArgumentException- If specified IPv4!isValidIPv4(String)
-
getOriginalClass
Gets the original (abstract, API) class of the specified manager's instance.- Parameters:
manager- Manager's instance- Returns:
- Manager's original class
-
addAndGet
Creates a copy of the input collection, adds the specified collection's elements and then returns it.- Type Parameters:
T- Collection's type- Parameters:
input- Input collectionargs- Collection to add- Returns:
- Copy of
input+args
-
removeAndGet
Creates a copy of the input collection, removes the specified collection's elements and then returns it.- Type Parameters:
T- Collection's type- Parameters:
input- Input collectionargs- Collection to remove- Returns:
- Copy of
input-args
-
getStringFromList
public static String getStringFromList(List<?> list, boolean translateColorCodes, boolean retainNewLines) Creates a string representation of the specified list like the following:
"[random string, 3, that was a number as a string]"- Parameters:
list- List to transformtranslateColorCodes- Whether to translate colorsretainNewLines- Whether to retain new lines or to replace them with spaces- Returns:
- String representing the list
-
getListFromString
Creates a list from a string representation obtained usinggetStringFromList(List, boolean, boolean).- Parameters:
string- String representing the list- Returns:
- List from the string representation
-
reverse
public static void reverse(char[] array) Reverses the specified char array.- Parameters:
array- Array to reverse
-
arrayIndexOf
Gets the index of the specified string in the given array.Will return -1 if the string is not present.
- Parameters:
array- Array to checkstring- String to checkignoreCase- Whether to ignore case- Returns:
- String's index in the array
-
arrayContains
Checks ifarrayIndexOf(String[], String, boolean)!= -1.- Parameters:
array- Array to checkstring- String to checkignoreCase- Whether to ignore case- Returns:
- Whether the array contains the string
-
removeFromArray
Creates a copy of the specified array, removes the given string and then returns it.- Parameters:
array- Input arraystring- String to removeignoreCase- Whether to ignore case- Returns:
- New array
-
capitalizeEveryWord
Capitalizes every word in the specified string.- Parameters:
input- String to capitalize- Returns:
- Capitalized string
-
getTime
Calculates the time in milliseconds expressed by an input string.Will return -1 if the input is invalid or the time is < 0s or if
!allow0sand the time is 0s. Input string must not contain spaces and timestamps must be divided by a comma.Recognized time indicators: Identifier Value s/S Second m Minute h/H Hour d/D Day w/W Week M Month y/Y Year Example: "23d,7h,39s"
- Parameters:
input- Input stringaddCurrent- Whether to add current timeallow0s- Whether to allow the "0s" timestamp- Returns:
- Time in milliseconds or -1 if invalid input
-
getTime
public static long getTime(int years, int months, int weeks, int days, int hours, int minutes, int seconds, boolean addCurrent) Converts the specified years, months, weeks, days, hours, minutes and seconds to their milliseconds value.- Parameters:
years- Years' amountmonths- Months' amountweeks- Weeks' amountdays- Days' amounthours- Hours' amountminutes- Minutes' amountseconds- Seconds' amountaddCurrent- Whether to add current time- Returns:
- Time in milliseconds
-
replaceNumericPlaceholders
Replaces numeric placeholders in a string with the given arguments:{0}will be replaced withargs[0]{1}will be replaced withargs[1]{7}will be replaced withargs[7]
- Parameters:
string- String containing placeholdersargs- Optional arguments- Returns:
- String with placeholders translated
-
replaceCustomPlaceholders
public static String replaceCustomPlaceholders(String string, String[] placeholders, Object... args) Replaces custom placeholders in a string with the given arguments:placeholders[0]will be replaced withargs[0]placeholders[1]will be replaced withargs[1]placeholders[7]will be replaced withargs[7]
- Parameters:
string- String containing placeholdersplaceholders- Placeholders to translateargs- Optional arguments- Returns:
- String with placeholders translated
-
getTotalStorage
public static long getTotalStorage()Gets the total storage installed on/, in bytes.- Returns:
- Total storage
-
getFreeStorage
public static long getFreeStorage()Gets the free storage available on/, in bytes.- Returns:
- Free storage
-