Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/plugins/bed.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,25 @@ function inject (bot) {
}
}

await bot.activateBlock(bedBlock)
bot.activateBlock(bedBlock)

await waitUntilSleep()
}
}

async function waitUntilSleep () {
return new Promise((resolve, reject) => {
const timeoutForSleep = setTimeout(() => {
reject(new Error('bot is not sleeping'))
}, 3000)

bot.once('sleep', () => {
clearTimeout(timeoutForSleep)
resolve()
})
})
}

bot._client.on('game_state_change', (packet) => {
if (packet.reason === 0) {
// occurs when you can't spawn in your bed and your spawn point gets reset
Expand Down
1 change: 0 additions & 1 deletion test/externalTests/bed.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ module.exports = () => async (bot) => {
// Sleep
assert(!bot.isSleeping)
await bot.sleep(bot.blockAt(bedPos1))
await once(bot, 'sleep')

// Wake
assert(bot.isSleeping)
Expand Down