From d641927fce55b1cb669a62565fc5289cc34e92c2 Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Wed, 25 Dec 2019 10:11:08 +1100
Subject: [PATCH] SPIGOT-5481: PlayerBedLeaveEvent returns wrong bed location

---
 nms-patches/EntityHuman.patch | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/nms-patches/EntityHuman.patch b/nms-patches/EntityHuman.patch
index 4620b9f29c..2f3e13db52 100644
--- a/nms-patches/EntityHuman.patch
+++ b/nms-patches/EntityHuman.patch
@@ -362,7 +362,13 @@
  
          this.entitySleep(blockposition);
          this.sleepTicks = 0;
-@@ -1215,6 +1373,23 @@
+@@ -1210,11 +1368,28 @@
+     }
+ 
+     public void wakeup(boolean flag, boolean flag1) {
++        BlockPosition bedPosition = this.getBedPosition().orElse(null); // CraftBukkit
+         super.entityWakeup();
+         if (this.world instanceof WorldServer && flag1) {
              ((WorldServer) this.world).everyoneSleeping();
          }
  
@@ -371,9 +377,8 @@
 +            Player player = (Player) this.getBukkitEntity();
 +
 +            org.bukkit.block.Block bed;
-+            BlockPosition blockposition = this.getBedPosition().orElse(null);
-+            if (blockposition != null) {
-+                bed = this.world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
++            if (bedPosition != null) {
++                bed = this.world.getWorld().getBlockAt(bedPosition.getX(), bedPosition.getY(), bedPosition.getZ());
 +            } else {
 +                bed = this.world.getWorld().getBlockAt(player.getLocation());
 +            }