-
Notifications
You must be signed in to change notification settings - Fork 71
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
Always inject player for player events #1352
Conversation
As injection is implemented, this will likely cause more problems than fix. The only offline player errors that I'm still aware of would actually be exacerbated by this -- an event within an event. I wrote a solution that only injects on join and uninjects on quit, but there are still other issues to consider such that I never considered it a complete solution. |
Thinking about it more broadly, do you think that storing the player reference in the event handler environment would solve these issues? |
That would only directly fix player() and not when using player names for arguments. The only known issue right now is teleporting players cross worlds particularly on player_quit, since this causes a player_spawn event, and will uninject the player for the remainder of that player_quit bind. (I think this should be able to be worked around for now by putting the teleport at the end of the script, until this is fixed) |
Prevent player events from firing for offline players in edge cases where players have just left the server.
99d0271
to
b12caff
Compare
Rebased PR on master and implemented nested event player injection support. Running live on my server to see whether it solves the issue for which this PR was made. |
That's a good solution to the nesting issue, but I think we need to go back to the original problem, which I'll try to lay out here. During certain events that include the 'player' key, the player object cannot be retrieved by name from the server's player list. Sometimes this can be expected, as with player_login, while other times it's unexpected, as with player_spawn. At some point we decided to use the injected players map to store these references, even though it was designed for capture_runas(). Maybe this helped back then, but today Player.isOnline() checks if the player exists in the player list, so even if we could pass this player object to functions, they'd still be considered offline and throw an exception in Static.GetPlayer(). This means the only thing injection is doing right now is helping add the player to the environment in a roundabout fashion. This could be done better by just checking if the underlying event is an MCPlayerEvent, with a fallback for other events with 'player' that don't need injection. It also turns out the player is in the player list during player_join and player_quit events these days, so injection isn't even needed there anyway. There's one additional wrinkle. Player.isOnline() checks the player list by UUID, not name, and it turns out there's one event where these maps are desynced: player_spawn. This is the one event where injection DOES help, since the player would be online despite not being able to fetch them by name from the player list. I'm wondering if a workaround to this could be added to the abstraction implementation instead, since I would consider this a bug in the server implementation. Regarding player_command after a player quits, I believe that was fixed in Craftbukkit. |
I pushed some changes based on my updated understanding of the issue. This still leaves some unresolved questions, but it does fix event injection nesting issues. Unresolved issues:
|
Thanks for pushing the changes. It sounds like that makes this PR obsolete. Should I close this? |
It does make the PR obsolete, but not the previously mentioned issues surrounding this subject. If you close this, I could open up an issue to track this conversation. |
Sounds good. I'll let you create an issue for this. You can close this PR when that's done. |
Continued in issue #1370 |
Prevent player events from firing for offline players in edge cases where players have just left the server.