Resolve some requested fixes

This commit is contained in:
Cryptite 2023-05-06 11:47:48 -05:00
parent 2f20697d27
commit 8b713e1650
1 changed files with 9 additions and 12 deletions

View File

@ -6,13 +6,12 @@ Subject: [PATCH] Add PlayerPreRespawnLocationEvent
diff --git a/src/main/java/io/papermc/paper/event/player/PlayerPreRespawnLocationEvent.java b/src/main/java/io/papermc/paper/event/player/PlayerPreRespawnLocationEvent.java diff --git a/src/main/java/io/papermc/paper/event/player/PlayerPreRespawnLocationEvent.java b/src/main/java/io/papermc/paper/event/player/PlayerPreRespawnLocationEvent.java
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..cf81752c60fb1cd5a649c50acea759036ba9d094 index 0000000000000000000000000000000000000000..bae7b9d61a061f9a4cc812c1b9107b2695dd5374
--- /dev/null --- /dev/null
+++ b/src/main/java/io/papermc/paper/event/player/PlayerPreRespawnLocationEvent.java +++ b/src/main/java/io/papermc/paper/event/player/PlayerPreRespawnLocationEvent.java
@@ -0,0 +1,68 @@ @@ -0,0 +1,65 @@
+package io.papermc.paper.event.player; +package io.papermc.paper.event.player;
+ +
+import org.apache.commons.lang3.Validate;
+import org.bukkit.Location; +import org.bukkit.Location;
+import org.bukkit.entity.Player; +import org.bukkit.entity.Player;
+import org.bukkit.event.HandlerList; +import org.bukkit.event.HandlerList;
@ -25,7 +24,7 @@ index 0000000000000000000000000000000000000000..cf81752c60fb1cd5a649c50acea75903
+ * 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 PlayerPreRespawnLocationEvent extends PlayerEvent { +public class PlayerPreRespawnLocationEvent extends PlayerEvent {
+ private static final HandlerList handlers = new HandlerList(); + private static final HandlerList HANDLER_LIST = new HandlerList();
+ private final PlayerRespawnEvent.RespawnReason respawnReason; + private final PlayerRespawnEvent.RespawnReason respawnReason;
+ private Location respawnLocation; + private Location respawnLocation;
+ +
@ -41,20 +40,17 @@ index 0000000000000000000000000000000000000000..cf81752c60fb1cd5a649c50acea75903
+ */ + */
+ @Nullable + @Nullable
+ public Location getRespawnLocation() { + public Location getRespawnLocation() {
+ return this.respawnLocation; + return this.respawnLocation != null ? this.respawnLocation.clone() : null;
+ } + }
+ +
+ /** + /**
+ * Sets the new respawn location. + * Sets the new respawn location.
+ * + *
+ * @param respawnLocation The exact location for the respawn.<br/> + * @param respawnLocation The exact location for the respawn. Can be set to null to invalidate any previously called/modified events<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 + * <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. + * providing a good respawn location for a Player.
+ */ + */
+ public void setRespawnLocation(@NotNull Location respawnLocation) { + public void setRespawnLocation(@Nullable Location respawnLocation) {
+ Validate.notNull(respawnLocation, "Respawn location can not be null");
+ Validate.notNull(respawnLocation.getWorld(), "Respawn world can not be null");
+
+ this.respawnLocation = respawnLocation; + this.respawnLocation = respawnLocation;
+ } + }
+ +
@ -63,6 +59,7 @@ index 0000000000000000000000000000000000000000..cf81752c60fb1cd5a649c50acea75903
+ * + *
+ * @return the reason the event was called. + * @return the reason the event was called.
+ */ + */
+ @NotNull
+ public PlayerRespawnEvent.RespawnReason getRespawnReason() { + public PlayerRespawnEvent.RespawnReason getRespawnReason() {
+ return respawnReason; + return respawnReason;
+ } + }
@ -70,11 +67,11 @@ index 0000000000000000000000000000000000000000..cf81752c60fb1cd5a649c50acea75903
+ @NotNull + @NotNull
+ @Override + @Override
+ public HandlerList getHandlers() { + public HandlerList getHandlers() {
+ return handlers; + return HANDLER_LIST;
+ } + }
+ +
+ @NotNull + @NotNull
+ public static HandlerList getHandlerList() { + public static HandlerList getHandlerList() {
+ return handlers; + return HANDLER_LIST;
+ } + }
+} +}