Skip to content

API reference Obsidian.API

IPlayer interface

public interface IPlayer : ILiving, IEntity, IAttachmentHolder

In Obsidian.API.

Properties

PlayerAbility Abilities { get; set; }float Absorption { get; set; }IAdvancements Advancements { get; }short AttackTime { get; set; }

CarriedItem

ItemStack CarriedItem { get; set; }

The item currently being held by the player. Not null if they're in a container screen and carrying the item.

ClientInformation ClientInformation { get; set; }string ClientIP { get; }byte CurrentContainerId { get; }short CurrentHeldItemSlot { get; set; }IScoreboard CurrentScoreboard { get; set; }short DeathTime { get; set; }List<short> DraggedSlots { get; }

DragStart

DraggingState DragStart { get; set; }

How the player started dragging items across slots, while IPlayer.IsDragging: DraggingState.StartLeft splits the carried stack evenly, DraggingState.StartRight places one item per slot and DraggingState.StartMiddle (creative only) a full stack.

Container EnderInventory { get; }float FallDistance { get; set; }float FoodExhaustionLevel { get; set; }int FoodLevel { get; set; }float FoodSaturationLevel { get; set; }int FoodTickTimer { get; set; }GameMode GameMode { get; set; }double HeadY { get; }short HurtTime { get; set; }bool InHorseInventory { get; set; }PlayerInput Input { get; set; }Container Inventory { get; }bool IsDragging { get; set; }Vector? LastDeathLocation { get; set; }ConcurrentHashSet<long> LoadedChunks { get; }ILogger Logger { get; }

MovementAbilities

MovementAbilities MovementAbilities { get; }

What the player's movement grants add up to (see IPlayer.SetMovementAbilities).

BaseContainer OpenedContainer { get; set; }int Ping { get; }

Respawning

bool Respawning { get; }

Whether the player is between dying and coming back in a level. They can't act meanwhile.

IServer Server { get; }List<SkinProperty> SkinProperties { get; set; }bool Sleeping { get; set; }short SleepTimer { get; set; }

Statistics

IStatistics Statistics { get; }

The player's statistics. A player that keeps none, like another engine's by default, reads zero for each and drops increments, so that gameplay counting them works for any player.

int TeleportId { get; set; }string Username { get; }int XpLevel { get; set; }

XpP

float XpP { get; set; }

How far the player is through their current level, from 0 to 1.

int XpTotal { get; set; }

Methods

AttackAsync(IEntity, bool)

ValueTask<bool> AttackAsync(IEntity target, bool sneaking = false);

Attacks target with the held item, like a client's attack: only in reach, and through PlayerAttackEntityEventArgs, which plugins can cancel. The hit lands on the target's level tick.

Returns

Whether the target was in reach and the attack's event wasn't cancelled.

ValueTask ClearDialogAsync();

DisconnectAsync(ChatMessage)

ValueTask DisconnectAsync(ChatMessage reason);

Disconnects the player and waits for their leave, which waits for their tick under way. Called from inside a level's tick, or any player's tick, grant or save, the leave finishes after the ticks, without being waited for.

DisplayScoreboardAsync(IScoreboard, DisplaySlot)

ValueTask DisplayScoreboardAsync(IScoreboard scoreboard, DisplaySlot position);

Shows scoreboard's objective and scores to the player in position. The player must have been added to the scoreboard first.

Remarks

The packets are queued with the scoreboard's other updates and removals, which the player gets in order, and sent shortly after this returns. A packet sent to the player directly afterwards may arrive first, so change the scoreboard through IScoreboard rather than with packets of your own.

ItemStack GetHeldItem();ItemStack GetOffHandItem();

GiveExperienceAsync(int)

ValueTask GiveExperienceAsync(int points);

Gives the player experience points, which can level them up, as an orb or an advancement's reward does. Unlike an orb's, they don't mend items.

Task<bool> GrantPermissionAsync(string permission);bool HasAllPermissions(IEnumerable<string> permissions);bool HasAnyPermission(IEnumerable<string> permissions);bool HasPermission(string permission);

InteractAsync(IEntity, InteractionHand, bool)

ValueTask<bool> InteractAsync(IEntity target, InteractionHand hand = 0, bool sneaking = false);

Interacts with target, like a client's use on it: through EntityInteractEventArgs, then the entity's interaction, like boarding a saddled pig, or the item's use on it. Those run on the target's level tick.

Returns

Whether the target was in reach and the interaction's event wasn't cancelled.

KickAsync(ChatMessage)

ValueTask KickAsync(ChatMessage reason);

Kicks the player; it waits for their leave like IPlayer.DisconnectAsync.

KickAsync(string)

ValueTask KickAsync(string reason);

Kicks the player; it waits for their leave like IPlayer.DisconnectAsync.

Task LoadAsync(bool loadFromPersistentWorld = true);ValueTask OpenInventoryAsync(BaseContainer container);

QueuePacketAsync(IClientboundPacket)

ValueTask QueuePacketAsync(IClientboundPacket packet);

Queues a packet for the player's client. Packet handlers see it in the client's outgoing pipeline, after the call returned; the call never waits for them. Players without a client ignore it.

ReleaseUsingItemAsync()

ValueTask ReleaseUsingItemAsync();

Lets go of the item the player is using, like a client does: a drawn bow or trident fires, and eating stops.

RemoveMovementAbilities(string)

bool RemoveMovementAbilities(string id);

Takes back the grant IPlayer.SetMovementAbilities made under id.

Returns

Whether there was one.

Task RespawnAsync(DataKept dataKept = 2);Task<bool> RevokePermissionAsync(string permission);

SaveAsync()

Task SaveAsync();

Saves the player's data, statistics and advancements.

Remarks

It waits for the player's tick, grant or save under way. Called from the player's own, it saves at once as part of it.

SendActionBarAsync(string)

ValueTask SendActionBarAsync(string text);

Sends an action bar text to the player.

Parameters

text
The text of the action bar.
ValueTask SendMessageAsync(ChatMessage message);ValueTask SendMessageAsync(ChatMessage message, Guid sender, SecureMessageSignature messageSignature);

SendPacket(IClientboundPacket)

bool SendPacket(IClientboundPacket packet);

Sends a packet to the player's client without packet handlers: immediately, or right after the packets queued before it that are still on their way. Players without a client ignore it.

Returns

Whether the packet was sent or is on its way.

ValueTask SendPlayerInfoAsync();ValueTask SendSoundAsync(ISoundEffect soundEffect);

SendSubtitleAsync(ChatMessage, int, int, int)

ValueTask SendSubtitleAsync(ChatMessage subtitle, int fadeIn, int stay, int fadeOut);

Sends a subtitle message to the player.

Parameters

subtitle
The title text
fadeIn
Time in ticks for the title to fade in
stay
Time in ticks for the title to stay on screen
fadeOut
Time in ticks for the title to fade out

SendTitleAsync(ChatMessage, ChatMessage, int, int, int)

ValueTask SendTitleAsync(ChatMessage title, ChatMessage subtitle, int fadeIn, int stay, int fadeOut);

Sends a title and subtitle message to the player.

Parameters

title
The title text
subtitle
The subtitle text
fadeIn
Time in ticks for the title to fade in
stay
Time in ticks for the title to stay on screen
fadeOut
Time in ticks for the title to fade out

SendTitleAsync(ChatMessage, int, int, int)

ValueTask SendTitleAsync(ChatMessage title, int fadeIn, int stay, int fadeOut);

Sends a title message to the player.

Parameters

title
The title text
fadeIn
Time in ticks for the title to fade in
stay
Time in ticks for the title to stay on screen
fadeOut
Time in ticks for the title to fade out
ValueTask SetActionBarTextAsync(ChatMessage message);ValueTask SetGamemodeAsync(GameMode gamemode);

SetMovementAbilities(string, MovementAbilities)

void SetMovementAbilities(string id, MovementAbilities abilities);

Grants the player movement abilities under id, replacing an earlier grant with the same id; grants with other ids add up (see MovementAbilities.Combine). Grants aren't saved, and a plugin's are taken back when it unloads.

Parameters

id
The grant's identifier, like ruby:cloud_boots.
abilities
The abilities; negative extra jumps count as none.
ValueTask ShowDialogAsync(DialogElement dialog);ValueTask SpawnParticleAsync(ParticleData data);

StabAsync()

ValueTask StabAsync();

Jabs with the spear in the main hand, like a client's stab, once the attack has recharged.

StopUsingItem()

void StopUsingItem();

Stops using an item without its effect, as when the player picks another hotbar slot.

TeleportToDimensionAsync(string)

Task<bool> TeleportToDimensionAsync(string dimension);

Sends the player to the spawn of a dimension of their world, by its name: the world's own (like minecraft:overworld), vanilla's other dimensions, or a plugin's, like ruby:crystal_world.

Returns

Whether the player was sent: not when their world has no such dimension, or they're dead.

TryStartGliding()

bool TryStartGliding();

Starts gliding, like a client's jump in mid-air: with a glider on the chest or the ability to glide, and out of fluids.

Returns

Whether the player glides.

Task<bool> UpdateChunksAsync(bool unloadAll = false, int distance = 0);ValueTask UpdateDisplayNameAsync(string newDisplayName);ValueTask UpdatePlayerInfoAsync();

UseItemAsync(InteractionHand)

ValueTask UseItemAsync(InteractionHand hand = 0);

Uses the item in hand, like a client's use in the air: through PlayerInteractEventArgs, then the item's behaviour, or the player starts eating, drawing a bow or the like until IPlayer.ReleaseUsingItemAsync.

On this page