Class Ollivanders2Common
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
FieldsModifier and TypeFieldDescriptionstatic final doubleThe horizontal drag factor for players through airstatic final doubleThe vertical drag factor for players through airstatic final StringDefault world label used for serializing and unserializing locationsstatic final StringDefault x-coordinate label used for serializing and unserializing locationsstatic final StringDefault y-coordinate label used for serializing and unserializing locationsstatic final StringDefault z-coordinate label used for serializing and unserializing locationsstatic final RandomGlobal Random instance for generating random numbers across the plugin.static final intThe number of ticks per hour for an MC server.static final intThe number of ticks per minute for an MC server.static final intThe number of ticks per second for an MC server.static final List<org.bukkit.Material> All trapdoor materials.static final doubleThe drag factor for players moving underwater. -
Constructor Summary
ConstructorsConstructorDescriptionOllivanders2Common(@NotNull Ollivanders2 plugin) Constructor that initializes the common utility class. -
Method Summary
Modifier and TypeMethodDescription@NotNull BooleanbooleanFromString(@NotNull String boolString) Get a boolean from a string.static org.bukkit.util.VectorcalculateVelocityForDistance(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.VectorcalculateVerticalVelocity(double distance, double dragFactor, boolean upwards) Calculate the velocity needed to travel in +/-Y a target distance with a given drag factor.static voidchatDropoff(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.LocationdeserializeLocation(@NotNull Map<String, String> locData, @NotNull String labelPrefix) Returns a Location from serialized data.static @NotNull StringenumRecode(@NotNull String s) Transform an enum name string to a human-readable format.static @NotNull StringfirstLetterCapitalize(@NotNull String str) Capitalize the first letter of each word while lowercasing the rest.static voidflair(org.bukkit.Location location, int radius, int intensity) Create a particle flair effect around a location using SMOKE particles.static voidflair(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 voidflair(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> getDoors()Get all the doors - doors, trapdoors, gatesstatic List<org.bukkit.Material> Get all the strict doors - ends in "_DOOR", not trapdoor or gatesstatic List<org.bukkit.Material> Get all the unbreakbable materials.static voidInitialize all the materials lists based on the loaded MC materials.@Nullable IntegerintegerFromString(@NotNull String intString) Get an integer from a string.static booleanisAdjacentTo(@NotNull org.bukkit.block.Block block1, @NotNull org.bukkit.block.Block block2) Check if a block is adjacent to another blockstatic booleanisChest(org.bukkit.block.Block block) Determine if a block is a cheststatic booleanisChest(org.bukkit.Material material) Determine if a material is a cheststatic booleanisDoor(org.bukkit.block.Block block) Determine if a block is a door or trapdoorstatic booleanisDoor(org.bukkit.Material material) Determine if a material is a doorstatic booleanisHotBlock(org.bukkit.block.Block block) Determine if a block is a hot blockstatic booleanisHotBlock(org.bukkit.Material material) Determine if a material is a hot blockstatic booleanisInside(@NotNull org.bukkit.Location sourceLocation, @NotNull org.bukkit.Location checkLocation, int radius) Determine if a location is within a radius of another locationstatic booleanisNaturalLog(org.bukkit.block.Block block) Determine if a block is a natural logstatic booleanisNaturalLog(org.bukkit.Material material) Determine if a material is a natural logstatic booleanisSign(org.bukkit.block.Block block) Determine if a block is a signstatic booleanisSign(org.bukkit.Material material) Determine if a material is a signstatic booleanisWallSign(org.bukkit.block.Block block) Determine if a block is a wall signstatic booleanisWallSign(org.bukkit.Material material) Determine if a material is a wall signstatic booleanlocationEquals(@NotNull org.bukkit.Location loc1, @NotNull org.bukkit.Location loc2) Are two locations the same?static org.bukkit.block.BlockplayerFacingBlockType(@NotNull org.bukkit.entity.Player player, @NotNull org.bukkit.Material blockType) Determine if a player is facing a block type.voidprintDebugMessage(@NotNull String message, @Nullable Exception exception, @Nullable RuntimeException runtimeException, boolean isWarning) Print debug messages to the server log.voidprintLogMessage(@NotNull String message, @Nullable Exception exception, @Nullable RuntimeException runtimeException, boolean isWarning) Print debug messages to the server log.static booleanrequiresLibsDisguises(O2PotionType potionType) Determine if a potion requires LibsDisguisesstatic booleanrequiresLibsDisguises(O2SpellType spellType) Determine if a spell requires LibsDisguisesstatic voidsendMessageInRadius(@NotNull String message, @NotNull org.bukkit.Location location, int radius) Send a message to all players in a radius of a locationstatic voidsendTitleMessage(@NotNull String title, @Nullable String subtitle, @NotNull List<org.bukkit.entity.Player> players) Send a title message to all players.serializeLocation(@NotNull org.bukkit.Location location, @NotNull String labelPrefix) Serialize a Locationstatic @NotNull org.bukkit.util.VectorsphereToVector(double[] sphere, int radius) Convert spherical coordinates to a Cartesian vector.@Nullable UUIDuuidFromString(@NotNull String uuid) Create a UUID from a string.
-
Field Details
-
locationWorldLabel
Default world label used for serializing and unserializing locations- See Also:
-
locationXLabel
Default x-coordinate label used for serializing and unserializing locations- See Also:
-
locationYLabel
Default y-coordinate label used for serializing and unserializing locations- See Also:
-
locationZLabel
Default z-coordinate label used for serializing and unserializing locations- See Also:
-
ticksPerSecond
public static final int ticksPerSecondThe number of ticks per second for an MC server.- See Also:
-
ticksPerMinute
public static final int ticksPerMinuteThe number of ticks per minute for an MC server.- See Also:
-
ticksPerHour
public static final int ticksPerHourThe number of ticks per hour for an MC server.- See Also:
-
underWaterDragFactor
public static final double underWaterDragFactorThe drag factor for players moving underwater.- See Also:
-
airVerticalDragFactor
public static final double airVerticalDragFactorThe vertical drag factor for players through air- See Also:
-
airHorizontalDragFactor
public static final double airHorizontalDragFactorThe horizontal drag factor for players through air- See Also:
-
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
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
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
Create a UUID from a string.- Parameters:
uuid- the UUID as a string- Returns:
- the UUID or null if an exception occurred.
-
integerFromString
Get an integer from a string.- Parameters:
intString- the integer as a string- Returns:
- the Integer or null if an exception occurred
-
booleanFromString
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 locationcheckLocation- the location to checkradius- 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 listradius- The radius of the block list- Returns:
- List of blocks that are within radius of the location.
-
enumRecode
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
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 serializelabelPrefix- 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 datalabelPrefix- 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 checkblockType- 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 effectradius- the radius of the sphere in blocksintensity- 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 effectradius- the radius of the sphere in blocksintensity- the density of particles (0-10+, capped at 10). Higher intensity means more particles spaced closer togethereffectType- 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 effectradius- the radius of the sphere in blocksintensity- the density of particles (0-10+, capped at 10). Higher intensity means more particles spaced closer togetherparticleType- 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 messagesubtitle- the subtitleplayers- 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 sendlocation- the location of the messageradius- 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 messageexception- the exception, if applicableruntimeException- the runtime exception, if applicableisWarning- 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 messageexception- the exception, if applicableruntimeException- the runtime exception, if applicableisWarning- 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 1loc2- 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 setlocation- 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
Get all the doors - doors, trapdoors, gates- Returns:
- the list of doors
-
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
Determine if a spell requires LibsDisguises- Parameters:
spellType- the spell type to check- Returns:
- true if it requires LibsDisguises, false otherwise
-
requiresLibsDisguises
Determine if a potion requires LibsDisguises- Parameters:
potionType- the potion type to check- Returns:
- true if it requires LibsDisguises, false otherwise
-
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 blockblock2- 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 fromdistance- the number of blocks to traveldragFactor- the drag factortowards- 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 traveldragFactor- the drag factorupwards- is the velocity in the +Y direction, else -Y- Returns:
- the calculated velocity vector
-