Code Patterns

Copy-paste examples for common plugin tasks. Commands, events, ECS, GUI, and more.

← Back to Patterns
player

Get Player Position

Get the current position of a player using the TransformComponent.

Example Code

java
TransformComponent transform = store.getComponent(ref, TransformComponent.getComponentType());
if (transform == null) {
    player.sendMessage(Message.raw("Could not get position!"));
    return;
}

Vector3d position = transform.getPosition();
double x = position.getX();
double y = position.getY();
double z = position.getZ();

player.sendMessage(Message.raw(String.format("Position: %.1f, %.1f, %.1f", x, y, z)));

Thread Safety

Reading components is thread-safe but should be done on the world thread for consistency.

Common Mistakes

Not checking for null TransformComponent. Entity might not have a transform yet.