This PR attempts to increase session creation and removal safety while increasing flexibility for third party developers.
Changes
SessionListener
onLogin() priority was set to highest and uses the tag @ignoreCancelledto prevent Parties from creating a session for a player that will be immediately disconnected.
onQuit() priority was set to lowest, allowing third party plugin developers to use Sessions on this event without specifying a higher priority. The listener also checks whether the session exists before trying to remove it.
SessionFactory
Added the (static) function hasSession() to let third party developers check if a session exists and additionally reuse code internally.
Both createSession() and removeSession() throw exceptions now if they are used improperly.
About the PR
Right now, the sessions are removed on a very unsafe way (it doesn't even check if the player has a session).
https://github.com/Diduhless/Parties/blob/e9565ba148c5a4beee68b0a9efde5a6697178b81/src/diduhless/parties/listener/SessionListener.php#L20-L22
This PR attempts to increase session creation and removal safety while increasing flexibility for third party developers.
Changes
SessionListener
onLogin() priority was set to highest and uses the tag
@ignoreCancelled
to prevent Parties from creating a session for a player that will be immediately disconnected.onQuit() priority was set to lowest, allowing third party plugin developers to use Sessions on this event without specifying a higher priority. The listener also checks whether the session exists before trying to remove it.
SessionFactory
Added the (static) function hasSession() to let third party developers check if a session exists and additionally reuse code internally.
Both createSession() and removeSession() throw exceptions now if they are used improperly.