2021-03-15 23:00:00 +01:00
--- a/net/minecraft/server/commands/CommandTeleport.java
+++ b/net/minecraft/server/commands/CommandTeleport.java
2024-10-22 17:15:00 +02:00
@@ -31,6 +31,14 @@
2021-03-15 23:00:00 +01:00
import net.minecraft.world.phys.Vec2F;
import net.minecraft.world.phys.Vec3D;
2021-03-08 22:47:33 +01:00
2018-09-07 12:32:57 +02:00
+// CraftBukkit start
2024-10-22 17:15:00 +02:00
+import net.minecraft.server.level.EntityPlayer;
2018-09-07 12:32:57 +02:00
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.event.entity.EntityTeleportEvent;
2023-03-14 17:30:00 +01:00
+import org.bukkit.event.player.PlayerTeleportEvent;
2018-09-07 12:32:57 +02:00
+// CraftBukkit end
2021-03-08 22:47:33 +01:00
+
2018-09-07 12:32:57 +02:00
public class CommandTeleport {
2022-06-07 18:00:00 +02:00
private static final SimpleCommandExceptionType INVALID_POSITION = new SimpleCommandExceptionType(IChatBaseComponent.translatable("commands.teleport.invalidPosition"));
2024-10-22 17:15:00 +02:00
@@ -167,7 +175,30 @@
float f4 = MathHelper.wrapDegrees(f2);
float f5 = MathHelper.wrapDegrees(f3);
2017-06-04 00:39:36 +02:00
2024-10-22 17:15:00 +02:00
- if (entity.teleportTo(worldserver, d3, d4, d5, set, f4, f5, true)) {
2023-03-14 17:30:00 +01:00
+ // CraftBukkit start - Teleport event
+ boolean result;
+ if (entity instanceof EntityPlayer player) {
2024-10-22 17:15:00 +02:00
+ result = player.teleportTo(worldserver, d3, d4, d5, set, f4, f5, true, PlayerTeleportEvent.TeleportCause.COMMAND);
2023-03-14 17:30:00 +01:00
+ } else {
2024-10-22 17:15:00 +02:00
+ Location to = new Location(worldserver.getWorld(), d3, d4, d5, f4, f5);
2020-06-25 02:00:00 +02:00
+ EntityTeleportEvent event = new EntityTeleportEvent(entity.getBukkitEntity(), entity.getBukkitEntity().getLocation(), to);
2021-06-11 13:33:49 +02:00
+ worldserver.getCraftServer().getPluginManager().callEvent(event);
2020-06-25 02:00:00 +02:00
+ if (event.isCancelled()) {
+ return;
+ }
2018-09-07 12:32:57 +02:00
+
2024-10-22 17:15:00 +02:00
+ d3 = to.getX();
+ d4 = to.getY();
+ d5 = to.getZ();
+ f4 = to.getYaw();
+ f5 = to.getPitch();
2020-06-25 02:00:00 +02:00
+ worldserver = ((CraftWorld) to.getWorld()).getHandle();
2023-03-14 17:30:00 +01:00
+
2024-10-22 17:15:00 +02:00
+ result = entity.teleportTo(worldserver, d3, d4, d5, set, f4, f5, true);
2023-03-14 17:30:00 +01:00
+ }
+
+ if (result) {
2020-06-25 02:00:00 +02:00
+ // CraftBukkit end
2024-10-22 17:15:00 +02:00
if (lookat != null) {
lookat.perform(commandlistenerwrapper, entity);
2023-03-14 17:30:00 +01:00
}