Floodgate Integration (Bedrock Support)
Relevant source files
The following files were used as context for generating this wiki page:- Plugin/src/main/java/xyz/xreatlabs/nexauth/common/integration/FloodgateIntegration.java
- Plugin/src/main/java/xyz/xreatlabs/nexauth/paper/FloodgateHelper.java
- Plugin/src/main/java/xyz/xreatlabs/nexauth/common/AuthenticNexAuth.java
- Plugin/src/main/resources/paper-plugin.yml
- Plugin/src/main/java/xyz/xreatlabs/nexauth/common/command/Command.java
- README.md
NexAuth provides support for Minecraft Bedrock Edition players through integration with the Floodgate plugin. This allows users connecting via GeyserMC to be authenticated by NexAuth. The integration is automatically enabled when NexAuth detects the Floodgate plugin on the server, providing a seamless experience for server administrators.
This system works by wrapping the Floodgate API to identify Bedrock players and applying specific logic to handle their connection and authentication flow. This includes special handling on Paper servers to work around potential packet processing issues and restricting certain commands that are not applicable to Bedrock players.
Sources: README.md:19, Plugin/src/main/java/xyz/xreatlabs/nexauth/common/AuthenticNexAuth.java:338-341
Activation and Detection
The Floodgate integration is designed to be plug-and-play. During its startup sequence, NexAuth checks for the presence of the Floodgate plugin. If detected, it initializes the FloodgateIntegration class and enables Bedrock support features.
Sources: Plugin/src/main/java/xyz/xreatlabs/nexauth/common/AuthenticNexAuth.java:338-341
The following diagram illustrates the activation logic:
Dependency Declaration
NexAuth declares a soft dependency on Floodgate, ensuring it loads before NexAuth if present. This is configured in the plugin's metadata files.
paper-plugin.yml
dependencies:
server:
floodgate:
load: "BEFORE"
required: false
Sources: Plugin/src/main/resources/paper-plugin.yml:9-12
Core Components
FloodgateIntegration Class
This class acts as a direct wrapper for the Floodgate API, simplifying interactions and centralizing the logic for identifying Bedrock players.
This diagram shows that FloodgateIntegration uses the singleton instance of the FloodgateApi to perform its checks.
Sources: Plugin/src/main/java/xyz/xreatlabs/nexauth/common/integration/FloodgateIntegration.java:13-32
Key Methods
| Method | Description | Source File |
|---|---|---|
isFloodgateId(UUID uuid) | Checks if a given UUID belongs to a Floodgate (Bedrock) player by calling api.isFloodgatePlayer(uuid). | FloodgateIntegration.java:20-22 |
getPlayer(String username) | Retrieves a FloodgatePlayer object by iterating through all online Floodgate players and matching their username. Returns null if not found. | FloodgateIntegration.java:24-32 |
Player Identification
NexAuth uses helper methods within the main AuthenticNexAuth class to quickly determine if a player is connecting from Bedrock.
fromFloodgate(UUID uuid): This is the primary method used to check if a player's UUID is a Floodgate-generated one. It returnstrueonly if Floodgate is enabled and theisFloodgateIdcheck passes.fromFloodgate(String username): A similar check, but based on the player's username.
These checks are used in various parts of the plugin, such as command handling, to apply Bedrock-specific logic.
Sources: Plugin/src/main/java/xyz/xreatlabs/nexauth/common/AuthenticNexAuth.java:932-934, Plugin/src/main/java/xyz/xreatlabs/nexauth/common/AuthenticNexAuth.java:953-955
Command Handling
To prevent issues, certain commands are disabled for Bedrock players. When a command is executed, a check is performed to see if the player is a Floodgate user. If so, an error message is sent, and the command is blocked.
// From Command.java
protected User getUser(P player) {
// ...
var uuid = plugin.getPlatformHandle().getUUIDForPlayer(player);
if (plugin.fromFloodgate(uuid)) throw new InvalidCommandArgument(getMessage("error-from-floodgate"));
return plugin.getDatabaseProvider().getByUUID(uuid);
}
Sources: Plugin/src/main/java/xyz/xreatlabs/nexauth/common/command/Command.java:68-74
Paper-Specific Packet Handling
On Paper servers, NexAuth includes a FloodgateHelper class to address a specific issue where Floodgate's packet handling tasks might not run correctly. This helper intercepts the login start packet to ensure the Bedrock player's data is processed correctly.
Sources: Plugin/src/main/java/xyz/xreatlabs/nexauth/paper/FloodgateHelper.java:17-23
The process is as follows:
- The
processFloodgateTasksmethod is called with thePacketReceiveEvent. - It retrieves the
FloodgatePlayerobject from the Netty channel attributes. - It checks for and applies any pending kick messages set by Floodgate.
- It sets the player's username in the login packet to the
correctUsernameprovided by Floodgate. - Finally, it removes Floodgate's original data handler from the channel pipeline to prevent conflicts.
The following sequence diagram shows this interaction:
This diagram visualizes the steps taken by FloodgateHelper to manually process Floodgate data during the login sequence on a Paper server.
Sources: Plugin/src/main/java/xyz/xreatlabs/nexauth/paper/FloodgateHelper.java:24-44
Summary
The Floodgate integration in NexAuth is a critical feature for servers that support both Java and Bedrock Edition players. It is enabled automatically upon detecting the Floodgate plugin and provides robust mechanisms for identifying and handling Bedrock player connections. Through a combination of API wrapping, conditional logic, and platform-specific workarounds like the FloodgateHelper for Paper, NexAuth ensures that Bedrock players are correctly managed within its authentication system.
Sources: README.md:19, Plugin/src/main/java/xyz/xreatlabs/nexauth/common/AuthenticNexAuth.java:338-341