Skip to content

Allow annotated event listeners with only one method #92

Open
@lucko

Description

@lucko

I have a mod that (previously, and now) uses @SubscribeEvent annotations in listener classes. The mod has a number of these listener classes, with event subscriptions organised in a way that makes sense for the project. e.g. world events, connection events, etc. split into their own class.

The same registration approach (with the SubscribeEvent annotation) is used for all listeners - it is consistent.

One of the listener classes (currently) only listens to one event. The check below now prevents that listener class from using the annotation-based approach.

else if (listeners.size() == 1)
throw new IllegalArgumentException("Only a single listener found in " + listenerClass + ". You should directly call addListener() on the EventBus of " + firstValidListenerEventType.getSimpleName() + " instead.");

I assume this was done with good intentions to nudge people towards the 'new' way - but I feel in some cases (like the one outlined above) the annotation approach does make sense even with only one event being listened to.

Please could you reconsider.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions