Skip to content

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.

Formats a location using its world name and block coordinates:

String location = BukkitToString.formatLocation(player.getLocation());

Example output:

world 120 64 -35

The X, Y, and Z values are taken from the location’s block coordinates.

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.5

Use this format when exact coordinates or rotation are relevant.

Returns the Bukkit world’s name:

String worldName = BukkitToString.formatWorld(player.getWorld());

Example output:

world

Formats a Bukkit Vector using its X, Y, and Z coordinates:

String vector = BukkitToString.formatVector(direction);

Example output:

0.0 1.0 -1.0

Formats the block at a location together with its position:

String block = BukkitToString.formatBlock(player.getLocation());

Example output:

STONE at world 120 64 -35

The block type is combined with the formatted block location.

Converts a Bukkit Material into its lowercase enum name:

String material = BukkitToString.formatMaterial(Material.DIAMOND_SWORD);

Example output:

diamond_sword

This is useful when a Bukkit material should be displayed without the uppercase Java enum representation.

Formats an ItemStack using its amount and material:

String item = BukkitToString.formatItem(itemStack);

For a normal item, the output looks like:

3x diamond

null values and air items are represented as:

air

This makes the method useful when formatting inventory contents or other potentially empty item values.

Formats an entity using its entity type and block location:

String entity = BukkitToString.formatEntity(entity);

Example output:

zombie at world 120 64 -35

The entity type is converted to lowercase and combined with its formatted location.

Formats a player using their name and block location:

String player = BukkitToString.formatPlayer(player);

Example output:

Steve at world 120 64 -35

This is useful for compact player-related messages and log output.

Formats the yaw and pitch stored in a location:

String rotation = BukkitToString.formatRotation(player.getLocation());

Example output:

yaw:90.0 pitch:12.5

Unlike formatLocationDetailed, this method only includes rotation.

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.

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.

Formats a world using its Bukkit name.

Parameter Type Description
world World The world to format.

Returns the world’s name.

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.

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.

Formats a Bukkit material using its lowercase enum name.

Parameter Type Description
material Material The material to format.

Returns the lowercase material name.

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.

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.

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.

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.

For more PaperMC and Bukkit utilities, see the Reedwork utility collection.

For color formatting and Adventure components, see Color Utilities.