### InputMode Usage Example Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/07-Types.md Shows how to get a player's input mode and check for specific modes like TOUCH or physical input methods (KEYBOARD, CONTROLLER). ```java InputMode inputMode = player.getInputMode(); if (inputMode == InputMode.TOUCH) { System.out.println("Player on touchscreen device"); } boolean hasPhysicalInput = inputMode == InputMode.KEYBOARD || inputMode == InputMode.CONTROLLER; ``` -------------------------------- ### Complete Floodgate Event Listener Example Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/04-Events.md A comprehensive example demonstrating how to create a listener class, register multiple event subscribers (specifically for SkinApplyEvent), handle events, and properly unregister subscribers on shutdown. ```java public class MyFloodgateEventListener { private final FloodgateApi floodgateApi; private final List> subscribers = new ArrayList<>(); public MyFloodgateEventListener() { this.floodgateApi = FloodgateApi.getInstance(); registerListeners(); } private void registerListeners() { FloodgateEventBus eventBus = floodgateApi.getEventBus(); // Subscribe to skin apply events FloodgateSubscriber skinSubscriber = eventBus.subscribe(eventBus.newSubscriber( SkinApplyEvent.class, this::onSkinApply )); subscribers.add(skinSubscriber); } private void onSkinApply(SkinApplyEvent event) { FloodgatePlayer player = event.player(); if (shouldApplySkin(player)) { System.out.println("Applying skin to " + player.getUsername()); } else { event.setCancelled(true); System.out.println("Skin application cancelled for " + player.getUsername()); } } private boolean shouldApplySkin(FloodgatePlayer player) { // Custom logic to determine if skin should be applied return !player.isLinked(); } public void shutdown() { FloodgateEventBus eventBus = floodgateApi.getEventBus(); for (FloodgateSubscriber subscriber : subscribers) { eventBus.unsubscribe(subscriber); } } } ``` -------------------------------- ### Velocity Plugin Setup and Event Subscription Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/10-GettingStarted.md Basic Velocity plugin setup with dependency injection for logging and subscribing to player initial server choice events. Requires FloodgateApi and Velocity API. ```java import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent; import com.velocitypowered.api.plugin.Plugin; import com.google.inject.Inject; import org.slf4j.Logger; import org.geysermc.floodgate.api.FloodgateApi; @Plugin(id = "myfloodgateplugin") public class MyFloodgateVelocityPlugin { @Inject private Logger logger; @Subscribe public void onServerChoice(PlayerChooseInitialServerEvent event) { FloodgateApi api = FloodgateApi.getInstance(); if (api.isFloodgatePlayer(event.getPlayer().getUniqueId())) { logger.info("Bedrock player " + event.getPlayer().getUsername() + " joining"); } } } ``` -------------------------------- ### Complete FloodgateLogger Example Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/05-Logger.md A comprehensive example demonstrating the usage of FloodgateLogger for various logging scenarios including info, warn, and error messages, as well as detailed debug information. ```java public class LinkRequestHandler { @Inject private FloodgateLogger logger; @Inject private PlayerLink playerLink; public void handleLinkRequest(FloodgatePlayer player, String javaUsername) { logger.info("Processing link request for {}", player.getUsername()); try { playerLink.createLinkRequest( player.getJavaUniqueId(), javaUsername, player.getUsername() ).thenAccept(result -> { if (result instanceof String) { String code = (String) result; logger.info("Link code generated: {}", code); // Send code to player } else if (result instanceof LinkRequestResult) { LinkRequestResult error = (LinkRequestResult) result; logger.warn("Link request failed for {}: {}", player.getUsername(), error); } }); } catch (Exception e) { logger.error("Error creating link request for {}", player.getUsername(), e); } } public void debugPlayerInfo(FloodgatePlayer player) { if (!logger.isDebug()) { return; } logger.debug("=== Player Debug Info ==="); logger.debug("Username: {}", player.getUsername()); logger.debug("XUID: {}", player.getXuid()); logger.debug("Device: {}", player.getDeviceOs()); logger.debug("Language: {}", player.getLanguageCode()); logger.debug("UI Profile: {}", player.getUiProfile()); logger.debug("Input Mode: {}", player.getInputMode()); logger.debug("From Proxy: {}", player.isFromProxy()); logger.debug("Linked: {}", player.isLinked()); } } ``` -------------------------------- ### Example Environment Setup for Floodgate Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/08-Configuration.md Set environment variables to configure Floodgate's debug mode and database connection details. These variables are particularly useful for overriding or providing sensitive information like database passwords. ```bash export FLOODGATE_DEBUG=true export FLOODGATE_DATABASE_TYPE=mysql export FLOODGATE_DATABASE_HOST=db.example.com export FLOODGATE_DATABASE_PORT=3306 export FLOODGATE_DATABASE_NAME=floodgate_prod export FLOODGATE_DATABASE_USER=floodgate export FLOODGATE_DATABASE_PASSWORD=secure_password ``` -------------------------------- ### Checking Floodgate Availability Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/10-GettingStarted.md Verify if the Floodgate API is installed and initialized by attempting to get its instance. A NullPointerException indicates Floodgate is not available. ```java try { FloodgateApi api = FloodgateApi.getInstance(); // Floodgate is installed and initialized } catch (NullPointerException e) { // Floodgate not available System.out.println("Floodgate API not available"); } ``` -------------------------------- ### Get Bedrock Client Version Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/02-FloodgatePlayer.md Retrieves the version of the Bedrock client the player is using. Example format: "1.20.0". ```java String version = player.getVersion(); System.out.println("Client version: " + version); ``` -------------------------------- ### Handling Device Operating System Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/07-Types.md Example of how to check the DeviceOs of a FloodgatePlayer. This can be used for platform-specific logic or messages. ```java FloodgatePlayer player = api.getPlayer(uuid); DeviceOs deviceOs = player.getDeviceOs(); if (deviceOs == DeviceOs.XBOX) { System.out.println("Player is on Xbox"); } switch (deviceOs) { case MOBILE: System.out.println("Mobile device"); break; case CONSOLE: System.out.println("Console device"); break; case WINDOWS: System.out.println("Windows PC"); break; } ``` -------------------------------- ### Spigot/Bukkit Plugin YML Configuration Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/10-GettingStarted.md Example plugin.yml for a Spigot/Bukkit plugin that depends on Floodgate and defines a command. ```yaml name: MyFloodgatePlugin version: 1.0.0 description: Example Floodgate plugin depend: - Floodgate main: com.example.MyFloodgatePlugin commands: bedrock: description: Check if player is Bedrock usage: /bedrock ``` -------------------------------- ### Complete Bedrock Player Usage Example Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/02-FloodgatePlayer.md Demonstrates how to retrieve and display various information about a Bedrock player connected via Floodgate. Includes checks for linked Java accounts. ```java public void handleBedrockPlayer(FloodgatePlayer player) { System.out.println("=== Bedrock Player Info ==="); System.out.println("Real username: " + player.getUsername()); System.out.println("Server username: " + player.getCorrectUsername()); System.out.println("XUID: " + player.getXuid()); System.out.println("Client version: " + player.getVersion()); System.out.println("Device OS: " + player.getDeviceOs()); System.out.println("Language: " + player.getLanguageCode()); System.out.println("Input mode: " + player.getInputMode()); System.out.println("UI Profile: " + player.getUiProfile()); System.out.println("From proxy: " + player.isFromProxy()); if (player.isLinked()) { LinkedPlayer linkedAccount = player.getLinkedPlayer(); System.out.println("Linked to Java: " + linkedAccount.getJavaUsername()); } } ``` -------------------------------- ### TriFunction Usage Example Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/07-Types.md Illustrates creating a TriFunction to format a string based on name, age, and active status, and then composing it with another function to get the length of the resulting string. ```java TriFunction formatter = (name, age, active) -> active ? name + "(" + age + ")" : "inactive"; String result = formatter.apply("Alice", 30, true); // "Alice(30)" // Compose with another function TriFunction lengthFormatter = formatter.andThen(String::length); int length = lengthFormatter.apply("Alice", 30, true); // 9 ``` -------------------------------- ### UiProfile Usage Example Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/07-Types.md Demonstrates how to retrieve and check a player's UI profile. Use this to adapt behavior based on the client's interface. ```java UiProfile uiProfile = player.getUiProfile(); if (uiProfile == UiProfile.POCKET) { System.out.println("Player using touch UI"); } ``` -------------------------------- ### Create Link Request Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/03-PlayerLink.md Initiates a link request from a Java player to a Bedrock player. Use this to start the linking process. ```java CompletableFuture createLinkRequest( @NonNull UUID javaId, @NonNull String javaUsername, @NonNull String bedrockUsername ) ``` ```java playerLink.createLinkRequest(javaUuid, javaUsername, bedrockUsername) .thenAccept(result -> { if (result instanceof String) { String linkCode = (String) result; System.out.println("Link code: " + linkCode); } else if (result instanceof LinkRequestResult) { LinkRequestResult error = (LinkRequestResult) result; System.out.println("Request failed: " + error); } }); ``` -------------------------------- ### BedrockData Usage Example Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/07-Types.md Demonstrates how to access and print various details from BedrockData, such as username, device name, and language code. Ensure BedrockData is not null before accessing its methods. ```java BedrockData bedrockData = handshakeData.getBedrockData(); if (bedrockData != null) { System.out.println("Username: " + bedrockData.getUsername()); System.out.println("Device: " + bedrockData.getDeviceName()); System.out.println("Language: " + bedrockData.getLanguageCode()); } ``` -------------------------------- ### Example: Send Custom Packet by FloodgatePlayer Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/06-UnsafeAPI.md Illustrates sending a custom packet to a player using their FloodgatePlayer object. This method requires obtaining the FloodgatePlayer instance first. ```java Unsafe unsafe = FloodgateApi.getInstance().unsafe(); FloodgatePlayer bedrockPlayer = api.getPlayer(uuid); byte[] customData = buildCustomPacketData(); unsafe.sendPacket(bedrockPlayer, 42, customData); ``` -------------------------------- ### Example: Send Custom Packet by UUID Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/06-UnsafeAPI.md Demonstrates sending a custom packet to a player using their UUID. Ensure the packet data is correctly formatted and the packet ID is valid for the protocol version. ```java Unsafe unsafe = FloodgateApi.getInstance().unsafe(); // Send a custom packet byte[] packetData = new byte[] { /* binary data */ }; unsafe.sendPacket(playerId, 42, packetData); ``` -------------------------------- ### Velocity Floodgate Configuration with MySQL Linking Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/08-Configuration.md This configuration example is for Floodgate on Velocity, specifically enabling MySQL for player account linking. It includes settings for username prefix, locale, and global linking. ```yaml # plugins/floodgate/config.yml keyFileName: "key.pem" usernamePrefix: "." replaceSpaces: false defaultLocale: "en_US" disconnect: invalidKey: "Floodgate validation failed" invalidArgumentsLength: "Authentication data malformed" playerLink: enabled: true requireLink: false enableOwnLinking: true allowed: true linkCodeTimeout: 1800 # 30 minutes type: "mysql" enableGlobalLinking: true metrics: enabled: true uuid: "auto-generated" debug: false configVersion: 1 ``` -------------------------------- ### Accessing Linked Player Information Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/07-Types.md Example of retrieving and displaying information about a linked Bedrock player. This requires obtaining a FloodgatePlayer object first and checking if they are linked. ```java FloodgatePlayer player = api.getPlayer(uuid); if (player.isLinked()) { LinkedPlayer linked = player.getLinkedPlayer(); System.out.println("Linked Java username: " + linked.getJavaUsername()); } ``` -------------------------------- ### Get Username Prefix Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/01-FloodgateApi.md Retrieve the configured prefix for Bedrock player usernames. This helps differentiate them from Java players. ```java FloodgateApi api = FloodgateApi.getInstance(); String prefix = api.getPlayerPrefix(); System.out.println("Player prefix: " + prefix); ``` -------------------------------- ### Complete Example: Custom Packet Sender Class Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/06-UnsafeAPI.md A comprehensive Java class demonstrating how to use the Unsafe API to send custom alerts and broadcast packets. It includes error handling and placeholder methods for packet building. ```java public class CustomPacketSender { private final Unsafe unsafe; private final FloodgateApi api; public CustomPacketSender() { this.api = FloodgateApi.getInstance(); this.unsafe = api.unsafe(); } public void sendCustomAlert(UUID playerId) { FloodgatePlayer player = api.getPlayer(playerId); if (player == null || !api.isFloodgatePlayer(playerId)) { return; } try { // Build a custom packet payload // This is a simplified example - actual implementation // would require proper Bedrock packet encoding byte[] packetData = buildAlertPacketData("Custom Message"); // Send packet ID 0x6A (example - use actual packet ID) unsafe.sendPacket(player, 0x6A, packetData); } catch (Exception e) { System.err.println("Failed to send custom packet: " + e.getMessage()); } } private byte[] buildAlertPacketData(String message) { // Implementation would encode message to Bedrock protocol format // This is pseudocode - actual implementation needs proper serialization return message.getBytes(); } public void broadcastCustomPacket(int packetId, byte[] data) { for (FloodgatePlayer player : api.getPlayers()) { try { unsafe.sendPacket(player, packetId, data); } catch (Exception e) { System.err.println("Failed to send packet to " + player.getUsername() + ": " + e.getMessage()); } } } } ``` -------------------------------- ### Get Floodgate API Instance Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/INDEX.md Obtain the singleton instance of the FloodgateApi to access its functionalities. This is the primary entry point for interacting with the Floodgate system. ```java FloodgateApi api = FloodgateApi.getInstance(); ``` -------------------------------- ### Get Player Link Manager Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/01-FloodgateApi.md Retrieves the PlayerLink manager, which handles the linking of Java Edition and Bedrock Edition player accounts. ```java PlayerLink playerLink = FloodgateApi.getInstance().getPlayerLink(); ``` -------------------------------- ### Safely Access Floodgate API Instance Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/10-GettingStarted.md Provides a utility method to safely get the Floodgate API instance, handling potential NullPointerExceptions if Floodgate is not initialized. Also demonstrates safe player retrieval. ```java public FloodgateApi getFloodgateApi() { try { return FloodgateApi.getInstance(); } catch (NullPointerException e) { System.err.println("Floodgate not initialized"); return null; } } public void safeGetPlayer(UUID uuid) { FloodgateApi api = getFloodgateApi(); if (api == null) return; FloodgatePlayer player = api.getPlayer(uuid); if (player != null) { System.out.println("Player: " + player.getUsername()); } } ``` -------------------------------- ### Get Bedrock Device Operating System Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/02-FloodgatePlayer.md Retrieves the operating system of the Bedrock client. Returns an enum value representing the device OS (e.g., WINDOWS, IOS, XBOX). ```java DeviceOs deviceOs = player.getDeviceOs(); if (deviceOs == DeviceOs.MOBILE) { System.out.println("Playing on mobile!"); } ``` -------------------------------- ### Get Bedrock Player Metadata Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/01-FloodgateApi.md Retrieve detailed metadata for a Bedrock player using their UUID. Returns null if the player is not a Bedrock player. ```java UUID playerId = event.getPlayer().getUniqueId(); FloodgatePlayer player = FloodgateApi.getInstance().getPlayer(playerId); if (player != null) { System.out.println("Device OS: " + player.getDeviceOs()); System.out.println("XUID: " + player.getXuid()); } ``` -------------------------------- ### Get Bedrock Client Language Code Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/02-FloodgatePlayer.md Retrieves the language code of the Bedrock client. Returns an ISO language code (e.g., "en_US", "de_DE"). ```java String language = player.getLanguageCode(); System.out.println("Language: " + language); ``` -------------------------------- ### Get All Online Bedrock Players Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/01-FloodgateApi.md Get a collection of all currently online players connected via Floodgate. The returned collection is unmodifiable. ```java FloodgateApi api = FloodgateApi.getInstance(); for (FloodgatePlayer player : api.getPlayers()) { System.out.println("Bedrock player: " + player.getUsername()); } ``` -------------------------------- ### Subscribe to SkinApplyEvent with Exception Handling Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/09-Errors.md Demonstrates how to subscribe to an event and handle potential exceptions within the event processing logic. Exceptions are caught and logged by the event system, allowing other subscribers to continue. ```java try { eventBus.subscribe(eventBus.newSubscriber( SkinApplyEvent.class, event -> { // Exceptions here are caught by event system processEvent(event); } )); } catch (Exception e) { logger.error("Failed to subscribe to event", e); } ``` -------------------------------- ### Get Xbox User Identifier (XUID) Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/02-FloodgatePlayer.md Retrieves the player's Xbox User Identifier as a string. ```java String xuid = player.getXuid(); System.out.println("XUID: " + xuid); ``` -------------------------------- ### Using Different Log Levels Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/09-Errors.md Demonstrates the use of various log levels (ERROR, WARN, DEBUG) to categorize and report different types of issues. Use ERROR for critical failures, WARN for recoverable problems, and DEBUG for detailed diagnostics. ```java // ERROR - prevents normal operation logger.error("Database connection lost"); // WARN - recoverable issue logger.warn("Link request timed out, user must retry"); // DEBUG - diagnostic information if (logger.isDebug()) { logger.debug("Link request created with code: {}", code); } ``` -------------------------------- ### Get Real Bedrock Username Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/02-FloodgatePlayer.md Retrieves the original Bedrock gamertag without any modifications, prefixes, or shortening. ```java String realUsername = player.getUsername(); ``` -------------------------------- ### Initiating Bedrock Account Linking Process Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/10-GettingStarted.md Initiate the account linking process by creating a link request. This asynchronous operation returns a link code or an error result, which is then handled. ```java public void startAccountLink(UUID javaId, String javaUsername, String bedrockUsername) { PlayerLink playerLink = FloodgateApi.getInstance().getPlayerLink(); playerLink.createLinkRequest(javaId, javaUsername, bedrockUsername) .thenAccept(result -> { if (result instanceof String) { String code = (String) result; System.out.println("Link code: " + code); // Send code to player } else if (result instanceof LinkRequestResult) { LinkRequestResult error = (LinkRequestResult) result; System.out.println("Link creation failed: " + error); } }) .exceptionally(ex -> { System.err.println("Database error: " + ex.getMessage()); return null; }); } ``` -------------------------------- ### transfer Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/02-FloodgatePlayer.md Initiates a transfer of the player to a different server. This is typically used for server proxies or network setups. ```APIDOC ## transfer ### Description Transfers this player to another server. ### Method ```java default boolean transfer(String address, int port) ``` ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Parameters #### Path Parameters * **address** (String) - Required - Hostname or IP of destination * **port** (int) - Required - Port of destination server ### Response #### Success Response (boolean) * Returns `true` if the transfer was initiated, `false` otherwise. ### Response Example ```java player.transfer("other.server.com", 19132); ``` ``` -------------------------------- ### Get Database Name Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/03-PlayerLink.md Retrieves the name of the currently used database backend implementation. Useful for debugging or logging. ```java String getName() String dbName = playerLink.getName(); System.out.println("Using database: " + dbName); ``` -------------------------------- ### getDeviceOs Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/02-FloodgatePlayer.md Retrieves the operating system of the Bedrock client. ```APIDOC ## getDeviceOs ### Description Returns the operating system of the Bedrock client. ### Method GET ### Endpoint N/A (SDK Method) ### Parameters None ### Response #### Success Response - **deviceOs** (DeviceOs) - Enum value representing device OS (WINDOWS, IOS, MACOS, XBOX, SWITCH, PS4, etc.). ``` -------------------------------- ### Get Java Server Username Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/02-FloodgatePlayer.md Retrieves the processed username for the Java server. This is not used if the player is linked to a Java account. ```java String serverUsername = player.getJavaUsername(); System.out.println("Server username: " + serverUsername); ``` -------------------------------- ### Create a Player Account Link Request Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/INDEX.md Initiate the account linking process by creating a link request. This method returns a verification code upon successful creation, which can then be used to complete the link. ```java playerLink.createLinkRequest(javaId, javaUsername, bedrockUsername) .thenAccept(result -> { if (result instanceof String) { System.out.println("Code: " + (String) result); } }); ``` -------------------------------- ### MySQL Database Configuration Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/08-Configuration.md Configure the MySQL database connection, including server address, port, database name, credentials, and SSL usage. This snippet shows the parameters for connecting to a MySQL server. ```yaml mysql: address: "localhost" port: 3306 database: "floodgate" username: "root" password: "password" useSSL: false settings: {} ``` -------------------------------- ### Get Unsafe API Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/01-FloodgateApi.md Retrieve the unsafe API instance for low-level packet operations. This is used for advanced functionalities not covered by the standard API. ```java Unsafe unsafe() { return null; } ``` ```java Unsafe unsafe = FloodgateApi.getInstance().unsafe(); ``` -------------------------------- ### Get Gamertag for Bedrock Player by XUID Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/01-FloodgateApi.md Asynchronously retrieves the gamertag of a Bedrock player using their XUID. Returns null if the player is not found. ```java FloodgateApi.getInstance().getGamertagFor(1234567890123456789L) .thenAccept(gamertag -> { if (gamertag != null) { System.out.println("Gamertag: " + gamertag); } }); ``` -------------------------------- ### Spigot/Bukkit Bedrock Command Implementation Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/10-GettingStarted.md Implement a command executor for Spigot/Bukkit to check if a player is a Bedrock player and display their device OS. Requires FloodgateApi and Bukkit API. ```java import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.geysermc.floodgate.api.FloodgateApi; import org.geysermc.floodgate.api.player.FloodgatePlayer; public class BedrockCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (!(sender instanceof Player)) { sender.sendMessage("Player command only"); return false; } Player player = (Player) sender; FloodgateApi api = FloodgateApi.getInstance(); if (api.isFloodgatePlayer(player.getUniqueId())) { FloodgatePlayer bedrockPlayer = api.getPlayer( player.getUniqueId()); sender.sendMessage("§aYou are a Bedrock player!"); sender.sendMessage("Device: " + bedrockPlayer.getDeviceOs()); } else { sender.sendMessage("§cYou are not a Bedrock player"); } return true; } } ``` -------------------------------- ### Get Linked Java Account Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/02-FloodgatePlayer.md Retrieves the linked Java account if the player is linked. Returns the linked account object, or null if not linked. ```java LinkedPlayer linkedAccount = player.getLinkedPlayer(); if (linkedAccount != null) { System.out.println("Linked to: " + linkedAccount.getJavaUsername()); } ``` -------------------------------- ### getVersion Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/02-FloodgatePlayer.md Retrieves the version of the Bedrock client the player is using. ```APIDOC ## getVersion ### Description Returns the Bedrock client version. ### Method GET ### Endpoint N/A (SDK Method) ### Parameters None ### Response #### Success Response - **version** (String) - Client version string (e.g., "1.20.0"). ``` -------------------------------- ### Get Bedrock UI Profile Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/02-FloodgatePlayer.md Retrieves the user interface profile of the Bedrock client. Returns an enum value (e.g., CLASSIC, POCKET). ```java UiProfile uiProfile = player.getUiProfile(); ``` -------------------------------- ### getName Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/03-PlayerLink.md Returns the name of the database backend implementation currently in use. ```APIDOC ## getName ### Description Returns the name of the database backend implementation currently in use. ### Method ```java String getName() ``` ### Response #### Success Response - **name** (String) - The implementation name (e.g., "SQLite", "MySQL", "MongoDB"), or null if disabled. ### Request Example ```java String dbName = playerLink.getName(); System.out.println("Using database: " + dbName); ``` ``` -------------------------------- ### Get UUID for Bedrock Player by Gamertag Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/01-FloodgateApi.md Asynchronously retrieves the Floodgate-generated UUID for a Bedrock player using their gamertag. Returns null if the player is not found. ```java FloodgateApi.getInstance().getUuidFor("PlayerName") .thenAccept(uuid -> { if (uuid != null) { System.out.println("Player UUID: " + uuid); } }); ``` -------------------------------- ### Get Link Verification Timeout Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/03-PlayerLink.md Returns the duration, in seconds, for which a link request remains valid. This helps in understanding how long a user has to complete the verification. ```java long getVerifyLinkTimeout() long timeout = playerLink.getVerifyLinkTimeout(); System.out.println("Link requests expire after " + timeout + " seconds"); ``` -------------------------------- ### getPlayer Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/01-FloodgateApi.md Retrieves metadata about a Bedrock player by UUID. ```APIDOC ## getPlayer ### Description Retrieves metadata about a Bedrock player by UUID. ### Method GET ### Endpoint N/A (Java method) ### Parameters #### Path Parameters - **uuid** (UUID) - Required - UUID of the online Bedrock player ### Response #### Success Response - **Return Value** (FloodgatePlayer) - Floodgate player object, or null if not a Bedrock player ### Request Example ```java UUID playerId = event.getPlayer().getUniqueId(); FloodgatePlayer player = FloodgateApi.getInstance().getPlayer(playerId); if (player != null) { System.out.println("Device OS: " + player.getDeviceOs()); System.out.println("XUID: " + player.getXuid()); } ``` ``` -------------------------------- ### Subscribe to Skin Apply Events Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/10-GettingStarted.md Listen for skin apply events and conditionally cancel them for unlinked players. Requires FloodgateApi and SkinApplyEvent. ```java public void setupSkinEventListener() { FloodgateEventBus eventBus = FloodgateApi.getInstance().getEventBus(); eventBus.subscribe(eventBus.newSubscriber( SkinApplyEvent.class, event -> { FloodgatePlayer player = event.player(); System.out.println("Skin for: " + player.getUsername()); // Only apply skins to unlinked players if (player.isLinked()) { event.setCancelled(true); } } )); } ``` -------------------------------- ### Get Online Bedrock Player Count Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/01-FloodgateApi.md Retrieve the number of Bedrock players currently connected through Floodgate. This is a quick way to check player load. ```java int bedrock_player_count = FloodgateApi.getInstance().getPlayerCount(); ``` -------------------------------- ### Get Bedrock Input Mode Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/02-FloodgatePlayer.md Retrieves the input method used by the Bedrock player. Returns an enum value (e.g., KEYBOARD, MOUSE, TOUCH). ```java InputMode inputMode = player.getInputMode(); if (inputMode == InputMode.TOUCH) { System.out.println("Player is on touch device"); } ``` -------------------------------- ### Good Error Logging with Context Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/09-Errors.md Illustrates effective error logging by including relevant contextual information such as usernames and results, making debugging easier compared to vague messages. ```java // Good - includes relevant information logger.error("Failed to link player {} to Java account {}. Result: {}", bedrockUsername, javaUsername, result); // Avoid - vague error message logger.error("Link failed"); ``` -------------------------------- ### Inject FloodgateLogger in a Class Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/05-Logger.md Demonstrates how to inject the FloodgateLogger into a class using Guice's @Inject annotation for use in methods. ```java import com.google.inject.Inject; public class MyFloodgateAddon { @Inject private FloodgateLogger logger; public void initialize() { logger.info("Initializing addon"); // ... initialization code ... logger.info("Addon initialized"); } public void processPlayer(FloodgatePlayer player) { if (logger.isDebug()) { logger.debug("Processing player: {} from {}", player.getUsername(), player.getDeviceOs()); } } public void shutdown() { logger.warn("Shutting down addon"); } } ``` -------------------------------- ### Handling Link Request Results Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/07-Types.md Example of how to use the LinkRequestResult enum to process the outcome of a link verification. This is typically used within a callback or future. ```java playerLink.verifyLinkRequest(bedrockId, javaUsername, bedrockUsername, code) .thenAccept(result -> { switch (result) { case LINK_COMPLETED: System.out.println("Success!"); break; case INVALID_CODE: System.out.println("Wrong code"); break; case REQUEST_EXPIRED: System.out.println("Code expired"); break; case ALREADY_LINKED: System.out.println("Already linked"); break; default: System.out.println("Error: " + result); } }); ``` -------------------------------- ### Subscribe to SkinApplyEvent Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/INDEX.md Register a listener for the SkinApplyEvent. This event is triggered when a Bedrock player's skin needs to be applied to their Java player model, allowing for custom skin handling. ```java eventBus.subscribe(eventBus.newSubscriber( SkinApplyEvent.class, event -> System.out.println("Skin for: " + event.player().getUsername()) )); ``` -------------------------------- ### Get XUID for Bedrock Player by Gamertag Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/01-FloodgateApi.md Asynchronously retrieves the Xbox User ID (XUID) for a Bedrock player using their gamertag. Handles cases where the player is not found. ```java FloodgateApi.getInstance().getXuidFor("PlayerName") .thenAccept(xuid -> { if (xuid != null) { System.out.println("XUID: " + xuid); } }); ``` -------------------------------- ### Initialize PlayerLink Connection Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/03-PlayerLink.md Called by Floodgate to initialize the connection and set up required database collections. This is typically called internally during plugin initialization. ```java playerLink.load(); ``` -------------------------------- ### Java Player Account Linking Implementation Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/03-PlayerLink.md This Java class demonstrates how to use the PlayerLink API to manage account linking requests, including initiating a link, verifying a link with a code, and unlinking accounts. It handles asynchronous operations and potential results. ```java public class LinkManager { private final PlayerLink playerLink; public LinkManager(PlayerLink playerLink) { this.playerLink = playerLink; } public void initiateLink(UUID javaId, String javaUsername, String bedrockUsername) { playerLink.createLinkRequest(javaId, javaUsername, bedrockUsername) .thenAccept(result -> { if (result instanceof String) { String code = (String) result; System.out.println("Link code: " + code); // Send code to player to share with Bedrock player } else if (result instanceof LinkRequestResult) { LinkRequestResult error = (LinkRequestResult) result; System.out.println("Failed to create link request: " + error); } }); } public void verifyLink(UUID bedrockId, String javaUsername, String bedrockUsername, String code) { playerLink.verifyLinkRequest(bedrockId, javaUsername, bedrockUsername, code) .thenAccept(result -> { if (result == LinkRequestResult.LINK_COMPLETED) { System.out.println("Successfully linked accounts!"); } else { System.out.println("Link verification failed: " + result); } }); } public void unlinkAccount(UUID javaId) { playerLink.unlinkPlayer(javaId) .thenRun(() -> System.out.println("Account unlinked")) .exceptionally(ex -> { ex.printStackTrace(); return null; }); } } ``` -------------------------------- ### Get Actual Server Unique ID Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/02-FloodgatePlayer.md Retrieves the UUID that the server actually uses for this player. This will be the linked Java UUID if the player is linked, otherwise it will be the Floodgate-generated UUID. ```java UUID actualUuid = player.getCorrectUniqueId(); ``` -------------------------------- ### Events - SkinApplyEvent Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/README.md Handles events related to player skin application, allowing for custom skin management for Bedrock players. ```APIDOC ## SkinApplyEvent ### Description An event triggered when a player's skin is applied. This can be used to modify or handle skin changes for Bedrock players. ### Method `subscribeToSkinEvents(Consumer handler)` ### Parameters #### Method Parameters - **handler** (Consumer) - Required - A consumer function that will be called when a SkinApplyEvent occurs. ### Example ```java FloodgateApi.getInstance().getEventBus().subscribeToSkinEvents(event -> { // Handle skin apply event logic here // event.getPlayer() returns the player // event.getSkin() returns the skin data }); ``` ``` -------------------------------- ### FloodgateApi - Entry Point Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/INDEX.md Access the main Floodgate API interface to interact with Floodgate functionalities. This is the primary entry point for most operations. ```APIDOC ## FloodgateApi - Entry Point ### Description Access the main Floodgate API interface to interact with Floodgate functionalities. This is the primary entry point for most operations. ### Usage ```java FloodgateApi api = FloodgateApi.getInstance(); ``` ``` -------------------------------- ### MongoDB Database Configuration Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/08-Configuration.md Configure the MongoDB connection using a connection string and optional settings. This snippet details how to connect to a MongoDB instance. ```yaml mongodb: connectionString: "mongodb://localhost:27017/floodgate" settings: {} ``` -------------------------------- ### Get Actual Server Username Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/02-FloodgatePlayer.md Retrieves the username that the server actually uses for this player. This will be the linked Java username if the player is linked, otherwise it will be the processed Java server username. ```java String actualUsername = player.getCorrectUsername(); ``` -------------------------------- ### Check if Player is Bedrock and Get Player Data Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/INDEX.md Determine if a player is connecting via Floodgate and retrieve their Bedrock player data. This is useful for applying Bedrock-specific logic or features. ```java if (api.isFloodgatePlayer(uuid)) { FloodgatePlayer player = api.getPlayer(uuid); System.out.println("Device: " + player.getDeviceOs()); } ``` -------------------------------- ### Handle No Pending Link Request Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/09-Errors.md If no pending link request exists for the player, log the event and initiate a new link request. ```java if (result == LinkRequestResult.NO_LINK_REQUESTED) { System.out.println("No pending link request for this player"); // Initiate new link request } ``` -------------------------------- ### linkPlayer Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/03-PlayerLink.md Creates a link between a Bedrock account and a Java account. Returns a future completed on success or exceptionally on failure. ```APIDOC ## linkPlayer ### Description Creates a link between a Bedrock account and a Java account. ### Method POST (conceptual, as this is an SDK method) ### Endpoint N/A (SDK Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **bedrockId** (UUID) - Required - UUID of the Bedrock player (Floodgate format) - **javaId** (UUID) - Required - UUID of the Java player - **username** (String) - Required - Username of the Java player ### Request Example ```java playerLink.linkPlayer(bedrockUuid, javaUuid, javaUsername) .thenRun(() -> System.out.println("Link successful")) .exceptionally(ex -> { System.err.println("Link failed: " + ex.getMessage()); return null; }); ``` ### Response #### Success Response `CompletableFuture` – A future completed on success. #### Response Example (See Request Example for usage, response is handled within the CompletableFuture) ERROR HANDLING: - Returns completed exceptionally on failure ``` -------------------------------- ### Enable Debug Logging Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/10-GettingStarted.md Enable debug logging by setting the 'debug' option to true in your config.yml file. This is useful for troubleshooting. ```yaml debug: true ``` -------------------------------- ### Get Java Server Unique ID Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/02-FloodgatePlayer.md Retrieves the UUID that will be used on the Java server. This is generated by Floodgate based on the player's XUID and is not used if the player is linked to a Java account. ```java UUID floodgateUuid = player.getJavaUniqueId(); ``` -------------------------------- ### Implement Custom Floodgate Event Subscriber Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/04-Events.md Implement the `FloodgateSubscriber` interface to create a custom handler for specific events like `SkinApplyEvent`. Register the subscriber with the event bus to receive event notifications. ```java public class CustomSubscriber implements FloodgateSubscriber { @Override public void accept(SkinApplyEvent event) { // Handle event } } // Register FloodgateSubscriber subscriber = new CustomSubscriber(); eventBus.subscribe(subscriber); ``` -------------------------------- ### Send Simple Form to Bedrock Player Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/01-FloodgateApi.md Sends a pre-built Cumulus SimpleForm to a specified Bedrock player. Ensure the player's UUID is valid. ```java SimpleForm form = new SimpleForm("Title", "Content"); FloodgateApi.getInstance().sendForm(playerId, form); ``` -------------------------------- ### Subscribing to SkinApplyEvent Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/04-Events.md Subscribe to SkinApplyEvent to react when a Bedrock player's skin is received and about to be applied. This snippet demonstrates how to log the player's username and conditionally cancel the skin application. ```java FloodgateEventBus eventBus = FloodgateApi.getInstance().getEventBus(); eventBus.subscribe(eventBus.newSubscriber(SkinApplyEvent.class, event -> { FloodgatePlayer player = event.player(); System.out.println("Skin being applied to: " + player.getUsername()); if (player.isLinked()) { // Don't apply skin for linked players event.setCancelled(true); } })); ``` -------------------------------- ### getUiProfile Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/02-FloodgatePlayer.md Retrieves the user interface profile of the Bedrock client. ```APIDOC ## getUiProfile ### Description Returns the user interface profile of the Bedrock client. ### Method GET ### Endpoint N/A (SDK Method) ### Parameters None ### Response #### Success Response - **uiProfile** (UiProfile) - Enum value (CLASSIC, POCKET, etc.). ``` -------------------------------- ### MySQL Databases Configuration for Floodgate Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/08-Configuration.md Configure the MySQL database connection details for Floodgate. This file specifies the host, port, database name, username, and password, along with SSL and other settings. ```yaml # plugins/Floodgate/databases.yml mysql: address: "database.example.com" port: 3306 database: "floodgate_prod" username: "floodgate_user" password: "${FLOODGATE_DATABASE_PASSWORD}" useSSL: true settings: serverTimezone: "UTC" autoReconnect: true cachePrepStmts: true prepStmtCacheSize: 250 prepStmtCacheSqlLimit: 2048 ``` -------------------------------- ### SkinApplyEvent Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/04-Events.md Represents an event fired when a Bedrock player's skin is received and about to be applied. It allows inspection and modification of the skin data. ```APIDOC ## SkinApplyEvent ### Description Fired when a Bedrock player's skin is received and about to be applied. Allows for inspection of the current and new skin, and modification of the skin to be applied. The event is cancellable. ### Methods - **player()**: Returns the `FloodgatePlayer` for whom the skin is being applied. - **currentSkin()**: Returns the `SkinData` of the currently applied skin, or null if none. - **newSkin()**: Returns the `SkinData` of the skin that is about to be applied. - **newSkin(SkinData skinData)**: Sets the `SkinData` to be applied. This method returns the current event instance. ### SkinData Interface Represents skin texture data. - **value()**: Returns the base64-encoded skin texture value. - **signature()**: Returns the signature of the skin texture. ### Cancellation By default, `SkinApplyEvent` is cancelled if the player already has a skin applied. This behavior can be overridden by calling `setCancelled(false)`. ``` -------------------------------- ### PlayerLink - Initiate Account Linking Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/README.md Initiates the account linking process for a Bedrock player, allowing them to connect their Bedrock account to a Java Edition account. ```APIDOC ## Initiate Account Linking ### Description Starts the process for a Bedrock player to link their account with a Java Edition account. ### Method `linkAccount(Player player, String verificationCode)` ### Parameters #### Method Parameters - **player** (Player) - Required - The Bedrock player initiating the link. - **verificationCode** (String) - Required - The code provided for verification. ### Example ```java // Assuming verificationCode is obtained through another means FloodgateApi.getInstance().getPlayerLink().linkAccount(player, verificationCode); ``` ``` -------------------------------- ### Link Bedrock and Java Accounts Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/03-PlayerLink.md Creates a link between a Bedrock account and a Java account using their respective UUIDs and the Java player's username. Handles success and failure asynchronously. ```java playerLink.linkPlayer(bedrockUuid, javaUuid, javaUsername) .thenRun(() -> System.out.println("Link successful")) .exceptionally(ex -> { System.err.println("Link failed: " + ex.getMessage()); return null; }); ``` -------------------------------- ### Transfer Player to Another Server Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/10-GettingStarted.md Initiate a player transfer to a different server using their UUID, host, and port. Only works for Bedrock players. Requires FloodgateApi. ```java public void transferPlayer(UUID uuid, String serverHost, int serverPort) { FloodgateApi api = FloodgateApi.getInstance(); if (!api.isFloodgatePlayer(uuid)) { System.out.println("Can only transfer Bedrock players"); return; } if (api.transferPlayer(uuid, serverHost, serverPort)) { System.out.println("Player transfer initiated"); } else { System.out.println("Transfer failed"); } } ``` -------------------------------- ### Player Linking Configuration Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/08-Configuration.md Configure account linking features, including enabling/disabling linking, requiring it for joining, and setting timeouts. This snippet outlines the available player linking options. ```yaml playerLink: enabled: false requireLink: false enableOwnLinking: true allowed: false linkCodeTimeout: 3600 type: "sqlite" enableGlobalLinking: false ``` -------------------------------- ### SQLite Database Configuration Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/08-Configuration.md Configure the SQLite database connection, specifying the file path and any additional settings. This is used for local database storage. ```yaml sqlite: file: "floodgate.db" settings: {} ``` -------------------------------- ### Check if Linking is Enabled and Allowed Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/03-PlayerLink.md A convenience method that checks if account linking is both enabled and new linking requests are allowed. Use this to determine if a user can initiate a new link. ```java default boolean isEnabledAndAllowed() if (playerLink.isEnabledAndAllowed()) { // Can create link requests } ``` -------------------------------- ### Log Informational Message with Formatting Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/05-Logger.md Logs a general informational message about the application's state or progress. Useful for tracking normal operations. ```java logger.info("Floodgate loaded successfully"); ``` ```java logger.info("Connected to {} players", playerCount); ``` -------------------------------- ### Use {} Placeholders for Log Messages Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/05-Logger.md Use `{}` placeholders for efficient and readable log message formatting. Avoid string concatenation for log messages. ```java // Good logger.info("Player {} joined from {}", username, deviceOs); // Avoid logger.info("Player " + username + " joined from " + deviceOs); ``` -------------------------------- ### createLinkRequest Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/03-PlayerLink.md Initiates a link request from a Java player to a Bedrock player. This method returns a CompletableFuture that resolves with a link code on success or a LinkRequestResult on failure. ```APIDOC ## createLinkRequest ### Description Initiates a link request from a Java player to a Bedrock player. This method returns a CompletableFuture that resolves with a link code on success or a LinkRequestResult on failure. ### Method ```java CompletableFuture createLinkRequest( @NonNull UUID javaId, @NonNull String javaUsername, @NonNull String bedrockUsername ) ``` ### Parameters #### Path Parameters - **javaId** (UUID) - Required - UUID of the Java player initiating link - **javaUsername** (String) - Required - Username of the Java player - **bedrockUsername** (String) - Required - Username of the Bedrock player (receiver) ### Response #### Success Response - **result** (String or LinkRequestResult) - A future containing the link code (String) on success, or LinkRequestResult on failure. ### Request Example ```java playerLink.createLinkRequest(javaUuid, javaUsername, bedrockUsername) .thenAccept(result -> { if (result instanceof String) { String linkCode = (String) result; System.out.println("Link code: " + linkCode); } else if (result instanceof LinkRequestResult) { LinkRequestResult error = (LinkRequestResult) result; System.out.println("Request failed: " + error); } }); ``` ``` -------------------------------- ### Transfer Bedrock Player to Another Server Source: https://github.com/geysermc/floodgate/blob/master/_autodocs/01-FloodgateApi.md Initiates a server transfer for a Bedrock player to a specified address and port. Ensure the address and port are correct. ```java boolean success = FloodgateApi.getInstance() .transferPlayer(playerId, "other.server.com", 19132); ```