Add PlayerPreRespawnEvent
This commit is contained in:
@@ -6,13 +6,14 @@ Subject: [PATCH] Add PlayerData Events
|
|||||||
|
|
||||||
diff --git a/src/main/java/com/destroystokyo/paper/event/player/PlayerLoadDataEvent.java b/src/main/java/com/destroystokyo/paper/event/player/PlayerLoadDataEvent.java
|
diff --git a/src/main/java/com/destroystokyo/paper/event/player/PlayerLoadDataEvent.java b/src/main/java/com/destroystokyo/paper/event/player/PlayerLoadDataEvent.java
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..ae0132d9c7ae17b478d1d504961e1fd6b479f6d0
|
index 0000000000000000000000000000000000000000..2501922ea0fe84ed07e33503d84dd74a423e39e3
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/src/main/java/com/destroystokyo/paper/event/player/PlayerLoadDataEvent.java
|
+++ b/src/main/java/com/destroystokyo/paper/event/player/PlayerLoadDataEvent.java
|
||||||
@@ -0,0 +1,63 @@
|
@@ -0,0 +1,64 @@
|
||||||
+package com.destroystokyo.paper.event.player;
|
+package com.destroystokyo.paper.event.player;
|
||||||
+
|
+
|
||||||
+import com.google.gson.JsonObject;
|
+import com.google.gson.JsonObject;
|
||||||
|
+import org.bukkit.Bukkit;
|
||||||
+import org.bukkit.event.Event;
|
+import org.bukkit.event.Event;
|
||||||
+import org.bukkit.event.HandlerList;
|
+import org.bukkit.event.HandlerList;
|
||||||
+import org.jetbrains.annotations.NotNull;
|
+import org.jetbrains.annotations.NotNull;
|
||||||
@@ -30,7 +31,7 @@ index 0000000000000000000000000000000000000000..ae0132d9c7ae17b478d1d504961e1fd6
|
|||||||
+ private JsonObject statistics;
|
+ private JsonObject statistics;
|
||||||
+
|
+
|
||||||
+ public PlayerLoadDataEvent(@NotNull UUID playerId) {
|
+ public PlayerLoadDataEvent(@NotNull UUID playerId) {
|
||||||
+ super();
|
+ super(!Bukkit.isPrimaryThread());
|
||||||
+ this.playerId = playerId;
|
+ this.playerId = playerId;
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
|
|||||||
66
patches/api/0019-Add-PlayerPreRespawnEvent.patch
Normal file
66
patches/api/0019-Add-PlayerPreRespawnEvent.patch
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Cryptite <cryptite@gmail.com>
|
||||||
|
Date: Sat, 28 Dec 2024 07:59:54 -0600
|
||||||
|
Subject: [PATCH] Add PlayerPreRespawnEvent
|
||||||
|
|
||||||
|
|
||||||
|
diff --git a/src/main/java/io/papermc/paper/event/player/PlayerPreRespawnEvent.java b/src/main/java/io/papermc/paper/event/player/PlayerPreRespawnEvent.java
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000000000000000000000000000000000000..c98a1e76e565d4b95b5fe31f734f8ab496348ecb
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/src/main/java/io/papermc/paper/event/player/PlayerPreRespawnEvent.java
|
||||||
|
@@ -0,0 +1,54 @@
|
||||||
|
+package io.papermc.paper.event.player;
|
||||||
|
+
|
||||||
|
+import org.apache.commons.lang3.Validate;
|
||||||
|
+import org.bukkit.Location;
|
||||||
|
+import org.bukkit.entity.Player;
|
||||||
|
+import org.bukkit.event.HandlerList;
|
||||||
|
+import org.bukkit.event.player.PlayerEvent;
|
||||||
|
+import org.jetbrains.annotations.NotNull;
|
||||||
|
+import org.jetbrains.annotations.Nullable;
|
||||||
|
+
|
||||||
|
+/**
|
||||||
|
+ * Called before a player's respawn location is determined.
|
||||||
|
+ */
|
||||||
|
+public class PlayerPreRespawnEvent extends PlayerEvent {
|
||||||
|
+ private static final HandlerList handlers = new HandlerList();
|
||||||
|
+ private Location respawnLocation;
|
||||||
|
+
|
||||||
|
+ public PlayerPreRespawnEvent(@NotNull final Player respawnPlayer) {
|
||||||
|
+ super(respawnPlayer);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * Gets the current respawn location
|
||||||
|
+ *
|
||||||
|
+ * @return Location current respawn location
|
||||||
|
+ */
|
||||||
|
+ @Nullable
|
||||||
|
+ public Location getRespawnLocation() {
|
||||||
|
+ return this.respawnLocation;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * Sets the new respawn location
|
||||||
|
+ *
|
||||||
|
+ * @param respawnLocation new location for the respawn
|
||||||
|
+ */
|
||||||
|
+ public void setRespawnLocation(@NotNull Location respawnLocation) {
|
||||||
|
+ Validate.notNull(respawnLocation, "Respawn location can not be null");
|
||||||
|
+ Validate.notNull(respawnLocation.getWorld(), "Respawn world can not be null");
|
||||||
|
+
|
||||||
|
+ this.respawnLocation = respawnLocation;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @NotNull
|
||||||
|
+ @Override
|
||||||
|
+ public HandlerList getHandlers() {
|
||||||
|
+ return handlers;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @NotNull
|
||||||
|
+ public static HandlerList getHandlerList() {
|
||||||
|
+ return handlers;
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
66
patches/server/0029-Add-PlayerPreRespawnEvent.patch
Normal file
66
patches/server/0029-Add-PlayerPreRespawnEvent.patch
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Cryptite <cryptite@gmail.com>
|
||||||
|
Date: Sat, 28 Dec 2024 07:59:54 -0600
|
||||||
|
Subject: [PATCH] Add PlayerPreRespawnEvent
|
||||||
|
|
||||||
|
|
||||||
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
||||||
|
index 46f060f33fcbc6a4568a7fcfba29e83a4d192578..3f2f5673663b812cba05c058a7afd3598eb4685a 100644
|
||||||
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
||||||
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
||||||
|
@@ -807,25 +807,37 @@ public abstract class PlayerList {
|
||||||
|
boolean isRespawn = false;
|
||||||
|
// Paper end - Add PlayerPostRespawnEvent
|
||||||
|
|
||||||
|
- // CraftBukkit start - fire PlayerRespawnEvent
|
||||||
|
- TeleportTransition teleporttransition;
|
||||||
|
- if (location == null) {
|
||||||
|
- 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) { // 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;
|
||||||
|
+ // Slice start
|
||||||
|
+ TeleportTransition teleporttransition = null;
|
||||||
|
+ io.papermc.paper.event.player.PlayerPreRespawnEvent preRespawnEvent = new io.papermc.paper.event.player.PlayerPreRespawnEvent(entityplayer.getBukkitEntity());
|
||||||
|
+ preRespawnEvent.callEvent();
|
||||||
|
+ Location respawnLocation = preRespawnEvent.getRespawnLocation();
|
||||||
|
+ if (respawnLocation != null) {
|
||||||
|
+ teleporttransition = new TeleportTransition(((CraftWorld) respawnLocation.getWorld()).getHandle(), CraftLocation.toVec3D(respawnLocation), Vec3.ZERO, respawnLocation.getYaw(), respawnLocation.getPitch(), TeleportTransition.DO_NOTHING);
|
||||||
|
+ }
|
||||||
|
+ // Slice end
|
||||||
|
+
|
||||||
|
+ if (teleporttransition == null) {
|
||||||
|
+ // CraftBukkit start - fire PlayerRespawnEvent
|
||||||
|
+ if (location == null) {
|
||||||
|
+ 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) { // 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
|
||||||
|
}
|
||||||
|
- // Spigot End
|
||||||
|
ServerLevel worldserver = teleporttransition.newLevel();
|
||||||
|
entityplayer1.spawnIn(worldserver);
|
||||||
|
entityplayer1.unsetRemoved();
|
||||||
Reference in New Issue
Block a user