Protocolize

repository·master·Indexed 43 days ago

https://github.com/exceptionflug/protocolize

A protocol manipulation framework for BungeeCord and Velocity proxy servers that allows developers to intercept and manipulate Minecraft protocol packets. It provides a protocolize-api (v2.4.2) for Maven and Gradle projects, supporting Minecraft versions 1.14 - 1.21 by default, with legacy support for 1.8.x - 1.13.2 via additional modules.

Tokens
2.2K
Snippets
10
Records
14
Agent score
55%

What's inside Protocolize

  1. Add Protocolize to Maven project

    master

    To use the Protocolize API in a Maven project, add the exceptionflug repository and the protocolize-api dependency. Note that the scope should be set to provided because the plugin is installed on the proxy server at runtime.

    <repository>
        <id>exceptionflug</id>
        <url>https://mvn.exceptionflug.de/repository/exceptionflug-public/</url>
    </repository>
    
    <dependency>
        <groupId>dev.simplix</groupId>
        <artifactId>protocolize-api</artifactId>
        <version>2.4.2</version>
        <scope>provided</scope>
    </dependency>
  2. Add Protocolize to Gradle project

    master

    To use the Protocolize API in a Gradle project, add the exceptionflug Maven repository and use compileOnly for the protocolize-api dependency.

    repositories {
        maven {
            url = uri('https://mvn.exceptionflug.de/repository/exceptionflug-public/')
        }
    }
    
    dependencies {
        compileOnly("dev.simplix:protocolize-api:2.4.1")
    }
  3. Default implemented packet classes

    master

    The default data module includes implementations for the following packet classes in the dev.simplix.protocolize.data.packets package:

    PacketClass
    Player block placementBlockPlacement
    Inventory clickClickWindow
    Close inventoryCloseWindow
    Confirm transactionConfirmTransaction
    Held item changeHeldItemChange
    Named sound effectNamedSoundEffect
    Sound effectSoundEffect
    Open inventoryOpenWindow
    Player look updatePlayerLook
    Player position updatePlayerPosition
    Player position and look updatePlayerPositionLook
    Player slot updateSetSlot
    Player item interactionUseItem
    Inventory itemsWindowItems
    Inventory propertiesWindowProperty
  4. Create a WritableBookContentComponent

    master

    Use the static create method on the WritableBookContentComponent interface to instantiate a new component. This method uses the internal Protocolize service to resolve the appropriate factory. You must provide a list of WriteablePage objects.

    List<WriteablePage> pages = List.of(new WriteablePage("Hello World", "Hello World"));
    WritableBookContentComponent component = WritableBookContentComponent.create(pages);
  5. Convert ChatElement to various formats

    master

    Once you have a ChatElement<T>, you can extract the underlying component or convert it back into a specific data format using the following methods:

    • asComponent(): Returns the underlying component of type T.
    • asJson(): Returns the component as a JSON string.
    • asLegacyText(): Returns the component as a legacy color-coded string.
    • asNbt(): Returns the component as an NBT Tag<?>.
    • toString(): Returns the component as legacy text.
    ChatElement<T> element = ChatElement.ofLegacyText("§bBlue Text");
    
    String json = element.asJson();
    String legacy = element.asLegacyText();
    Tag<?> nbt = element.asNbt();
    T component = element.asComponent();
  6. Construct ChatElement instances

    master

    Use the static factory methods on the ChatElement interface to create chat components from different input formats. These methods automatically resolve the appropriate ComponentConverter via the Protocolize service provider.

    Available factory methods:

    • ofLegacyText(String text): Creates a ChatElement from a legacy Minecraft-style color-coded string.
    • ofJson(String text): Creates a ChatElement from a JSON-formatted component string.
    • ofNbt(Tag<?> tag): Creates a ChatElement from an NBT tag.
    // Create from legacy text
    ChatElement<T> legacy = ChatElement.ofLegacyText("§aHello World");
    
    // Create from JSON
    ChatElement<T> json = ChatElement.ofJson("{\"text\": \"Hello\"}");
    
    // Create from NBT
    ChatElement<T> nbt = ChatElement.ofNbt(someNbtTag);
  7. Use WritableBookContentComponent to manage book pages

    master

    The WritableBookContentComponent interface allows you to manage a collection of WriteablePage objects. It extends StructuredComponent and provides methods to manipulate the page list.

    // Get all pages
    List<WriteablePage> pages = component.getPages();
    
    // Add a new page
    component.addPage(new WriteablePage("New Page Content", "New Page Content"));
    
    // Remove a specific page
    component.removePage(somePage);
    
    // Clear all pages
    component.removeAllPages();
    
    // Set the entire list of pages
    component.setPages(newPagesList);
  8. Use the /protocolize command in BungeeCord

    master

    The /protocolize command is the primary CLI entrypoint for managing the Protocolize plugin on a BungeeCord proxy. It can be executed by the console or players (depending on the sub-command).

    Sub-commands

    No arguments

    Running /protocolize without any arguments displays the current version and author of the plugin.

    debug

    Running /protocolize debug generates a debug report and saves it to a file named protocolize-debug.txt in the server's root directory.

    Note: This sub-command can only be executed by the console. If a player attempts to use it, the command will fail with an error message.

    ### Usage Examples
    
    # Display version information (Console or Player)
    /protocolize
    
    # Generate a debug report (Console ONLY)
    /protocolize debug