Skip to content

Latest commit

 

History

History
79 lines (63 loc) · 2.53 KB

README.md

File metadata and controls

79 lines (63 loc) · 2.53 KB

Alfajor

A ViaVersion hack library to intercept and override packet mappers of specific protocols.

Example code

public class DemoBukkitPlugin extends JavaPlugin {

    @Override
    public void onLoad() {
        // Shortcut of Via.getManager().getProtocolManager().getProtocol();
        Protocol1_8To1_9 protocol = ViaAlfajor.getProtocol(Protocol1_8To1_9.class);
        // Class to start the dirty tricks
        ProtocolHandle<ClientboundPackets1_8, ServerboundPackets1_9> handle = ProtocolHandle.wrap(protocol);
        // Append a PacketHandlers to the add_mob mapping
        // It wouldn't override any registered handler, only run after it
        handle.injectClientbound(ClientboundPackets1_8.ADD_MOB,
            remapper -> {
                // Do whatever you want here
            });

        // Append a handler for serverbound packets
        handle.injectServerbound(ServerboundPackets1_9.MOVE_VEHICLE,
            remapper -> {
                //...
            }
        );

        // Replace the whole add_mob handler chain.
        handle.injectOverrideClientbound(ClientboundPackets1_8.ADD_MOB,
            remapper -> {
                // ...
            });
    }
}

Note:

  • The remapper in every callback is a PacketHandlers instance; use .map(...)/.handler(...) on it to build the field mapping, same as when writing a ViaVersion Protocol yourself
  • Be careful with adding handlers; fields and objects might already be consumed and will throw an exception

There is a plugin example of coloured beds for clients that support it with a 1.8.8 server base.

Dependency

Maven:

<repositories>
    <repository>
        <id>unnamed-snapshots</id>
        <url>https://repo.unnamed.team/repository/unnamed-snapshots/</url>
    </repository>
</repositories>

<dependency>
    <groupId>me.oczi.alfajor</groupId>
    <artifactId>Alfajor-api</artifactId>
    <version>1.1-SNAPSHOT</version>
    <scope>compile</scope>
</dependency>

Gradle:

repositories {
    maven { url 'https://repo.unnamed.team/repository/unnamed-snapshots/' }
}

compileOnly('me.oczi.alfajor:Alfajor-api:1.1-SNAPSHOT')

Build

The entire project is built with JDK 17 using ViaVersion 5.11.0 as the target.

The API is licensed under The MIT License and the plugin example is under GPL v3 License.