diff --git a/patches/api/Improve-PortalEvents.patch b/patches/api/Improve-PortalEvents.patch index 5a6af09866..fd6fea0745 100644 --- a/patches/api/Improve-PortalEvents.patch +++ b/patches/api/Improve-PortalEvents.patch @@ -119,7 +119,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + */ + @Deprecated + @Override -+ public @NotNull java.util.Set getRelativeTeleportationFlags() { ++ public @NotNull java.util.Set getRelativeTeleportationFlags() { + return super.getRelativeTeleportationFlags(); + } + // Paper end diff --git a/patches/api/More-Teleport-API.patch b/patches/api/More-Teleport-API.patch index 2af6c4a6cd..6afecaca92 100644 --- a/patches/api/More-Teleport-API.patch +++ b/patches/api/More-Teleport-API.patch @@ -35,44 +35,93 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + */ + 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..0000000000000000000000000000000000000000 --- /dev/null -+++ b/src/main/java/io/papermc/paper/entity/RelativeTeleportFlag.java ++++ b/src/main/java/io/papermc/paper/entity/TeleportFlag.java @@ -0,0 +0,0 @@ +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. ++ *

++ * Represents coordinates in a teleportation that should be handled relatively. ++ *

++ * 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. ++ *

++ * 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. ++ *

++ * 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. ++ *

++ * 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 @@ -90,69 +139,26 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Paper start - Teleport API + /** + * Teleports this entity to the given location. -+ *

-+ * 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 true 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. -+ *

-+ * 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 true 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. -+ *

-+ * 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 true 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. -+ *

-+ * 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 true 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 + /** @@ -177,28 +183,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + void setRotation(float yaw, float pitch); + + /** -+ * Teleports this entity to the given location. -+ *

-+ * 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. -+ * -+ *

-+ * 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 true 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 0000000000000000000000000000000000000000..00000000000000000000000000000000 + /** + * 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); + } + + /** @@ -244,7 +228,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Paper start - Teleport API + private boolean dismounted = true; -+ private final java.util.Set teleportFlagSet; ++ private final java.util.Set teleportFlagSet; + // Paper end + public PlayerTeleportEvent(@NotNull final Player player, @NotNull final Location from, @Nullable final Location to) { @@ -259,7 +243,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // 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 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 teleportFlagSet) { + super(player, from, to); + + this.dismounted = dismounted; @@ -294,7 +278,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + */ + @org.jetbrains.annotations.ApiStatus.Experimental + @NotNull -+ public java.util.Set getRelativeTeleportationFlags() { ++ public java.util.Set getRelativeTeleportationFlags() { + return this.teleportFlagSet; + } + // Paper end diff --git a/patches/server/More-Teleport-API.patch b/patches/server/More-Teleport-API.patch index 7703f14915..b1f88b344d 100644 --- a/patches/server/More-Teleport-API.patch +++ b/patches/server/More-Teleport-API.patch @@ -16,7 +16,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 - PlayerTeleportEvent event = new PlayerTeleportEvent(player, from.clone(), to.clone(), cause); + // Paper start - Teleport API -+ Set relativeFlags = java.util.EnumSet.noneOf(io.papermc.paper.entity.RelativeTeleportFlag.class); ++ Set relativeFlags = java.util.EnumSet.noneOf(io.papermc.paper.entity.TeleportFlag.Relative.class); + for (net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket.RelativeArgument relativeArgument : set) { + relativeFlags.add(org.bukkit.craftbukkit.entity.CraftPlayer.toApiRelativeFlag(relativeArgument)); + } @@ -39,17 +39,20 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 @Override public boolean teleport(Location location, TeleportCause cause) { + // Paper start - Teleport passenger API -+ return teleport(location, cause, false); ++ return teleport(location, cause, new io.papermc.paper.entity.TeleportFlag[0]); + } + + @Override -+ public boolean teleport(Location location, TeleportCause cause, boolean ignorePassengers, boolean dismount) { ++ public boolean teleport(Location location, TeleportCause cause, io.papermc.paper.entity.TeleportFlag... flags) { + // Paper end Preconditions.checkArgument(location != null, "location cannot be null"); location.checkFinite(); + // Paper start - Teleport passenger API ++ Set flagSet = Set.of(flags); ++ boolean dismount = !flagSet.contains(io.papermc.paper.entity.TeleportFlag.EntityState.RETAIN_VEHICLE); ++ boolean ignorePassengers = flagSet.contains(io.papermc.paper.entity.TeleportFlag.EntityState.RETAIN_PASSENGERS); + // Don't allow teleporting between worlds while keeping passengers -+ if (ignorePassengers && this.entity.isVehicle() && location.getWorld() != this.getWorld()) { ++ if (flagSet.contains(io.papermc.paper.entity.TeleportFlag.EntityState.RETAIN_PASSENGERS) && this.entity.isVehicle() && location.getWorld() != this.getWorld()) { + return false; + } + @@ -93,12 +96,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 @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]); ++ return this.teleport(location, cause, new io.papermc.paper.entity.TeleportFlag[0]); + } + + @Override @@ -125,7 +123,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + }; + } + -+ public static net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket.RelativeArgument toNmsRelativeFlag(io.papermc.paper.entity.RelativeTeleportFlag apiFlag) { ++ public static net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket.RelativeArgument toNmsRelativeFlag(io.papermc.paper.entity.TeleportFlag.Relative apiFlag) { + return switch (apiFlag) { + case X -> net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket.RelativeArgument.X; + case Y -> net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket.RelativeArgument.Y; @@ -135,22 +133,35 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + }; + } + -+ public static io.papermc.paper.entity.RelativeTeleportFlag toApiRelativeFlag(net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket.RelativeArgument nmsFlag) { ++ public static io.papermc.paper.entity.TeleportFlag.Relative 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; ++ case X -> io.papermc.paper.entity.TeleportFlag.Relative.X; ++ case Y -> io.papermc.paper.entity.TeleportFlag.Relative.Y; ++ case Z -> io.papermc.paper.entity.TeleportFlag.Relative.Z; ++ case X_ROT -> io.papermc.paper.entity.TeleportFlag.Relative.PITCH; ++ case Y_ROT -> io.papermc.paper.entity.TeleportFlag.Relative.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)); ++ public boolean teleport(Location location, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause, io.papermc.paper.entity.TeleportFlag... flags) { ++ java.util.Set relativeArguments; ++ java.util.Set allFlags; ++ if (flags.length == 0) { ++ relativeArguments = Set.of(); ++ allFlags = Set.of(); ++ } else { ++ relativeArguments = java.util.EnumSet.noneOf(net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket.RelativeArgument.class); ++ allFlags = new HashSet<>(); ++ for (io.papermc.paper.entity.TeleportFlag flag : flags) { ++ if (flag instanceof io.papermc.paper.entity.TeleportFlag.Relative relativeTeleportFlag) { ++ relativeArguments.add(toNmsRelativeFlag(relativeTeleportFlag)); ++ } ++ allFlags.add(flag); ++ } + } ++ boolean dismount = !allFlags.contains(io.papermc.paper.entity.TeleportFlag.EntityState.RETAIN_VEHICLE); ++ boolean ignorePassengers = allFlags.contains(io.papermc.paper.entity.TeleportFlag.EntityState.RETAIN_PASSENGERS); + // Paper end - Teleport API Preconditions.checkArgument(location != null, "location"); Preconditions.checkArgument(location.getWorld() != null, "location.world"); @@ -187,6 +198,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 // SPIGOT-5509: Wakeup, similar to riding if (this.isSleeping()) { @@ -0,0 +0,0 @@ public class CraftPlayer extends CraftHumanEntity implements Player { + ServerLevel toWorld = ((CraftWorld) to.getWorld()).getHandle(); + + // Close any foreign inventory +- if (this.getHandle().containerMenu != this.getHandle().inventoryMenu) { ++ if (this.getHandle().containerMenu != this.getHandle().inventoryMenu && !allFlags.contains(io.papermc.paper.entity.TeleportFlag.EntityState.RETAIN_OPEN_INVENTORY)) { // Paper + this.getHandle().closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.TELEPORT); // Paper + } // Check if the fromWorld and toWorld are the same. if (fromWorld == toWorld) {