Format Bukkit Objects as Strings
BukkitToString provides formatting utilities for converting common Bukkit objects into compact, human-readable strings.
It is useful for PaperMC plugin messages, command output, logging, debugging, and other situations where Bukkit data needs to be displayed as text.
The utility produces readable representations of selected object properties. It does not serialize objects into a reversible format.
Locations
Section titled “Locations”formatLocation(Location location)
Section titled “formatLocation(Location location)”Formats a location using its world name and block coordinates:
String location = BukkitToString.formatLocation(player.getLocation());Example output:
world 120 64 -35The X, Y, and Z values are taken from the location’s block coordinates.
formatLocationDetailed(Location location)
Section titled “formatLocationDetailed(Location location)”Formats a location using its world name, exact coordinates, yaw, and pitch:
String location = BukkitToString.formatLocationDetailed(player.getLocation());Example output:
world 120.5 64.0 -35.25 yaw:90.0 pitch:12.5Use this format when exact coordinates or rotation are relevant.
Worlds
Section titled “Worlds”formatWorld(World world)
Section titled “formatWorld(World world)”Returns the Bukkit world’s name:
String worldName = BukkitToString.formatWorld(player.getWorld());Example output:
worldVectors
Section titled “Vectors”formatVector(Vector vector)
Section titled “formatVector(Vector vector)”Formats a Bukkit Vector using its X, Y, and Z coordinates:
String vector = BukkitToString.formatVector(direction);Example output:
0.0 1.0 -1.0Blocks
Section titled “Blocks”formatBlock(Location location)
Section titled “formatBlock(Location location)”Formats the block at a location together with its position:
String block = BukkitToString.formatBlock(player.getLocation());Example output:
STONE at world 120 64 -35The block type is combined with the formatted block location.
Materials
Section titled “Materials”formatMaterial(Material material)
Section titled “formatMaterial(Material material)”Converts a Bukkit Material into its lowercase enum name:
String material = BukkitToString.formatMaterial(Material.DIAMOND_SWORD);Example output:
diamond_swordThis is useful when a Bukkit material should be displayed without the uppercase Java enum representation.
formatItem(ItemStack item)
Section titled “formatItem(ItemStack item)”Formats an ItemStack using its amount and material:
String item = BukkitToString.formatItem(itemStack);For a normal item, the output looks like:
3x diamondnull values and air items are represented as:
airThis makes the method useful when formatting inventory contents or other potentially empty item values.
Entities
Section titled “Entities”formatEntity(Entity entity)
Section titled “formatEntity(Entity entity)”Formats an entity using its entity type and block location:
String entity = BukkitToString.formatEntity(entity);Example output:
zombie at world 120 64 -35The entity type is converted to lowercase and combined with its formatted location.
Players
Section titled “Players”formatPlayer(Player player)
Section titled “formatPlayer(Player player)”Formats a player using their name and block location:
String player = BukkitToString.formatPlayer(player);Example output:
Steve at world 120 64 -35This is useful for compact player-related messages and log output.
Rotation
Section titled “Rotation”formatRotation(Location location)
Section titled “formatRotation(Location location)”Formats the yaw and pitch stored in a location:
String rotation = BukkitToString.formatRotation(player.getLocation());Example output:
yaw:90.0 pitch:12.5Unlike formatLocationDetailed, this method only includes rotation.
formatLocation(Location location)
Section titled “formatLocation(Location location)”Formats a location using its world name and block coordinates.
| Parameter | Type | Description |
|---|---|---|
location |
Location |
The location to format. |
Returns a string containing the world name and block coordinates.
formatLocationDetailed(Location location)
Section titled “formatLocationDetailed(Location location)”Formats a location using its world name, exact coordinates, yaw, and pitch.
| Parameter | Type | Description |
|---|---|---|
location |
Location |
The location to format. |
Returns a string containing the world, exact coordinates, yaw, and pitch.
formatWorld(World world)
Section titled “formatWorld(World world)”Formats a world using its Bukkit name.
| Parameter | Type | Description |
|---|---|---|
world |
World |
The world to format. |
Returns the world’s name.
formatVector(Vector vector)
Section titled “formatVector(Vector vector)”Formats a vector using its X, Y, and Z coordinates.
| Parameter | Type | Description |
|---|---|---|
vector |
Vector |
The vector to format. |
Returns a space-separated string containing the vector coordinates.
formatBlock(Location location)
Section titled “formatBlock(Location location)”Formats the block at the specified location together with its block position.
| Parameter | Type | Description |
|---|---|---|
location |
Location |
The location of the block. |
Returns a string containing the block type and formatted location.
formatMaterial(Material material)
Section titled “formatMaterial(Material material)”Formats a Bukkit material using its lowercase enum name.
| Parameter | Type | Description |
|---|---|---|
material |
Material |
The material to format. |
Returns the lowercase material name.
formatItem(ItemStack item)
Section titled “formatItem(ItemStack item)”Formats an item using its amount and material.
| Parameter | Type | Description |
|---|---|---|
item |
ItemStack |
The item to format. |
Returns the formatted item, or air when the item is null or an air item.
formatEntity(Entity entity)
Section titled “formatEntity(Entity entity)”Formats an entity using its type and block location.
| Parameter | Type | Description |
|---|---|---|
entity |
Entity |
The entity to format. |
Returns a string containing the entity type and location.
formatPlayer(Player player)
Section titled “formatPlayer(Player player)”Formats a player using their name and block location.
| Parameter | Type | Description |
|---|---|---|
player |
Player |
The player to format. |
Returns a string containing the player’s name and location.
formatRotation(Location location)
Section titled “formatRotation(Location location)”Formats the yaw and pitch of a location.
| Parameter | Type | Description |
|---|---|---|
location |
Location |
The location containing the rotation. |
Returns a string containing the yaw and pitch.
Related utilities
Section titled “Related utilities”For more PaperMC and Bukkit utilities, see the Reedwork utility collection.
For color formatting and Adventure components, see Color Utilities.