Interface Extra
This class contains various utility functions that don't fit into more specific utility classes, including string formatting and probability calculations. All methods are static and the class cannot be instantiated.
-
Field Summary
Fields -
Method Summary
Static MethodsModifier and TypeMethodDescriptionstatic BooleanChance(double percent) Determines if a random event occurs based on the given probability percentage.static StringConverts an object to a String, formatting Doubles to two decimal places.static StringformatLocation(org.bukkit.Location loc, String format) Formats a Location object into a string based on a provided format template.static StringUppercaseFirstLetter(String string) Converts a string to title case, capitalizing the first letter of each word.
-
Field Details
-
rand
Shared Random instance used for probability calculations
-
-
Method Details
-
formatDouble
Converts an object to a String, formatting Doubles to two decimal places.Example: 3.14159 -> "3.14"; other objects use String.valueOf semantics.
- Parameters:
d- the object to stringify- Returns:
- a string formatted to two decimal places
-
UppercaseFirstLetter
Converts a string to title case, capitalizing the first letter of each word.Underscores are converted to spaces, and the first letter of each word (separated by spaces or other non-letter characters) is capitalized while all other letters are lowercased.
Example: "DIAMOND_SWORD" becomes "Diamond Sword"
- Parameters:
string- the input string to format- Returns:
- the formatted string with each word capitalized
-
Chance
Determines if a random event occurs based on the given probability percentage.Generates a random number between 0 and 100 (exclusive) and compares it to the provided percentage. This is useful for implementing random drop chances, proc effects, and other probability-based game mechanics.
Example: Chance(25.0) has a 25% probability of returning true.
- Parameters:
percent- the probability percentage (0.0 to 100.0)- Returns:
- true if the random roll is less than or equal to the percentage; false otherwise
-
formatLocation
Formats a Location object into a string based on a provided format template.The format string can contain the following placeholders:
- %w - world name
- %x - X coordinate (formatted to 2 decimal places)
- %y - Y coordinate (formatted to 2 decimal places)
- %z - Z coordinate (formatted to 2 decimal places)
- Parameters:
loc- the Location to formatformat- the format string containing placeholders for world and coordinates- Returns:
- the formatted location string with placeholders replaced by actual values
-