aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0280-Add-PlayerPostRespawnEvent.patch
blob: 5adb0c50ef4258198cf0d2c81e87dfcb20c0aa35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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] Add PlayerPostRespawnEvent


diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index dffc7f0c9c730bc629ee169eca3a7a997c2cc7b1..29110c0b950c3073ab699d8ad1523ece2e8d3408 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -705,6 +705,10 @@ public abstract class PlayerList {
 
             entityplayer1.addTag(s);
         }
+        // Paper start - Add PlayerPostRespawnEvent
+        boolean isBedSpawn = false;
+        boolean isRespawn = false;
+        // Paper end - Add PlayerPostRespawnEvent
 
         // CraftBukkit start - fire PlayerRespawnEvent
         TeleportTransition teleporttransition;
@@ -712,11 +716,16 @@ public abstract class PlayerList {
             teleporttransition = entityplayer.findRespawnPositionAndUseSpawnBlock(!flag, TeleportTransition.DO_NOTHING, reason);
 
             if (!flag) entityplayer.reset(); // SPIGOT-4785
+           // Paper start - Add PlayerPostRespawnEvent
+           if (teleporttransition == null) return entityplayer; // Early exit, mirrors belows early return for disconnected players in respawn event
+           isRespawn = true;
+           location = CraftLocation.toBukkit(teleporttransition.position(), teleporttransition.newLevel().getWorld(), teleporttransition.yRot(), teleporttransition.xRot());
+           // Paper end - Add PlayerPostRespawnEvent
         } else {
             teleporttransition = new TeleportTransition(((CraftWorld) location.getWorld()).getHandle(), CraftLocation.toVec3D(location), Vec3.ZERO, location.getYaw(), location.getPitch(), TeleportTransition.DO_NOTHING);
         }
         // Spigot Start
-        if (teleporttransition == null) {
+        if (teleporttransition == null) { // Paper - Add PlayerPostRespawnEvent - diff on change - spigot early returns if respawn pos is null, that is how they handle disconnected player in respawn event
             return entityplayer;
         }
         // Spigot End
@@ -764,6 +773,11 @@ public abstract class PlayerList {
             if (iblockdata.is(Blocks.RESPAWN_ANCHOR)) {
                 entityplayer1.connection.send(new ClientboundSoundPacket(SoundEvents.RESPAWN_ANCHOR_DEPLETE, SoundSource.BLOCKS, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), 1.0F, 1.0F, worldserver.getRandom().nextLong()));
             }
+            // Paper start - Add PlayerPostRespawnEvent
+            if (iblockdata.is(net.minecraft.tags.BlockTags.BEDS) && !teleporttransition.missingRespawnBlock()) {
+                isBedSpawn = true;
+            }
+            // Paper end - Add PlayerPostRespawnEvent
         }
         // Added from changeDimension
         this.sendAllPlayerInfo(entityplayer); // Update health, etc...
@@ -785,6 +799,13 @@ public abstract class PlayerList {
         if (entityplayer.connection.isDisconnected()) {
             this.save(entityplayer);
         }
+
+        // Paper start - Add PlayerPostRespawnEvent
+        if (isRespawn) {
+            cserver.getPluginManager().callEvent(new com.destroystokyo.paper.event.player.PlayerPostRespawnEvent(entityplayer.getBukkitEntity(), location, isBedSpawn));
+        }
+        // Paper end - Add PlayerPostRespawnEvent
+
         // CraftBukkit end
 
         return entityplayer1;