Fix hasFiredAsync
parameter when AsyncPlayerSendCommandsEvent
is called
#10896
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.
AsyncPlayerSendCommandsEvent
is fired twice, once async, then sync. The javadocs suggest using the logicif (event.isAsynchronous() || !event.hasFiredAsync()) { // do stuff }
to only react to the async event.However, this check will currently pass during both times the event fires. As seen using this simple plugin:
When a player logs in, the event is fired like so:
Both times the event is called, the
hasFiredAsync
value isfalse
. Therefore!event.hasFiredAsync()
is alwaystrue
, and// do stuff
would always run.This PR simply makes it so the second time the event is called,
hasFiredAsync
istrue
:With this,
if (event.isAsynchronous() || !event.hasFiredAsync()) { // do stuff }
will only do stuff during the async event, as the javadocs suggest.I imagine this is a copy-paste error back from when the event was first added in this commit: fdf41b7#diff-1b1388b7c287d608bf170cd9f7f3ac9477793ac427c444b8968f86e9f4477468R20-R28.
The javadocs mention
If for some reason we are unable to send this asynchronously in the future, only the sync method will fire
. If the async call is eventually removed, I imagine the sync event call should havehasFiredAsync
set tofalse
(which would then be a correct statement). I believe that is the intended purpose of suggesting theif (event.isAsynchronous() || !event.hasFiredAsync()) { // do stuff }
logic, so that// do stuff
is still run if the async call is ever removed.