Teleportation API (#6562)
This commit is contained in:
		
					parent
					
						
							
								d6e0ab24da
							
						
					
				
			
			
				commit
				
					
						09a1be7aef
					
				
			
		
					 4 changed files with 507 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -332,3 +332,7 @@ public net.minecraft.world.entity.projectile.FireworkRocketEntity life
 | 
			
		|||
 | 
			
		||||
# More Projectile API
 | 
			
		||||
public net.minecraft.world.entity.projectile.FishingHook timeUntilLured
 | 
			
		||||
 | 
			
		||||
# Teleport API
 | 
			
		||||
public net.minecraft.server.network.ServerGamePacketListenerImpl internalTeleport(DDDFFLjava/util/Set;Z)V
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										304
									
								
								patches/api/More-Teleport-API.patch
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										304
									
								
								patches/api/More-Teleport-API.patch
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,304 @@
 | 
			
		|||
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..0000000000000000000000000000000000000000
 | 
			
		||||
--- /dev/null
 | 
			
		||||
+++ b/src/main/java/io/papermc/paper/entity/LookAnchor.java
 | 
			
		||||
@@ -0,0 +0,0 @@
 | 
			
		||||
+package io.papermc.paper.entity;
 | 
			
		||||
+
 | 
			
		||||
+import org.bukkit.Location;
 | 
			
		||||
+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 location/entity.
 | 
			
		||||
+ *
 | 
			
		||||
+ * @see org.bukkit.entity.Player#lookAt(Location, LookAnchor)
 | 
			
		||||
+ * @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/RelativeTeleportFlag.java b/src/main/java/io/papermc/paper/entity/RelativeTeleportFlag.java
 | 
			
		||||
new file mode 100644
 | 
			
		||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
 | 
			
		||||
--- /dev/null
 | 
			
		||||
+++ b/src/main/java/io/papermc/paper/entity/RelativeTeleportFlag.java
 | 
			
		||||
@@ -0,0 +0,0 @@
 | 
			
		||||
+package io.papermc.paper.entity;
 | 
			
		||||
+
 | 
			
		||||
+import org.bukkit.Location;
 | 
			
		||||
+import org.bukkit.event.player.PlayerTeleportEvent;
 | 
			
		||||
+
 | 
			
		||||
+/**
 | 
			
		||||
+ * Represents coordinates in a teleportation that should be handled relatively.
 | 
			
		||||
+ *
 | 
			
		||||
+ * @see org.bukkit.entity.Player#teleport(Location, PlayerTeleportEvent.TeleportCause, boolean, boolean, RelativeTeleportFlag...)
 | 
			
		||||
+ */
 | 
			
		||||
+@org.jetbrains.annotations.ApiStatus.Experimental
 | 
			
		||||
+public enum RelativeTeleportFlag {
 | 
			
		||||
+    /**
 | 
			
		||||
+     * 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;
 | 
			
		||||
+
 | 
			
		||||
+}
 | 
			
		||||
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
 | 
			
		||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 | 
			
		||||
--- a/src/main/java/org/bukkit/entity/Entity.java
 | 
			
		||||
+++ b/src/main/java/org/bukkit/entity/Entity.java
 | 
			
		||||
@@ -0,0 +0,0 @@ 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.
 | 
			
		||||
+     * <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
 | 
			
		||||
+     * @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);
 | 
			
		||||
+    }
 | 
			
		||||
+
 | 
			
		||||
+    /**
 | 
			
		||||
+     * 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
 | 
			
		||||
+     * @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);
 | 
			
		||||
+    // 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 | 
			
		||||
--- a/src/main/java/org/bukkit/entity/Player.java
 | 
			
		||||
+++ b/src/main/java/org/bukkit/entity/Player.java
 | 
			
		||||
@@ -0,0 +0,0 @@ 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
 | 
			
		||||
+     */
 | 
			
		||||
+    @org.jetbrains.annotations.ApiStatus.Experimental
 | 
			
		||||
+    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
 | 
			
		||||
+     * @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 location.
 | 
			
		||||
+     *
 | 
			
		||||
+     * @param location Location to look at
 | 
			
		||||
+     * @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);
 | 
			
		||||
+    }
 | 
			
		||||
+
 | 
			
		||||
+    /**
 | 
			
		||||
+     * 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
 | 
			
		||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 | 
			
		||||
--- a/src/main/java/org/bukkit/event/player/PlayerTeleportEvent.java
 | 
			
		||||
+++ b/src/main/java/org/bukkit/event/player/PlayerTeleportEvent.java
 | 
			
		||||
@@ -0,0 +0,0 @@ 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.RelativeTeleportFlag> 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) {
 | 
			
		||||
@@ -0,0 +0,0 @@ public class PlayerTeleportEvent extends PlayerMoveEvent {
 | 
			
		||||
         this.cause = cause;
 | 
			
		||||
     }
 | 
			
		||||
 
 | 
			
		||||
+    // 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) {
 | 
			
		||||
+        super(player, from, to);
 | 
			
		||||
+
 | 
			
		||||
+        this.dismounted = dismounted;
 | 
			
		||||
+        this.teleportFlagSet = teleportFlagSet;
 | 
			
		||||
+        this.cause = cause;
 | 
			
		||||
+    }
 | 
			
		||||
+    // Paper end
 | 
			
		||||
+
 | 
			
		||||
     /**
 | 
			
		||||
      * Gets the cause of this teleportation event
 | 
			
		||||
      *
 | 
			
		||||
@@ -0,0 +0,0 @@ public class PlayerTeleportEvent extends PlayerMoveEvent {
 | 
			
		||||
         UNKNOWN;
 | 
			
		||||
     }
 | 
			
		||||
 
 | 
			
		||||
+    // Paper start - Teleport API
 | 
			
		||||
+    /**
 | 
			
		||||
+     * Gets if the player will be dismounted in this teleportation.
 | 
			
		||||
+     *
 | 
			
		||||
+     * @return dismounted or not
 | 
			
		||||
+     */
 | 
			
		||||
+    @org.jetbrains.annotations.ApiStatus.Experimental
 | 
			
		||||
+    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.@NotNull RelativeTeleportFlag> getRelativeTeleportationFlags() {
 | 
			
		||||
+        return this.teleportFlagSet;
 | 
			
		||||
+    }
 | 
			
		||||
+    // Paper end
 | 
			
		||||
+
 | 
			
		||||
     @NotNull
 | 
			
		||||
     @Override
 | 
			
		||||
     public HandlerList getHandlers() {
 | 
			
		||||
							
								
								
									
										198
									
								
								patches/server/More-Teleport-API.patch
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										198
									
								
								patches/server/More-Teleport-API.patch
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,198 @@
 | 
			
		|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
 | 
			
		||||
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
 | 
			
		||||
Date: Sun, 5 Sep 2021 12:15:59 -0400
 | 
			
		||||
Subject: [PATCH] More Teleport API
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
 | 
			
		||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 | 
			
		||||
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
 | 
			
		||||
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
 | 
			
		||||
@@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
 | 
			
		||||
             return false; // CraftBukkit - Return event status
 | 
			
		||||
         }
 | 
			
		||||
 
 | 
			
		||||
-        PlayerTeleportEvent event = new PlayerTeleportEvent(player, from.clone(), to.clone(), cause);
 | 
			
		||||
+        // Paper start - Teleport API
 | 
			
		||||
+        Set<io.papermc.paper.entity.RelativeTeleportFlag> relativeFlags = java.util.EnumSet.noneOf(io.papermc.paper.entity.RelativeTeleportFlag.class);
 | 
			
		||||
+        for (net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket.RelativeArgument relativeArgument : set) {
 | 
			
		||||
+            relativeFlags.add(org.bukkit.craftbukkit.entity.CraftPlayer.toApiRelativeFlag(relativeArgument));
 | 
			
		||||
+        }
 | 
			
		||||
+        PlayerTeleportEvent event = new PlayerTeleportEvent(player, from.clone(), to.clone(), cause, flag, java.util.Set.copyOf(relativeFlags));
 | 
			
		||||
+        // Paper end
 | 
			
		||||
         this.cserver.getPluginManager().callEvent(event);
 | 
			
		||||
 
 | 
			
		||||
         if (event.isCancelled() || !to.equals(event.getTo())) {
 | 
			
		||||
-            set.clear(); // Can't relative teleport
 | 
			
		||||
+            //set.clear(); // Can't relative teleport // Paper - Teleport API: Now you can!
 | 
			
		||||
             to = event.isCancelled() ? event.getFrom() : event.getTo();
 | 
			
		||||
             d0 = to.getX();
 | 
			
		||||
             d1 = to.getY();
 | 
			
		||||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
 | 
			
		||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 | 
			
		||||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
 | 
			
		||||
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
 | 
			
		||||
@@ -0,0 +0,0 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
 | 
			
		||||
 
 | 
			
		||||
     @Override
 | 
			
		||||
     public boolean teleport(Location location, TeleportCause cause) {
 | 
			
		||||
+        // Paper start - Teleport passenger API
 | 
			
		||||
+        return teleport(location, cause, false);
 | 
			
		||||
+    }
 | 
			
		||||
+
 | 
			
		||||
+    @Override
 | 
			
		||||
+    public boolean teleport(Location location, TeleportCause cause, boolean ignorePassengers, boolean dismount) {
 | 
			
		||||
+        // Paper end
 | 
			
		||||
         Preconditions.checkArgument(location != null, "location cannot be null");
 | 
			
		||||
         location.checkFinite();
 | 
			
		||||
+        // Paper start - Teleport passenger API
 | 
			
		||||
+        // Don't allow teleporting between worlds while keeping passengers
 | 
			
		||||
+        if (ignorePassengers && this.entity.isVehicle() && location.getWorld() != this.getWorld()) {
 | 
			
		||||
+            return false;
 | 
			
		||||
+        }
 | 
			
		||||
+
 | 
			
		||||
+        // Don't allow to teleport between worlds if remaining on vehicle
 | 
			
		||||
+        if (!dismount && this.entity.isPassenger() && location.getWorld() != this.getWorld()) {
 | 
			
		||||
+            return false;
 | 
			
		||||
+        }
 | 
			
		||||
+        // Paper end
 | 
			
		||||
 
 | 
			
		||||
-        if (this.entity.isVehicle() || this.entity.isRemoved()) {
 | 
			
		||||
+        if ((!ignorePassengers && this.entity.isVehicle()) || this.entity.isRemoved()) { // Paper - Teleport passenger API
 | 
			
		||||
             return false;
 | 
			
		||||
         }
 | 
			
		||||
 
 | 
			
		||||
         // If this entity is riding another entity, we must dismount before teleporting.
 | 
			
		||||
-        this.entity.stopRiding();
 | 
			
		||||
+        if (dismount) this.entity.stopRiding(); // Paper - Teleport passenger API
 | 
			
		||||
 
 | 
			
		||||
         // Let the server handle cross world teleports
 | 
			
		||||
         if (location.getWorld() != null && !location.getWorld().equals(this.getWorld())) {
 | 
			
		||||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
 | 
			
		||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 | 
			
		||||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
 | 
			
		||||
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
 | 
			
		||||
@@ -0,0 +0,0 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
 | 
			
		||||
 
 | 
			
		||||
     @Override
 | 
			
		||||
     public void setRotation(float yaw, float pitch) {
 | 
			
		||||
-        throw new UnsupportedOperationException("Cannot set rotation of players. Consider teleporting instead.");
 | 
			
		||||
+        // Paper start - Teleport API
 | 
			
		||||
+        Location targetLocation = this.getEyeLocation();
 | 
			
		||||
+        targetLocation.setYaw(yaw);
 | 
			
		||||
+        targetLocation.setPitch(pitch);
 | 
			
		||||
+
 | 
			
		||||
+        org.bukkit.util.Vector direction = targetLocation.getDirection();
 | 
			
		||||
+        targetLocation.add(direction);
 | 
			
		||||
+        this.lookAt(targetLocation, io.papermc.paper.entity.LookAnchor.EYES);
 | 
			
		||||
+        // Paper end
 | 
			
		||||
     }
 | 
			
		||||
 
 | 
			
		||||
     // Paper start - Chunk priority
 | 
			
		||||
@@ -0,0 +0,0 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
 | 
			
		||||
 
 | 
			
		||||
     @Override
 | 
			
		||||
     public boolean teleport(Location location, PlayerTeleportEvent.TeleportCause cause) {
 | 
			
		||||
+        // Paper start - Teleport API
 | 
			
		||||
+        return this.teleport(location, cause, false);
 | 
			
		||||
+    }
 | 
			
		||||
+
 | 
			
		||||
+    @Override
 | 
			
		||||
+    public boolean teleport(Location location, PlayerTeleportEvent.TeleportCause cause, boolean ignorePassengers, boolean dismount) {
 | 
			
		||||
+        return this.teleport(location, cause, ignorePassengers, dismount, new io.papermc.paper.entity.RelativeTeleportFlag[0]);
 | 
			
		||||
+    }
 | 
			
		||||
+
 | 
			
		||||
+    @Override
 | 
			
		||||
+    public void lookAt(@NotNull org.bukkit.entity.Entity entity, @NotNull io.papermc.paper.entity.LookAnchor playerAnchor, @NotNull io.papermc.paper.entity.LookAnchor entityAnchor) {
 | 
			
		||||
+        this.getHandle().lookAt(toNmsAnchor(playerAnchor), ((CraftEntity) entity).getHandle(), toNmsAnchor(entityAnchor));
 | 
			
		||||
+    }
 | 
			
		||||
+
 | 
			
		||||
+    @Override
 | 
			
		||||
+    public void lookAt(double x, double y, double z, @NotNull io.papermc.paper.entity.LookAnchor playerAnchor) {
 | 
			
		||||
+        this.getHandle().lookAt(toNmsAnchor(playerAnchor), new Vec3(x, y, z));
 | 
			
		||||
+    }
 | 
			
		||||
+
 | 
			
		||||
+    public static net.minecraft.commands.arguments.EntityAnchorArgument.Anchor toNmsAnchor(io.papermc.paper.entity.LookAnchor nmsAnchor) {
 | 
			
		||||
+        return switch (nmsAnchor) {
 | 
			
		||||
+            case EYES -> net.minecraft.commands.arguments.EntityAnchorArgument.Anchor.EYES;
 | 
			
		||||
+            case FEET -> net.minecraft.commands.arguments.EntityAnchorArgument.Anchor.FEET;
 | 
			
		||||
+        };
 | 
			
		||||
+    }
 | 
			
		||||
+
 | 
			
		||||
+    public static io.papermc.paper.entity.LookAnchor toApiAnchor(net.minecraft.commands.arguments.EntityAnchorArgument.Anchor playerAnchor) {
 | 
			
		||||
+        return switch (playerAnchor) {
 | 
			
		||||
+            case EYES -> io.papermc.paper.entity.LookAnchor.EYES;
 | 
			
		||||
+            case FEET -> io.papermc.paper.entity.LookAnchor.FEET;
 | 
			
		||||
+        };
 | 
			
		||||
+    }
 | 
			
		||||
+
 | 
			
		||||
+    public static net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket.RelativeArgument toNmsRelativeFlag(io.papermc.paper.entity.RelativeTeleportFlag apiFlag) {
 | 
			
		||||
+        return switch (apiFlag) {
 | 
			
		||||
+            case X -> net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket.RelativeArgument.X;
 | 
			
		||||
+            case Y -> net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket.RelativeArgument.Y;
 | 
			
		||||
+            case Z -> net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket.RelativeArgument.Z;
 | 
			
		||||
+            case PITCH -> net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket.RelativeArgument.X_ROT;
 | 
			
		||||
+            case YAW -> net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket.RelativeArgument.Y_ROT;
 | 
			
		||||
+        };
 | 
			
		||||
+    }
 | 
			
		||||
+
 | 
			
		||||
+    public static io.papermc.paper.entity.RelativeTeleportFlag toApiRelativeFlag(net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket.RelativeArgument nmsFlag) {
 | 
			
		||||
+        return switch (nmsFlag) {
 | 
			
		||||
+            case X -> io.papermc.paper.entity.RelativeTeleportFlag.X;
 | 
			
		||||
+            case Y -> io.papermc.paper.entity.RelativeTeleportFlag.Y;
 | 
			
		||||
+            case Z -> io.papermc.paper.entity.RelativeTeleportFlag.Z;
 | 
			
		||||
+            case X_ROT -> io.papermc.paper.entity.RelativeTeleportFlag.PITCH;
 | 
			
		||||
+            case Y_ROT -> io.papermc.paper.entity.RelativeTeleportFlag.YAW;
 | 
			
		||||
+        };
 | 
			
		||||
+    }
 | 
			
		||||
+
 | 
			
		||||
+    @Override
 | 
			
		||||
+    public boolean teleport(Location location, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause, boolean ignorePassengers, boolean dismount, io.papermc.paper.entity.RelativeTeleportFlag... flags) {
 | 
			
		||||
+        var relativeArguments = java.util.EnumSet.noneOf(net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket.RelativeArgument.class);
 | 
			
		||||
+        for (io.papermc.paper.entity.RelativeTeleportFlag flag : flags) {
 | 
			
		||||
+            relativeArguments.add(toNmsRelativeFlag(flag));
 | 
			
		||||
+        }
 | 
			
		||||
+        // Paper end - Teleport API
 | 
			
		||||
         Preconditions.checkArgument(location != null, "location");
 | 
			
		||||
         Preconditions.checkArgument(location.getWorld() != null, "location.world");
 | 
			
		||||
+        // Paper start - Teleport passenger API
 | 
			
		||||
+        // Don't allow teleporting between worlds while keeping passengers
 | 
			
		||||
+        if (ignorePassengers && entity.isVehicle() && location.getWorld() != this.getWorld()) {
 | 
			
		||||
+            return false;
 | 
			
		||||
+        }
 | 
			
		||||
+
 | 
			
		||||
+        // Don't allow to teleport between worlds if remaining on vehicle
 | 
			
		||||
+        if (!dismount && entity.isPassenger() && location.getWorld() != this.getWorld()) {
 | 
			
		||||
+            return false;
 | 
			
		||||
+        }
 | 
			
		||||
+        // Paper end
 | 
			
		||||
         location.checkFinite();
 | 
			
		||||
 
 | 
			
		||||
         ServerPlayer entity = this.getHandle();
 | 
			
		||||
@@ -0,0 +0,0 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
 | 
			
		||||
            return false;
 | 
			
		||||
         }
 | 
			
		||||
 
 | 
			
		||||
-        if (entity.isVehicle()) {
 | 
			
		||||
+        if (entity.isVehicle() && !ignorePassengers) { // Paper - Teleport API
 | 
			
		||||
             return false;
 | 
			
		||||
         }
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +0,0 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
 | 
			
		||||
         }
 | 
			
		||||
 
 | 
			
		||||
         // If this player is riding another entity, we must dismount before teleporting.
 | 
			
		||||
-        entity.stopRiding();
 | 
			
		||||
+        if (dismount) entity.stopRiding(); // Paper - Teleport API
 | 
			
		||||
 
 | 
			
		||||
         // SPIGOT-5509: Wakeup, similar to riding
 | 
			
		||||
         if (this.isSleeping()) {
 | 
			
		||||
@@ -0,0 +0,0 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
 | 
			
		||||
 
 | 
			
		||||
         // Check if the fromWorld and toWorld are the same.
 | 
			
		||||
         if (fromWorld == toWorld) {
 | 
			
		||||
-            entity.connection.teleport(to);
 | 
			
		||||
+            entity.connection.internalTeleport(to.getX(), to.getY(), to.getZ(), to.getYaw(), to.getPitch(), relativeArguments, dismount); // Paper - Teleport API
 | 
			
		||||
         } else {
 | 
			
		||||
             server.getHandle().respawn(entity, toWorld, true, to, !toWorld.paperConfig().environment.disableTeleportationSuffocationCheck); // Paper
 | 
			
		||||
         }
 | 
			
		||||
| 
						 | 
				
			
			@ -11,7 +11,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 | 
			
		|||
@@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
 | 
			
		||||
     }
 | 
			
		||||
 
 | 
			
		||||
     private void internalTeleport(double d0, double d1, double d2, float f, float f1, Set<ClientboundPlayerPositionPacket.RelativeArgument> set, boolean flag) {
 | 
			
		||||
     public void internalTeleport(double d0, double d1, double d2, float f, float f1, Set<ClientboundPlayerPositionPacket.RelativeArgument> set, boolean flag) {
 | 
			
		||||
+        // Paper start
 | 
			
		||||
+        if (player.isRemoved()) {
 | 
			
		||||
+            LOGGER.info("Attempt to teleport removed player {} restricted", player.getScoreboardName());
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue