Geyser Documentation

repository·master·Indexed 26 days ago

https://github.com/geysermc/geyser

Geyser is a proxy that bridges Minecraft: Bedrock Edition and Minecraft: Java Edition, enabling cross-platform play by translating network packets between the two game protocols. This documentation covers server setup, compiling from source, and developing Geyser extensions, including the implementation of custom commands using the Command, CommandExecutor, and CommandSource APIs.

Tokens
1.7K
Snippets
0
Records
12
Agent score
90%

What's inside Geyser

  1. Overview of Geyser

    master
    Geyser is a proxy that bridges the gap between Minecraft: Bedrock Edition and Minecraft: Java Edition. It allows Bedrock Edition users to join Java Edition servers by translating packets between the two different game protocols. Note that because of the nature of protocol translation, some features may not work perfectly.
  2. Compile Geyser from source

    master

    To build Geyser from the repository, follow these steps:

    1. Clone the repository to your local machine.
    2. Navigate to the Geyser root directory and initialize submodules:
      git submodule update --init --recursive
    3. Build the project using Gradle:
      ./gradlew build
    4. The build artifacts can be found in the bootstrap/build folder.
  3. Define custom commands in Geyser extensions

    master

    To create a new command for your Geyser extension, use the Command.builder(Extension extension) method. You must specify a source type (any class extending CommandSource, such as GeyserConnection) to ensure the command executor receives the correct type of source.

    Key configuration options include:

    • name(String name): The command name.
    • description(String description): A description of the command.
    • permission(String permission): The permission node required to run the command.
    • aliases(List<String> aliases): A list of alternative names for the command.
    • playerOnly(boolean playerOnly): If true, the command can only be executed by players.
    • bedrockOnly(boolean bedrockOnly): If true, the command can only be executed by Bedrock players.
    • executor(CommandExecutor<T> executor): The logic to run when the command is called.

    Finally, call build() to create the Command instance.

  4. Implement custom commands in Geyser extensions

    master

    To add custom commands to a Geyser extension, extend the GeyserExtensionCommand class. This class handles the integration with the extension's root command and provides a builder pattern for defining command properties like name, description, permissions, and execution logic.

    Key requirements:

    • The extension must have a non-blank rootCommand() defined.
    • You must specify a sourceType (the class of the object that will be passed to your executor).
    • You must provide a CommandExecutor to handle the command logic.

    Note: If the sourceType is GeyserConnection, the command is automatically treated as bedrockOnly.

  5. Configure command permissions in Geyser standalone mode

    master

    In standalone mode, you can manage command access by configuring PermissionConfiguration. This allows you to define sets of permissions that are granted or denied by default. Use the following keys in your configuration file:

    • defaultPermissions: A set of permission strings that are granted by default.
    • defaultDeniedPermissions: A set of permission strings that are denied by default.
  6. Use Command.Builder to construct commands

    master

    The Command.Builder<T> interface is used to configure and instantiate a Command. The generic type T represents the CommandSource type that will be passed to the command's executor.

    MethodDescription
    source(Class<? extends T> sourceType)Defines the source type (e.g., GeyserConnection.class).
    name(String name)Sets the command name.
    description(String description)Sets the command description.
    permission(String permission)Sets the permission node required.
    aliases(List<String> aliases)Sets the command aliases.
    playerOnly(boolean playerOnly)Sets if the command is player-only.
    bedrockOnly(boolean bedrockOnly)Sets if the command is Bedrock-only.
    executor(CommandExecutor<T> executor)Sets the command executor.
    build()Returns the constructed Command.
  7. Use the GeyserExtensionCommand.Builder to define commands

    master

    The GeyserExtensionCommand.Builder<T> is used to configure the properties of a new command. Use the following methods to set up your command:

    • source(Class<? extends T> sourceType): Defines the type of the command source (e.g., GeyserCommandSource or GeyserConnection).
    • name(String name): The command name.
    • description(String description): The command description.
    • permission(String permission): The permission required to run the command.
    • permission(String permission, TriState defaultValue): Sets the permission and its default state.
    • aliases(List<String> aliases): A list of alternative names for the command.
    • playerOnly(boolean playerOnly): If true, the command can only be run by players.
    • bedrockOnly(boolean bedrockOnly): If true, the command can only be run by Bedrock players.
    • executor(CommandExecutor<T> executor): The logic to run when the command is invoked.
    • executableOnConsole(boolean executableOnConsole): A convenience method; if false, it sets playerOnly to true.
  8. Implement CommandExecutor to handle commands in Geyser extensions

    master

    To handle command execution within a Geyser extension, implement the CommandExecutor<T> interface. The execute method is called when a command is triggered, providing the command source, the command object itself, and the array of arguments passed by the user. The generic type T must extend CommandSource.

    Implement this interface to define custom logic for how your extension responds to specific commands.

  9. Use the CommandSource interface to interact with command executors

    master
    The CommandSource interface represents an entity capable of receiving commands and messages (such as a player or the server console). When implementing or using command logic, you can use this interface to send messages back to the user, check for permissions, or identify if the source is a specific Bedrock player via their GeyserConnection.
  10. Implement the Command interface

    master

    The Command interface represents a registered command in Geyser. When implementing or interacting with a command, the following methods are available:

    • name(): Returns the command name.
    • description(): Returns the command description.
    • permission(): Returns the permission node string.
    • aliases(): Returns an unmodifiable list of aliases.
    • isPlayerOnly(): Returns true if the command is restricted to players.
    • isBedrockOnly(): Returns true if the command is restricted to Bedrock players.
  11. CommandSource API Reference

    master

    The CommandSource interface provides the following methods for interacting with the source of a command:

    • String name(): Returns the name of the command source.
    • void sendMessage(String message): Sends a single message to the command source.
    • void sendMessage(String[] messages): Sends an array of messages to the command source.
    • boolean isConsole(): Returns true if the source is the server console.
    • @Nullable UUID playerUuid(): Returns the Java UUID if the source is a player; otherwise returns null.
    • @Nullable GeyserConnection connection(): Returns the GeyserConnection if the source is a Bedrock player connected to this Geyser instance; otherwise returns null.
    • String locale(): Returns the locale of the command source.
    • boolean hasPermission(String permission): Checks if the command source has the specified permission node.