Skip to content

Added method to wait until sleep function is in reality sleeping#2617

Merged
u9g merged 9 commits into
PrismarineJS:masterfrom
sefirosweb:fixing_sleeping_Bed
Jun 14, 2022
Merged

Added method to wait until sleep function is in reality sleeping#2617
u9g merged 9 commits into
PrismarineJS:masterfrom
sefirosweb:fixing_sleeping_Bed

Conversation

@sefirosweb
Copy link
Copy Markdown
Contributor

@sefirosweb sefirosweb commented May 7, 2022

  • The FAQ doesn't contain a resolution to my issue

Versions

  • mineflayer: 4.3.0
  • server: vanilla 1.18.1
  • node: Dockerized: node:16.13-bullseye

Detailed description of a problem

If the bot click on bed at same time when other bot/player click on bed and steal him they don't return any error,
The function no return an error

I attach video you can see a bit better: https://youtu.be/S5PrYqO4KRk

Expected behavior

Throw an error

@sefirosweb
Copy link
Copy Markdown
Contributor Author

How i can rerun tests?

@amoraschi
Copy link
Copy Markdown
Contributor

Push some changes, but doesn't the sleeping duration vary with the server's TPS?

@sefirosweb
Copy link
Copy Markdown
Contributor Author

Push some changes, but doesn't the sleeping duration vary with the server's TPS?

Yes, but the idea is not to get the sleeping duration, only they detect if bot are sleeping or not,
Because they don't return if the bot can be clicked correctly to bed

@sefirosweb
Copy link
Copy Markdown
Contributor Author

Seems this PR break the test of sleep, checking..

…conds, only return an error when over 3 seconds is not sleeping
@sefirosweb
Copy link
Copy Markdown
Contributor Author

@amoraschi done!

I think now is much better, (See code)

the sleep function waits until the sleep event is triggered,

If there is no error and the event is not triggered then it returns an error indicating that it has not been able to sleep
So in this way we will avoid errors that the .catch event of sleep() is never fired

I removed in the test "await once(bot, 'sleep')" because sleep now wait to this trigger

Copy link
Copy Markdown
Contributor

@amoraschi amoraschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Promise should reject instead of resolve inside the setTimeout

Comment thread lib/plugins/bed.js Outdated
@sefirosweb sefirosweb changed the title Added timeout for detect if bot still sleeping or not Added method to wait until sleep function is in reality sleeping May 7, 2022
@u9g
Copy link
Copy Markdown
Member

u9g commented Jun 14, 2022

Thanks

@u9g u9g merged commit 9dfa882 into PrismarineJS:master Jun 14, 2022
@sefirosweb sefirosweb deleted the fixing_sleeping_Bed branch January 28, 2023 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants