Paper/patches/api/0369-More-Teleport-API.patch

288 Zeilen
11 KiB
Diff

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
index 0000000000000000000000000000000000000000..c8312691c27ae436029ec5011ddf073582b12cba
2022-07-22 21:36:43 +02:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/entity/LookAnchor.java
@@ -0,0 +1,25 @@
+package io.papermc.paper.entity;
+
+import io.papermc.paper.math.Position;
2022-07-22 21:36:43 +02:00
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.LivingEntity;
+
+/**
+ * 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
+ *
+ * @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)
+ */
+@org.jetbrains.annotations.ApiStatus.Experimental
+public enum LookAnchor {
+ /**
+ * Represents the entity's feet.
+ * @see LivingEntity#getLocation()
+ */
+ FEET,
+ /**
+ * Represents the entity's eyes.
+ * @see LivingEntity#getEyeLocation()
+ */
+ EYES;
+}
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
index 0000000000000000000000000000000000000000..dbacefc919fd6ed6a0f5cdaa0f695a12eda9cc3f
2022-07-22 21:36:43 +02:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/entity/TeleportFlag.java
@@ -0,0 +1,83 @@
2022-07-22 21:36:43 +02:00
+package io.papermc.paper.entity;
+
+import org.bukkit.Location;
+import org.bukkit.event.player.PlayerTeleportEvent;
+import org.jetbrains.annotations.ApiStatus;
2022-07-22 21:36:43 +02:00
+
+/**
+ * Represents a flag that can be set on teleportation that may
+ * slightly modify the behavior.
2022-07-22 21:36:43 +02:00
+ *
+ * @see EntityState
+ * @see Relative
2022-07-22 21:36:43 +02:00
+ */
+@ApiStatus.Experimental
+public sealed interface TeleportFlag permits TeleportFlag.EntityState, TeleportFlag.Relative {
+
2022-07-22 21:36:43 +02: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
+ */
+ @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;
+ }
+
2022-07-22 21:36:43 +02:00
+ /**
+ * Represents flags that effect the entity's state on
+ * teleportation.
2022-07-22 21:36:43 +02:00
+ */
+ @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;
+ }
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
index ab0ceaba9ddcbe20a8b8a1fc3ed19cb3c64ecd3d..97f0bc6573c8ba09de77061b6312b91cd713221d 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
@@ -123,10 +123,34 @@ 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
+ * @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
+ */
+ @org.jetbrains.annotations.ApiStatus.Experimental
+ 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
+ * @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
+ */
+ @org.jetbrains.annotations.ApiStatus.Experimental
+ 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
index 71bddfd5980452e5f55ea1c6eaa70bad3345739f..b063aba9439f1f32f0716c636d28b2821eeb4fcf 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
@@ -3046,6 +3046,49 @@ 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
+ */
+ @org.jetbrains.annotations.ApiStatus.Experimental
+ 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
+ */
+ @org.jetbrains.annotations.ApiStatus.Experimental
+ void lookAt(double x, double y, double z, @NotNull io.papermc.paper.entity.LookAnchor playerAnchor);
+
+ /**
+ * Causes the player to look towards the given position.
2022-07-22 21:36:43 +02:00
+ *
+ * @param position Position to look at in the player's current world
+ * @param playerAnchor What part of the player should face the given position
2022-07-22 21:36:43 +02:00
+ */
+ @org.jetbrains.annotations.ApiStatus.Experimental
+ 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
+ */
+ @org.jetbrains.annotations.ApiStatus.Experimental
+ 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
Updated Upstream (Bukkit/CraftBukkit) (#9485) 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: 82af5dc6 SPIGOT-7396: Add PlayerSignOpenEvent 3f0281ca SPIGOT-7063, PR-763: Add DragonBattle#initiateRespawn with custom EnderCrystals f83c8df4 PR-873: Add PlayerRecipeBookClickEvent 14560d39 SPIGOT-7435: Add TeleportCause#EXIT_BED 2cc6db92 SPIGOT-7422, PR-887: Add API to set sherds on decorated pots 36022f02 PR-883: Add ItemFactory#getSpawnEgg 12eb5c46 PR-881: Update Scoreboard Javadocs, remove explicit exception throwing f6d8d44a PR-882: Add modern time API methods to ban API 21a7b710 Upgrade some Maven plugins to reduce warnings 11fd1225 PR-886: Deprecate the SmithingRecipe constructor as it now does nothing dbd1761d SPIGOT-7406: Improve documentation for getDragonBattle CraftBukkit Changes: d548daac2 SPIGOT-7446: BlockState#update not updating a spawner's type to null 70e0bc050 SPIGOT-7447: Fix --forceUpgrade 6752f1d63 SPIGOT-7396: Add PlayerSignOpenEvent 847b4cad5 SPIGOT-7063, PR-1071: Add DragonBattle#initiateRespawn with custom EnderCrystals c335a555f PR-1212: Add PlayerRecipeBookClickEvent 4be756ecb SPIGOT-7445: Fix opening smithing inventory db70bd6ed SPIGOT-7441: Fix issue placing certain items in creative/op f7fa6d993 SPIGOT-7435: Add TeleportCause#EXIT_BED b435e8e8d SPIGOT-7349: Player#setDisplayName not working when message/format unmodified a2fafdd1d PR-1232: Re-add fix for player rotation 7cf863de1 PR-1233: Remove some old MC bug fixes now fixed in vanilla 08ec344ad Fix ChunkGenerator#generateCaves never being called 5daeb502a SPIGOT-7422, PR-1228: Add API to set sherds on decorated pots 52faa6b32 PR-1224: Add ItemFactory#getSpawnEgg 01cae71b7 SPIGOT-7429: Fix LEFT_CLICK_AIR not working for passable entities and spectators a94277a18 PR-1223: Remove non-existent scoreboard display name/prefix/suffix limits 36b107660 PR-1225: Add modern time API methods to ban API 59ead25bc Upgrade some Maven plugins to reduce warnings 202fc5c4e Increase outdated build delay ce545de57 SPIGOT-7398: TextDisplay#setInterpolationDuration incorrectly updates the line width Spigot Changes: b41c46db Rebuild patches 3374045a SPIGOT-7431: Fix EntityMountEvent returning opposite entities 0ca4eb66 Rebuild patches
2023-08-06 02:21:59 +02:00
index 2deae344c88920ab95eefd2f65df5c858e04750b..32f78f2e32280f5c9ee7394b77ed929845f127d2 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;
+ 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
+ @org.jetbrains.annotations.ApiStatus.Experimental
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
*
Updated Upstream (Bukkit/CraftBukkit) (#9485) 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: 82af5dc6 SPIGOT-7396: Add PlayerSignOpenEvent 3f0281ca SPIGOT-7063, PR-763: Add DragonBattle#initiateRespawn with custom EnderCrystals f83c8df4 PR-873: Add PlayerRecipeBookClickEvent 14560d39 SPIGOT-7435: Add TeleportCause#EXIT_BED 2cc6db92 SPIGOT-7422, PR-887: Add API to set sherds on decorated pots 36022f02 PR-883: Add ItemFactory#getSpawnEgg 12eb5c46 PR-881: Update Scoreboard Javadocs, remove explicit exception throwing f6d8d44a PR-882: Add modern time API methods to ban API 21a7b710 Upgrade some Maven plugins to reduce warnings 11fd1225 PR-886: Deprecate the SmithingRecipe constructor as it now does nothing dbd1761d SPIGOT-7406: Improve documentation for getDragonBattle CraftBukkit Changes: d548daac2 SPIGOT-7446: BlockState#update not updating a spawner's type to null 70e0bc050 SPIGOT-7447: Fix --forceUpgrade 6752f1d63 SPIGOT-7396: Add PlayerSignOpenEvent 847b4cad5 SPIGOT-7063, PR-1071: Add DragonBattle#initiateRespawn with custom EnderCrystals c335a555f PR-1212: Add PlayerRecipeBookClickEvent 4be756ecb SPIGOT-7445: Fix opening smithing inventory db70bd6ed SPIGOT-7441: Fix issue placing certain items in creative/op f7fa6d993 SPIGOT-7435: Add TeleportCause#EXIT_BED b435e8e8d SPIGOT-7349: Player#setDisplayName not working when message/format unmodified a2fafdd1d PR-1232: Re-add fix for player rotation 7cf863de1 PR-1233: Remove some old MC bug fixes now fixed in vanilla 08ec344ad Fix ChunkGenerator#generateCaves never being called 5daeb502a SPIGOT-7422, PR-1228: Add API to set sherds on decorated pots 52faa6b32 PR-1224: Add ItemFactory#getSpawnEgg 01cae71b7 SPIGOT-7429: Fix LEFT_CLICK_AIR not working for passable entities and spectators a94277a18 PR-1223: Remove non-existent scoreboard display name/prefix/suffix limits 36b107660 PR-1225: Add modern time API methods to ban API 59ead25bc Upgrade some Maven plugins to reduce warnings 202fc5c4e Increase outdated build delay ce545de57 SPIGOT-7398: TextDisplay#setInterpolationDuration incorrectly updates the line width Spigot Changes: b41c46db Rebuild patches 3374045a SPIGOT-7431: Fix EntityMountEvent returning opposite entities 0ca4eb66 Rebuild patches
2023-08-06 02:21:59 +02:00
@@ -88,6 +103,31 @@ 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
+ */
+ @org.jetbrains.annotations.ApiStatus.Experimental
+ @NotNull
+ 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() {