Add TeleportFlags (#8855)

Abstracts relative teleport flags and instead makes a generic TeleportFlag option. This has the benefit of being able to easily add new flags in the future.
This adds a new flag, which allows you to keep inventories open when teleporting players (vanilla behavior).

These are breaking changes to the teleport api, however, it's still marked as experimental so I find this a fair change.
This commit is contained in:
Owen 2023-03-04 17:07:23 -05:00 committed by GitHub
parent 8a815a0eae
commit d30cda1273
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 157 additions and 155 deletions

View file

@ -35,51 +35,100 @@ index 0000000000000000000000000000000000000000..7713a5b7e06da185685f18e79eae2c97
+ */
+ EYES;
+}
diff --git a/src/main/java/io/papermc/paper/entity/RelativeTeleportFlag.java b/src/main/java/io/papermc/paper/entity/RelativeTeleportFlag.java
diff --git a/src/main/java/io/papermc/paper/entity/TeleportFlag.java b/src/main/java/io/papermc/paper/entity/TeleportFlag.java
new file mode 100644
index 0000000000000000000000000000000000000000..0426ee8bd71142b6f933a479c0f2e5ef6043147d
index 0000000000000000000000000000000000000000..dbacefc919fd6ed6a0f5cdaa0f695a12eda9cc3f
--- /dev/null
+++ b/src/main/java/io/papermc/paper/entity/RelativeTeleportFlag.java
@@ -0,0 +1,34 @@
+++ b/src/main/java/io/papermc/paper/entity/TeleportFlag.java
@@ -0,0 +1,83 @@
+package io.papermc.paper.entity;
+
+import org.bukkit.Location;
+import org.bukkit.event.player.PlayerTeleportEvent;
+import org.jetbrains.annotations.ApiStatus;
+
+/**
+ * Represents coordinates in a teleportation that should be handled relatively.
+ * Represents a flag that can be set on teleportation that may
+ * slightly modify the behavior.
+ *
+ * @see org.bukkit.entity.Player#teleport(Location, PlayerTeleportEvent.TeleportCause, boolean, boolean, RelativeTeleportFlag...)
+ * @see EntityState
+ * @see Relative
+ */
+@org.jetbrains.annotations.ApiStatus.Experimental
+public enum RelativeTeleportFlag {
+@ApiStatus.Experimental
+public sealed interface TeleportFlag permits TeleportFlag.EntityState, TeleportFlag.Relative {
+
+ /**
+ * Represents the player's X coordinate
+ * Note: These flags only work on {@link org.bukkit.entity.Player} entities.
+ * <p>
+ * Represents coordinates in a teleportation that should be handled relatively.
+ * <p>
+ * Coordinates of the location that the client should handle as relative teleportation
+ * Relative teleportation flags are only used client side, and cause the player to not lose velocity in that
+ * specific coordinate. The location of the teleportation will not change.
+ *
+ * @see org.bukkit.entity.Player#teleport(Location, PlayerTeleportEvent.TeleportCause, TeleportFlag...)
+ */
+ X,
+ @ApiStatus.Experimental
+ enum Relative implements TeleportFlag {
+ /**
+ * Represents the player's X coordinate
+ */
+ X,
+ /**
+ * Represents the player's Y coordinate
+ */
+ Y,
+ /**
+ * Represents the player's Z coordinate
+ */
+ Z,
+ /**
+ * Represents the player's yaw
+ */
+ YAW,
+ /**
+ * Represents the player's pitch
+ */
+ PITCH;
+ }
+
+ /**
+ * Represents the player's Y coordinate
+ * Represents flags that effect the entity's state on
+ * teleportation.
+ */
+ Y,
+ /**
+ * Represents the player's Z coordinate
+ */
+ Z,
+ /**
+ * Represents the player's yaw
+ */
+ YAW,
+ /**
+ * Represents the player's pitch
+ */
+ PITCH;
+ @ApiStatus.Experimental
+ enum EntityState implements TeleportFlag {
+ /**
+ * If all passengers should not be required to be removed prior to teleportation.
+ * <p>
+ * Note:
+ * Teleporting to a different world with this flag present while the entity has entities riding it
+ * will cause this teleportation to return false and not occur.
+ */
+ RETAIN_PASSENGERS,
+ /**
+ * If the entity should not be dismounted if they are riding another entity.
+ * <p>
+ * Note:
+ * Teleporting to a different world with this flag present while this entity is riding another entity will
+ * cause this teleportation to return false and not occur.
+ */
+ RETAIN_VEHICLE,
+ /**
+ * Indicates that a player should not have their current open inventory closed when teleporting.
+ * <p>
+ * Note:
+ * This option will be ignored when teleported to a different world.
+ */
+ RETAIN_OPEN_INVENTORY;
+ }
+
+}
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
index b878509ff536f2d728c800a0ae6cd36802570b31..9bfe62185acb2a208268a2db3aa81dad9e0eed5e 100644
index b878509ff536f2d728c800a0ae6cd36802570b31..ec2adecad37c321b7852c34020dc1c61bef5dd8d 100644
--- a/src/main/java/org/bukkit/entity/Entity.java
+++ b/src/main/java/org/bukkit/entity/Entity.java
@@ -122,10 +122,77 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
@@ -122,10 +122,34 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
*
* @param yaw the yaw
* @param pitch the pitch
@ -90,79 +139,36 @@ index b878509ff536f2d728c800a0ae6cd36802570b31..9bfe62185acb2a208268a2db3aa81dad
+ // Paper start - Teleport API
+ /**
+ * Teleports this entity to the given location.
+ * <p>
+ * Note: Teleporting to a different world with ignorePassengers to true while the entity has entities riding it
+ * will cause this teleportation to return false and not occur.
+ *
+ * @param location New location to teleport this entity to
+ * @param ignorePassengers If all passengers should not be required to be removed prior to teleportation
+ * @param teleportFlags Flags to be used in this teleportation
+ * @return <code>true</code> if the teleport was successful
+ */
+ @org.jetbrains.annotations.ApiStatus.Experimental
+ default boolean teleport(@NotNull Location location, boolean ignorePassengers) {
+ return this.teleport(location, TeleportCause.PLUGIN, ignorePassengers);
+ default boolean teleport(@NotNull Location location, @NotNull io.papermc.paper.entity.TeleportFlag @NotNull... teleportFlags) {
+ return this.teleport(location, TeleportCause.PLUGIN, teleportFlags);
+ }
+
+ /**
+ * Teleports this entity to the given location.
+ * <p>
+ * Note: Teleporting to a different world with ignorePassengers to true while the entity has entities riding it
+ * will cause this teleportation to return false and not occur.
+ *
+ * @param location New location to teleport this entity to
+ * @param cause The cause of this teleportation
+ * @param ignorePassengers If all passengers should not be required to be removed prior to teleportation
+ * @param teleportFlags Flags to be used in this teleportation
+ * @return <code>true</code> if the teleport was successful
+ */
+ @org.jetbrains.annotations.ApiStatus.Experimental
+ default boolean teleport(@NotNull Location location, @NotNull TeleportCause cause, boolean ignorePassengers) {
+ return this.teleport(location, cause, ignorePassengers, true);
+ }
+
+ /**
+ * Teleports this entity to the given location.
+ * <p>
+ * Note: Teleporting to a different world with ignorePassengers to true while the entity has entities riding it
+ * will cause this teleportation to return false and not occur.
+ * Note: Teleporting to a different world with dismount to false while this entity is riding another entity will
+ * cause this teleportation to return false and not occur.
+ *
+ * @param location New location to teleport this entity to
+ * @param ignorePassengers If all passengers should not be required to be removed prior to teleportation
+ * @param dismount If the entity should be dismounted if they are riding another entity
+ * @return <code>true</code> if the teleport was successful
+ */
+ @org.jetbrains.annotations.ApiStatus.Experimental
+ default boolean teleport(@NotNull Location location, boolean ignorePassengers, boolean dismount) {
+ return this.teleport(location, TeleportCause.PLUGIN, ignorePassengers, dismount);
+ }
+
+ /**
+ * Teleports this entity to the given location.
+ * <p>
+ * Note: Teleporting to a different world with ignorePassengers to true while the entity has entities riding it
+ * will cause this teleportation to return false and not occur.
+ * Note: Teleporting to a different world with dismount to false while this entity is riding another entity will
+ * cause this teleportation to return false and not occur.
+ *
+ * @param location New location to teleport this entity to
+ * @param cause The cause of this teleportation
+ * @param ignorePassengers If all passengers should not be required to be removed prior to teleportation
+ * @param dismount If the entity should be dismounted if they are riding another entity
+ * @return <code>true</code> if the teleport was successful
+ */
+ @org.jetbrains.annotations.ApiStatus.Experimental
+ boolean teleport(@NotNull Location location, @NotNull TeleportCause cause, boolean ignorePassengers, boolean dismount);
+ boolean teleport(@NotNull Location location, @NotNull TeleportCause cause, @NotNull io.papermc.paper.entity.TeleportFlag @NotNull... teleportFlags);
+ // Paper end - Teleport API
+
/**
* Teleports this entity to the given location. If this entity is riding a
* vehicle, it will be dismounted prior to teleportation.
diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java
index 17ad43c24dc2e18f5cde0ac0bfae1de9fe415964..6fbdcf6e5df2e613db022d38fc1e170578ef5e8a 100644
index 17ad43c24dc2e18f5cde0ac0bfae1de9fe415964..02979f3bce2d771120a39287cdfcb12c5487a23f 100644
--- a/src/main/java/org/bukkit/entity/Player.java
+++ b/src/main/java/org/bukkit/entity/Player.java
@@ -2757,6 +2757,71 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -2757,6 +2757,49 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
String getClientBrandName();
// Paper end
@ -177,28 +183,6 @@ index 17ad43c24dc2e18f5cde0ac0bfae1de9fe415964..6fbdcf6e5df2e613db022d38fc1e1705
+ void setRotation(float yaw, float pitch);
+
+ /**
+ * Teleports this entity to the given location.
+ * <p>
+ * Note: Teleporting to a different world with ignorePassengers to true while the entity has entities riding it
+ * will cause this teleportation to return false and not occur.
+ * Note: Teleporting to a different world with dismount to false while this entity is riding another entity will
+ * cause this teleportation to return false and not occur.
+ *
+ * <p>
+ * Relative teleportation flags are only used client side, and cause the player to not lose velocity in that
+ * specific coordinate. The location of the teleportation will not change.
+ *
+ * @param location New location to teleport this entity to
+ * @param cause The cause of this teleportation
+ * @param ignorePassengers If all passengers should not be required to be removed prior to teleportation
+ * @param dismount If the entity should be dismounted if they are riding another entity
+ * @param teleportFlags Coordinates of the location that the client should handle as relative teleportation
+ * @return <code>true</code> if the teleport was successful
+ */
+ @org.jetbrains.annotations.ApiStatus.Experimental
+ boolean teleport(@NotNull Location location, @NotNull org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause, boolean ignorePassengers, boolean dismount, @NotNull io.papermc.paper.entity.RelativeTeleportFlag @NotNull... teleportFlags);
+
+ /**
+ * Causes the player to look towards the given position.
+ *
+ * @param x x coordinate
@ -212,12 +196,12 @@ index 17ad43c24dc2e18f5cde0ac0bfae1de9fe415964..6fbdcf6e5df2e613db022d38fc1e1705
+ /**
+ * Causes the player to look towards the given location.
+ *
+ * @param location Location to look at
+ * @param position Position to look at in the player's current world
+ * @param playerAnchor What part of player should face the location
+ */
+ @org.jetbrains.annotations.ApiStatus.Experimental
+ default void lookAt(@NotNull Location location, @NotNull io.papermc.paper.entity.LookAnchor playerAnchor) {
+ this.lookAt(location.getX(), location.getY(), location.getZ(), playerAnchor);
+ default void lookAt(@NotNull io.papermc.paper.math.Position position, @NotNull io.papermc.paper.entity.LookAnchor playerAnchor) {
+ this.lookAt(position.x(), position.y(), position.z(), playerAnchor);
+ }
+
+ /**
@ -235,7 +219,7 @@ index 17ad43c24dc2e18f5cde0ac0bfae1de9fe415964..6fbdcf6e5df2e613db022d38fc1e1705
@Override
Spigot spigot();
diff --git a/src/main/java/org/bukkit/event/player/PlayerTeleportEvent.java b/src/main/java/org/bukkit/event/player/PlayerTeleportEvent.java
index 113e620ce38bb8ff97cf24e309af59b717774b36..149725da2468cf2e8cf3877f78b4a9b749ec1e51 100644
index 113e620ce38bb8ff97cf24e309af59b717774b36..cc75d2e84e68a1f63ec91a909c37407a46ddb16a 100644
--- a/src/main/java/org/bukkit/event/player/PlayerTeleportEvent.java
+++ b/src/main/java/org/bukkit/event/player/PlayerTeleportEvent.java
@@ -13,8 +13,14 @@ public class PlayerTeleportEvent extends PlayerMoveEvent {
@ -244,7 +228,7 @@ index 113e620ce38bb8ff97cf24e309af59b717774b36..149725da2468cf2e8cf3877f78b4a9b7
+ // Paper start - Teleport API
+ private boolean dismounted = true;
+ private final java.util.Set<io.papermc.paper.entity.RelativeTeleportFlag> teleportFlagSet;
+ private final java.util.Set<io.papermc.paper.entity.TeleportFlag.Relative> teleportFlagSet;
+ // Paper end
+
public PlayerTeleportEvent(@NotNull final Player player, @NotNull final Location from, @Nullable final Location to) {
@ -259,7 +243,7 @@ index 113e620ce38bb8ff97cf24e309af59b717774b36..149725da2468cf2e8cf3877f78b4a9b7
+ // Paper start - Teleport API
+ @org.jetbrains.annotations.ApiStatus.Experimental
+ public PlayerTeleportEvent(@NotNull final Player player, @NotNull final Location from, @Nullable final Location to, @NotNull final TeleportCause cause, boolean dismounted, @NotNull java.util.Set<io.papermc.paper.entity.@NotNull RelativeTeleportFlag> teleportFlagSet) {
+ public PlayerTeleportEvent(@NotNull final Player player, @NotNull final Location from, @Nullable final Location to, @NotNull final TeleportCause cause, boolean dismounted, @NotNull java.util.Set<io.papermc.paper.entity.TeleportFlag.@NotNull Relative> teleportFlagSet) {
+ super(player, from, to);
+
+ this.dismounted = dismounted;
@ -294,7 +278,7 @@ index 113e620ce38bb8ff97cf24e309af59b717774b36..149725da2468cf2e8cf3877f78b4a9b7
+ */
+ @org.jetbrains.annotations.ApiStatus.Experimental
+ @NotNull
+ public java.util.Set<io.papermc.paper.entity.@NotNull RelativeTeleportFlag> getRelativeTeleportationFlags() {
+ public java.util.Set<io.papermc.paper.entity.TeleportFlag.@NotNull Relative> getRelativeTeleportationFlags() {
+ return this.teleportFlagSet;
+ }
+ // Paper end

View file

@ -25,10 +25,10 @@ index 3f7e860de4e28745fcdf8d2f41f4a8c210f48909..39fa4c65e0f61450901662ff5c08d54a
// Paper end
}
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
index 9bfe62185acb2a208268a2db3aa81dad9e0eed5e..33a6b7a27dc91552799c07a7aad9b3df31ad13f7 100644
index ec2adecad37c321b7852c34020dc1c61bef5dd8d..833a8abcdcbe70b2912779f6e179fa3739d099bd 100644
--- a/src/main/java/org/bukkit/entity/Entity.java
+++ b/src/main/java/org/bukkit/entity/Entity.java
@@ -929,4 +929,26 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
@@ -886,4 +886,26 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
*/
boolean isInPowderedSnow();
// Paper end

View file

@ -5,10 +5,10 @@ Subject: [PATCH] Elder Guardian appearance API
diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java
index 478c175d1fcb9a6d1211c50618eec4b9b14bc0ba..9ac0f78d1bf434e501c32382ad2e517a1e19fbfa 100644
index ebe926bff51954785a6f2ad518ba31eaf8bc8f82..2c4ee85e845f145ae7c6d27e4cac46ab9c23b5b2 100644
--- a/src/main/java/org/bukkit/entity/Player.java
+++ b/src/main/java/org/bukkit/entity/Player.java
@@ -2853,6 +2853,24 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -2831,6 +2831,24 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
void lookAt(@NotNull org.bukkit.entity.Entity entity, @NotNull io.papermc.paper.entity.LookAnchor playerAnchor, @NotNull io.papermc.paper.entity.LookAnchor entityAnchor);
// Paper end - Teleport API

View file

@ -5,10 +5,10 @@ Subject: [PATCH] Add Player Warden Warning API
diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java
index 9ac0f78d1bf434e501c32382ad2e517a1e19fbfa..3a450af12df6c71e91eab34237dcbf870708f3c6 100644
index 2c4ee85e845f145ae7c6d27e4cac46ab9c23b5b2..c480f251f912d14726f3f2fc8f40bd921eb39fe6 100644
--- a/src/main/java/org/bukkit/entity/Player.java
+++ b/src/main/java/org/bukkit/entity/Player.java
@@ -2869,6 +2869,59 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -2847,6 +2847,59 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
* @param silent whether sound should be silenced
*/
void showElderGuardian(boolean silent);

View file

@ -5,10 +5,10 @@ Subject: [PATCH] Add Sneaking API for Entities
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
index 33a6b7a27dc91552799c07a7aad9b3df31ad13f7..cdbc7329cf5f67d66e31eb31e83b9e7997040f72 100644
index 833a8abcdcbe70b2912779f6e179fa3739d099bd..11cf1bb585e2754bda443b776e9fcaf0a6cc289e 100644
--- a/src/main/java/org/bukkit/entity/Entity.java
+++ b/src/main/java/org/bukkit/entity/Entity.java
@@ -781,6 +781,25 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
@@ -738,6 +738,25 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
@NotNull
Pose getPose();
@ -35,7 +35,7 @@ index 33a6b7a27dc91552799c07a7aad9b3df31ad13f7..cdbc7329cf5f67d66e31eb31e83b9e79
* Get the category of spawn to which this entity belongs.
*
diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java
index 4d7089da20e0667fd7e67ef4da073d938e7b9a67..b27d7414f34f1d49c56dbc33d6d23bc822adf721 100644
index d162b838a25d7eed6b8fc66c630e8c68e809c4cd..3f2025023dc5cecb37af136042809e9800c77594 100644
--- a/src/main/java/org/bukkit/entity/Player.java
+++ b/src/main/java/org/bukkit/entity/Player.java
@@ -296,6 +296,7 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM

View file

@ -69,7 +69,7 @@ index 67fb9d93e808e907fa980f3004d415ae5d0a53fc..97e36c7f6e09276fbae20eaeee096556
/**
* Set the Block radius to search in for available portals.
diff --git a/src/main/java/org/bukkit/event/player/PlayerPortalEvent.java b/src/main/java/org/bukkit/event/player/PlayerPortalEvent.java
index 57eeeafae84f83a939925820e827769749ff27ec..da753259e3c461d9fd40b7eb7d0abf7965497a47 100644
index 57eeeafae84f83a939925820e827769749ff27ec..929a997671de8202efb9da97fbf9b4a0bf7c37e8 100644
--- a/src/main/java/org/bukkit/event/player/PlayerPortalEvent.java
+++ b/src/main/java/org/bukkit/event/player/PlayerPortalEvent.java
@@ -32,6 +32,53 @@ public class PlayerPortalEvent extends PlayerTeleportEvent {
@ -119,7 +119,7 @@ index 57eeeafae84f83a939925820e827769749ff27ec..da753259e3c461d9fd40b7eb7d0abf79
+ */
+ @Deprecated
+ @Override
+ public @NotNull java.util.Set<io.papermc.paper.entity.@NotNull RelativeTeleportFlag> getRelativeTeleportationFlags() {
+ public @NotNull java.util.Set<io.papermc.paper.entity.TeleportFlag.@NotNull Relative> getRelativeTeleportationFlags() {
+ return super.getRelativeTeleportationFlags();
+ }
+ // Paper end