Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ public Location getFrom() {
* Sets the location that this entity moved from
*
* @param from New location this entity moved from
* @throws IllegalArgumentException if the location is not finite
*/
public void setFrom(@NotNull Location from) {
from.checkFinite();
this.from = from.clone();
}

Expand All @@ -63,9 +65,15 @@ public Location getTo() {
* Sets the location that this entity moved to
*
* @param to New Location this entity moved to
* @throws IllegalArgumentException if the location is not finite
*/
public void setTo(@Nullable Location to) {
this.to = to != null ? to.clone() : null;
if (to != null) {
to.checkFinite();
this.to = to.clone();
} else {
this.to = null;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,10 @@ public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}

private void validateLocation(@NotNull Location loc) {
private void validateLocation(Location loc) {
Preconditions.checkArgument(loc != null, "Cannot use null location!");
Preconditions.checkArgument(loc.getWorld() != null, "Cannot use null location with null world!");
loc.checkFinite();
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@

return true;
} else {
@@ -1175,10 +_,77 @@
@@ -1175,10 +_,76 @@
}

public void teleport(double x, double y, double z, float yaw, float pitch) {
Expand Down Expand Up @@ -1036,9 +1036,8 @@
+ final io.papermc.paper.entity.TeleportFlag.Relative flag = org.bukkit.craftbukkit.entity.CraftPlayer.deltaRelativeToAPI(relativeArgument);
+ if (flag != null) relativeFlags.add(flag);
+ }
+ PlayerTeleportEvent event = new PlayerTeleportEvent(player, from.clone(), to.clone(), cause, java.util.Set.copyOf(relativeFlags));
+ PlayerTeleportEvent event = CraftEventFactory.callPlayerTeleportEvent(player, from.clone(), to.clone(), cause, java.util.Set.copyOf(relativeFlags));
+ // Paper end - Teleport API
+ this.cserver.getPluginManager().callEvent(event);
+
+ if (event.isCancelled() || !to.equals(event.getTo())) {
+ // set = Collections.emptySet(); // Can't relative teleport // Paper - Teleport API; Now you can!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.bukkit.craftbukkit.CraftSound;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer;
import org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry;
import org.bukkit.craftbukkit.util.CraftChatMessage;
Expand Down Expand Up @@ -295,6 +296,8 @@ public boolean teleport(Location location, TeleportCause cause) {
public boolean teleport(Location location, TeleportCause cause, io.papermc.paper.entity.TeleportFlag... flags) {
// Paper end
Preconditions.checkArgument(location != null, "location cannot be null");
Preconditions.checkArgument(location.getWorld() != null, "world of location cannot be null");
Preconditions.checkArgument(ServerLevel.isInSpawnableBounds(CraftLocation.toBlockPosition(location)), "location is out of spawnable bounds [x/z between %s and %s or y between %s and %s]", -ServerLevel.MAX_LEVEL_SIZE, ServerLevel.MAX_LEVEL_SIZE, ServerLevel.MIN_ENTITY_SPAWN_Y, ServerLevel.MAX_ENTITY_SPAWN_Y);
location.checkFinite();
// Paper start - Teleport passenger API
Set<io.papermc.paper.entity.TeleportFlag> flagSet = new HashSet<>(List.of(flags)); // Wrap into list while multiple old flags link to the same new one
Expand All @@ -316,11 +319,10 @@ public boolean teleport(Location location, TeleportCause cause, io.papermc.paper
}

// Paper start - fix teleport event not being called
org.bukkit.event.entity.EntityTeleportEvent event = new org.bukkit.event.entity.EntityTeleportEvent(
this, this.getLocation(), location);
org.bukkit.event.entity.EntityTeleportEvent event = CraftEventFactory.callEntityTeleportEvent(this.getHandle(), location);
// cancelling the event is handled differently for players and entities,
// entities just stop teleporting, players will still teleport to the "from" location of the event
if (!event.callEvent() || event.getTo() == null) {
if (event.isCancelled() || event.getTo() == null) {
return false;
}
location = event.getTo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1378,8 +1378,9 @@ public boolean teleport(Location location, org.bukkit.event.player.PlayerTelepor
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");
Preconditions.checkArgument(location != null, "location cannot be null");
Preconditions.checkArgument(location.getWorld() != null, "world of location cannot be null");
Preconditions.checkArgument(ServerLevel.isInSpawnableBounds(CraftLocation.toBlockPosition(location)), "location is out of spawnable bounds [x/z between %s and %s or y between %s and %s]", -ServerLevel.MAX_LEVEL_SIZE, ServerLevel.MAX_LEVEL_SIZE, ServerLevel.MIN_ENTITY_SPAWN_Y, ServerLevel.MAX_ENTITY_SPAWN_Y);
// Paper start - Teleport passenger API
// Don't allow teleporting between worlds while keeping passengers
if (ignorePassengers && entity.isVehicle() && location.getWorld() != this.getWorld()) {
Expand Down Expand Up @@ -1412,8 +1413,7 @@ public boolean teleport(Location location, org.bukkit.event.player.PlayerTelepor
// To = Players new Location if Teleport is Successful
Location to = location;
// Create & Call the Teleport Event.
PlayerTeleportEvent event = new PlayerTeleportEvent(this, from, to, cause, Set.copyOf(relativeArguments)); // Paper - Teleport API
this.server.getPluginManager().callEvent(event);
PlayerTeleportEvent event = CraftEventFactory.callPlayerTeleportEvent(this, from, to, cause, Set.copyOf(relativeArguments)); // Paper - Teleport API

// Return False to inform the Plugin that the Teleport was unsuccessful/cancelled.
if (event.isCancelled()) {
Expand All @@ -1432,6 +1432,7 @@ public boolean teleport(Location location, org.bukkit.event.player.PlayerTelepor
from = event.getFrom();
// Grab the new To Location dependent on whether the event was cancelled.
to = event.getTo();
Preconditions.checkArgument(ServerLevel.isInSpawnableBounds(CraftLocation.toBlockPosition(to)), "destination for PlayerTeleportEvent is out of spawnable bounds [x/z between %s and %s or y between %s and %s]", -ServerLevel.MAX_LEVEL_SIZE, ServerLevel.MAX_LEVEL_SIZE, ServerLevel.MIN_ENTITY_SPAWN_Y, ServerLevel.MAX_ENTITY_SPAWN_Y);
// Grab the To and From World Handles.
ServerLevel fromWorld = ((CraftWorld) from.getWorld()).getHandle();
ServerLevel toWorld = ((CraftWorld) to.getWorld()).getHandle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.papermc.paper.adventure.PaperAdventure;
import io.papermc.paper.connection.HorriblePlayerLoginEventHack;
import io.papermc.paper.connection.PlayerConnection;
import io.papermc.paper.entity.TeleportFlag;
import io.papermc.paper.event.connection.PlayerConnectionValidateLoginEvent;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand Down Expand Up @@ -100,6 +101,7 @@
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.inventory.CraftItemType;
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
import org.bukkit.craftbukkit.util.CraftLocation;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.craftbukkit.util.CraftVector;
import org.bukkit.entity.AbstractHorse;
Expand Down Expand Up @@ -242,6 +244,7 @@
import org.bukkit.event.player.PlayerShearEntityEvent;
import org.bukkit.event.player.PlayerSignOpenEvent;
import org.bukkit.event.player.PlayerStatisticIncrementEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerUnleashEntityEvent;
import org.bukkit.event.raid.RaidFinishEvent;
import org.bukkit.event.raid.RaidSpawnWaveEvent;
Expand Down Expand Up @@ -1942,6 +1945,21 @@ public static EntityTeleportEvent callEntityTeleportEvent(Entity nmsEntity, Loca

Bukkit.getPluginManager().callEvent(event);

if (!event.isCancelled() && event.getTo() != null) {
Preconditions.checkArgument(ServerLevel.isInSpawnableBounds(CraftLocation.toBlockPosition(event.getTo())), "destination for EntityTeleportEvent is out of spawnable bounds [x/z between %s and %s or y between %s and %s]", -ServerLevel.MAX_LEVEL_SIZE, ServerLevel.MAX_LEVEL_SIZE, ServerLevel.MIN_ENTITY_SPAWN_Y, ServerLevel.MAX_ENTITY_SPAWN_Y);
}

return event;
}

public static PlayerTeleportEvent callPlayerTeleportEvent(Player player, Location from, Location to, PlayerTeleportEvent.TeleportCause cause, Set<TeleportFlag.Relative> teleportFlags) {
PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to, cause, teleportFlags);
event.callEvent();

if (!event.isCancelled()) {
Preconditions.checkArgument(ServerLevel.isInSpawnableBounds(CraftLocation.toBlockPosition(event.getTo())), "destination for PlayerTeleportEvent is out of spawnable bounds [x/z between %s and %s or y between %s and %s]", -ServerLevel.MAX_LEVEL_SIZE, ServerLevel.MAX_LEVEL_SIZE, ServerLevel.MIN_ENTITY_SPAWN_Y, ServerLevel.MAX_ENTITY_SPAWN_Y);
}

return event;
}

Expand Down
Loading