cloudburstmc/protocol

repository·3.0·Indexed 19 days ago

https://github.com/cloudburstmc/protocol

A Minecraft protocol library providing implementations for Bedrock Edition network communication across multiple versions. It is used by projects such as Cloudburst, ProxyPass, Geyser, and BedrockConnect. The library includes comprehensive data structures for Bedrock command information, including CommandData, CommandParam, and CommandOverloadData, as well as support for the bedrock-connection dependency.

Tokens
4.7K
Snippets
17
Records
19
Agent score
64%

What's inside cloudburstmc-protocol

  1. Overview of the Protocol library

    3.0
    The Protocol library is a Minecraft protocol implementation that supports multiple versions, specifically focusing on Bedrock Edition. It is used by major projects such as Cloudburst, ProxyPass, Geyser, and BedrockConnect to handle network communication for Bedrock clients.
  2. Add the Protocol library to a Maven project

    3.0

    To use the protocol library in a Maven project, add the opencollab-snapshots repository to your <repositories> section and include the bedrock-connection dependency in your <dependencies> section.

    <repositories>
        <repository>
            <id>opencollab-snapshots</id>
            <url>https://repo.opencollab.dev/maven-snapshots/</url>
        </repository>
    </repositories>
    
    <dependencies>
        <dependency>
            <groupId>org.cloudburstmc.protocol</groupId>
            <artifactId>bedrock-connection</artifactId>
            <version>3.0.0.Beta13-SNAPSHOT</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
  3. Add the Protocol library to a Gradle project

    3.0

    To use the protocol library in a Gradle project, add the OpenCollab Maven snapshot repository to your repositories block and include the bedrock-connection dependency. Note that the version used in this example is a snapshot; you should check the latest available version in the OpenCollab Maven repository.

    repositories {
        maven("https://repo.opencollab.dev/maven-snapshots/")
    }
    
    dependencies {
        implementation("org.cloudburstmc.protocol:bedrock-connection:3.0.0.Beta13-SNAPSHOT")
    }
  4. Represent command symbol data with CommandSymbolData

    3.0

    The CommandSymbolData class is used to represent the metadata associated with command symbols in the Bedrock protocol. It encapsulates a base integer value along with several bitwise flags that define the nature of the command parameter (e.g., whether it is an enumeration or has a postfix).

    Key properties include:

    • value: The core integer value of the symbol.
    • commandEnum: Indicates if the symbol is part of a command enumeration.
    • softEnum: Indicates if the symbol is a 'soft' enumeration.
    • postfix: Indicates if the symbol uses a postfix.

    You can create an instance by deserializing an integer type using CommandSymbolData.deserialize(int type), which extracts the flags and the base value. To convert the object back into its protocol-compliant integer representation, use the serialize() method.

    // Deserializing from a protocol integer
    int protocolType = 0x200000; // Example: an ENUM flag
    CommandSymbolData data = CommandSymbolData.deserialize(protocolType);
    
    // Accessing properties
    int baseValue = data.getValue();
    boolean isEnum = data.isCommandEnum();
    
    // Serializing back to a protocol integer
    int serialized = data.serialize();
  5. Use SoftEnumUpdateType for command enum updates

    3.0

    The SoftEnumUpdateType enum defines the available operations for updating an enumeration within a command context. Use these constants to specify how an existing enum should be modified during a soft update:

    • ADD: Adds a new value to the enumeration.
    • REMOVE: Removes an existing value from the enumeration.
    • REPLACE: Replaces an existing value with a new one.
    public enum SoftEnumUpdateType {
        ADD,
        REMOVE,
        REPLACE
    }
  6. Use CommandEnumConstraint for command enumeration types

    3.0

    The CommandEnumConstraint enum defines the available constraint types used when specifying command enumeration constraints in the Bedrock protocol. These constraints are used to restrict or validate command usage based on specific server-side permissions or settings.

    // Available enum constants:
    CommandEnumConstraint.CHEATS_ENABLED
    CommandEnumConstraint.OPERATOR_PERMISSIONS
    CommandEnumConstraint.HOST_PERMISSIONS
    CommandEnumConstraint.ALLOW_ALIASES
  7. Use CommandData.Flag to configure command behavior

    3.0

    The CommandData.Flag enum provides bit flags that can be used to modify how a command is treated by the Bedrock protocol. These flags control visibility, execution rules, and synchronization.

    Available flags:

    • TEST_USAGE: Used for testing purposes.
    • HIDDEN_FROM_COMMAND_BLOCK: Prevents the command from being used in command blocks.
    • HIDDEN_FROM_PLAYER: Hides the command from the player's command suggestions/list.
    • HIDDEN_FROM_AUTOMATION: Hides the command from automated systems.
    • LOCAL_SYNC: Indicates local synchronization requirements.
    • EXECUTE_DISALLOWED: Marks the command as disallowed for execution.
    • MESSAGE_TYPE: Relates to the message type of the command.
    • NOT_CHEAT: Indicates the command is not considered a cheat.
    • ASYNC: Indicates the command can be handled asynchronously.
    public enum Flag {
        TEST_USAGE, // 1
        HIDDEN_FROM_COMMAND_BLOCK, // 2
        HIDDEN_FROM_PLAYER, // 4
        HIDDEN_FROM_AUTOMATION, // 8
        LOCAL_SYNC, // 16
        EXECUTE_DISALLOWED, // 32
        MESSAGE_TYPE, // 64
        NOT_CHEAT,// 128
        ASYNC // 256
    }
  8. Identify command origin types with CommandOriginType

    3.0

    The CommandOriginType enum defines the various sources or contexts from which a command can be executed within the Bedrock protocol. This is used to distinguish between commands issued by players, automated systems, server entities, or specific game contexts.

    public enum CommandOriginType {
        PLAYER,
        BLOCK,
        MINECART_BLOCK,
        DEV_CONSOLE,
        TEST,
        AUTOMATION_PLAYER,
        CLIENT_AUTOMATION,
        DEDICATED_SERVER,
        ENTITY,
        VIRTUAL,
        GAME_ARGUMENT,
        ENTITY_SERVER,
        PRECOMPILED,
        GAME_DIRECTOR_ENTITY_SERVER,
        SCRIPT,
        EXECUTE_CONTEXT
    }
  9. Reference the available CommandParam constants

    3.0

    The CommandParam class provides a set of predefined constants representing different types of Bedrock command parameters. These constants are used to define the expected type and structure of arguments within a command. When working with Bedrock command data, you should use these static instances to specify parameter types like INT, STRING, TARGET, JSON, or BLOCK_POSITION.

    Commonly used parameter types include:

    • Numeric: INT, FLOAT, INT_RANGE, RATIONAL_RANGE.
    • Targets: TARGET, WILDCARD_TARGET, NON_ID_TARGET.
    • Selectors: SCORE_SELECTOR, TAG_SELECTOR, PERMISSION_SELECTOR.
    • Data Formats: JSON, JSON_ARRAY, BLOCK_STATE, FILE_PATH.
    • Coordinates: COORD_X_INT, COORD_Y_INT, COORD_Z_INT, POSITION.
    • Commands: COMMAND, SLASH_COMMAND, CHAINED_COMMAND.
    // Example of using predefined CommandParam constants
    CommandParam myParam = CommandParam.INT;
    CommandParam myTarget = CommandParam.TARGET;
    CommandParam myJson = CommandParam.JSON;
  10. Reference the CommandParamType enumeration

    3.0

    The CommandParamType enum defines the various types of parameters used in Bedrock command structures. When parsing or constructing commands, use these tokens to identify the expected data type for a specific command argument (e.g., INT, STRING, TARGET, JSON, etc.).

    public enum CommandParamType {
        UNKNOWN,
        INT,
        FLOAT,
        VALUE,
        R_VALUE,
        WILDCARD_INT,
        OPERATOR,
        COMPARE_OPERATOR,
        TARGET, // selection
        STANDALONE_TARGET,
        WILDCARD_TARGET,
        NON_ID_TARGET,
        SCORE_ARG,
        SCORE_ARGS,
        SCORE_SELECT_PARAM,
        SCORE_SELECTOR,
        TAG_SELECTOR,
        FILE_PATH,
        FILE_PATH_VAL,
        FILE_PATH_CONT,
        INT_RANGE_VAL,
        INT_RANGE_POST_VAL,
        INT_RANGE,
        INT_RANGE_FULL,
        RATIONAL_RANGE_VAL,
        RATIONAL_RANGE_POST_VAL,
        RATIONAL_RANGE,
        RATIONAL_RANGE_FULL,
        SEL_ARGS,
        ARGS,
        ARG,
        MARG,
        MVALUE,
        NAME,
        TYPE,
        FAMILY,
        PERMISSION,
        PERMISSIONS,
        PERMISSION_SELECTOR,
        PERMISSION_ELEMENT,
        PERMISSION_ELEMENTS,
        TAG,
        HAS_ITEM_ELEMENT,
        HAS_ITEM_ELEMENTS,
        HAS_ITEM,
        HAS_ITEMS,
        HAS_ITEM_SELECTOR,
        EQUIPMENT_SLOTS,
        PROPERTY_VALUE,
        HAS_PROPERTY_PARAM_VALUE,
        HAS_PROPERTY_PARAM_ENUM_VALUE,
        HAS_PROPERTY_ARG,
        HAS_PROPERTY_ARGS,
        HAS_PROPERTY_ELEMENT,
        HAS_PROPERTY_ELEMENTS,
        HAS_PROPERTY_SELECTOR,
        STRING, // id
        ID,
        ID_CONT,
        COORD_X_INT,
        COORD_Y_INT,
        COORD_Z_INT,
        COORD_X_FLOAT,
        COORD_Y_FLOAT,
        COORD_Z_FLOAT,
        BLOCK_POSITION, // int position
        POSITION, // float position
        MESSAGE_XP,
        MESSAGE,
        MESSAGE_ROOT,
        POST_SELECTOR,
        TEXT, // raw text
        TEXT_CONT,
        JSON_VALUE,
        JSON_FIELD,
        JSON, // json object
        JSON_OBJECT_FIELDS,
        JSON_OBJECT_CONT,
        JSON_ARRAY,
        JSON_ARRAY_VALUES,
        JSON_ARRAY_CONT,
        BLOCK_STATE,
        BLOCK_STATE_KEY,
        BLOCK_STATE_VALUE,
        BLOCK_STATE_VALUES,
        BLOCK_STATES,
        BLOCK_STATES_CONT,
        CLOCK_TIME_MARKER_NAME,
        COMMAND,
        SLASH_COMMAND,
        CHAINED_COMMAND,
        CODE_BUILDER_ARG,
        CODE_BUILDER_ARGS,
        CODE_BUILDER_SELECT_PARAM,
        CODE_BUILDER_SELECTOR,
    }