feat: add plugin support

This commit is contained in:
Alexander Medvedev committed 2026-09-08 17:33:35 +02:00
1 parent 9ca11c175f
commit a100ba9549
29 files changed
+3496 -57

No files matched your search

+6
View File
@@ -0,0 +1,6 @@
interface command {
use types.{command-sender};
/// Reply to a command sender
reply: func(sender: command-sender, message: string);
}
+15
View File
@@ -0,0 +1,15 @@
interface context {
use types.{event-priority};
use event.{event-type};
resource context {
/// Register an event listener for an event type with priority
register-event: func(handler-id: u32, event-type: event-type, priority: event-priority);
/// Register a proxy command
register-command: func(command-id: u32, name: string, description: string, aliases: list<string>, permission: option<string>);
/// Get path to the plugin's data folder (e.g. plugins/data/<plugin-name>)
get-data-folder: func() -> string;
}
}
+106
View File
@@ -0,0 +1,106 @@
interface event {
use types.{event-priority};
enum event-type {
proxy-ping,
player-pre-login,
player-login,
player-join,
server-connect,
server-connected,
player-disconnect,
player-chat,
player-command,
plugin-message,
}
record proxy-ping-event {
client-ip: string,
protocol-version: u32,
virtual-host: string,
motd: string,
max-players: u32,
online-players: u32,
version-name: string,
}
record player-pre-login-event {
client-ip: string,
username: string,
protocol-version: u32,
virtual-host: string,
cancelled: bool,
cancel-reason: option<string>,
}
record player-login-event {
uuid: string,
username: string,
client-ip: string,
cancelled: bool,
cancel-reason: option<string>,
}
record player-join-event {
uuid: string,
username: string,
client-ip: string,
initial-server: string,
}
record server-connect-event {
uuid: string,
username: string,
current-server: option<string>,
target-server: string,
cancelled: bool,
cancel-reason: option<string>,
}
record server-connected-event {
uuid: string,
username: string,
server-name: string,
}
record player-disconnect-event {
uuid: string,
username: string,
last-server: option<string>,
}
record player-chat-event {
uuid: string,
username: string,
message: string,
cancelled: bool,
}
record player-command-event {
uuid: string,
username: string,
command: string,
cancelled: bool,
}
record plugin-message-event {
channel: string,
data: list<u8>,
player-uuid: option<string>,
server-name: option<string>,
cancelled: bool,
}
variant event {
proxy-ping(proxy-ping-event),
player-pre-login(player-pre-login-event),
player-login(player-login-event),
player-join(player-join-event),
server-connect(server-connect-event),
server-connected(server-connected-event),
player-disconnect(player-disconnect-event),
player-chat(player-chat-event),
player-command(player-command-event),
plugin-message(plugin-message-event),
}
}
+11
View File
@@ -0,0 +1,11 @@
interface logging {
enum level {
trace,
debug,
info,
warn,
error,
}
log: func(level: level, message: string);
}
+9
View File
@@ -0,0 +1,9 @@
interface metadata {
record plugin-metadata {
name: string,
version: string,
authors: list<string>,
description: option<string>,
dependencies: list<string>,
}
}
+34
View File
@@ -0,0 +1,34 @@
package vine:plugin@0.1.0;
world plugin {
use context.{context};
use event.{event};
use types.{command-sender};
use metadata.{plugin-metadata};
import logging;
import proxy;
import context;
import command;
/// Called once by the host to initialize the plugin instance.
export init-plugin: func();
/// Called when the plugin is loaded into the proxy.
export on-load: func(ctx: context) -> result<_, string>;
/// Called when the plugin is being unloaded.
export on-unload: func(ctx: context) -> result<_, string>;
/// Provides plugin metadata to the proxy host.
export get-metadata: func() -> plugin-metadata;
/// Dispatches an event to the plugin handler.
export handle-event: func(handler-id: u32, evt: event) -> event;
/// Dispatches a command execution to the plugin.
export handle-command: func(command-id: u32, sender: command-sender, args: list<string>) -> result<s32, string>;
/// Dispatches command suggestion / tab completion to the plugin.
export handle-command-suggestion: func(command-id: u32, sender: command-sender, args: list<string>) -> list<string>;
}
+33
View File
@@ -0,0 +1,33 @@
interface proxy {
use types.{player-info, server-info};
/// Returns the total number of connected players.
get-player-count: func() -> u32;
/// Returns a list of all connected players.
get-players: func() -> list<player-info>;
/// Returns information for a specific player by username.
get-player-by-name: func(username: string) -> option<player-info>;
/// Returns information for a specific player by UUID string.
get-player-by-uuid: func(uuid: string) -> option<player-info>;
/// Returns a list of configured backend servers.
get-servers: func() -> list<server-info>;
/// Broadcasts a system chat message to all connected players and console.
broadcast: func(message: string);
/// Sends a system chat message to a specific player by UUID.
send-message: func(player-uuid: string, message: string) -> bool;
/// Disconnects/kicks a player by UUID with the given reason.
disconnect-player: func(player-uuid: string, reason: string) -> bool;
/// Requests switching/connecting a player to a backend server.
connect-player: func(player-uuid: string, server-name: string) -> bool;
/// Sends a plugin message / custom payload to a player.
send-plugin-message: func(player-uuid: string, channel: string, data: list<u8>) -> bool;
}
+35
View File
@@ -0,0 +1,35 @@
interface types {
record player-info {
uuid: string,
username: string,
current-server: string,
client-ip: string,
protocol-version: u32,
}
record server-info {
name: string,
address: string,
player-count: u32,
}
enum event-priority {
lowest,
low,
normal,
high,
highest,
monitor,
}
enum command-sender-type {
console,
player,
}
record command-sender {
sender-type: command-sender-type,
name: string,
player-uuid: option<string>,
}
}