Skip to content

Player ​

Overview ​

Player is the entity class representing the player in Minecraft, inheriting from LivingEntity. It has unique ability systems, inventory, experience, game modes, etc., supporting rich scripting operations.

Mechanism Description ​

  • Inherits from LivingEntity, extending abilities, inventory, experience, gameMode, advancements and other systems.
  • Supports tick auto-update, event-driven, NBT persistence.
  • Common methods: getName, getUuid, getAbilities, getInventory, addExperience, setGameMode, sendMessage, isCreative, isSpectator, isSleeping, etc.

Common Methods ​

js
// Get player name and UUID
const name = player.getName();
// To get a name that can be used directly
const name = player.username;
const uuid = player.getUuid();

// Send message
player.sendMessage('Hello, world!');

// Check creative/spectator mode
if (player.isCreative()) { /* ... */ }
if (player.isSpectator()) { /* ... */ }

// Add experience
player.addExperience(100);

// Get inventory contents
const inventory = player.getInventory();

Notes ​

  • Only Player entities support abilities, inventory, experience, game mode and other operations.
  • Some methods are only available on the server side or in specific events, pay attention to compatibility.
  • For detailed types and parameters, refer to .

Advanced ​

  • Player is the core of KubeJS player scripting development. It is recommended to combine vanilla source code with Forge documentation for in-depth study.
  • Related subclasses: ServerPlayer, AbstractClientPlayer, etc.