Skip to content

Feat: generic events #8

@0x000006

Description

@0x000006

Generic events would be really useful for avoiding repetitive if conditions at the beginning of an event handler, thus improving readability.

A possible solution for this problem is a new typed event handler like @​GenericEventHandler(Something.class) and an IGenericEvent interface with a getClass() method which returns Class.

An example use case for typed events would be this:

@GenericEventHandler(CustomPayloadS2CPacket.class)
private void onPluginMessageReceive(GenericPacketEvent.Receive<CustomPayloadS2CPacket> event) {
    // event.packet is of type CustomPayloadS2CPacket at compile time
}

instead of

@EventHandler
private void onPluginMessageReceive(PacketEvent.Receive event) {
    if (!(event.packet instanceof CustomPayloadS2CPacket packet)) {
        return;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions