Add events for other plugins to interact with player data saving and injection #24
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.