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)
privatevoidonPluginMessageReceive(GenericPacketEvent.Receive<CustomPayloadS2CPacket> event) {
// event.packet is of type CustomPayloadS2CPacket at compile time
}instead of
@EventHandlerprivatevoidonPluginMessageReceive(PacketEvent.Receiveevent) {
if (!(event.packetinstanceofCustomPayloadS2CPacketpacket)) {
return;
}
}
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:
instead of