-
Notifications
You must be signed in to change notification settings - Fork 243
Bad fix of hasPermission() on null #1865
Comments
You're not supposed to to kick from a login event handler. You're supposed to cancel the event. That should make it behave correctly. Don't worry, I've seen a lot of plugin devs get that wrong... |
^_^ it's still an issue however, and should be catered for. |
@dschwartz783 this also goes to other events, such as block placement, block interaction, entity damage, etc. In fact, cancelled or not, |
@Muqsit the issues about other events is still not fully resolved. |
This is not going to be straightforward. I added an exception throw for getting permissions of an offline player and that in itself caused a server crash when broadcasting the player quit message. This is a very widespread issue. |
On the plus side, this problem will only affect cancellables. Which means that PlayerQuitEvent wouldn't need such an override anyway. |
Totally confirmed but. PurePerms crashes the server when I join (noone else), but it shouldn't kick me though |
Throw all the blame on me for the fix 😂 |
Issue description
Currently, when a plugin kicks a player in PlayerLoginEvent, etc., the server will continue to execute code that handles the client without checking whether the player is online. While there are no errors, it is WRONG for the server to continue doing stuff on a player that isn't online, assuming it is online.
Previously, this problem was mainly reflected by the internal call on
Player::hasPermission
that leads to a crash. Although an explicit null check is done on hasPermission, callinghasPermission
on a closed player should indeed raise a warning (through throwing an exception) rather than returning a boolean false, as some plugins may hence cache and assume that the answer isfalse
, while the actual value is undefined.Vice versa. This also applies to myriad event calls related to players. Refer to comments below.
Possible resolution
Event::isCancelled
inPlayerEvent
(and probablyEntityEvent
too), and add a check to confirm that the player is online:PlayerEvent::isCancelled
for events that should not implement such check, such asPlayerQuitEvent
:Side effects
Slight backwards incompatibility. We cannot ask older plugins that declare events like
PlayerQuitEvent
to overrideisCancelled
.Resolution of side effects
I have been unable to come up with any resolution of side effects.
However, according to @shoghicp, the main author of the PocketMine event and plugin system, plugins SHOULD NOT extend PlayerEvent, etc. All events declared by plugins should extend
PluginEvent
. (It is believed that an exception is plugin events that share same handler lists as default events are not included by this statement, although this is not a good idea either)For old plugins that extend
PluginEvent
, they are totally not covered by the proposed change in the Possible Resolution section above. The issues with them may or may not continue to exist, but they will only have the chance to get better, not worse, anyway.Steps to reproduce the issue
Write a plugin that kicks a player in
Player(Pre)?LoginEvent
without cancelling the event.OS and versions
Crashdump, backtrace, memory dumps, plugins list or other files
Plugin used to produce the issue.
The text was updated successfully, but these errors were encountered: