### Get Proxy Version Example Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/01-proxy-server-api.md Example of how to retrieve and display the proxy version. ```java ProxyVersion version = proxy.getVersion(); System.out.println("Velocity " + version.getVersion()); ``` -------------------------------- ### Complete Plugin Messaging Example Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/06-server-connections-and-messaging.md A full example demonstrating channel creation, registration, sending messages to players, receiving messages, and unregistering channels upon proxy shutdown. ```java public class MessagingPlugin { private ProxyServer proxy; private ChannelIdentifier channel; @Subscribe public void onProxyInitialize(ProxyInitializeEvent event) { this.proxy = event.getServer(); // Create and register channel this.channel = proxy.getChannelRegistrar().create("mynamespace", "mydata"); proxy.getChannelRegistrar().register(channel); } @Subscribe public void onLogin(LoginEvent event) { Player player = event.getPlayer(); // Send initial message to player's client proxy.getScheduler().buildTask(this, () -> { byte[] greeting = "Welcome!".getBytes(StandardCharsets.UTF_8); player.sendPluginMessage(channel, greeting); }).delay(1, TimeUnit.SECONDS).schedule(); } @Subscribe public void onPluginMessage(PluginMessageEvent event) { if (!event.getIdentifier().equals(channel)) { return; } String message = new String(event.getData(), StandardCharsets.UTF_8); System.out.println("Received plugin message: " + message); } @Subscribe public void onProxyShutdown(ProxyShutdownEvent event) { // Unregister channel proxy.getChannelRegistrar().unregister(channel); } } ``` -------------------------------- ### Bandwidth Management Example in Java Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/09-advanced-topics.md Implement bandwidth management by subscribing to `ServerConnectedEvent`. This example shows how to check player latency and potentially apply rate limiting or other adjustments. ```java @Subscribe public void onServerConnect(ServerConnectedEvent event) { Player player = event.getPlayer(); // Apply rate limiting per player if (player.getPing() > 200) { // High latency - might reduce packet frequency } } ``` -------------------------------- ### Registering Commands on Proxy Initialization Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/08-event-catalog.md Subscribe to ProxyInitializeEvent to perform setup tasks when the Velocity proxy starts. This example shows how to register a custom command. ```java import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.proxy.ProxyServer; public class ProxyInitializationListener { @Subscribe public void onProxyInitialize(ProxyInitializeEvent event) { ProxyServer proxy = event.getServer(); // Register commands proxy.getCommandManager().register( proxy.getCommandManager().metaBuilder("mycommand").plugin(this).build(), new MyCommand() ); } } ``` -------------------------------- ### Basic Plugin Setup Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/00-index.md This is the main class for a Velocity plugin. It registers commands, schedules tasks, and registers event listeners upon proxy initialization. It also includes an example of handling a login event. ```java import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.event.player.LoginEvent; import com.velocitypowered.api.plugin.Plugin; import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.command.CommandManager; import com.velocitypowered.api.scheduler.Scheduler; import com.velocitypowered.api.event.EventManager; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import java.time.Duration; @Plugin(id = "myplugin", name = "My Plugin", version = "1.0", authors = {"you"}) public class MyPlugin { private ProxyServer proxy; @Subscribe public void onProxyInitialize(ProxyInitializeEvent event) { this.proxy = event.getServer(); // Register commands registerCommands(); // Schedule tasks scheduleTasks(); // Register event listeners registerEvents(); } private void registerCommands() { CommandManager cm = proxy.getCommandManager(); cm.register( cm.metaBuilder("mycommand").plugin(this).build(), new MyCommand() ); } private void scheduleTasks() { Scheduler scheduler = proxy.getScheduler(); scheduler.buildTask(this, () -> { System.out.println("Periodic task"); }).repeat(Duration.ofSeconds(30)).schedule(); } private void registerEvents() { EventManager em = proxy.getEventManager(); em.register(this, this); } @Subscribe public void onLogin(LoginEvent event) { event.getPlayer().sendMessage( Component.text("Welcome!", NamedTextColor.GREEN) ); } } ``` -------------------------------- ### Shutdown Proxy with Reason Example Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/01-proxy-server-api.md Example of shutting down the proxy with a custom kick message. ```java Component reason = Component.text("Server is shutting down for maintenance"); proxy.shutdown(reason); ``` -------------------------------- ### Install CMake on macOS Source: https://github.com/papermc/velocity/blob/dev/3.0.0/native/README.md Installs the CMake build system on macOS using Homebrew, a prerequisite for building native libraries on this platform. ```bash brew install cmake ``` -------------------------------- ### matchServer(String partialName) Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/01-proxy-server-api.md Matches all servers whose names start with the provided partial name. ```APIDOC ## matchServer(String partialName) ### Description Matches all servers whose names start with the provided partial name. ### Signature ```java Collection matchServer(String partialName) ``` ### Parameters #### Path Parameters - **partialName** (String) - Required - The partial name to check for ### Return Type `Collection` - All servers whose names start with the partial name ``` -------------------------------- ### Redirect Player on Server Pre-Connect Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/08-event-catalog.md Fired before a player connects to a server, allowing redirection. This example redirects players to a 'maintenance' server if available. ```java @Subscribe public void onServerPreConnect(ServerPreConnectEvent event) { Player player = event.getPlayer(); RegisteredServer intendedServer = event.getOriginalServer(); // Redirect players to a specific server Optional maintenance = proxy.getServer("maintenance"); if (maintenance.isPresent()) { event.setResult(ServerResult.allowed(maintenance.get())); } } ``` -------------------------------- ### Register a SimpleCommand Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/04-command-system.md Register a SimpleCommand with its associated CommandMeta. This example shows a basic teleport command that sends messages to the source. ```java SimpleCommand command = invocation -> { if (invocation.arguments().length == 0) { invocation.source().sendMessage(Component.text("Usage: /spawn")); return; } invocation.source().sendMessage(Component.text("Teleporting to spawn...")); }; CommandMeta meta = commandManager.metaBuilder("spawn") .aliases("respawn") .plugin(plugin) .build(); commandManager.register(meta, command); ``` -------------------------------- ### Get a Registered Server by Name Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/01-proxy-server-api.md Retrieves a registered server instance by its name. The search is case-insensitive. Use this to get a specific server for operations. ```java Optional server = proxy.getServer("survival"); if (server.isPresent()) { // Use the server } ``` -------------------------------- ### Velocity Configuration File Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/09-advanced-topics.md Example of the default velocity.toml configuration file, showing settings for the server, query, forwarding, and advanced options. ```toml [server] bind = "0.0.0.0:25577" motd = "A Velocity Proxy" max-player-count = 100 online-mode = true prevent-client-vpn-bypass = false [query] enabled = false port = 25577 [forwarding] mode = "modern" [advanced] compression-threshold = 256 compression-level = -1 ``` -------------------------------- ### Preventing Command Execution Based on Source Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/08-event-catalog.md Subscribe to CommandExecuteEvent to intercept commands before they are executed. This example denies commands starting with 'stop' unless executed by the console. ```java import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.command.CommandExecuteEvent; import com.velocitypowered.api.command.CommandResult; import com.velocitypowered.api.event.PostOrder; public class CommandListener { @Subscribe(priority = PostOrder.FIRST) public void onCommand(CommandExecuteEvent event) { if (event.getCommand().startsWith("stop")) { // Only allow console to stop if (!event.getCommandSource().isConsole()) { event.setResult(CommandResult.denied()); } } } } ``` -------------------------------- ### Get Proxy Version Information Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/07-types-and-utilities.md Retrieves and prints the vendor, name, and version of the proxy. Requires an initialized proxy instance. ```java ProxyVersion version = proxy.getVersion(); System.out.println(version.getVendor() + " " + version.getName() + " " + version.getVersion()); ``` -------------------------------- ### ServerInfo.getName() Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/06-server-connections-and-messaging.md Gets the name of the server. ```APIDOC ## ServerInfo.getName() ### Description Gets the name of the server. ### Signature ```java final String getName() ``` ### Return Type `String` - The server name ``` -------------------------------- ### Get Command Suggestions Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/04-command-system.md Asynchronously retrieves command completion suggestions for a partial command line. Does not include tooltips. ```java CompletableFuture> offerSuggestions(CommandSource source, String cmdLine) ``` -------------------------------- ### ServerInfo.getAddress() Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/06-server-connections-and-messaging.md Gets the address of the server. ```APIDOC ## ServerInfo.getAddress() ### Description Gets the address of the server. ### Signature ```java final InetSocketAddress getAddress() ``` ### Return Type `InetSocketAddress` - The server address and port ### Example ```java InetSocketAddress addr = serverInfo.getAddress(); System.out.println("Server: " + addr.getHostName() + ":" + addr.getPort()); ``` ``` -------------------------------- ### Get Console Command Source Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/01-proxy-server-api.md Retrieve a CommandSource for console-initiated commands. ```java ConsoleCommandSource getConsoleCommandSource() ``` -------------------------------- ### Schedule task with delay and repeat Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/05-scheduler-and-plugins.md This example demonstrates scheduling a task that first waits for a delay and then repeats at a specified interval. It also shows how to cancel the scheduled task. ```java ScheduledTask task = scheduler.buildTask(plugin, () -> { System.out.println("Running"); }) .delay(1, TimeUnit.SECONDS) .repeat(10, TimeUnit.SECONDS) .schedule(); // Later: cancel the task task.cancel(); ``` -------------------------------- ### Use Adventure Key in Player Data Storage Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/07-types-and-utilities.md An example of using a created Adventure Key to store player-specific data, such as cookies. ```java Key cookieId = Key.key("mymod", "playerdata"); player.storeCookie(cookieId, data); ``` -------------------------------- ### Get Proxy Configuration Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/01-proxy-server-api.md Retrieve the ProxyConfig instance containing proxy configuration details. ```java ProxyConfig getConfiguration() ``` -------------------------------- ### Detect Modded Clients Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/09-advanced-topics.md Implement `PlayerModInfoResponseEvent` to inspect `ModInfo` and identify specific mods like OptiFine installed on the client. ```java @Subscribe public void onModInfo(PlayerModInfoResponseEvent event) { ModInfo modInfo = event.getMods(); Player player = event.getPlayer(); System.out.println("Client: " + modInfo.getType()); for (ModInfo.Mod mod : modInfo.getMods()) { System.out.println("Mod: " + mod.getId() + " v" + mod.getVersion()); // Check for specific mods if (mod.getId().equals("optifine")) { logger.info("OptiFine user detected"); } } } ``` -------------------------------- ### matchPlayer(String partialName) Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/01-proxy-server-api.md Matches all players whose names start with the provided partial name. ```APIDOC ## matchPlayer(String partialName) ### Description Matches all players whose names start with the provided partial name. ### Method GET (conceptual) ### Endpoint N/A (Java API) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```java Collection matches = proxy.matchPlayer("Steve"); // Returns all players with usernames starting with "Steve" ``` ### Response #### Success Response - **matches** (Collection) - All players whose names start with the partial name ``` -------------------------------- ### Get All Registered Servers Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/01-proxy-server-api.md Retrieves all servers currently registered with the proxy. Useful for iterating through available servers or displaying a list. ```java Collection servers = proxy.getAllServers(); for (RegisteredServer server : servers) { System.out.println("Server: " + server.getServerInfo().getName()); } ``` -------------------------------- ### Subscribing to Velocity Events Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/00-index.md Provides examples of how to subscribe to events within the Velocity plugin system using the `@Subscribe` annotation. Different priorities can be specified. ```java @Subscribe public void onProxyInitialize(ProxyInitializeEvent event) { } @Subscribe(priority = PostOrder.EARLY) public void onLogin(LoginEvent event) { } ``` -------------------------------- ### Get Brigadier Command Suggestions Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/04-command-system.md Asynchronously retrieves Brigadier-compatible command suggestions, including tooltips. Useful for integrated command parsing. ```java CompletableFuture offerBrigadierSuggestions(CommandSource source, String cmdLine) ``` -------------------------------- ### Choose Initial Server for New Players Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/08-event-catalog.md Fired when choosing the initial server for a new player. This snippet routes new players to a 'tutorial' server if it exists. ```java @Subscribe(priority = PostOrder.EARLY) public void onChooseServer(PlayerChooseInitialServerEvent event) { // Route new players to tutorial server Optional tutorial = proxy.getServer("tutorial"); if (tutorial.isPresent()) { event.setInitialServer(tutorial.get()); } } ``` -------------------------------- ### Get Player Settings Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/02-player-api.md Retrieves the player's client settings. This object contains various preferences set by the player's client. ```java PlayerSettings getPlayerSettings() ``` -------------------------------- ### Build and Run Velocity Test Proxy Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/09-advanced-topics.md Build the Velocity project using Gradle and then run the generated Velocity proxy JAR file. Ensure you have Java installed and the build process completes successfully. ```bash ./gradlew build java -jar proxy/build/libs/velocity-*-all.jar ``` -------------------------------- ### Handle Player Login Event in Velocity Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/07-types-and-utilities.md A complete example of handling the `LoginEvent` in Velocity to access and process player information, client settings, mod details, and protocol versions before sending a welcome message. ```java @Subscribe public void onLogin(LoginEvent event) { Player player = event.getPlayer(); // Access player info GameProfile profile = player.getGameProfile(); System.out.println("Player: " + profile.getName()); System.out.println("UUID: " + player.getUniqueId()); // Check client settings if (player.hasSentPlayerSettings()) { PlayerSettings settings = player.getPlayerSettings(); System.out.println("Locale: " + settings.getLocale()); System.out.println("Render distance: " + settings.getViewDistance()); } // Check for mods Optional mods = player.getModInfo(); if (mods.isPresent()) { System.out.println("Client type: " + mods.get().getType()); } // Check protocol version ProtocolVersion version = player.getProtocolVersion(); if (version.isGreaterThanOrEqual(ProtocolVersion.MINECRAFT_1_20_5)) { // Send 1.20.5+ specific features } // Send welcome message Component welcome = Component.text("Welcome ").color(NamedTextColor.GREEN) .append(Component.text(player.getUsername(), NamedTextColor.AQUA)); player.sendMessage(welcome); } ``` -------------------------------- ### Build macOS Native Libraries Source: https://github.com/papermc/velocity/blob/dev/3.0.0/native/README.md Builds native libraries for macOS aarch64. Assumes CMake is installed. x86_64 is not tested but expected to work. ```bash ./build-support/compile-macos.sh ``` -------------------------------- ### Get Pending Resource Packs Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/02-player-api.md Retrieves the resource packs that the player is currently downloading or is prompted to install. This method is available for Minecraft versions 1.20.3 and later. ```APIDOC ## getPendingResourcePacks() ### Description Gets the resource packs the player is currently downloading or is prompted to install (1.20.3+). ### Method Signature ```java @NotNull Collection getPendingResourcePacks() ``` ### Return Type `Collection` - Collection of pending resource packs ``` -------------------------------- ### Implement a SimpleCommand in Java Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/04-command-system.md Demonstrates a full implementation of a custom command using the SimpleCommand interface. Includes permission checks, argument parsing, and player targeting. This is useful for creating custom commands that interact with players and servers. ```java public class TeleportCommand implements SimpleCommand { private final ProxyServer proxy; public TeleportCommand(ProxyServer proxy) { this.proxy = proxy; } @Override public void execute(Invocation invocation) { CommandSource source = invocation.getSource(); String[] args = invocation.getArguments(); // Check permission if (!source.hasPermission("teleport.command")) { source.sendMessage(Component.text("No permission", NamedTextColor.RED)); return; } // Check if player if (!(source instanceof Player)) { source.sendMessage(Component.text("Must be a player")); return; } Player player = (Player) source; if (args.length < 1) { player.sendMessage(Component.text("Usage: /tp ")); return; } Optional target = proxy.getPlayer(args[0]); if (!target.isPresent()) { player.sendMessage(Component.text("Player not found")); return; } target.get().getCurrentServer().ifPresent(server -> { player.createConnectionRequest(server.getServer()).connect(); }); } } ``` ```java // In plugin initialization: public void onProxyInitialize(ProxyInitializeEvent event) { CommandManager cmdManager = proxy.getCommandManager(); cmdManager.register( cmdManager.metaBuilder("tp") .aliases("teleport") .plugin(this) .build(), new TeleportCommand(proxy) ); } ``` -------------------------------- ### Get Pending Resource Packs Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/02-player-api.md Retrieves a collection of resource packs that the player is currently downloading or has been prompted to install. This functionality is available from Minecraft version 1.20.3 onwards. ```java @NotNull Collection getPendingResourcePacks() ``` -------------------------------- ### Initialize Plugin and Register Commands/Tasks Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/05-scheduler-and-plugins.md This code demonstrates how to initialize a plugin upon proxy startup. It registers a custom command and schedules a one-time task to run after initialization. Ensure the `ProxyInitializeEvent` is subscribed to. ```java public class MyPlugin { private ProxyServer proxy; @Subscribe public void onProxyInitialize(ProxyInitializeEvent event) { this.proxy = event.getServer(); // Register commands proxy.getCommandManager().register( proxy.getCommandManager().metaBuilder("mycommand").plugin(this).build(), new MyCommand() ); // Schedule tasks proxy.getScheduler().buildTask(this, () -> { System.out.println("Plugin initialized"); }).schedule(); } @Subscribe public void onProxyShutdown(ProxyShutdownEvent event) { System.out.println("Plugin shutting down"); // Cleanup is automatic for scheduled tasks } } ``` -------------------------------- ### RegisteredServer Interface Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/06-server-connections-and-messaging.md Represents a server registered with the proxy and provides methods to interact with it, such as retrieving server information, sending plugin messages, getting connected players, and pinging the server. ```APIDOC ## RegisteredServer Interface Represents a server registered with the proxy and can be used to send data to it. **Location:** `com.velocitypowered.api.proxy.server.RegisteredServer` ### Key Methods **getServerInfo()** - Returns the ServerInfo for this registered server **sendPluginMessage(ChannelIdentifier, byte[])** - Sends a plugin message to the server **getPlayersConnected()** - Returns all players connected to this server **ping()** - Pings the server and returns latency ``` -------------------------------- ### Create and Send Resource Pack Offer Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/07-types-and-utilities.md Builds a ResourcePackInfo object with optional hash, prompt, and force settings, then sends it to the player. Ensure the URL is valid and the hash (if provided) is correct. ```java ResourcePackInfo pack = proxy.createResourcePackBuilder( "https://example.com/pack.zip") .setHash(sha1HashBytes) .setPrompt(Component.text("Accept our resource pack?")) .setShouldForce(false) .build(); player.sendResourcePackOffer(pack); ``` -------------------------------- ### Create Adventure Keys Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/07-types-and-utilities.md Demonstrates various ways to create namespaced keys using the `Key.key()` method. Useful for identifying game elements like blocks, items, or custom data. ```java Key key = Key.key("namespace", "path"); ``` ```java Key key = Key.key("namespace:path"); ``` ```java Key key = Key.key("minecraftpath"); // Defaults to minecraft namespace ``` -------------------------------- ### offerSuggestions Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/04-command-system.md Asynchronously collects completion suggestions for a partial command line, without tooltips. Returns a CompletableFuture containing a list of suggestion strings. ```APIDOC ## offerSuggestions(CommandSource source, String cmdLine) ### Description Asynchronously collects completion suggestions for a partial command line (without tooltips). ### Method Signature ```java CompletableFuture> offerSuggestions(CommandSource source, String cmdLine) ``` ### Parameters #### Path Parameters * **source** (CommandSource) - Required - The command source * **cmdLine** (String) - Required - The partially completed command ### Return Type `CompletableFuture>` - List of suggestion strings ``` -------------------------------- ### Handle Plugin Messages Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/00-index.md Demonstrates how to register a channel, send plugin messages, and listen for incoming messages on that channel. ```java // Register channel ChannelIdentifier channel = proxy.getChannelRegistrar() .create("mynamespace", "data"); // Send message player.sendPluginMessage(channel, data); // Listen for responses @Subscribe public void onPluginMessage(PluginMessageEvent event) { if (event.getIdentifier().equals(channel)) { byte[] data = event.getData(); // Process... } } ``` -------------------------------- ### Documentation Structure Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/README.md This tree outlines the logical reading order of the Velocity API documentation, starting with the index and progressing through various modules like player management, events, and commands. ```markdown 00-index.md ← Start here ├── 01-proxy-server-api.md (Main entry point) ├── 02-player-api.md (Player management) ├── 03-event-system.md (Events) ├── 04-command-system.md (Commands) ├── 05-scheduler-and-plugins.md (Task scheduling) ├── 06-server-connections-and-messaging.md (Servers & messaging) ├── 07-types-and-utilities.md (Data types) ├── 08-event-catalog.md (All events) └── 09-advanced-topics.md (Best practices & advanced) ``` -------------------------------- ### Get Proxy Version Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/01-proxy-server-api.md Retrieve the ProxyVersion information for the proxy. ```java ProxyVersion getVersion() ``` -------------------------------- ### Read Custom Plugin Configuration Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/09-advanced-topics.md Demonstrates how plugins can read their own custom configuration files from the plugins directory. Ensure the file exists before attempting to read its content. ```java // Custom plugin configuration Path configPath = Paths.get("plugins", "myplugin", "config.conf"); if (Files.exists(configPath)) { String configContent = new String(Files.readAllBytes(configPath)); // Parse configuration } ``` -------------------------------- ### Get Scheduler Instance Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/01-proxy-server-api.md Retrieve the Scheduler for scheduling tasks. ```java Scheduler getScheduler() ``` -------------------------------- ### Get PluginManager Instance Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/01-proxy-server-api.md Retrieve the PluginManager for managing plugins. ```java PluginManager getPluginManager() ``` -------------------------------- ### Create ServerInfo Object Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/06-server-connections-and-messaging.md Instantiates a new ServerInfo object with a given name and socket address. Use this to define a server that players can connect to. ```java ServerInfo survivalServer = new ServerInfo( "survival", new InetSocketAddress("survival.example.com", 25565) ); ``` -------------------------------- ### Get Tab List Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/02-player-api.md Retrieves the player's tab list. ```APIDOC ## getTabList() ### Description Returns the player's tab list. ### Method Signature ```java TabList getTabList() ``` ### Return Type `TabList` - The player's tab list ### Request Example ```java TabList tabList = player.getTabList(); ``` ``` -------------------------------- ### getServer(String name) Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/01-proxy-server-api.md Retrieves a registered server instance by its name. The search is case-insensitive. ```APIDOC ## getServer(String name) ### Description Retrieves a registered server instance by its name. The search is case-insensitive. ### Signature ```java Optional getServer(String name) ``` ### Parameters #### Path Parameters - **name** (String) - Required - The name of the server (case-insensitive) ### Return Type `Optional` - An Optional containing the registered server if found ### Example ```java Optional server = proxy.getServer("survival"); if (server.isPresent()) { // Use the server } ``` ``` -------------------------------- ### Get EventManager Instance Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/01-proxy-server-api.md Retrieve the EventManager for registering event listeners. ```java EventManager getEventManager() ``` -------------------------------- ### Configuration and State Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/01-proxy-server-api.md Retrieve proxy configuration, version, bound address, and console command source. ```APIDOC ## getConfiguration() ### Description Gets the ProxyConfig instance containing proxy configuration. ### Method ```java ProxyConfig getConfiguration() ``` ### Return Type `ProxyConfig` — The proxy configuration ``` ```APIDOC ## getVersion() ### Description Returns the version of the proxy. ### Method ```java ProxyVersion getVersion() ``` ### Return Type `ProxyVersion` — The proxy version information ### Example ```java ProxyVersion version = proxy.getVersion(); System.out.println("Velocity " + version.getVersion()); ``` ``` ```APIDOC ## getBoundAddress() ### Description Gets the address that this proxy is bound to. This does not necessarily indicate the external IP address of the proxy. ### Method ```java InetSocketAddress getBoundAddress() ``` ### Return Type `InetSocketAddress` — The address the proxy is bound to ``` ```APIDOC ## getConsoleCommandSource() ### Description Returns a CommandSource instance that can be used to determine if a command is being invoked by the console or a console-like executor. ### Method ```java ConsoleCommandSource getConsoleCommandSource() ``` ### Return Type `ConsoleCommandSource` — The console command source ``` -------------------------------- ### Get CommandManager Instance Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/01-proxy-server-api.md Retrieve the CommandManager to register and execute commands. ```java CommandManager getCommandManager() ``` -------------------------------- ### Get ChannelRegistrar Instance Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/01-proxy-server-api.md Retrieve the ChannelRegistrar for managing plugin messaging channels. ```java ChannelRegistrar getChannelRegistrar() ``` -------------------------------- ### Get Player List Footer Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/02-player-api.md Retrieves the player's player list footer. ```APIDOC ## getPlayerListFooter() ### Description Returns the player's player list footer. ### Method Signature ```java Component getPlayerListFooter() ``` ### Return Type `Component` - The player's player list footer ``` -------------------------------- ### Create a Raw Registered Server Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/01-proxy-server-api.md Creates a `RegisteredServer` object without integrating it into the proxy's internal server map. This is typically for advanced use cases where manual management is required. ```java RegisteredServer server = proxy.createRawRegisteredServer(info); ``` -------------------------------- ### createRawRegisteredServer(ServerInfo server) Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/01-proxy-server-api.md Creates a raw RegisteredServer without tying it into the internal server map. ```APIDOC ## createRawRegisteredServer(ServerInfo server) ### Description Creates a raw RegisteredServer without tying it into the internal server map. ### Signature ```java RegisteredServer createRawRegisteredServer(ServerInfo server) ``` ### Parameters #### Path Parameters - **server** (ServerInfo) - Required - The server information ### Return Type `RegisteredServer` - The created raw registered server ``` -------------------------------- ### Get Player List Header Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/02-player-api.md Retrieves the player's player list header. ```APIDOC ## getPlayerListHeader() ### Description Returns the player's player list header. ### Method Signature ```java Component getPlayerListHeader() ``` ### Return Type `Component` - The player's player list header ``` -------------------------------- ### Get Bound Address Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/01-proxy-server-api.md Retrieve the InetSocketAddress the proxy is bound to. This may not be the external IP. ```java InetSocketAddress getBoundAddress() ``` -------------------------------- ### Creating Resource Packs with Builder Pattern Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/00-index.md Shows how to construct a `ResourcePackInfo` object using the builder pattern. This pattern is used for complex object creation with multiple configuration options. ```java ResourcePackInfo pack = proxy.createResourcePackBuilder(url) .setHash(hash) .setPrompt(prompt) .build(); ``` -------------------------------- ### Accessing Proxy and Player Interfaces Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/00-index.md Demonstrates how to obtain interface instances for core Velocity objects like ProxyServer and Player. These are typically retrieved from events or existing objects. ```java ProxyServer proxy = event.getServer(); // Interface, not concrete class Player player = proxy.getPlayer(uuid).get(); // Interface ``` -------------------------------- ### ServerInfo Constructor Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/06-server-connections-and-messaging.md Creates a new ServerInfo object representing a server that a player can connect to. This object is immutable and thread-safe. ```APIDOC ## ServerInfo Constructor ### Description Creates a new ServerInfo object. ### Signature ```java public ServerInfo(String name, InetSocketAddress address) ``` ### Parameters #### Path Parameters - **name** (String) - Required - The name for the server - **address** (InetSocketAddress) - Required - The address of the server to connect to ### Request Example ```java ServerInfo survivalServer = new ServerInfo( "survival", new InetSocketAddress("survival.example.com", 25565) ); ``` ``` -------------------------------- ### Implement SimpleCommand in Java Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/04-command-system.md Use SimpleCommand for basic commands that accept string arguments. Ensure arguments are validated and parsed correctly. ```java SimpleCommand command = invocation -> { if (invocation.arguments().length < 1) { invocation.source().sendMessage(Component.text("Usage: /tppos ")); return; } try { int x = Integer.parseInt(invocation.arguments()[0]); int z = Integer.parseInt(invocation.arguments()[1]); // Execute teleportation } catch (NumberFormatException e) { invocation.source().sendMessage(Component.text("Invalid coordinates")); } }; commandManager.register( commandManager.metaBuilder("tppos").plugin(plugin).build(), command); ``` -------------------------------- ### Get PluginContainer from Instance Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/05-scheduler-and-plugins.md Retrieve the PluginContainer for a given plugin instance. Useful for accessing plugin metadata. ```java Optional container = pluginManager.fromInstance(this); if (container.isPresent()) { System.out.println("Plugin: " + container.get().getDescription().getName()); } ``` -------------------------------- ### Send Resource Pack on Login Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/09-advanced-topics.md Send a resource pack to a player upon login. Ensure the client is ready by sending the pack offer after a short delay. ```java import java.util.concurrent.TimeUnit; import java.util.UUID; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent; import com.velocitypowered.api.event.player.LoginEvent; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.resource_pack.ResourcePackInfo; import com.velocitypowered.api.util.ComponentMessage; import net.kyori.adventure.text.Component; // Assuming 'proxy' is an instance of com.velocitypowered.api.proxy.ProxyServer // Assuming 'logger' is an instance of org.slf4j.Logger // Assuming 'calculateSHA1' is a utility method to compute SHA1 hash // Assuming 'getPlayerData' and 'applyPlayerData' are custom methods public class ResourcePackManager { private final com.velocitypowered.api.proxy.ProxyServer proxy; private final org.slf4j.Logger logger; private Map pendingPacks = new ConcurrentHashMap<>(); public ResourcePackManager(com.velocitypowered.api.proxy.ProxyServer proxy, org.slf4j.Logger logger) { this.proxy = proxy; this.logger = logger; } @Subscribe public void onLogin(LoginEvent event) { Player player = event.getPlayer(); // Create resource pack ResourcePackInfo pack = proxy.createResourcePackBuilder( "https://example.com/resourcepack.zip") .setHash(calculateSHA1("resourcepack.zip")) .setPrompt(Component.text("Accept resource pack?")) .setShouldForce(false) .build(); // Send after delay to ensure client is ready proxy.getScheduler().buildTask(this, () -> { player.sendResourcePackOffer(pack); }) .delay(1, TimeUnit.SECONDS) .schedule(); } // Placeholder for custom event handling if needed // @Subscribe // public void onResourcePackOffer(/* custom event */) { // // Track pending packs // } @Subscribe public void onResourcePackStatus(PlayerResourcePackStatusEvent event) { Player player = event.getPlayer(); switch (event.getStatus()) { case SUCCESSFULLY_LOADED: logger.info(player.getUsername() + " loaded resource pack"); pendingPacks.remove(player.getUniqueId()); break; case DECLINED: logger.warn(player.getUsername() + " declined resource pack"); player.disconnect(Component.text("Resource pack required")); break; case FAILED_DOWNLOAD: logger.warn(player.getUsername() + " failed to download resource pack"); break; } } // Dummy method for SHA1 calculation, replace with actual implementation private String calculateSHA1(String filename) { // Implementation to calculate SHA1 hash of the file return "dummy-sha1-hash"; } } ``` -------------------------------- ### getClientBrand() Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/02-player-api.md Gets the brand of the player's client. This can be useful for identifying specific client versions or modifications. ```APIDOC ## getClientBrand() ### Description Gets the player's client brand. ### Method ```java @Nullable String getClientBrand() ``` ### Return Type `String` (nullable) — The player's client brand, or null ### Example ```java String brand = player.getClientBrand(); if (brand != null) { System.out.println("Client: " + brand); } ``` ``` -------------------------------- ### Get Player Username Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/02-player-api.md Retrieves the current username of the player. Useful for logging or displaying player information. ```java String username = player.getUsername(); System.out.println("Player: " + username); ``` -------------------------------- ### getPlayerSettings() Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/02-player-api.md Retrieves the player's client settings. This includes various preferences and configurations set by the player's client. ```APIDOC ## getPlayerSettings() ### Description Returns the player's client settings. ### Method ```java PlayerSettings getPlayerSettings() ``` ### Return Type `PlayerSettings` — The player's client settings ``` -------------------------------- ### offerBrigadierSuggestions Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/04-command-system.md Asynchronously collects Brigadier suggestions for a partial command, including tooltips. Returns a CompletableFuture containing Brigadier Suggestions. ```APIDOC ## offerBrigadierSuggestions(CommandSource source, String cmdLine) ### Description Asynchronously collects Brigadier suggestions for a partial command (with tooltips). ### Method Signature ```java CompletableFuture offerBrigadierSuggestions(CommandSource source, String cmdLine) ``` ### Parameters #### Path Parameters * **source** (CommandSource) - Required - The command source * **cmdLine** (String) - Required - The partially completed command ### Return Type `CompletableFuture` - Brigadier Suggestions with tooltips ``` -------------------------------- ### Get Channel Identifier Name Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/06-server-connections-and-messaging.md Retrieve the string representation of a channel identifier. Useful for logging or debugging. ```java String channelName = identifier.getId(); System.out.println("Channel: " + channelName); ``` -------------------------------- ### Get All Loaded Plugins Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/05-scheduler-and-plugins.md Obtain a collection of all PluginContainers currently loaded on the proxy. Useful for iterating through all active plugins. ```java Collection plugins = pluginManager.getPlugins(); for (PluginContainer plugin : plugins) { System.out.println("Plugin: " + plugin.getDescription().getName()); } ``` -------------------------------- ### Get PluginContainer by ID Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/05-scheduler-and-plugins.md Retrieve a PluginContainer using its unique ID. Use this when you know the plugin's identifier. ```java Optional plugin = pluginManager.getPlugin("my-plugin"); if (plugin.isPresent()) { // Use the plugin } ``` -------------------------------- ### Access Proxy Configuration Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/09-advanced-topics.md Retrieve and inspect various proxy settings such as online mode, player count, MOTD, and query port. Also shows how to check the player info forwarding mode. ```java ProxyConfig config = proxy.getConfiguration(); // Check settings boolean online = config.getOnlineMode(); int maxPlayers = config.getMaxPlayerCount(); String motd = config.getMotd(); int queryPort = config.getQueryPort(); // Forwarding mode config.getPlayerInfoForwardingMode(); // NONE, LEGACY, MODERN, etc. ``` -------------------------------- ### Build CommandMeta with Aliases Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/04-command-system.md Use metaBuilder to create CommandMeta with a primary alias and additional aliases. Ensure the plugin instance is provided. ```java CommandMeta meta = commandManager.metaBuilder("spawn") .aliases("respawn", "home") .plugin(plugin) .build(); ``` -------------------------------- ### Get Player List Footer Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/02-player-api.md Retrieves the current footer component displayed in the player's tab list. ```java Component getPlayerListFooter() ``` -------------------------------- ### Compile Linux Compression Native Library Source: https://github.com/papermc/velocity/blob/dev/3.0.0/native/README.md A script to compile the native compression library for Linux. Requires build tools, OpenSSL, and potential script adjustments. ```bash build-support/compile-linux-compress.sh ``` -------------------------------- ### Get Player List Header Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/02-player-api.md Retrieves the current header component displayed in the player's tab list. ```java Component getPlayerListHeader() ``` -------------------------------- ### Scheduling Tasks with Fluent TaskBuilder Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/00-index.md Demonstrates the fluent API provided by `TaskBuilder` for configuring and scheduling tasks. This includes setting delays, repeat intervals, and the task itself. ```java scheduler.buildTask(plugin, runnable) .delay(5, TimeUnit.SECONDS) .repeat(Duration.ofSeconds(30)) .schedule(); ``` -------------------------------- ### Get Server Address Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/06-server-connections-and-messaging.md Retrieves the InetSocketAddress of the server. This can be used to log or display the server's host and port. ```java InetSocketAddress addr = serverInfo.getAddress(); System.out.println("Server: " + addr.getHostName() + ":" + addr.getPort()); ``` -------------------------------- ### Create Custom Server Links Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/07-types-and-utilities.md Creates a list of custom links to be displayed in the pause menu for a player. Requires Minecraft 1.21 or later. Each link has a display label and a URL. ```java List links = Arrays.asList( new ServerLink("Website", "https://example.com"), new ServerLink("Discord", "https://discord.gg/example") ); player.setServerLinks(links); ``` -------------------------------- ### Build Linux Native Libraries Source: https://github.com/papermc/velocity/blob/dev/3.0.0/native/README.md Builds native libraries for both OpenSSL 1.1.x and OpenSSL 3.x.x on x86_64 and aarch64 platforms for Linux. Requires Docker with multi-platform build support. ```bash ./build-support/build-all-linux-natives.sh ``` -------------------------------- ### Get Player Tab List Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/02-player-api.md Retrieves the TabList object associated with a player, allowing for manipulation of the player list display. ```java TabList getTabList() ``` ```java TabList tabList = player.getTabList(); ``` -------------------------------- ### ConnectionRequestBuilder.connectWithIndication() Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/06-server-connections-and-messaging.md Attempts to connect the player to the server while showing connection indication to the client. This method returns a CompletableFuture with the connection result. ```APIDOC ## ConnectionRequestBuilder.connectWithIndication() Attempts to connect the player while showing connection indication to the client. ### Method `connectWithIndication()` ### Return Type: `CompletableFuture` — Same as connect() **Source:** `com.velocitypowered.api.proxy.ConnectionRequestBuilder` ``` -------------------------------- ### getAllServers() Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/01-proxy-server-api.md Retrieves all servers registered with the proxy. ```APIDOC ## getAllServers() ### Description Retrieves all servers registered with the proxy. ### Signature ```java Collection getAllServers() ``` ### Return Type `Collection` - All registered servers ### Example ```java Collection servers = proxy.getAllServers(); for (RegisteredServer server : servers) { System.out.println("Server: " + server.getServerInfo().getName()); } ``` ``` -------------------------------- ### Get Mod Information from Player Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/07-types-and-utilities.md Retrieves and prints mod information for a player if available. Requires checking for Optional presence. ```java Optional mods = player.getModInfo(); if (mods.isPresent()) { System.out.println("Type: " + mods.get().getType()); for (ModInfo.Mod mod : mods.get().getMods()) { System.out.println(" - " + mod.getId() + " v" + mod.getVersion()); } } ``` -------------------------------- ### Register a New Server Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/01-proxy-server-api.md Registers a new server with the proxy. An `IllegalArgumentException` is thrown if a server with the same name already exists. Ensure the `ServerInfo` is correctly configured. ```java ServerInfo info = new ServerInfo("creative", new InetSocketAddress("creative.example.com", 25565)); RegisteredServer server = proxy.registerServer(info); ``` -------------------------------- ### Get Player by UUID Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/01-proxy-server-api.md Retrieves a player by their unique identifier (UUID). This is a reliable way to find a player, as UUIDs are unique. ```java UUID uuid = UUID.fromString("550e8400-e29b-41d4-a716-446655440000"); Optional player = proxy.getPlayer(uuid); ``` -------------------------------- ### Connect Player to Server with Result Handling Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/06-server-connections-and-messaging.md Initiates a connection to a specified server and handles the asynchronous result. Use when a simple connection attempt is needed and the outcome must be processed. ```java Optional server = proxy.getServer("survival"); if (server.isPresent()) { player.createConnectionRequest(server.get()).connect() .thenAccept(result -> { if (result.isSuccessful()) { System.out.println("Connected successfully"); } else { player.sendMessage(Component.text("Connection failed: " + result.getStatus())); } }); } ``` -------------------------------- ### Get Player by Username Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/01-proxy-server-api.md Retrieves a player by their username. The search is case-insensitive. Use this to interact with a specific player if their username is known. ```java ProxyServer proxy = /* obtained from plugin manager */; Optional player = proxy.getPlayer("Steve"); if (player.isPresent()) { player.get().sendMessage(Component.text("Welcome!")); } ``` -------------------------------- ### Accessing Player Game Profile and Properties Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/07-types-and-utilities.md Demonstrates how to retrieve a player's game profile, including their name, UUID, and iterating through their properties to find specific ones like textures. ```java GameProfile profile = player.getGameProfile(); System.out.println("Player: " + profile.getName() + " (" + profile.getId() + ")"); for (GameProfile.Property prop : profile.getProperties()) { if (prop.getName().equals("textures")) { System.out.println("Textures: " + prop.getValue()); } } ``` -------------------------------- ### Repeating Task Scheduling with Cancellation Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/05-scheduler-and-plugins.md Shows how to schedule a task that repeats at a fixed interval and how to cancel it programmatically. ```APIDOC ## Repeating Task with Cancellation ### Description Schedules a task to run repeatedly at a specified interval and provides a mechanism to cancel it. ### Method Signature `proxy.getScheduler().buildTask(plugin, taskConsumer).repeat(Duration duration).schedule()` ### Example ```java public void scheduleRepeatingTask() { ScheduledTask task = proxy.getScheduler() .buildTask(plugin, scheduledTask -> { if (shouldStop()) { scheduledTask.cancel(); System.out.println("Task cancelled"); } // Perform periodic work }) .repeat(Duration.ofSeconds(30)) .schedule(); } ``` ``` -------------------------------- ### Formatting Messages with Adventure Components Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/00-index.md Illustrates how to create and send formatted messages using the Kyori Adventure API. This allows for rich text formatting with colors and styling. ```java Component message = Component.text("Hello ", NamedTextColor.GREEN) .append(Component.text(player.getUsername(), NamedTextColor.AQUA)); player.sendMessage(message); ``` -------------------------------- ### Compile Linux Crypto Native Library Source: https://github.com/papermc/velocity/blob/dev/3.0.0/native/README.md A script to compile the native encryption library for Linux. Requires build tools, OpenSSL, and potential script adjustments. ```bash build-support/compile-linux-crypto.sh ``` -------------------------------- ### registerServer(ServerInfo server) Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/01-proxy-server-api.md Registers a server with the proxy. A server with this name should not already exist. ```APIDOC ## registerServer(ServerInfo server) ### Description Registers a server with the proxy. A server with this name should not already exist. ### Signature ```java RegisteredServer registerServer(ServerInfo server) ``` ### Parameters #### Path Parameters - **server** (ServerInfo) - Required - The server information to register ### Return Type `RegisteredServer` - The newly registered server ### Throws `IllegalArgumentException` - if a server with this name is already registered ### Example ```java ServerInfo info = new ServerInfo("creative", new InetSocketAddress("creative.example.com", 25565)); RegisteredServer server = proxy.registerServer(info); ``` ``` -------------------------------- ### ConnectionRequestBuilder.connect() Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/06-server-connections-and-messaging.md Attempts to connect the player to the server. Returns a CompletableFuture with the connection result, indicating success or various failure reasons. ```APIDOC ## ConnectionRequestBuilder.connect() Attempts to connect the player to the server. ### Method `connect()` ### Return Type `CompletableFuture` — A future with the connection result ### Possible Results: - `Result.Status.SUCCESS` - Connection successful - `Result.Status.IN_PROGRESS` - Connection already in progress - `Result.Status.ALREADY_CONNECTED` - Player already connected to this server - `Result.Status.CONNECTION_CANCELLED` - Connection was cancelled by an event - `Result.Status.CONNECTION_IN_PROGRESS` - Another connection is pending - `Result.Status.SERVER_DISCONNECTED` - Server disconnected during connection - `Result.Status.NO_SERVER_AVAILABLE` - No server available (offline-mode) ### Example: ```java Optional server = proxy.getServer("survival"); if (server.isPresent()) { player.createConnectionRequest(server.get()).connect() .thenAccept(result -> { if (result.isSuccessful()) { System.out.println("Connected successfully"); } else { player.sendMessage(Component.text("Connection failed: " + result.getStatus())); } }); } ``` **Source:** `com.velocitypowered.api.proxy.ConnectionRequestBuilder` ``` -------------------------------- ### Get Client Brand Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/09-advanced-topics.md Retrieve the client's brand string during the `LoginEvent` to identify the client type (e.g., vanilla, fabric, forge). ```java @Subscribe public void onLogin(LoginEvent event) { String brand = event.getPlayer().getClientBrand(); if (brand != null) { logger.info("Client brand: " + brand); } // Common brands: // - "vanilla" // - "fabric" // - "forge" // - "MultiMC" // - "Lunar Client" } ``` -------------------------------- ### Ensure Plugin Container Exists Source: https://github.com/papermc/velocity/blob/dev/3.0.0/_autodocs/05-scheduler-and-plugins.md Get the PluginContainer for a plugin instance, throwing an exception if one does not exist. Use this when you expect a container to be present. ```java PluginContainer container = pluginManager.ensurePluginContainer(this); ```