Rename to PlayerPreRespawnLocationEvent and further clarify what setRespawnLocation does

This commit is contained in:
Cryptite 2023-05-03 11:14:09 -05:00
parent 828cd13188
commit 9f64deb098
2 changed files with 14 additions and 12 deletions

View file

@ -1,15 +1,15 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Cryptite <cryptite@gmail.com> From: Cryptite <cryptite@gmail.com>
Date: Mon, 1 May 2023 15:23:34 -0500 Date: Mon, 1 May 2023 15:23:34 -0500
Subject: [PATCH] Add PlayerGetRespawnLocationEvent Subject: [PATCH] Add PlayerPreRespawnLocationEvent
diff --git a/src/main/java/com/destroystokyo/paper/event/player/PlayerGetRespawnLocationEvent.java b/src/main/java/com/destroystokyo/paper/event/player/PlayerGetRespawnLocationEvent.java diff --git a/src/main/java/com/destroystokyo/paper/event/player/PlayerPreRespawnLocationEvent.java b/src/main/java/com/destroystokyo/paper/event/player/PlayerPreRespawnLocationEvent.java
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..98e369de90ac2b71363bb0a45bb5baaf14e1cd5a index 0000000000000000000000000000000000000000..b321cc19d6ca57050233339ced6c84d9f793f1b6
--- /dev/null --- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/player/PlayerGetRespawnLocationEvent.java +++ b/src/main/java/com/destroystokyo/paper/event/player/PlayerPreRespawnLocationEvent.java
@@ -0,0 +1,55 @@ @@ -0,0 +1,57 @@
+package com.destroystokyo.paper.event.player; +package com.destroystokyo.paper.event.player;
+ +
+import org.apache.commons.lang3.Validate; +import org.apache.commons.lang3.Validate;
@ -24,11 +24,11 @@ index 0000000000000000000000000000000000000000..98e369de90ac2b71363bb0a45bb5baaf
+/** +/**
+ * Called when a respawn event tries to determine the location of a respawn. This is called before {@link PlayerRespawnEvent} + * Called when a respawn event tries to determine the location of a respawn. This is called before {@link PlayerRespawnEvent}
+ */ + */
+public class PlayerGetRespawnLocationEvent extends PlayerEvent { +public class PlayerPreRespawnLocationEvent extends PlayerEvent {
+ private static final HandlerList handlers = new HandlerList(); + private static final HandlerList handlers = new HandlerList();
+ private Location respawnLocation; + private Location respawnLocation;
+ +
+ public PlayerGetRespawnLocationEvent(@NotNull final Player respawnPlayer) { + public PlayerPreRespawnLocationEvent(@NotNull final Player respawnPlayer) {
+ super(respawnPlayer); + super(respawnPlayer);
+ } + }
+ +
@ -43,9 +43,11 @@ index 0000000000000000000000000000000000000000..98e369de90ac2b71363bb0a45bb5baaf
+ } + }
+ +
+ /** + /**
+ * Sets the new respawn location + * Sets the new respawn location.
+ * + *
+ * @param respawnLocation new location for the respawn + * @param respawnLocation The exact location for the respawn.<br/>
+ * <b>Note:</b> If this is provided, <b>no vanilla logic that calculates "safe" respawn locations will be done.</b> It is up to you to ensure you are
+ * providing a good respawn location for a Player.
+ */ + */
+ public void setRespawnLocation(@NotNull Location respawnLocation) { + public void setRespawnLocation(@NotNull Location respawnLocation) {
+ Validate.notNull(respawnLocation, "Respawn location can not be null"); + Validate.notNull(respawnLocation, "Respawn location can not be null");

View file

@ -1,11 +1,11 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Cryptite <cryptite@gmail.com> From: Cryptite <cryptite@gmail.com>
Date: Mon, 1 May 2023 15:23:34 -0500 Date: Mon, 1 May 2023 15:23:34 -0500
Subject: [PATCH] Add PlayerGetRespawnLocationEvent Subject: [PATCH] Add PlayerPreRespawnLocationEvent
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index 4d837c1530a3031a4c2a5a39d87bd013d60e14a6..3f3d9bb6274ba370cf8e401015e9f0979e398824 100644 index 4d837c1530a3031a4c2a5a39d87bd013d60e14a6..75e7430fcc2d55575aadbdf2cb0c3969d7b63741 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java --- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java +++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -835,6 +835,14 @@ public abstract class PlayerList { @@ -835,6 +835,14 @@ public abstract class PlayerList {
@ -14,7 +14,7 @@ index 4d837c1530a3031a4c2a5a39d87bd013d60e14a6..3f3d9bb6274ba370cf8e401015e9f097
if (location == null) { if (location == null) {
+ // Paper start + // Paper start
+ Player respawnPlayer = entityplayer1.getBukkitEntity(); + Player respawnPlayer = entityplayer1.getBukkitEntity();
+ com.destroystokyo.paper.event.player.PlayerGetRespawnLocationEvent preRespawnEvent = new com.destroystokyo.paper.event.player.PlayerGetRespawnLocationEvent(respawnPlayer); + com.destroystokyo.paper.event.player.PlayerPreRespawnLocationEvent preRespawnEvent = new com.destroystokyo.paper.event.player.PlayerPreRespawnLocationEvent(respawnPlayer);
+ preRespawnEvent.callEvent(); + preRespawnEvent.callEvent();
+ location = preRespawnEvent.getRespawnLocation(); + location = preRespawnEvent.getRespawnLocation();
+ +