LuckPerms

LuckPerms

905k Downloads

Add an event when player's primary group changes

NEZNAMY opened this issue ยท 2 comments

commented

Description

Adding an API event that would trigger when player's primary group changes.
Currently the closest event that can be used is UserDataRecalculateEvent, however, this event is being called very frequently and multiple times at once from several threads even when group didn't change, which makes is sub-optimal at best.
Additionally, I have seen this event not being called on world/server switch where player's primary group has changed due to contexts, which makes the event impossible to use reliably.

Proposed Behaviour

An event that triggers (preferably only once) whenever player's primary group changes.

Extra Details

This will allow a more reliable event-based hook instead of using a periodic task.

commented

I remember using a similar event in the past (may have been this one), however it was being called so frequently that the final performance was in fact way worse than before.

commented

You can use NodeMutateEvent and check if the PermissionHolder receiving/losing groups is instance of a User and you can check that way if their primary group is different. It's not the exact same thing but it does exactly what you want and this only gets called when permission information gets changed for a Node (Group/Player).