Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - New API #3243

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Conversation

Ingrim4
Copy link
Collaborator

@Ingrim4 Ingrim4 commented Sep 22, 2024

This PR initiates the development of a new API as outlined in #2996, aiming to improve the overall maintainability and flexibility of ProtocolLib. As this is the first draft, backward compatibility may be (temporarily) broken, and it will primarily serve to track progress and gather feedback on API design and concerns. The PR will remain a work-in-progress until all current features have been incorporated into the new API, with stability and structure refined for broader usage.

I encourage everyone to participate in shaping this new API. If you have suggestions, concerns, or alternative approaches, feel free to contribute your thoughts. Feedback on design decisions, modularity, or areas where backward compatibility might be preserved is especially welcome. This collaborative effort will help ensure the API meets the needs of both current and future developers. Please don’t hesitate to recommend changes or improvements as we refine the API together.

Register an async listener

protocolLib.createListener(plugin)
    .types(PacketTypes.Game.LEVEL_CHUNK)
    .priority(PacketListenerPriority.LOW)
    .ignoreCancelledPackets()
    .registerAsync((packet, context) -> {
        Chunk chunk = Chunk.from(packet);
        
        // do processing here ...

        context.addTransmissionListener(chunk::markSent);
        context.resumeProcessing();
    });

Sending/Receiving packets

protocolLib.connection(player)
    .packetOperation()
    .skipProcessing()
    .postTransmission(chunk::markSent)
    .send(chunk.packet());

protocolLib.connection(player)
    .sendPacket(chunk.packet());

protocolLib.sendPacket(player, chunk.packet());

@Ingrim4 Ingrim4 self-assigned this Sep 22, 2024
@Dymeth
Copy link

Dymeth commented Oct 21, 2024

At this stage everything looks easy to interact with.
I'd like to see the rest of the interfaces.

Separation of API and implementation is a change that has been needed for a long time, and I'm glad there is someone willing to take it on now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants