From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MisterVector <whizkid3000@hotmail.com>
Date: Fri, 26 Oct 2018 21:31:00 -0700
Subject: [PATCH] Implement PlayerPostRespawnEvent


diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
index faecf79341623305a2ae55cb9c4b8844adf0c5bb..b8302de65a7b04790594d23e0bb730b2d3a1b191 100644
--- a/src/main/java/net/minecraft/server/PlayerList.java
+++ b/src/main/java/net/minecraft/server/PlayerList.java
@@ -627,9 +627,14 @@ public abstract class PlayerList {
 
         // this.a(entityplayer1, entityplayer, worldserver); // CraftBukkit - removed
 
+        // Paper start
+        boolean isBedSpawn = false;
+        boolean isRespawn = false;
+        // Paper end
+
         // CraftBukkit start - fire PlayerRespawnEvent
         if (location == null) {
-            boolean isBedSpawn = false;
+            //boolean isBedSpawn = false; Paper - moved up
             CraftWorld cworld = (CraftWorld) this.server.server.getWorld(entityplayer.spawnWorld);
             if (cworld != null && blockposition != null) {
             Optional<Vec3D> optional = EntityHuman.getBed(cworld.getHandle(), blockposition, flag1);
@@ -662,6 +667,7 @@ public abstract class PlayerList {
 
             location = respawnEvent.getRespawnLocation();
             if (!flag) entityplayer.reset(); // SPIGOT-4785
+            isRespawn = true; // Paper
         } else {
             location.setWorld(server.getWorldServer(dimensionmanager).getWorld());
         }
@@ -723,6 +729,13 @@ public abstract class PlayerList {
         if (entityplayer.playerConnection.isDisconnected()) {
             this.savePlayerFile(entityplayer);
         }
+
+        // Paper start
+        if (isRespawn) {
+            cserver.getPluginManager().callEvent(new com.destroystokyo.paper.event.player.PlayerPostRespawnEvent(entityplayer.getBukkitEntity(), location, isBedSpawn));
+        }
+        // Paper end
+
         // CraftBukkit end
         return entityplayer1;
     }
