aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0365-More-Teleport-API.patch
blob: 5b2f5bb571af5c80dce8911a99fcad542e2be0ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
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..544eec787ea837f7d29df6519255840d6fe087d7
--- /dev/null
+++ b/src/main/java/io/papermc/paper/entity/LookAnchor.java
@@ -0,0 +1,24 @@
+package io.papermc.paper.entity;
+
+import io.papermc.paper.math.Position;
+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.
+ *
+ * @see org.bukkit.entity.Player#lookAt(Position, LookAnchor)
+ * @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;
+}
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..c8b5b570d44da9524bfc59c7e11b2ae59d4b79b9
--- /dev/null
+++ b/src/main/java/io/papermc/paper/entity/TeleportFlag.java
@@ -0,0 +1,79 @@
+package io.papermc.paper.entity;
+
+import org.bukkit.Location;
+import org.bukkit.event.player.PlayerTeleportEvent;
+
+/**
+ * Represents a flag that can be set on teleportation that may
+ * slightly modify the behavior.
+ *
+ * @see EntityState
+ * @see Relative
+ */
+public sealed interface TeleportFlag permits TeleportFlag.EntityState, TeleportFlag.Relative {
+
+    /**
+     * 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...)
+     */
+    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 flags that effect the entity's state on
+     * teleportation.
+     */
+    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 e1fe5d93eb7a1f96954d907dbbe0758f25bd1ce7..948d6a08ff459afd5d4d5b151c41d94d1d5847b6 100644
--- a/src/main/java/org/bukkit/entity/Entity.java
+++ b/src/main/java/org/bukkit/entity/Entity.java
@@ -126,10 +126,32 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
      *
      * @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
+     * @return <code>true</code> if the teleport was successful
+     */
+    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.
+     *
+     * @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
+     * @return <code>true</code> if the teleport was successful
+     */
+    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 c8a50647d34c70bc927c33c602f938a01bf6e7a9..14b744bd1a0595260c65d3870be5f3985fb95ccb 100644
--- a/src/main/java/org/bukkit/entity/Player.java
+++ b/src/main/java/org/bukkit/entity/Player.java
@@ -3400,6 +3400,45 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
     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);
+
+    /**
+     * Causes the player to look towards the given position.
+     *
+     * @param position Position to look at in the player's current world
+     * @param playerAnchor What part of the player should face the given position
+     */
+    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);
+    }
+
+    /**
+     * 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
index 2deae344c88920ab95eefd2f65df5c858e04750b..ccfb08af8c57ddac3062c2cec28d7ff428082709 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 {
     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;
+    // 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) {
@@ -23,6 +29,15 @@ public class PlayerTeleportEvent extends PlayerMoveEvent {
         this.cause = cause;
     }
 
+    // Paper start - Teleport API
+    @org.jetbrains.annotations.ApiStatus.Internal
+    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) {
+        super(player, from, to);
+        this.teleportFlagSet = teleportFlagSet;
+        this.cause = cause;
+    }
+    // Paper end
+
     /**
      * Gets the cause of this teleportation event
      *
@@ -88,6 +103,30 @@ public class PlayerTeleportEvent extends PlayerMoveEvent {
         UNKNOWN;
     }
 
+    // Paper start - Teleport API
+    /**
+     * Gets if the player will be dismounted in this teleportation.
+     *
+     * @return dismounted or not
+     * @deprecated dismounting on tp is no longer controlled by the server
+     */
+    @Deprecated(forRemoval = true)
+    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
+    public java.util.Set<io.papermc.paper.entity.TeleportFlag.@NotNull Relative> getRelativeTeleportationFlags() {
+        return this.teleportFlagSet;
+    }
+    // Paper end
+
     @NotNull
     @Override
     public HandlerList getHandlers() {