Developer API
On this page(9)
SnProxyUtility exposes a public developer API for other Velocity plugins: queue events, a read-only query service and two extension points. The API lives in the com.sn.proxyutility.api package inside the plugin jar. There is no separate artifact.
Only com.sn.proxyutility.api is a stable, kept contract. Everything else in the jar is obfuscated and internal. Do not call it.
Getting the jar
-
Download the latest release jar.
-
Install it into your local Maven repository:
mvn install:install-file -Dfile=SnProxyUtility-<version>.jar -DgroupId=com.sn \ -DartifactId=SnProxyUtility -Dversion=<version> -Dpackaging=jar -
Depend on it with
providedscope. Never shade it.
Quick start
Declare the dependency in your velocity-plugin.json, or in the dependencies of your @Plugin annotation:
"dependencies": [
{ "id": "snproxyutility", "optional": true }
]Resolve the API when you need it:
SnProxyUtilityAPI api = SnProxyUtilityProvider.get();
if (api != null) {
api.getQueuePosition(player.getUniqueId())
.ifPresent(place -> player.sendMessage(Component.text("Position " + place.position())));
}SnProxyUtility publishes the API when it handles ProxyInitializeEvent and withdraws it on shutdown. Resolve the reference when you need it. Do not cache it.
Master switch
API events can be disabled by the proxy owner with api-events.enabled: false in config.yml. The query service and the extension points stay available either way.
VirtualQueueSendEvent is the one event this switch does not turn off. It is the only answer to a virtual entry you added, so it always fires.
Events
Events are plain Velocity events. Subscribe to them through the proxy EventManager like any proxy event. Velocity delivers them on its event executor, never on a netty thread.
Cancellable events fire before the action. They use the Velocity ResultedEvent model: deny the result to abort the action.
| Event | Fired when | Cancel effect |
|---|---|---|
QueueJoinEvent | Before a player joins a server's queue: /queue, an intercepted direct connection, an auto-reconnect rejoin, or a queue bypass. Not fired when nothing would change. | The player is not queued and not moved out of a queue they already wait in. SnProxyUtility sends no message, so tell the player yourself. |
Notification events fire after the fact. They cannot be cancelled.
| Event | Fired when | Thread |
|---|---|---|
QueueLeaveEvent | After a player left a queue with /leavequeue. Other ways out of a queue do not fire it. | Velocity event executor (async) |
VirtualQueueSendEvent | A virtual queue entry reached the front of an open queue and was removed. See Virtual queue entries. | Velocity event executor (async) |
VirtualQueueDropEvent | The queue dropped a virtual entry on its own. See Virtual queue entries. | Velocity event executor (async) |
Payload getters:
| Event | Getters |
|---|---|
QueueJoinEvent | getPlayer(), getServer() (Velocity server name), isReconnect(), getResult() |
QueueLeaveEvent | getPlayer(), getServer() (Velocity server name) |
VirtualQueueSendEvent | getOwner() (plugin id), getServer() (Velocity server name), getId(), getName() |
VirtualQueueDropEvent | getOwner(), getServer(), getId(), getName(), getReason() (SERVER_REMOVED or QUEUE_DISABLED) |
Listen like any Velocity event:
@Subscribe
public void onQueueJoin(QueueJoinEvent event) {
if (event.getServer().equalsIgnoreCase("event") && !event.getPlayer().hasPermission("my.event")) {
event.setResult(ResultedEvent.GenericResult.denied());
event.getPlayer().sendMessage(Component.text("The event server is closed."));
}
}Event payloads are read-only. The result is the only thing a listener can change.
Query service
Every method reads in-memory state, never blocks and is safe from any thread. Server names match without regard to case. Results are immutable snapshots.
| Method | Returns | Notes |
|---|---|---|
getApiVersion() | String | The API contract version. |
isModuleEnabled(String moduleId) | boolean | Use the MODULE_RESTART, MODULE_MOTD, MODULE_COMMAND_BLOCKER, MODULE_QUEUE and MODULE_MAINTENANCE constants. |
getQueuedServers() | List<String> | Servers with a queue, in queue.yml order. Empty while the queue module is off. |
getQueue(String server) | Optional<QueueView> | Empty when the server has no queue or the queue module is off. |
getQueuePosition(UUID player) | Optional<QueuePositionView> | Empty when the player waits in no queue. |
getNextRestart() | Optional<Instant> | The next planned restart, including a manual countdown. Empty when none is planned or the restart module is off. |
isMaintenanceActive() | boolean | True while the network is in maintenance: the maintenance module is on and its mode is on. Follows /maintenance on|off and /snproxy reload at once. Added in API 1.2.0. |
Views:
| View | Components |
|---|---|
QueueView | server, displayName, status, lanes, size |
QueuePositionView | server, displayName, lane, position, total, status |
status is one of OPEN, WHITELIST, FULL, OFFLINE or PAUSED. lane and position start at 1. Position 1 of every lane leaves with the next batch.
QueueView.size and QueuePositionView.total count virtual entries too. getVirtualQueueSize(server) tells you how many of them are virtual.
Virtual queue entries
A virtual entry is a place in a server's queue for something that is not a connected player. A network bot that you inject straight on a backend is a typical case. The entry queues like a player, so real players see it in the size and in their position.
| Method | Returns | Notes |
|---|---|---|
enqueueVirtual(Object plugin, String server, UUID id, String name, int priority) | Optional<QueueEntryHandle> | Empty when the queue module is off, the server has no queue, or a connected player already has this id. |
cancelVirtualEntries(Object plugin) | int | Cancels every waiting entry of your plugin and returns how many there were. |
getVirtualQueueSize(String server) | int | How many places of the queue are virtual. |
Pass your plugin instance as plugin. It must be a registered Velocity plugin, or the call throws IllegalArgumentException. The entry belongs to your plugin id. The name is only used in logs and events. Players never see it.
priority uses the same scale as the priority tiers in queue.yml. Zero queues like a player without a tier. A higher value goes ahead of a lower one. Equal values keep arrival order.
The QueueEntryHandle follows the entry:
| Member | Notes |
|---|---|
getId(), getName(), getServer(), getOwner() | What you passed, with the server as Velocity spells it. |
getState() | WAITING, SENT or CANCELLED. |
isActive() | True while the state is WAITING. |
getPosition() | Optional<QueuePositionView>, empty once the entry is not waiting. |
cancel() | Removes the entry. Returns true only if it was waiting. Fires no event. |
What the queue does with it
- A virtual entry is ordered, laned and counted like a player of the same priority.
- SnProxyUtility never connects anything for it.
- When the entry reaches the front and the queue is
OPEN, the queue removes it and firesVirtualQueueSendEvent. You spawn the bot yourself. - A sent entry uses one place of the batch. With
limit-to-free-slotsit also uses one free slot until the next ping. - While the queue is
WHITELIST, the entry keeps its place. Nothing can be probed for it. - While the queue is
FULL,OFFLINE(a restarting server included) orPAUSED, nothing leaves. - Adding an id that already waits cancels the old entry and places the new one. Re-adding is safe.
- Entries are not saved. After a proxy restart you add them again.
VirtualQueueDropEventfires when the server leavesqueue.ymlor the queue module is switched off. A reload that keeps the server keeps its entries.- Velocity cannot unload a plugin at runtime. Call
cancelVirtualEntrieswhen you stop serving your entries. SnProxyUtility drops everything when the proxy shuts down.
The events reach every listener. Compare getOwner() with your plugin id and ignore the rest.
@Subscribe
public void onSend(VirtualQueueSendEvent event) {
if (!event.getOwner().equals("mybots")) {
return;
}
spawnBot(event.getId(), event.getName(), event.getServer());
}Server list player count
Add players to the online count of the server list with registerOnlineCountContribution.
| Method | Returns | Notes |
|---|---|---|
registerOnlineCountContribution(Object plugin, IntSupplier extraOnline) | OnlineCountContribution | Adds the supplied number to the online count of every ping. |
OnlineCountContribution has unregister() and isRegistered().
The contribution only applies while the MOTD module is enabled. With players.online.mode: REAL the reported count is the proxy count plus every contribution. With OFFSET the configured value is added on top. With STATIC the contributions are ignored. %online% shows the reported count. %real_online% stays the proxy count.
The supplier runs on a netty thread, once per server list ping. Return at once. Read a field or an atomic. Never block, query a database or call the scheduler.
A negative value counts as zero. A supplier that throws counts as zero and is logged once. A registration survives MOTD reloads. SnProxyUtility drops all of them when the proxy shuts down.
Versioning
Call getApiVersion() for the API contract version. It is independent of the plugin version. Additions bump the minor component. Existing members are never removed or changed; deprecated members keep working.
| API version | Plugin version | Added |
|---|---|---|
| 1.2.0 | 1.10.0 | isMaintenanceActive(), MODULE_MAINTENANCE |
| 1.1.0 | 1.7.0 | Virtual queue entries, online count contributions |
| 1.0.0 | 1.1.0 | Query service and queue events |