Skip to content
Open
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 @@ -53,7 +53,7 @@ public void setFrom(@NotNull Location from) {
*
* @return Location the player moved to
*/
@NotNull // Paper
@NotNull
public Location getTo() {
return to;
}
Expand Down Expand Up @@ -139,7 +139,8 @@ public void setCancelled(boolean cancel) {

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

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -764,9 +764,9 @@
+ final org.bukkit.event.player.PlayerTeleportEvent tpEvent;
+ // Paper start - gateway-specific teleport event
+ if (this.portalProcess != null && this.portalProcess.isSamePortal(((net.minecraft.world.level.block.EndGatewayBlock) net.minecraft.world.level.block.Blocks.END_GATEWAY)) && this.level().getBlockEntity(this.portalProcess.getEntryPosition()) instanceof net.minecraft.world.level.block.entity.TheEndGatewayBlockEntity theEndGatewayBlockEntity) {
+ tpEvent = new com.destroystokyo.paper.event.player.PlayerTeleportEndGatewayEvent(this.getBukkitEntity(), enter, exit.clone(), new org.bukkit.craftbukkit.block.CraftEndGateway(this.level().getWorld(), theEndGatewayBlockEntity));
+ tpEvent = new io.papermc.paper.event.player.PaperPlayerTeleportEndGatewayEvent(this.getBukkitEntity(), enter, exit.clone(), new org.bukkit.craftbukkit.block.CraftEndGateway(this.level().getWorld(), theEndGatewayBlockEntity));
+ } else {
+ tpEvent = new org.bukkit.event.player.PlayerTeleportEvent(this.getBukkitEntity(), enter, exit.clone(), teleportTransition.cause());
+ tpEvent = new io.papermc.paper.event.player.PaperPlayerTeleportEvent(this.getBukkitEntity(), enter, exit.clone(), teleportTransition.cause());
+ }
+ // Paper end - gateway-specific teleport event
+ org.bukkit.Bukkit.getServer().getPluginManager().callEvent(tpEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@
+ final io.papermc.paper.entity.TeleportFlag.Relative flag = org.bukkit.craftbukkit.entity.CraftEntity.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 = new io.papermc.paper.event.player.PaperPlayerTeleportEvent(player, from.clone(), to.clone(), cause, java.util.Set.copyOf(relativeFlags));
+ // Paper end - Teleport API
+ this.cserver.getPluginManager().callEvent(event);
+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,7 @@
+ // Paper start - gateway-specific teleport event
+ final org.bukkit.event.entity.EntityTeleportEvent teleEvent;
+ if (this.portalProcess != null && this.portalProcess.isSamePortal(((net.minecraft.world.level.block.EndGatewayBlock) Blocks.END_GATEWAY)) && this.level.getBlockEntity(this.portalProcess.getEntryPosition()) instanceof net.minecraft.world.level.block.entity.TheEndGatewayBlockEntity theEndGatewayBlockEntity) {
+ teleEvent = new com.destroystokyo.paper.event.entity.EntityTeleportEndGatewayEvent(this.getBukkitEntity(), this.getBukkitEntity().getLocation(), to, new org.bukkit.craftbukkit.block.CraftEndGateway(to.getWorld(), theEndGatewayBlockEntity));
+ teleEvent = new io.papermc.paper.event.entity.PaperEntityTeleportEndGatewayEvent(this.getBukkitEntity(), this.getBukkitEntity().getLocation(), to, new org.bukkit.craftbukkit.block.CraftEndGateway(to.getWorld(), theEndGatewayBlockEntity));
+ teleEvent.callEvent();
+ } else {
+ teleEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTeleportEvent(this, to);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1878,7 +1878,7 @@
+
+ if (flag) {
+ if (!(this instanceof ServerPlayer)) {
+ org.bukkit.event.entity.EntityTeleportEvent teleport = new org.bukkit.event.entity.EntityTeleportEvent(this.getBukkitEntity(), new Location(this.level().getWorld(), x1, y1, z1), new Location(this.level().getWorld(), x, d, z));
+ org.bukkit.event.entity.EntityTeleportEvent teleport = new io.papermc.paper.event.entity.PaperEntityTeleportEvent(this.getBukkitEntity(), new Location(this.level().getWorld(), x1, y1, z1), new Location(this.level().getWorld(), x, d, z));
+ this.level().getCraftServer().getPluginManager().callEvent(teleport);
+ if (!teleport.isCancelled() && teleport.getTo() != null) { // Paper
+ Location to = teleport.getTo();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.papermc.paper.event.entity;

import com.destroystokyo.paper.event.entity.EntityTeleportEndGatewayEvent;
import com.google.common.base.Preconditions;
import org.bukkit.Location;
import org.bukkit.block.EndGateway;
import org.bukkit.craftbukkit.util.CraftLocation;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

@NullMarked
public class PaperEntityTeleportEndGatewayEvent extends EntityTeleportEndGatewayEvent {

@ApiStatus.Internal
public PaperEntityTeleportEndGatewayEvent(final Entity entity, final Location from, final Location to, final EndGateway gateway) {
super(entity, from, to, gateway);
}

@Override
public void setTo(final @Nullable Location to) {
if (to != null) {
Preconditions.checkArgument(CraftLocation.isInSpawnableBounds(to), "destination Location is not in spawnable bounds");
}
super.setTo(to);
}

@Override
public void setFrom(final Location from) {
Preconditions.checkArgument(CraftLocation.isInSpawnableBounds(from), "origin Location is not in spawnable bounds");
super.setFrom(from);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.papermc.paper.event.entity;

import com.google.common.base.Preconditions;
import org.bukkit.Location;
import org.bukkit.craftbukkit.util.CraftLocation;
import org.bukkit.entity.Entity;
import org.bukkit.event.entity.EntityTeleportEvent;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

@NullMarked
public class PaperEntityTeleportEvent extends EntityTeleportEvent {

@ApiStatus.Internal
public PaperEntityTeleportEvent(final Entity entity, final Location from, @Nullable final Location to) {
super(entity, from, to);
}

@Override
public void setTo(@Nullable final Location to) {
if (to != null) {
Preconditions.checkArgument(CraftLocation.isInSpawnableBounds(to), "destination Location is not in spawnable bounds");
}
super.setTo(to);
}

@Override
public void setFrom(final Location from) {
Preconditions.checkArgument(CraftLocation.isInSpawnableBounds(from), "origin Location is not in spawnable bounds");
super.setFrom(from);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.papermc.paper.event.player;

import com.destroystokyo.paper.event.player.PlayerTeleportEndGatewayEvent;
import com.google.common.base.Preconditions;
import org.bukkit.Location;
import org.bukkit.block.EndGateway;
import org.bukkit.craftbukkit.util.CraftLocation;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;

@NullMarked
public class PaperPlayerTeleportEndGatewayEvent extends PlayerTeleportEndGatewayEvent {

@ApiStatus.Internal
public PaperPlayerTeleportEndGatewayEvent(final Player player, final Location from, final Location to, final EndGateway gateway) {
super(player, from, to, gateway);
}

@Override
public void setTo(final Location to) {
Preconditions.checkArgument(CraftLocation.isInSpawnableBounds(to), "destination Location is not in spawnable bounds");
super.setTo(to);
}

@Override
public void setFrom(final Location from) {
Preconditions.checkArgument(CraftLocation.isInSpawnableBounds(from), "origin Location is not in spawnable bounds");
super.setFrom(from);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.papermc.paper.event.player;

import com.google.common.base.Preconditions;
import io.papermc.paper.entity.TeleportFlag;
import org.bukkit.Location;
import org.bukkit.craftbukkit.util.CraftLocation;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import java.util.Set;

@NullMarked
public class PaperPlayerTeleportEvent extends PlayerTeleportEvent {

@ApiStatus.Internal
public PaperPlayerTeleportEvent(final Player player, final Location from, final @Nullable Location to) {
super(player, from, to);
}

@ApiStatus.Internal
public PaperPlayerTeleportEvent(final Player player, final Location from, final @Nullable Location to, final TeleportCause cause) {
super(player, from, to, cause);
}

@ApiStatus.Internal
public PaperPlayerTeleportEvent(final Player player, final Location from, final @Nullable Location to, final TeleportCause cause, final Set<TeleportFlag.Relative> teleportFlags) {
super(player, from, to, cause, teleportFlags);
}

@Override
public void setTo(final Location to) {
Preconditions.checkArgument(CraftLocation.isInSpawnableBounds(to), "destination Location is not in spawnable bounds");
super.setTo(to);
}

@Override
public void setFrom(final Location from) {
Preconditions.checkArgument(CraftLocation.isInSpawnableBounds(from), "origin Location is not in spawnable bounds");
super.setFrom(from);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,10 @@ public boolean teleport(Location location, TeleportCause cause) {

@Override
public boolean teleport(Location location, TeleportCause cause, TeleportFlag... flags) {
Preconditions.checkState(!this.entity.generation, "Cannot teleport entity to an other world during world generation");
Preconditions.checkArgument(location != null, "location cannot be null");
Preconditions.checkArgument(location.getWorld() != null, "Target world cannot be null");
Preconditions.checkState(!this.entity.generation, "Cannot teleport entity to an other world during world generation");
Preconditions.checkArgument(CraftLocation.isInSpawnableBounds(location), "location is out of spawnable bounds");
location.checkFinite();

return this.teleport0(location, cause, flags);
Expand Down Expand Up @@ -1112,9 +1113,10 @@ public void setOp(boolean value) {
// Paper start - more teleport API / async chunk API
@Override
public CompletableFuture<Boolean> teleportAsync(final Location location, final TeleportCause cause, final TeleportFlag... teleportFlags) {
Preconditions.checkState(!this.entity.generation, "Cannot teleport entity to an other world during world generation");
Preconditions.checkArgument(location != null, "location cannot be null");
Preconditions.checkArgument(location.getWorld() != null, "Target world cannot be null");
Preconditions.checkState(!this.entity.generation, "Cannot teleport entity to an other world during world generation");
Preconditions.checkArgument(CraftLocation.isInSpawnableBounds(location), "location is out of spawnable bounds");
location.checkFinite();
Location locationClone = location.clone(); // clone so we don't need to worry about mutations after this call.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import io.papermc.paper.event.entity.PaperEntityTeleportEvent;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.Connection;
Expand Down Expand Up @@ -1940,7 +1941,7 @@ public static EntityTeleportEvent callEntityTeleportEvent(Entity nmsEntity, doub

public static EntityTeleportEvent callEntityTeleportEvent(Entity nmsEntity, Location to) {
CraftEntity entity = nmsEntity.getBukkitEntity();
EntityTeleportEvent event = new org.bukkit.event.entity.EntityTeleportEvent(entity, entity.getLocation(), to);
EntityTeleportEvent event = new PaperEntityTeleportEvent(entity, entity.getLocation(), to);

Bukkit.getPluginManager().callEvent(event);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.core.Vec3i;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.pathfinder.Node;
import net.minecraft.world.phys.Vec3;
Expand Down Expand Up @@ -72,4 +73,8 @@ public static Location fromGlobalPos(net.minecraft.core.GlobalPos globalPos) {
public static Vec3 toVec3(Location loc) {
return new Vec3(loc.getX(), loc.getY(), loc.getZ());
}

public static boolean isInSpawnableBounds(Location loc) {
return ServerLevel.isInSpawnableBounds(CraftLocation.toBlockPosition(loc));
}
}
Loading