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

[MCTCommon/Events] Improve event firing and listening #199

Merged
merged 3 commits into from
Feb 23, 2024

Conversation

ScribbleTAS
Copy link
Member

@ScribbleTAS ScribbleTAS commented Feb 22, 2024

Improved event handling in preparation of #193
Continuation of my refactor attempt in c578256 , which I postponed at the time

Changes

Firing events

Added a single fireEvent() method that takes the class of the event to fire as a parameter
and removed the fire methods in each individual event.

Registering event listeners

Instead of the registry just being one big list with all event listeners, the registry is now a hasmap of arraylists.
This is to avoid iterating over the entire list, to find which event listeners listens for the event that is being fired.

By using the Event.class as a key during registering, EVENTLISTENER_REGISTRY.get() returns the list of listeners that do actually implement the event.

Registering lambdas

Coincidentally, it is now possible to register lambdas as event listeners.

Misc

Moved CompactPacketHandler to server package as that it where it actually belongs

@ScribbleTAS ScribbleTAS added this to the Beta1.0 milestone Feb 22, 2024
@ScribbleTAS ScribbleTAS added Enhancement New feature or request Common Issue relates to the common package labels Feb 22, 2024
@ScribbleTAS ScribbleTAS self-assigned this Feb 22, 2024
@ScribbleTAS ScribbleTAS marked this pull request as ready for review February 23, 2024 15:43
@ScribbleTAS ScribbleTAS merged commit dc9334d into MinecraftTAS:develop Feb 23, 2024
2 checks passed
@ScribbleTAS ScribbleTAS deleted the enhancement/events branch February 23, 2024 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Common Issue relates to the common package Enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants