PlayerBedLeaveEvent Specific Cause?

Discussion in 'Spigot Plugin Development' started by A_Brave_Panda, Aug 3, 2018.

  1. Hey there, so its been a while since I've played around with Spigot. Just curious if there is a way to get how the player left the bed, whether it is from them clicking leave bed, the bed was broken, or if they fully slept in the PlayerBedLeaveEvent event. I didn't see anything on the javadocs, but you all are sometimes better than the javadocs haha. Thanks for any help!
  2. It doesn't look like there is a way to get the reason, but there is possibly a way to check for the cause yourself.

    Because you can get the bed associated with the event (PlayerBedLeaveEvent#getBed(), returns Block), you can check if that Block exists, and if it doesn't, it's probably safe to assume that the bed existed when the event was triggered, then broken. I'm not 100% sure that the block will reflect that it's no longer a bed during the event handling, but it's always possible to run a task 1 tick later to be sure.

    The fully slept part is probably trickier. I can say that there's a sleepTicks value if you're using reflection/nms, although I can't think exactly how that'd be helpful. In general, if a player has slept for 100 ticks, they're kicked out of bed and the time is set to day. This would quite likely be a little different on multiplayer and may just require at least 100 before they're counted as sleeping in vanilla. So perhaps you could assume that if they're woken up and sleepTicks was above 100, it was fully slept, but there could be some false positives with that.
    • Informative Informative x 1
  3. Awesome, I appreciate the help and I will look into it! Thanks :)
  4. Mark as solved please.
  5. They didn't say it was solved. Just did they'd look into using what we've said so far.
    • Like Like x 1
    • Agree Agree x 1