2022-07-22 21:36:43 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
Date: Sun, 5 Sep 2021 00:36:05 -0400
Subject: [PATCH] More Teleport API
diff --git a/src/main/java/io/papermc/paper/entity/LookAnchor.java b/src/main/java/io/papermc/paper/entity/LookAnchor.java
new file mode 100644
2023-11-28 20:40:25 +01:00
index 0000000000000000000000000000000000000000..544eec787ea837f7d29df6519255840d6fe087d7
2022-07-22 21:36:43 +02:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/entity/LookAnchor.java
2023-11-28 20:40:25 +01:00
@@ -0,0 +1,24 @@
2022-07-22 21:36:43 +02:00
+package io.papermc.paper.entity;
+
2023-05-03 13:07:51 +02:00
+import io.papermc.paper.math.Position;
2022-07-22 21:36:43 +02:00
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.LivingEntity;
+
+/**
2023-05-03 13:07:51 +02:00
+ * Represents what part of the entity should be used when determining where to face a position/entity.
2022-07-22 21:36:43 +02:00
+ *
2023-05-03 13:07:51 +02:00
+ * @see org.bukkit.entity.Player#lookAt(Position, LookAnchor)
2022-07-22 21:36:43 +02:00
+ * @see org.bukkit.entity.Player#lookAt(Entity, LookAnchor, LookAnchor)
+ */
+public enum LookAnchor {
+ /**
+ * Represents the entity's feet.
+ * @see LivingEntity#getLocation()
+ */
+ FEET,
+ /**
+ * Represents the entity's eyes.
+ * @see LivingEntity#getEyeLocation()
+ */
+ EYES;
+}
2023-03-04 23:07:23 +01:00
diff --git a/src/main/java/io/papermc/paper/entity/TeleportFlag.java b/src/main/java/io/papermc/paper/entity/TeleportFlag.java
2022-07-22 21:36:43 +02:00
new file mode 100644
2023-11-28 20:40:25 +01:00
index 0000000000000000000000000000000000000000..c8b5b570d44da9524bfc59c7e11b2ae59d4b79b9
2022-07-22 21:36:43 +02:00
--- /dev/null
2023-03-04 23:07:23 +01:00
+++ b/src/main/java/io/papermc/paper/entity/TeleportFlag.java
2023-11-28 20:40:25 +01:00
@@ -0,0 +1,79 @@
2022-07-22 21:36:43 +02:00
+package io.papermc.paper.entity;
+
+import org.bukkit.Location;
+import org.bukkit.event.player.PlayerTeleportEvent;
+
+/**
2023-03-04 23:07:23 +01:00
+ * Represents a flag that can be set on teleportation that may
+ * slightly modify the behavior.
2022-07-22 21:36:43 +02:00
+ *
2023-03-04 23:07:23 +01:00
+ * @see EntityState
+ * @see Relative
2022-07-22 21:36:43 +02:00
+ */
2023-03-04 23:07:23 +01:00
+public sealed interface TeleportFlag permits TeleportFlag.EntityState, TeleportFlag.Relative {
+
2022-07-22 21:36:43 +02:00
+ /**
2023-03-04 23:07:23 +01:00
+ * 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...)
2022-07-22 21:36:43 +02:00
+ */
2023-03-04 23:07:23 +01:00
+ 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;
+ }
+
2022-07-22 21:36:43 +02:00
+ /**
2023-03-04 23:07:23 +01:00
+ * Represents flags that effect the entity's state on
+ * teleportation.
2022-07-22 21:36:43 +02:00
+ */
2023-03-04 23:07:23 +01:00
+ 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;
+ }
2022-07-22 21:36:43 +02:00
+
+}
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
2023-12-05 18:33:18 +01:00
index 953bb49b7079647450d3453356d1c8a91be94c01..2ea66188468cf32bcaedc5167d4b9b0c6ea9b0b3 100644
2022-07-22 21:36:43 +02:00
--- a/src/main/java/org/bukkit/entity/Entity.java
+++ b/src/main/java/org/bukkit/entity/Entity.java
2023-12-05 18:33:18 +01:00
@@ -126,10 +126,32 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
2022-07-22 21:36:43 +02:00
*
* @param yaw the yaw
* @param pitch the pitch
- * @throws UnsupportedOperationException if used for players
*/
public void setRotation(float yaw, float pitch);
+ // Paper start - Teleport API
+ /**
+ * Teleports this entity to the given location.
+ *
+ * @param location New location to teleport this entity to
2023-03-04 23:07:23 +01:00
+ * @param teleportFlags Flags to be used in this teleportation
2022-07-22 21:36:43 +02:00
+ * @return <code>true</code> if the teleport was successful
+ */
2023-03-04 23:07:23 +01:00
+ default boolean teleport(@NotNull Location location, @NotNull io.papermc.paper.entity.TeleportFlag @NotNull... teleportFlags) {
+ return this.teleport(location, TeleportCause.PLUGIN, teleportFlags);
2022-07-22 21:36:43 +02:00
+ }
+
+ /**
+ * Teleports this entity to the given location.
+ *
+ * @param location New location to teleport this entity to
+ * @param cause The cause of this teleportation
2023-03-04 23:07:23 +01:00
+ * @param teleportFlags Flags to be used in this teleportation
2022-07-22 21:36:43 +02:00
+ * @return <code>true</code> if the teleport was successful
+ */
2023-03-04 23:07:23 +01:00
+ boolean teleport(@NotNull Location location, @NotNull TeleportCause cause, @NotNull io.papermc.paper.entity.TeleportFlag @NotNull... teleportFlags);
2022-07-22 21:36:43 +02:00
+ // 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
Updated Upstream (Bukkit/CraftBukkit) (#10034)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
index 2ee4844870e00b3971d92f49f7b5607435053f7f..d7da0e2abd953805a076a4b5c48678ca27ed7759 100644
2022-07-22 21:36:43 +02:00
--- a/src/main/java/org/bukkit/entity/Player.java
+++ b/src/main/java/org/bukkit/entity/Player.java
Updated Upstream (Bukkit/CraftBukkit) (#10034)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
@@ -3259,6 +3259,45 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
2022-07-22 21:36:43 +02:00
String getClientBrandName();
// Paper end
+ // Paper start - Teleport API
+ /**
+ * Sets the player's rotation.
+ *
+ * @param yaw the yaw
+ * @param pitch the pitch
+ */
+ void setRotation(float yaw, float pitch);
+
+ /**
+ * Causes the player to look towards the given position.
+ *
+ * @param x x coordinate
+ * @param y y coordinate
+ * @param z z coordinate
+ * @param playerAnchor What part of the player should face the given position
+ */
+ void lookAt(double x, double y, double z, @NotNull io.papermc.paper.entity.LookAnchor playerAnchor);
+
+ /**
2023-05-03 13:07:51 +02:00
+ * Causes the player to look towards the given position.
2022-07-22 21:36:43 +02:00
+ *
2023-03-04 23:07:23 +01:00
+ * @param position Position to look at in the player's current world
2023-05-03 13:07:51 +02:00
+ * @param playerAnchor What part of the player should face the given position
2022-07-22 21:36:43 +02:00
+ */
2023-03-04 23:07:23 +01:00
+ 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);
2022-07-22 21:36:43 +02:00
+ }
+
+ /**
+ * Causes the player to look towards the given entity.
+ *
+ * @param entity Entity to look at
+ * @param playerAnchor What part of the player should face the entity
+ * @param entityAnchor What part of the entity the player should face
+ */
+ 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
+
@NotNull
@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
2023-11-28 20:40:25 +01:00
index 2deae344c88920ab95eefd2f65df5c858e04750b..ccfb08af8c57ddac3062c2cec28d7ff428082709 100644
2022-07-22 21:36:43 +02:00
--- 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 {
private static final HandlerList handlers = new HandlerList();
private TeleportCause cause = TeleportCause.UNKNOWN;
+ // Paper start - Teleport API
+ private boolean dismounted = true;
2023-03-04 23:07:23 +01:00
+ private final java.util.Set<io.papermc.paper.entity.TeleportFlag.Relative> teleportFlagSet;
2022-07-22 21:36:43 +02:00
+ // Paper end
+
public PlayerTeleportEvent(@NotNull final Player player, @NotNull final Location from, @Nullable final Location to) {
super(player, from, to);
+ teleportFlagSet = java.util.Collections.emptySet(); // Paper - Teleport API
}
public PlayerTeleportEvent(@NotNull final Player player, @NotNull final Location from, @Nullable final Location to, @NotNull final TeleportCause cause) {
2023-03-15 00:10:18 +01:00
@@ -23,6 +29,15 @@ public class PlayerTeleportEvent extends PlayerMoveEvent {
2022-07-22 21:36:43 +02:00
this.cause = cause;
}
+ // Paper start - Teleport API
2023-11-28 20:40:25 +01:00
+ @org.jetbrains.annotations.ApiStatus.Internal
2023-03-15 00:10:18 +01:00
+ public PlayerTeleportEvent(@NotNull final Player player, @NotNull final Location from, @Nullable final Location to, @NotNull final TeleportCause cause, @NotNull java.util.Set<io.papermc.paper.entity.TeleportFlag.@NotNull Relative> teleportFlagSet) {
2022-07-22 21:36:43 +02:00
+ super(player, from, to);
+ this.teleportFlagSet = teleportFlagSet;
+ this.cause = cause;
+ }
+ // Paper end
+
/**
* Gets the cause of this teleportation event
*
2023-11-28 20:40:25 +01:00
@@ -88,6 +103,30 @@ public class PlayerTeleportEvent extends PlayerMoveEvent {
2022-07-22 21:36:43 +02:00
UNKNOWN;
}
+ // Paper start - Teleport API
+ /**
+ * Gets if the player will be dismounted in this teleportation.
+ *
+ * @return dismounted or not
2023-03-15 00:10:18 +01:00
+ * @deprecated dismounting on tp is no longer controlled by the server
2022-07-22 21:36:43 +02:00
+ */
2023-03-15 00:10:18 +01:00
+ @Deprecated(forRemoval = true)
2022-07-22 21:36:43 +02:00
+ public boolean willDismountPlayer() {
+ return this.dismounted;
+ }
+
+ /**
+ * Returns the relative teleportation flags used in this teleportation.
+ * This determines which axis the player will not lose their velocity in.
+ *
+ * @return an immutable set of relative teleportation flags
+ */
+ @NotNull
2023-03-04 23:07:23 +01:00
+ public java.util.Set<io.papermc.paper.entity.TeleportFlag.@NotNull Relative> getRelativeTeleportationFlags() {
2022-07-22 21:36:43 +02:00
+ return this.teleportFlagSet;
+ }
+ // Paper end
+
@NotNull
@Override
public HandlerList getHandlers() {