Class Ollivanders2Common

java.lang.Object
net.pottercraft.ollivanders2.common.Ollivanders2Common

public class Ollivanders2Common extends Object
Utility class providing common functionality and constants for Ollivanders2.

Contains static collections of Minecraft material constants (doors, trapdoors, chests, signs, etc.), shared static utility methods for location operations, string transformations, particle effects, and player messaging. Also manages the global Random instance for consistent random number generation across the plugin.

This class serves as a central repository for shared data structures and utility methods that don't require state-specific to individual game objects. Instance methods use the plugin reference to access the logger and configuration.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    The horizontal drag factor for players through air
    static final double
    The vertical drag factor for players through air
    static final String
    Default world label used for serializing and unserializing locations
    static final String
    Default x-coordinate label used for serializing and unserializing locations
    static final String
    Default y-coordinate label used for serializing and unserializing locations
    static final String
    Default z-coordinate label used for serializing and unserializing locations
    static final Random
    Global Random instance for generating random numbers across the plugin.
    static final int
    The number of ticks per hour for an MC server.
    static final int
    The number of ticks per minute for an MC server.
    static final int
    The number of ticks per second for an MC server.
    static final List<org.bukkit.Material>
    All trapdoor materials.
    static final double
    The drag factor for players moving underwater.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor that initializes the common utility class.
  • Method Summary

    Modifier and Type
    Method
    Description
    @NotNull Boolean
    booleanFromString(@NotNull String boolString)
    Get a boolean from a string.
    static org.bukkit.util.Vector
    calculateVelocityForDistance(org.bukkit.Location source, double distance, double dragFactor, boolean towards)
    Calculate the velocity needed to travel a target distance in a target direction with a given drag factor.
    static org.bukkit.util.Vector
    calculateVerticalVelocity(double distance, double dragFactor, boolean upwards)
    Calculate the velocity needed to travel in +/-Y a target distance with a given drag factor.
    static void
    chatDropoff(Set<org.bukkit.entity.Player> recipients, int dropoff, org.bukkit.Location location)
    Filter the recipient set to only include players within the dropoff distance.
    @Nullable org.bukkit.Location
    deserializeLocation(@NotNull Map<String,String> locData, @NotNull String labelPrefix)
    Returns a Location from serialized data.
    static @NotNull String
    enumRecode(@NotNull String s)
    Transform an enum name string to a human-readable format.
    static @NotNull String
    Capitalize the first letter of each word while lowercasing the rest.
    static void
    flair(org.bukkit.Location location, int radius, int intensity)
    Create a particle flair effect around a location using SMOKE particles.
    static void
    flair(org.bukkit.Location location, int radius, int intensity, org.bukkit.Effect effectType)
    Create a particle flair effect around a location using the Bukkit Effect API.
    static void
    flair(org.bukkit.Location location, int radius, int intensity, org.bukkit.Particle particleType)
    Create a particle flair effect around a location using Bukkit Particle API.
    static @NotNull List<org.bukkit.block.Block>
    getBlocksInRadius(@NotNull org.bukkit.Location loc, double radius)
    Gets the blocks in a radius of a location.
    static List<org.bukkit.Material>
    Get all the doors - doors, trapdoors, gates
    static List<org.bukkit.Material>
    Get all the strict doors - ends in "_DOOR", not trapdoor or gates
    static List<org.bukkit.Material>
    Get all the unbreakbable materials.
    static void
    Initialize all the materials lists based on the loaded MC materials.
    @Nullable Integer
    integerFromString(@NotNull String intString)
    Get an integer from a string.
    static boolean
    isAdjacentTo(@NotNull org.bukkit.block.Block block1, @NotNull org.bukkit.block.Block block2)
    Check if a block is adjacent to another block
    static boolean
    isChest(org.bukkit.block.Block block)
    Determine if a block is a chest
    static boolean
    isChest(org.bukkit.Material material)
    Determine if a material is a chest
    static boolean
    isDoor(org.bukkit.block.Block block)
    Determine if a block is a door or trapdoor
    static boolean
    isDoor(org.bukkit.Material material)
    Determine if a material is a door
    static boolean
    isHotBlock(org.bukkit.block.Block block)
    Determine if a block is a hot block
    static boolean
    isHotBlock(org.bukkit.Material material)
    Determine if a material is a hot block
    static boolean
    isInside(@NotNull org.bukkit.Location sourceLocation, @NotNull org.bukkit.Location checkLocation, int radius)
    Determine if a location is within a radius of another location
    static boolean
    isNaturalLog(org.bukkit.block.Block block)
    Determine if a block is a natural log
    static boolean
    isNaturalLog(org.bukkit.Material material)
    Determine if a material is a natural log
    static boolean
    isSign(org.bukkit.block.Block block)
    Determine if a block is a sign
    static boolean
    isSign(org.bukkit.Material material)
    Determine if a material is a sign
    static boolean
    isWallSign(org.bukkit.block.Block block)
    Determine if a block is a wall sign
    static boolean
    isWallSign(org.bukkit.Material material)
    Determine if a material is a wall sign
    static boolean
    locationEquals(@NotNull org.bukkit.Location loc1, @NotNull org.bukkit.Location loc2)
    Are two locations the same?
    static org.bukkit.block.Block
    playerFacingBlockType(@NotNull org.bukkit.entity.Player player, @NotNull org.bukkit.Material blockType)
    Determine if a player is facing a block type.
    void
    printDebugMessage(@NotNull String message, @Nullable Exception exception, @Nullable RuntimeException runtimeException, boolean isWarning)
    Print debug messages to the server log.
    void
    printLogMessage(@NotNull String message, @Nullable Exception exception, @Nullable RuntimeException runtimeException, boolean isWarning)
    Print debug messages to the server log.
    static boolean
    Determine if a potion requires LibsDisguises
    static boolean
    Determine if a spell requires LibsDisguises
    static void
    sendMessageInRadius(@NotNull String message, @NotNull org.bukkit.Location location, int radius)
    Send a message to all players in a radius of a location
    static void
    sendTitleMessage(@NotNull String title, @Nullable String subtitle, @NotNull List<org.bukkit.entity.Player> players)
    Send a title message to all players.
    @Nullable Map<String,String>
    serializeLocation(@NotNull org.bukkit.Location location, @NotNull String labelPrefix)
    Serialize a Location
    static @NotNull org.bukkit.util.Vector
    sphereToVector(double[] sphere, int radius)
    Convert spherical coordinates to a Cartesian vector.
    @Nullable UUID
    uuidFromString(@NotNull String uuid)
    Create a UUID from a string.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • locationWorldLabel

      public static final String locationWorldLabel
      Default world label used for serializing and unserializing locations
      See Also:
    • locationXLabel

      public static final String locationXLabel
      Default x-coordinate label used for serializing and unserializing locations
      See Also:
    • locationYLabel

      public static final String locationYLabel
      Default y-coordinate label used for serializing and unserializing locations
      See Also:
    • locationZLabel

      public static final String locationZLabel
      Default z-coordinate label used for serializing and unserializing locations
      See Also:
    • ticksPerSecond

      public static final int ticksPerSecond
      The number of ticks per second for an MC server.
      See Also:
    • ticksPerMinute

      public static final int ticksPerMinute
      The number of ticks per minute for an MC server.
      See Also:
    • ticksPerHour

      public static final int ticksPerHour
      The number of ticks per hour for an MC server.
      See Also:
    • underWaterDragFactor

      public static final double underWaterDragFactor
      The drag factor for players moving underwater.
      See Also:
    • airVerticalDragFactor

      public static final double airVerticalDragFactor
      The vertical drag factor for players through air
      See Also:
    • airHorizontalDragFactor

      public static final double airHorizontalDragFactor
      The horizontal drag factor for players through air
      See Also:
    • trapdoors

      public static final List<org.bukkit.Material> trapdoors
      All trapdoor materials. Newer versions of minecraft have made checks to determine if a block is a trapdoor a lot harder than the olden days.
    • random

      public static final Random random
      Global Random instance for generating random numbers across the plugin.

      Seeded with System.currentTimeMillis() in the constructor to ensure different sequences across plugin reloads. All plugin components should use this shared instance rather than creating their own to maintain consistency in random number generation.

  • Constructor Details

    • Ollivanders2Common

      public Ollivanders2Common(@NotNull @NotNull Ollivanders2 plugin)
      Constructor that initializes the common utility class.

      Stores a reference to the plugin for accessing the logger and configuration, and seeds the global Random instance with the current system time to ensure different random sequences across plugin reloads.

      Parameters:
      plugin - a reference to the Ollivanders2 plugin instance
  • Method Details

    • initMaterials

      public static void initMaterials()
      Initialize all the materials lists based on the loaded MC materials. This was done statically but moved to dynamic to work with varying MC versions with different block types.
    • uuidFromString

      @Nullable public @Nullable UUID uuidFromString(@NotNull @NotNull String uuid)
      Create a UUID from a string.
      Parameters:
      uuid - the UUID as a string
      Returns:
      the UUID or null if an exception occurred.
    • integerFromString

      @Nullable public @Nullable Integer integerFromString(@NotNull @NotNull String intString)
      Get an integer from a string.
      Parameters:
      intString - the integer as a string
      Returns:
      the Integer or null if an exception occurred
    • booleanFromString

      @NotNull public @NotNull Boolean booleanFromString(@NotNull @NotNull String boolString)
      Get a boolean from a string.
      Parameters:
      boolString - the boolean as a string
      Returns:
      the Boolean or null if an exception occurred
    • isInside

      public static boolean isInside(@NotNull @NotNull org.bukkit.Location sourceLocation, @NotNull @NotNull org.bukkit.Location checkLocation, int radius)
      Determine if a location is within a radius of another location
      Parameters:
      sourceLocation - the source location
      checkLocation - the location to check
      radius - the radius from the source location
      Returns:
      true if checkLocation is in the radius of sourceLocation
    • getBlocksInRadius

      @NotNull public static @NotNull List<org.bukkit.block.Block> getBlocksInRadius(@NotNull @NotNull org.bukkit.Location loc, double radius)
      Gets the blocks in a radius of a location.
      Parameters:
      loc - The Location that is the center of the block list
      radius - The radius of the block list
      Returns:
      List of blocks that are within radius of the location.
    • enumRecode

      @NotNull public static @NotNull String enumRecode(@NotNull @NotNull String s)
      Transform an enum name string to a human-readable format.

      Converts the input to lowercase, splits on underscores, and joins the parts with spaces. For example: "AVADA_KEDAVRA" → "avada kedavra"

      Parameters:
      s - the enum name as a string (typically in CONSTANT_CASE format)
      Returns:
      a space-separated lowercase string with underscores removed
    • firstLetterCapitalize

      @NotNull public static @NotNull String firstLetterCapitalize(@NotNull @NotNull String str)
      Capitalize the first letter of each word while lowercasing the rest.

      Transforms each word in the string so that only the first letter is uppercase and all subsequent letters are lowercase. Words are separated by spaces. For example: "hello world" → "Hello World", "HELLO" → "Hello"

      Parameters:
      str - the string to convert
      Returns:
      a string with proper title case formatting
    • serializeLocation

      @Nullable public @Nullable Map<String,String> serializeLocation(@NotNull @NotNull org.bukkit.Location location, @NotNull @NotNull String labelPrefix)
      Serialize a Location
      Parameters:
      location - the Location to serialize
      labelPrefix - the prefix for the label string, assumes not empty or null
      Returns:
      a map of the serialized OLocation data
    • deserializeLocation

      @Nullable public @Nullable org.bukkit.Location deserializeLocation(@NotNull @NotNull Map<String,String> locData, @NotNull @NotNull String labelPrefix)
      Returns a Location from serialized data.
      Parameters:
      locData - the serialized location data
      labelPrefix - the label for the location field, ex. "Spell_Loc_Y-Value": "75.49627835773515" the prefix is "Spell_Loc"
      Returns:
      the location if the data was successfully read, null otherwise
    • playerFacingBlockType

      public static org.bukkit.block.Block playerFacingBlockType(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull org.bukkit.Material blockType)
      Determine if a player is facing a block type.
      Parameters:
      player - the player to check
      blockType - the block type to check
      Returns:
      the block if a player is facing a block of this type, null otherwise
    • flair

      public static void flair(org.bukkit.Location location, int radius, int intensity)
      Create a particle flair effect around a location using SMOKE particles.

      Spawns particles in a spherical pattern around the given location. The particles are distributed evenly across the sphere using spherical coordinates (inclination and azimuth angles). Defaults to SMOKE particles by calling flair(Location, int, int, Particle).

      Parameters:
      location - the center location for the particle effect
      radius - the radius of the sphere in blocks
      intensity - the density of particles (0-10+, capped at 10). Higher intensity means more particles.
    • flair

      public static void flair(org.bukkit.Location location, int radius, int intensity, org.bukkit.Effect effectType)
      Create a particle flair effect around a location using the Bukkit Effect API.

      Spawns particles in a spherical pattern around the given location using legacy Effect objects. Particles are distributed evenly across the sphere by iterating through spherical coordinates: inclination (polar angle, 0 to π) and azimuth (horizontal angle, 0 to 2π). The step size between points is determined by dividing π (or 2π) by the intensity value.

      Parameters:
      location - the center location for the particle effect
      radius - the radius of the sphere in blocks
      intensity - the density of particles (0-10+, capped at 10). Higher intensity means more particles spaced closer together
      effectType - the legacy Bukkit Effect to spawn at each point
    • flair

      public static void flair(org.bukkit.Location location, int radius, int intensity, org.bukkit.Particle particleType)
      Create a particle flair effect around a location using Bukkit Particle API.

      Spawns particles in a spherical pattern around the given location. Particles are distributed evenly across the sphere by iterating through spherical coordinates: inclination (polar angle, 0 to π) and azimuth (horizontal angle, 0 to 2π). The step size between points is determined by dividing π (or 2π) by the intensity value. This is the modern particle spawning method.

      Parameters:
      location - the center location for the particle effect
      radius - the radius of the sphere in blocks
      intensity - the density of particles (0-10+, capped at 10). Higher intensity means more particles spaced closer together
      particleType - the particle type to spawn at each point (e.g., SMOKE, FLAME, SPARK)
    • sphereToVector

      @NotNull public static @NotNull org.bukkit.util.Vector sphereToVector(double[] sphere, int radius)
      Convert spherical coordinates to a Cartesian vector.

      Transforms spherical coordinates (inclination and azimuth) into a 3D Cartesian vector relative to the origin. The inclination angle is the polar angle measured from the positive Y-axis, and the azimuth angle is measured from the positive X-axis in the horizontal plane.

      Used by flair effects to distribute particles in a spherical pattern around a center location.

      Parameters:
      sphere - a 2-element array where: - sphere[0] is the inclination (polar angle in radians, 0 to π) - sphere[1] is the azimuth (horizontal angle in radians, 0 to 2π)
      radius - the radius of the sphere, determining the distance from the origin
      Returns:
      a Vector representing the 3D position in Cartesian coordinates
    • sendTitleMessage

      public static void sendTitleMessage(@NotNull @NotNull String title, @Nullable @Nullable String subtitle, @NotNull @NotNull List<org.bukkit.entity.Player> players)
      Send a title message to all players.
      Parameters:
      title - the title message
      subtitle - the subtitle
      players - message recipients
    • sendMessageInRadius

      public static void sendMessageInRadius(@NotNull @NotNull String message, @NotNull @NotNull org.bukkit.Location location, int radius)
      Send a message to all players in a radius of a location
      Parameters:
      message - the message to send
      location - the location of the message
      radius - the radius around the location
    • printDebugMessage

      public void printDebugMessage(@NotNull @NotNull String message, @Nullable @Nullable Exception exception, @Nullable @Nullable RuntimeException runtimeException, boolean isWarning)
      Print debug messages to the server log.
      Parameters:
      message - the debug message
      exception - the exception, if applicable
      runtimeException - the runtime exception, if applicable
      isWarning - true if this should be at WARNING level, false if it should be INFO level
    • printLogMessage

      public void printLogMessage(@NotNull @NotNull String message, @Nullable @Nullable Exception exception, @Nullable @Nullable RuntimeException runtimeException, boolean isWarning)
      Print debug messages to the server log.
      Parameters:
      message - the debug message
      exception - the exception, if applicable
      runtimeException - the runtime exception, if applicable
      isWarning - true if this should be at WARNING level, false if it should be INFO level
    • locationEquals

      public static boolean locationEquals(@NotNull @NotNull org.bukkit.Location loc1, @NotNull @NotNull org.bukkit.Location loc2)
      Are two locations the same?
      Parameters:
      loc1 - location 1
      loc2 - location 2
      Returns:
      true if they are the same, false otherwise
    • chatDropoff

      public static void chatDropoff(Set<org.bukkit.entity.Player> recipients, int dropoff, org.bukkit.Location location)
      Filter the recipient set to only include players within the dropoff distance.

      Modifies the recipients set in-place, removing all players who are outside the specified distance from the source location. This is used to implement chat distance limitations where players too far away cannot hear spell or magic-related messages.

      A copy of the original recipient set is iterated to safely remove players from the original set without causing concurrent modification exceptions.

      Parameters:
      recipients - the set of players to filter (modified by this method)
      dropoff - the maximum distance in blocks for a player to remain in the recipient set
      location - the source location from which to measure distance
    • isDoor

      public static boolean isDoor(org.bukkit.block.Block block)
      Determine if a block is a door or trapdoor
      Parameters:
      block - the block to check
      Returns:
      true if it is a door or trapdoor, false otherwise
    • isDoor

      public static boolean isDoor(org.bukkit.Material material)
      Determine if a material is a door
      Parameters:
      material - the material to check
      Returns:
      true if it is a door, false otherwise
    • getDoors

      public static List<org.bukkit.Material> getDoors()
      Get all the doors - doors, trapdoors, gates
      Returns:
      the list of doors
    • getDoorsStrict

      public static List<org.bukkit.Material> getDoorsStrict()
      Get all the strict doors - ends in "_DOOR", not trapdoor or gates
      Returns:
      the list of doors
    • isChest

      public static boolean isChest(org.bukkit.block.Block block)
      Determine if a block is a chest
      Parameters:
      block - the block to check
      Returns:
      true if it is a chest, false otherwise
    • isChest

      public static boolean isChest(org.bukkit.Material material)
      Determine if a material is a chest
      Parameters:
      material - the material to check
      Returns:
      true if it is a chest, false otherwise
    • isSign

      public static boolean isSign(org.bukkit.block.Block block)
      Determine if a block is a sign
      Parameters:
      block - the block to check
      Returns:
      true if it is a sign, false otherwise
    • isSign

      public static boolean isSign(org.bukkit.Material material)
      Determine if a material is a sign
      Parameters:
      material - the material to check
      Returns:
      true if it is a sign, false otherwise
    • isWallSign

      public static boolean isWallSign(org.bukkit.block.Block block)
      Determine if a block is a wall sign
      Parameters:
      block - the block to check
      Returns:
      true if it is a wall sign, false otherwise
    • isWallSign

      public static boolean isWallSign(org.bukkit.Material material)
      Determine if a material is a wall sign
      Parameters:
      material - the material to check
      Returns:
      true if it is a wall sign, false otherwise
    • isHotBlock

      public static boolean isHotBlock(org.bukkit.block.Block block)
      Determine if a block is a hot block
      Parameters:
      block - the block to check
      Returns:
      true if it is a hot block, false otherwise
    • isHotBlock

      public static boolean isHotBlock(org.bukkit.Material material)
      Determine if a material is a hot block
      Parameters:
      material - the material to check
      Returns:
      true if it is a hot block, false otherwise
    • isNaturalLog

      public static boolean isNaturalLog(org.bukkit.block.Block block)
      Determine if a block is a natural log
      Parameters:
      block - the block to check
      Returns:
      true if it is a natural log, false otherwise
    • isNaturalLog

      public static boolean isNaturalLog(org.bukkit.Material material)
      Determine if a material is a natural log
      Parameters:
      material - the material to check
      Returns:
      true if it is a natural log, false otherwise
    • requiresLibsDisguises

      public static boolean requiresLibsDisguises(O2SpellType spellType)
      Determine if a spell requires LibsDisguises
      Parameters:
      spellType - the spell type to check
      Returns:
      true if it requires LibsDisguises, false otherwise
    • requiresLibsDisguises

      public static boolean requiresLibsDisguises(O2PotionType potionType)
      Determine if a potion requires LibsDisguises
      Parameters:
      potionType - the potion type to check
      Returns:
      true if it requires LibsDisguises, false otherwise
    • getUnbreakableMaterials

      public static List<org.bukkit.Material> getUnbreakableMaterials()
      Get all the unbreakbable materials.
      Returns:
      the list of unbreakable materials
    • isAdjacentTo

      public static boolean isAdjacentTo(@NotNull @NotNull org.bukkit.block.Block block1, @NotNull @NotNull org.bukkit.block.Block block2)
      Check if a block is adjacent to another block
      Parameters:
      block1 - the first block
      block2 - the second block
      Returns:
      true if the blocks are adjacent, false otherwise
    • calculateVelocityForDistance

      public static org.bukkit.util.Vector calculateVelocityForDistance(org.bukkit.Location source, double distance, double dragFactor, boolean towards)
      Calculate the velocity needed to travel a target distance in a target direction with a given drag factor.
      Parameters:
      source - the location to calculate direction from
      distance - the number of blocks to travel
      dragFactor - the drag factor
      towards - is the velocity towards the source (pull) or away (push)
      Returns:
      the calculated velocity needed to reach the target distance
    • calculateVerticalVelocity

      public static org.bukkit.util.Vector calculateVerticalVelocity(double distance, double dragFactor, boolean upwards)
      Calculate the velocity needed to travel in +/-Y a target distance with a given drag factor.
      Parameters:
      distance - the number of blocks to travel
      dragFactor - the drag factor
      upwards - is the velocity in the +Y direction, else -Y
      Returns:
      the calculated velocity vector