Skip to Content
⚠ Under Construction
ReferenceC++ APIPlayer

endstone::Player

Represents a player.

Bases: endstone::Mob, endstone::OfflinePlayer

Functions:

NameDescription
closeFormCloses the forms that are currently open for the player.
getAddressGets the socket address of this player.
getAllowFlightDetermines if the Player is allowed to fly via jump key double-tap.
getDeviceIdGets the player’s current device id.
getDeviceOSGets the player’s current device’s operation system (OS).
getEnderChestGet the player’s EnderChest inventory.
getExpLevelGets the players current experience level.
getExpProgressGets the players current experience progress towards the next level.
getFlySpeedGets the current allowed speed that a client can fly.
getGameModeGets this player’s current GameMode .
getGameVersionGets the player’s current game version.
getInventoryGet the player’s inventory.
getLocaleGets the player’s current locale.
getNameReturns the name of this player.
getPingGets the player’s average ping.
getScoreboardGets the Scoreboard displayed to this player.
getSkinGets the player’s skin.
getTotalExpGets the players total experience points.
getWalkSpeedGets the current allowed speed that a client can walk.
getXuidReturns the Xbox User ID (XUID) of this player.
giveExpGives the player the amount of experience specified.
giveExpLevelsGives the player the amount of experience levels specified.
isFlyingChecks to see if this player is currently flying or not.
isOpChecks if this player is a server operator.
isSneakingReturns if the player is in sneak mode.
isSprintingGets whether the player is sprinting or not.
kickKicks player with custom kick message.
performCommandMakes the player perform the given command.
playSoundPlay a sound for a player at the location.
resetTitleResets the title displayed to the player. This will clear the displayed title / subtitle and reset timings to their default values.
sendFormSends a form to the player.
sendPacketSends a packet to the player.
sendPopupSends this player a popup message.
sendTipSends this player a tip message.
sendTitleSends a title and a subtitle message to the player. If they are empty strings, the display will be updated as such. The titles will be displayed with the default timings.
sendTitleSends a title and a subtitle message to the player. If they are empty strings, the display will be updated as such.
sendToastSends this player a toast notification.
setAllowFlightSets if the Player is allowed to fly via jump key double-tap.
setExpLevelSets the players current experience level.
setExpProgressSets the players current experience progress towards the next level.
setFlySpeed
setFlyingMakes this player start or stop flying.
setGameModeSets this player’s current GameMode .
setOpSets the operator status of this player.
setScoreboard
setSneakingSets the sneak mode of the player.
setSprintingSets whether the player is sprinting or not.
setWalkSpeed
spawnParticleSpawns the particle at the target location.
spawnParticleSpawns the particle at the target location.
spawnParticleSpawns the particle at the target location.
spawnParticleSpawns the particle at the target location.
stopAllSoundsStop all sounds from playing.
stopSoundStop the specified sound from playing.
transferTransfers the player to another server.
updateCommandsSend the list of commands to the client.

closeForm

void closeForm()

Closes the forms that are currently open for the player.

getAddress

SocketAddress getAddress() const

Gets the socket address of this player.

Returns:

the player’s socket address

getAllowFlight

bool getAllowFlight() const

Determines if the Player is allowed to fly via jump key double-tap.

Returns:

True if the player is allowed to fly.

getDeviceId

std::string getDeviceId() const

Gets the player’s current device id.

Returns:

the player’s device id

getDeviceOS

std::string getDeviceOS() const

Gets the player’s current device’s operation system (OS).

Returns:

the player’s device OS

getEnderChest

Inventory &getEnderChest() const

Get the player’s EnderChest inventory.

Returns:

The EnderChest of the player

getExpLevel

int getExpLevel() const

Gets the players current experience level.

Returns:

Current experience level

getExpProgress

float getExpProgress() const

Gets the players current experience progress towards the next level.

This is a percentage value. 0.0 is “no progress” and 1.0 is “next level”.

Returns:

Current experience points

getFlySpeed

float getFlySpeed() const

Gets the current allowed speed that a client can fly.

Returns:

The current allowed speed, default is 0.05.

getGameMode

GameMode getGameMode() const

Gets this player’s current GameMode .

Returns:

Current game mode

getGameVersion

std::string getGameVersion() const

Gets the player’s current game version.

Returns:

the player’s game version

getInventory

PlayerInventory &getInventory() const

Get the player’s inventory.

Returns:

The inventory of the player, this also contains the armor slots.

getLocale

std::string getLocale() const

Gets the player’s current locale.

Returns:

the player’s locale

getName

std::string getName() override const

Returns the name of this player.

Returns:

Player name or null if we have not seen a name for this player yet

getPing

std::chrono::milliseconds getPing() const

Gets the player’s average ping.

Returns:

player ping

getScoreboard

Scoreboard &getScoreboard() const

Gets the Scoreboard displayed to this player.

Returns:

The current scoreboard seen by this player

getSkin

Skin getSkin() const

Gets the player’s skin.

Returns:

the player’s skin

getTotalExp

int getTotalExp() const

Gets the players total experience points.

This refers to the total amount of experience the player has collected over time and is not currently displayed to the client.

Returns:

Current total experience points

getWalkSpeed

float getWalkSpeed() const

Gets the current allowed speed that a client can walk.

Returns:

The current allowed speed, default is 0.10.

getXuid

std::string getXuid() const

Returns the Xbox User ID (XUID) of this player.

Returns:

Player XUID

giveExp

void giveExp(int amount)

Gives the player the amount of experience specified.

Parameters:

  • amount Exp amount to give

giveExpLevels

void giveExpLevels(int amount)

Gives the player the amount of experience levels specified.

Parameters:

  • amount amount of experience levels to give or take

isFlying

bool isFlying() const

Checks to see if this player is currently flying or not.

Returns:

True if the player is flying, else false.

isOp

bool isOp() const

Checks if this player is a server operator.

Returns:

true if this is an operator, otherwise false

isSneaking

bool isSneaking() const

Returns if the player is in sneak mode.

Returns:

true if player is in sneak mode

isSprinting

bool isSprinting() const

Gets whether the player is sprinting or not.

Returns:

true if player is sprinting.

kick

void kick(std::string message) const

Kicks player with custom kick message.

Parameters:

  • message kick message

performCommand

bool performCommand(std::string command) const

Makes the player perform the given command.

Parameters:

Returns:

true if the command was successful, otherwise false

playSound

void playSound(Location location, std::string sound, float volume, float pitch)

Play a sound for a player at the location.

Parameters:

  • location The location to play the sound
  • sound The internal sound name to play
  • volume The volume of the sound
  • pitch The pitch of the sound

resetTitle

void resetTitle() const

Resets the title displayed to the player. This will clear the displayed title / subtitle and reset timings to their default values.

sendForm

void sendForm(FormVariant form)

Sends a form to the player.

Parameters:

  • form The form to send

sendPacket

void sendPacket(int packet_id, std::string_view payload) const

Sends a packet to the player.

Parameters:

  • packet_id The packet ID to be sent.
  • payload The payload of the packet to be transmitted.

sendPopup

void sendPopup(std::string message) const

Sends this player a popup message.

Parameters:

  • message Message to be displayed

sendTip

void sendTip(std::string message) const

Sends this player a tip message.

Parameters:

  • message Message to be displayed

sendTitle

void sendTitle(std::string title, std::string subtitle) const

Sends a title and a subtitle message to the player. If they are empty strings, the display will be updated as such. The titles will be displayed with the default timings.

Parameters:

  • title Title text
  • subtitle Subtitle text
void sendTitle(std::string title, std::string subtitle, int fade_in, int stay, int fade_out) const

Sends a title and a subtitle message to the player. If they are empty strings, the display will be updated as such.

Parameters:

  • title Title text
  • subtitle Subtitle text
  • fade_in time in ticks for titles to fade in. Defaults to 10.
  • stay time in ticks for titles to stay. Defaults to 70.
  • fade_out time in ticks for titles to fade out. Defaults to 20.

sendToast

void sendToast(std::string title, std::string content) const

Sends this player a toast notification.

Parameters:

  • title The title of the toast notification.
  • content The content of the toast notification.

setAllowFlight

void setAllowFlight(bool flight)

Sets if the Player is allowed to fly via jump key double-tap.

Parameters:

  • flight If flight should be allowed.

setExpLevel

Result<void> setExpLevel(int level)

Sets the players current experience level.

Parameters:

  • level New experience level

setExpProgress

Result<void> setExpProgress(float progress)

Sets the players current experience progress towards the next level.

This is a percentage value. 0.0 is “no progress” and 1.0 is “next level”.

Parameters:

  • progress New experience progress

setFlySpeed

void setFlySpeed(float value) const

Sets the speed at which a client will fly.

Parameters:

  • value The new speed.

setFlying

Result<void> setFlying(bool value)

Makes this player start or stop flying.

Parameters:

  • value True to fly.

setGameMode

void setGameMode(GameMode mode)

Sets this player’s current GameMode .

Parameters:

  • mode New game mode

setOp

void setOp(bool value)

Sets the operator status of this player.

Parameters:

  • value New operator value

setScoreboard

void setScoreboard(Scoreboard &scoreboard)

@breif Sets the player’s visible Scoreboard.

Parameters:

setSneaking

void setSneaking(bool sneak)

Sets the sneak mode of the player.

Parameters:

  • sneak true if player should appear sneaking

setSprinting

void setSprinting(bool sprinting)

Sets whether the player is sprinting or not.

Parameters:

  • sprinting true if the player should be sprinting

setWalkSpeed

void setWalkSpeed(float value) const

Sets the speed at which a client will walk.

Parameters:

  • value The new speed.

spawnParticle

void spawnParticle(std::string name, Location location) const

Spawns the particle at the target location.

Parameters:

  • name the name of the particle effect to spawn
  • location the location to spawn at
void spawnParticle(std::string name, float x, float y, float z) const

Spawns the particle at the target location.

Parameters:

  • name the name of the particle effect to spawn
  • x the position on the x axis to spawn at
  • y the position on the y axis to spawn at
  • z the position on the z axis to spawn at
void spawnParticle(std::string name, Location location, std::optional<std::string> molang_variables_json) const

Spawns the particle at the target location.

Parameters:

  • name the name of the particle effect to spawn
  • location the location to spawn at
  • molang_variables_json the customizable molang variables that can be adjusted for this particle, in json
void spawnParticle(std::string name, float x, float y, float z, std::optional<std::string> molang_variables_json) const

Spawns the particle at the target location.

Parameters:

  • name the name of the particle effect to spawn
  • x the position on the x axis to spawn at
  • y the position on the y axis to spawn at
  • z the position on the z axis to spawn at
  • molang_variables_json the customizable molang variables that can be adjusted for this particle, in json

stopAllSounds

void stopAllSounds()

Stop all sounds from playing.

stopSound

void stopSound(std::string sound)

Stop the specified sound from playing.

Parameters:

  • sound the sound to stop

transfer

void transfer(std::string host, int port) const

Transfers the player to another server.

Parameters:

  • host Server address to transfer the player to.
  • port Server port to transfer the player to

updateCommands

void updateCommands() const

Send the list of commands to the client.

Generally useful to ensure the client has a complete list of commands after permission changes are done.

Last updated on