Skip to content

API reference Obsidian.API

IServer interface

public interface IServer : IDisposable

In Obsidian.API.

Properties

ReadOnlyMemory<byte> BrandData { get; }ICommandHandler CommandHandler { get; }ServerConfiguration Configuration { get; }ConcurrentDictionary<int, IClient> Connections { get; }

CraftingRecipeRevision

long CraftingRecipeRevision { get; }

The current recipe snapshot's process-local revision, changing whenever it is replaced.

IWorld DefaultWorld { get; }IEventDispatcher EventDispatcher { get; }ConcurrentDictionary<Guid, IPlayer> OnlinePlayers { get; }IOperatorList Operators { get; }int Port { get; }ProtocolVersion Protocol { get; }

RegisteredChannels

HashSet<string> RegisteredChannels { get; }

No longer filled: which channels a connection may use is per connection, see IClient.HasChannel.

IScoreboardManager ScoreboardManager { get; }DateTimeOffset StartTime { get; }int Tps { get; }string Version { get; }IWorldManager WorldManager { get; }

Methods

bool AddPlayer(IPlayer player);

AddServerPlayerAsync(Guid, string, IWorld)

Task<IPlayer> AddServerPlayerAsync(Guid uuid, string username, IWorld world = null);

Creates, loads, and registers a server-side player without opening a network connection.

Parameters

uuid
The player's UUID.
username
The player's username.
world
The world to spawn the player in. Uses IServer.DefaultWorld when null.

BroadcastMessage(ChatMessage)

void BroadcastMessage(ChatMessage message);

Sends a message to all players on this server.

BroadcastMessage(IWorld, ChatMessage)

void BroadcastMessage(IWorld world, ChatMessage message);

Sends a message to all players on the specified world.

IBossBar CreateBossBar(ChatMessage title, float health, BossBarColor color, BossBarDivisionType divisionType, BossBarFlags flags);

EvaluateCrafting(IReadOnlyList<ItemStack>, int)

CraftingEvaluation EvaluateCrafting(IReadOnlyList<ItemStack> grid, int width);

Evaluates a square crafting grid of width 2 or 3, without changing its stacks. Uses the same recipes and matching as the player's grid and crafting table. Returns null when nothing matches.

FindRecipe<TRecipe>(RecipeType<TRecipe>, IReadOnlyList<ItemStack>)

TRecipe FindRecipe<TRecipe>(RecipeType<TRecipe> type, IReadOnlyList<ItemStack> inputs) where TRecipe : class;

Finds the first matching recipe of a plugin's type in the current set, by lexical recipe identifier. Returns null when none matches or the type is unloaded. Do not retain a result across reloads.

IPlayer GetPlayer(Guid uuid);IPlayer GetPlayer(int entityId);IPlayer GetPlayer(string username);

GetRecipe(string)

IRecipe GetRecipe(string identifier);

Gets a detached built-in recipe by its identifier, or null. Custom plugin recipe types use GetRecipes.

GetRecipes<TRecipe>(RecipeType<TRecipe>)

IReadOnlyList<TRecipe> GetRecipes<TRecipe>(RecipeType<TRecipe> type) where TRecipe : class;

The current recipes of a plugin's type, in lexical recipe identifier order, like a machine's screen lists them. Empty when the type is unloaded. Do not retain the recipes across reloads.

GetSavedData<TValue>(SavedDataType<TValue>, Func<TValue>)

SavedData<TValue> GetSavedData<TValue>(SavedDataType<TValue> type, Func<TValue> create);

Gets world-wide data in the default world. Use ILevel.GetSavedData for another world or level.

IsPlayerOnline(Guid)

bool IsPlayerOnline(Guid uuid);

Checks if a player is online.

Parameters

uuid
The uuid you want to check for.

Returns

True if the player is online.

IsPlayerOnline(string)

bool IsPlayerOnline(string username);

Checks if a player is online.

Parameters

username
The username you want to check for.

Returns

True if the player is online.

bool IsWhitelisted(Guid uuid);bool IsWhitelisted(string username);

RegisterRecipes(IRecipe[])

void RegisterRecipes(params IRecipe[] recipes);

Registers recipes, which crafting grids, furnaces and players' recipe books use like vanilla's from now on; online players' books follow. Those a plugin registers through its own server are removed when it unloads.

bool RemovePlayer(IPlayer player);

RemoveServerPlayerAsync(IPlayer)

Task<bool> RemoveServerPlayerAsync(IPlayer player);

Removes a server-side player that was added through IServer.AddServerPlayerAsync: they leave like a network player, once their tick under way has ended.

Returns

Whether the player was online and is leaving. Called from inside a level's tick, or any player's tick, grant or save (the player's own included), the leave finishes after the ticks, without being waited for; adding a player with their name waits for it meanwhile.

Task RunAsync();

TryGetPlayer(Guid, IPlayer)

bool TryGetPlayer(Guid uuid, out IPlayer player);

Tries and gets an online player by uuid.

Parameters

uuid
The uuid of the player
player
The player if found.

Returns

True if a player is found, false if not.

TryGetPlayer(int, IPlayer)

bool TryGetPlayer(int entityId, out IPlayer player);

Tries and gets an online player by username.

Parameters

entityId
The IEntity.EntityId of the player
player
The player if found.

Returns

True if a player is found, false if not.

TryGetPlayer(string, IPlayer)

bool TryGetPlayer(string username, out IPlayer player);

Tries and gets an online player by username.

Parameters

username
The username of the player
player
The player if found.

Returns

True if a player is found, false if not.

On this page