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

Add events for other plugins to interact with player data saving and injection #24

Merged
merged 7 commits into from Jul 14, 2021

Conversation

TheNewHEROBRINEX
Copy link
Contributor

Introduction

This PR adds two cancellable events, one for data injection and one for data saving.

Changes

PerWorldPlayerDataInjectEvent

This event is called whenever a player joins the server or switches world, before data injection happens.
Other plugins can change whatever data is going to injected in the player or cancel the event to prevent the injection from happening at all.
I chose not to give a way for plugins to enforce data injection if the origin and the target worlds are in the same bundle or if the player has got the per-world-player.bypass permission to avoid useless queries to the database.

PerWorldPlayerDataSaveEvent

This event is called when a player quits the server or switches world, before data saving happens (so it's called before PerWorldPlayerDataInjectEvent).
Other plugins, also in this case, can change whatever data is going to be saved or cancel event to completely prevent data saving.
If the player has the per-world-player.bypass permission, the event will be called anyway but it will cancelled by default so that other plugins can still enforce data injection in some situations.
Currently, this implementation has got one issue, that is, there is no way for plugins to enforce data injection if the origin and target worlds are in the same bundle. This is because the two checks are in two different functions and I was not sure how to handle the situation, so I'm open to suggestions.

Minor changes

I added two debug messages, one after a data save is complete and the other when data save is cancelled so that plugin developers can understand if what happens it's actually what they wanted to achieve.

@Muqsit Muqsit added the enhancement New feature or request label Jul 12, 2021
@Muqsit Muqsit merged commit 50ce736 into BlockHorizons:master Jul 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants