--- a/net/minecraft/server/commands/TeleportCommand.java
+++ b/net/minecraft/server/commands/TeleportCommand.java
@@ -1,17 +1,19 @@
 package net.minecraft.server.commands;
 
 import com.mojang.brigadier.CommandDispatcher;
+import com.mojang.brigadier.builder.LiteralArgumentBuilder;
+import com.mojang.brigadier.builder.RequiredArgumentBuilder;
 import com.mojang.brigadier.exceptions.CommandSyntaxException;
 import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
 import com.mojang.brigadier.tree.LiteralCommandNode;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.EnumSet;
+import java.util.Iterator;
 import java.util.Locale;
 import java.util.Set;
 import javax.annotation.Nullable;
 import net.minecraft.commands.CommandSourceStack;
-import net.minecraft.commands.Commands;
 import net.minecraft.commands.arguments.EntityAnchorArgument;
 import net.minecraft.commands.arguments.EntityArgument;
 import net.minecraft.commands.arguments.coordinates.Coordinates;
@@ -30,173 +32,72 @@
 import net.minecraft.world.level.Level;
 import net.minecraft.world.phys.Vec2;
 import net.minecraft.world.phys.Vec3;
+// CraftBukkit start
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.event.entity.EntityTeleportEvent;
+import org.bukkit.event.player.PlayerTeleportEvent;
+// CraftBukkit end
 
 public class TeleportCommand {
-    private static final SimpleCommandExceptionType INVALID_POSITION = new SimpleCommandExceptionType(
-        Component.translatable("commands.teleport.invalidPosition")
-    );
+
+    private static final SimpleCommandExceptionType INVALID_POSITION = new SimpleCommandExceptionType(Component.translatable("commands.teleport.invalidPosition"));
+
+    public TeleportCommand() {}
 
     public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
-        LiteralCommandNode<CommandSourceStack> literalCommandNode = dispatcher.register(
-            Commands.literal("teleport")
-                .requires(source -> source.hasPermission(2))
-                .then(
-                    Commands.argument("location", Vec3Argument.vec3())
-                        .executes(
-                            context -> teleportToPos(
-                                    context.getSource(),
-                                    Collections.singleton(context.getSource().getEntityOrException()),
-                                    context.getSource().getLevel(),
-                                    Vec3Argument.getCoordinates(context, "location"),
-                                    WorldCoordinates.current(),
-                                    null
-                                )
-                        )
-                )
-                .then(
-                    Commands.argument("destination", EntityArgument.entity())
-                        .executes(
-                            context -> teleportToEntity(
-                                    context.getSource(),
-                                    Collections.singleton(context.getSource().getEntityOrException()),
-                                    EntityArgument.getEntity(context, "destination")
-                                )
-                        )
-                )
-                .then(
-                    Commands.argument("targets", EntityArgument.entities())
-                        .then(
-                            Commands.argument("location", Vec3Argument.vec3())
-                                .executes(
-                                    context -> teleportToPos(
-                                            context.getSource(),
-                                            EntityArgument.getEntities(context, "targets"),
-                                            context.getSource().getLevel(),
-                                            Vec3Argument.getCoordinates(context, "location"),
-                                            null,
-                                            null
-                                        )
-                                )
-                                .then(
-                                    Commands.argument("rotation", RotationArgument.rotation())
-                                        .executes(
-                                            context -> teleportToPos(
-                                                    context.getSource(),
-                                                    EntityArgument.getEntities(context, "targets"),
-                                                    context.getSource().getLevel(),
-                                                    Vec3Argument.getCoordinates(context, "location"),
-                                                    RotationArgument.getRotation(context, "rotation"),
-                                                    null
-                                                )
-                                        )
-                                )
-                                .then(
-                                    Commands.literal("facing")
-                                        .then(
-                                            Commands.literal("entity")
-                                                .then(
-                                                    Commands.argument("facingEntity", EntityArgument.entity())
-                                                        .executes(
-                                                            context -> teleportToPos(
-                                                                    context.getSource(),
-                                                                    EntityArgument.getEntities(context, "targets"),
-                                                                    context.getSource().getLevel(),
-                                                                    Vec3Argument.getCoordinates(context, "location"),
-                                                                    null,
-                                                                    new TeleportCommand.LookAtEntity(
-                                                                        EntityArgument.getEntity(context, "facingEntity"), EntityAnchorArgument.Anchor.FEET
-                                                                    )
-                                                                )
-                                                        )
-                                                        .then(
-                                                            Commands.argument("facingAnchor", EntityAnchorArgument.anchor())
-                                                                .executes(
-                                                                    context -> teleportToPos(
-                                                                            context.getSource(),
-                                                                            EntityArgument.getEntities(context, "targets"),
-                                                                            context.getSource().getLevel(),
-                                                                            Vec3Argument.getCoordinates(context, "location"),
-                                                                            null,
-                                                                            new TeleportCommand.LookAtEntity(
-                                                                                EntityArgument.getEntity(context, "facingEntity"),
-                                                                                EntityAnchorArgument.getAnchor(context, "facingAnchor")
-                                                                            )
-                                                                        )
-                                                                )
-                                                        )
-                                                )
-                                        )
-                                        .then(
-                                            Commands.argument("facingLocation", Vec3Argument.vec3())
-                                                .executes(
-                                                    context -> teleportToPos(
-                                                            context.getSource(),
-                                                            EntityArgument.getEntities(context, "targets"),
-                                                            context.getSource().getLevel(),
-                                                            Vec3Argument.getCoordinates(context, "location"),
-                                                            null,
-                                                            new TeleportCommand.LookAtPosition(Vec3Argument.getVec3(context, "facingLocation"))
-                                                        )
-                                                )
-                                        )
-                                )
-                        )
-                        .then(
-                            Commands.argument("destination", EntityArgument.entity())
-                                .executes(
-                                    context -> teleportToEntity(
-                                            context.getSource(),
-                                            EntityArgument.getEntities(context, "targets"),
-                                            EntityArgument.getEntity(context, "destination")
-                                        )
-                                )
-                        )
-                )
-        );
-        dispatcher.register(Commands.literal("tp").requires(source -> source.hasPermission(2)).redirect(literalCommandNode));
+        LiteralCommandNode<CommandSourceStack> literalcommandnode = dispatcher.register((LiteralArgumentBuilder) ((LiteralArgumentBuilder) ((LiteralArgumentBuilder) ((LiteralArgumentBuilder) net.minecraft.commands.Commands.literal("teleport").requires((commandlistenerwrapper) -> {
+            return commandlistenerwrapper.hasPermission(2);
+        })).then(net.minecraft.commands.Commands.argument("location", Vec3Argument.vec3()).executes((commandcontext) -> {
+            return TeleportCommand.teleportToPos((CommandSourceStack) commandcontext.getSource(), Collections.singleton(((CommandSourceStack) commandcontext.getSource()).getEntityOrException()), ((CommandSourceStack) commandcontext.getSource()).getLevel(), Vec3Argument.getCoordinates(commandcontext, "location"), WorldCoordinates.current(), (TeleportCommand.LookAt) null);
+        }))).then(net.minecraft.commands.Commands.argument("destination", EntityArgument.entity()).executes((commandcontext) -> {
+            return TeleportCommand.teleportToEntity((CommandSourceStack) commandcontext.getSource(), Collections.singleton(((CommandSourceStack) commandcontext.getSource()).getEntityOrException()), EntityArgument.getEntity(commandcontext, "destination"));
+        }))).then(((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("targets", EntityArgument.entities()).then(((RequiredArgumentBuilder) ((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("location", Vec3Argument.vec3()).executes((commandcontext) -> {
+            return TeleportCommand.teleportToPos((CommandSourceStack) commandcontext.getSource(), EntityArgument.getEntities(commandcontext, "targets"), ((CommandSourceStack) commandcontext.getSource()).getLevel(), Vec3Argument.getCoordinates(commandcontext, "location"), (Coordinates) null, (TeleportCommand.LookAt) null);
+        })).then(net.minecraft.commands.Commands.argument("rotation", RotationArgument.rotation()).executes((commandcontext) -> {
+            return TeleportCommand.teleportToPos((CommandSourceStack) commandcontext.getSource(), EntityArgument.getEntities(commandcontext, "targets"), ((CommandSourceStack) commandcontext.getSource()).getLevel(), Vec3Argument.getCoordinates(commandcontext, "location"), RotationArgument.getRotation(commandcontext, "rotation"), (TeleportCommand.LookAt) null);
+        }))).then(((LiteralArgumentBuilder) net.minecraft.commands.Commands.literal("facing").then(net.minecraft.commands.Commands.literal("entity").then(((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("facingEntity", EntityArgument.entity()).executes((commandcontext) -> {
+            return TeleportCommand.teleportToPos((CommandSourceStack) commandcontext.getSource(), EntityArgument.getEntities(commandcontext, "targets"), ((CommandSourceStack) commandcontext.getSource()).getLevel(), Vec3Argument.getCoordinates(commandcontext, "location"), (Coordinates) null, new TeleportCommand.LookAtEntity(EntityArgument.getEntity(commandcontext, "facingEntity"), EntityAnchorArgument.Anchor.FEET));
+        })).then(net.minecraft.commands.Commands.argument("facingAnchor", EntityAnchorArgument.anchor()).executes((commandcontext) -> {
+            return TeleportCommand.teleportToPos((CommandSourceStack) commandcontext.getSource(), EntityArgument.getEntities(commandcontext, "targets"), ((CommandSourceStack) commandcontext.getSource()).getLevel(), Vec3Argument.getCoordinates(commandcontext, "location"), (Coordinates) null, new TeleportCommand.LookAtEntity(EntityArgument.getEntity(commandcontext, "facingEntity"), EntityAnchorArgument.getAnchor(commandcontext, "facingAnchor")));
+        }))))).then(net.minecraft.commands.Commands.argument("facingLocation", Vec3Argument.vec3()).executes((commandcontext) -> {
+            return TeleportCommand.teleportToPos((CommandSourceStack) commandcontext.getSource(), EntityArgument.getEntities(commandcontext, "targets"), ((CommandSourceStack) commandcontext.getSource()).getLevel(), Vec3Argument.getCoordinates(commandcontext, "location"), (Coordinates) null, new TeleportCommand.LookAtPosition(Vec3Argument.getVec3(commandcontext, "facingLocation")));
+        }))))).then(net.minecraft.commands.Commands.argument("destination", EntityArgument.entity()).executes((commandcontext) -> {
+            return TeleportCommand.teleportToEntity((CommandSourceStack) commandcontext.getSource(), EntityArgument.getEntities(commandcontext, "targets"), EntityArgument.getEntity(commandcontext, "destination"));
+        }))));
+
+        dispatcher.register((LiteralArgumentBuilder) ((LiteralArgumentBuilder) net.minecraft.commands.Commands.literal("tp").requires((commandlistenerwrapper) -> {
+            return commandlistenerwrapper.hasPermission(2);
+        })).redirect(literalcommandnode));
     }
 
     private static int teleportToEntity(CommandSourceStack source, Collection<? extends Entity> targets, Entity destination) throws CommandSyntaxException {
-        for (Entity entity : targets) {
-            performTeleport(
-                source,
-                entity,
-                (ServerLevel)destination.level(),
-                destination.getX(),
-                destination.getY(),
-                destination.getZ(),
-                EnumSet.noneOf(RelativeMovement.class),
-                destination.getYRot(),
-                destination.getXRot(),
-                null
-            );
+        Iterator iterator = targets.iterator();
+
+        while (iterator.hasNext()) {
+            Entity entity1 = (Entity) iterator.next();
+
+            TeleportCommand.performTeleport(source, entity1, (ServerLevel) destination.level(), destination.getX(), destination.getY(), destination.getZ(), EnumSet.noneOf(RelativeMovement.class), destination.getYRot(), destination.getXRot(), (TeleportCommand.LookAt) null);
         }
 
         if (targets.size() == 1) {
-            source.sendSuccess(
-                () -> Component.translatable(
-                        "commands.teleport.success.entity.single", targets.iterator().next().getDisplayName(), destination.getDisplayName()
-                    ),
-                true
-            );
+            source.sendSuccess(() -> {
+                return Component.translatable("commands.teleport.success.entity.single", ((Entity) targets.iterator().next()).getDisplayName(), destination.getDisplayName());
+            }, true);
         } else {
-            source.sendSuccess(() -> Component.translatable("commands.teleport.success.entity.multiple", targets.size(), destination.getDisplayName()), true);
+            source.sendSuccess(() -> {
+                return Component.translatable("commands.teleport.success.entity.multiple", targets.size(), destination.getDisplayName());
+            }, true);
         }
 
         return targets.size();
     }
 
-    private static int teleportToPos(
-        CommandSourceStack source,
-        Collection<? extends Entity> targets,
-        ServerLevel world,
-        Coordinates location,
-        @Nullable Coordinates rotation,
-        @Nullable TeleportCommand.LookAt facingLocation
-    ) throws CommandSyntaxException {
-        Vec3 vec3 = location.getPosition(source);
-        Vec2 vec2 = rotation == null ? null : rotation.getRotation(source);
+    private static int teleportToPos(CommandSourceStack source, Collection<? extends Entity> targets, ServerLevel world, Coordinates location, @Nullable Coordinates rotation, @Nullable TeleportCommand.LookAt facingLocation) throws CommandSyntaxException {
+        Vec3 vec3d = location.getPosition(source);
+        Vec2 vec2f = rotation == null ? null : rotation.getRotation(source);
         Set<RelativeMovement> set = EnumSet.noneOf(RelativeMovement.class);
+
         if (location.isXRelative()) {
             set.add(RelativeMovement.X);
         }
@@ -222,32 +123,26 @@
             }
         }
 
-        for (Entity entity : targets) {
+        Iterator iterator = targets.iterator();
+
+        while (iterator.hasNext()) {
+            Entity entity = (Entity) iterator.next();
+
             if (rotation == null) {
-                performTeleport(source, entity, world, vec3.x, vec3.y, vec3.z, set, entity.getYRot(), entity.getXRot(), facingLocation);
+                TeleportCommand.performTeleport(source, entity, world, vec3d.x, vec3d.y, vec3d.z, set, entity.getYRot(), entity.getXRot(), facingLocation);
             } else {
-                performTeleport(source, entity, world, vec3.x, vec3.y, vec3.z, set, vec2.y, vec2.x, facingLocation);
+                TeleportCommand.performTeleport(source, entity, world, vec3d.x, vec3d.y, vec3d.z, set, vec2f.y, vec2f.x, facingLocation);
             }
         }
 
         if (targets.size() == 1) {
-            source.sendSuccess(
-                () -> Component.translatable(
-                        "commands.teleport.success.location.single",
-                        targets.iterator().next().getDisplayName(),
-                        formatDouble(vec3.x),
-                        formatDouble(vec3.y),
-                        formatDouble(vec3.z)
-                    ),
-                true
-            );
+            source.sendSuccess(() -> {
+                return Component.translatable("commands.teleport.success.location.single", ((Entity) targets.iterator().next()).getDisplayName(), TeleportCommand.formatDouble(vec3d.x), TeleportCommand.formatDouble(vec3d.y), TeleportCommand.formatDouble(vec3d.z));
+            }, true);
         } else {
-            source.sendSuccess(
-                () -> Component.translatable(
-                        "commands.teleport.success.location.multiple", targets.size(), formatDouble(vec3.x), formatDouble(vec3.y), formatDouble(vec3.z)
-                    ),
-                true
-            );
+            source.sendSuccess(() -> {
+                return Component.translatable("commands.teleport.success.location.multiple", targets.size(), TeleportCommand.formatDouble(vec3d.x), TeleportCommand.formatDouble(vec3d.y), TeleportCommand.formatDouble(vec3d.z));
+            }, true);
         }
 
         return targets.size();
@@ -257,61 +152,92 @@
         return String.format(Locale.ROOT, "%f", d);
     }
 
-    private static void performTeleport(
-        CommandSourceStack source,
-        Entity target,
-        ServerLevel world,
-        double x,
-        double y,
-        double z,
-        Set<RelativeMovement> movementFlags,
-        float yaw,
-        float pitch,
-        @Nullable TeleportCommand.LookAt facingLocation
-    ) throws CommandSyntaxException {
-        BlockPos blockPos = BlockPos.containing(x, y, z);
-        if (!Level.isInSpawnableBounds(blockPos)) {
-            throw INVALID_POSITION.create();
+    private static void performTeleport(CommandSourceStack source, Entity target, ServerLevel world, double x, double y, double z, Set<RelativeMovement> movementFlags, float yaw, float pitch, @Nullable TeleportCommand.LookAt facingLocation) throws CommandSyntaxException {
+        BlockPos blockposition = BlockPos.containing(x, y, z);
+
+        if (!Level.isInSpawnableBounds(blockposition)) {
+            throw TeleportCommand.INVALID_POSITION.create();
         } else {
-            float f = Mth.wrapDegrees(yaw);
-            float g = Mth.wrapDegrees(pitch);
-            if (target.teleportTo(world, x, y, z, movementFlags, f, g)) {
+            float f2 = Mth.wrapDegrees(yaw);
+            float f3 = Mth.wrapDegrees(pitch);
+
+            // CraftBukkit start - Teleport event
+            boolean result;
+            if (target instanceof ServerPlayer player) {
+                result = player.teleportTo(world, x, y, z, movementFlags, f2, f3, PlayerTeleportEvent.TeleportCause.COMMAND);
+            } else {
+                Location to = new Location(world.getWorld(), x, y, z, f2, f3);
+                EntityTeleportEvent event = new EntityTeleportEvent(target.getBukkitEntity(), target.getBukkitEntity().getLocation(), to);
+                world.getCraftServer().getPluginManager().callEvent(event);
+                if (event.isCancelled() || event.getTo() == null) { // Paper
+                    return;
+                }
+                to = event.getTo(); // Paper - actually track new location
+
+                x = to.getX();
+                y = to.getY();
+                z = to.getZ();
+                f2 = to.getYaw();
+                f3 = to.getPitch();
+                world = ((CraftWorld) to.getWorld()).getHandle();
+
+                result = target.teleportTo(world, x, y, z, movementFlags, f2, f3);
+            }
+
+            if (result) {
+                // CraftBukkit end
                 if (facingLocation != null) {
                     facingLocation.perform(source, target);
                 }
 
-                if (!(target instanceof LivingEntity livingEntity) || !livingEntity.isFallFlying()) {
-                    target.setDeltaMovement(target.getDeltaMovement().multiply(1.0, 0.0, 1.0));
+                label23:
+                {
+                    if (target instanceof LivingEntity) {
+                        LivingEntity entityliving = (LivingEntity) target;
+
+                        if (entityliving.isFallFlying()) {
+                            break label23;
+                        }
+                    }
+
+                    target.setDeltaMovement(target.getDeltaMovement().multiply(1.0D, 0.0D, 1.0D));
                     target.setOnGround(true);
                 }
 
-                if (target instanceof PathfinderMob pathfinderMob) {
-                    pathfinderMob.getNavigation().stop();
+                if (target instanceof PathfinderMob) {
+                    PathfinderMob entitycreature = (PathfinderMob) target;
+
+                    entitycreature.getNavigation().stop();
                 }
+
             }
         }
     }
 
     @FunctionalInterface
-    interface LookAt {
+    private interface LookAt {
+
         void perform(CommandSourceStack source, Entity entity);
     }
 
-    static record LookAtEntity(Entity entity, EntityAnchorArgument.Anchor anchor) implements TeleportCommand.LookAt {
+    private static record LookAtPosition(Vec3 position) implements TeleportCommand.LookAt {
+
         @Override
         public void perform(CommandSourceStack source, Entity entity) {
-            if (entity instanceof ServerPlayer serverPlayer) {
-                serverPlayer.lookAt(source.getAnchor(), this.entity, this.anchor);
-            } else {
-                entity.lookAt(source.getAnchor(), this.anchor.apply(this.entity));
-            }
+            entity.lookAt(source.getAnchor(), this.position);
         }
     }
 
-    static record LookAtPosition(Vec3 position) implements TeleportCommand.LookAt {
+    private static record LookAtEntity(Entity entity, EntityAnchorArgument.Anchor anchor) implements TeleportCommand.LookAt {
+
         @Override
         public void perform(CommandSourceStack source, Entity entity) {
-            entity.lookAt(source.getAnchor(), this.position);
+            if (entity instanceof ServerPlayer entityplayer) {
+                entityplayer.lookAt(source.getAnchor(), this.entity, this.anchor);
+            } else {
+                entity.lookAt(source.getAnchor(), this.anchor.apply(this.entity));
+            }
+
         }
     }
 }
