Interface Extra


public interface Extra
Miscellaneous utility class providing common helper methods.

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
    Modifier and Type
    Field
    Description
    static final Random
    Shared Random instance used for probability calculations
  • Method Summary

    Static Methods
    Modifier and Type
    Method
    Description
    static Boolean
    Chance(double percent)
    Determines if a random event occurs based on the given probability percentage.
    static String
    Converts an object to a String, formatting Doubles to two decimal places.
    static String
    formatLocation(org.bukkit.Location loc, String format)
    Formats a Location object into a string based on a provided format template.
    static String
    Converts a string to title case, capitalizing the first letter of each word.
  • Field Details

    • rand

      static final Random rand
      Shared Random instance used for probability calculations
  • Method Details

    • formatDouble

      static String formatDouble(Double d)
      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

      static String UppercaseFirstLetter(String string)
      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

      static Boolean Chance(double percent)
      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

      static String formatLocation(org.bukkit.Location loc, String format)
      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)
      Example: formatLocation(loc, "%w: %x, %y, %z") might return "world: 100.00, 64.00, -50.00".
      Parameters:
      loc - the Location to format
      format - the format string containing placeholders for world and coordinates
      Returns:
      the formatted location string with placeholders replaced by actual values