--- 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,43 +32,57 @@
 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.v1_20_R2.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"));
 
+    public TeleportCommand() {}
+
     public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
-        LiteralCommandNode<CommandSourceStack> literalCommandNode = dispatcher.register(Commands.literal("teleport").requires((source) -> {
-            return source.hasPermission(2);
-        }).then(Commands.argument("location", Vec3Argument.vec3()).executes((context) -> {
-            return teleportToPos(context.getSource(), Collections.singleton(context.getSource().getEntityOrException()), context.getSource().getLevel(), Vec3Argument.getCoordinates(context, "location"), WorldCoordinates.current(), (TeleportCommand.LookAt)null);
-        })).then(Commands.argument("destination", EntityArgument.entity()).executes((context) -> {
-            return 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) -> {
-            return teleportToPos(context.getSource(), EntityArgument.getEntities(context, "targets"), context.getSource().getLevel(), Vec3Argument.getCoordinates(context, "location"), (Coordinates)null, (TeleportCommand.LookAt)null);
-        }).then(Commands.argument("rotation", RotationArgument.rotation()).executes((context) -> {
-            return teleportToPos(context.getSource(), EntityArgument.getEntities(context, "targets"), context.getSource().getLevel(), Vec3Argument.getCoordinates(context, "location"), RotationArgument.getRotation(context, "rotation"), (TeleportCommand.LookAt)null);
-        })).then(Commands.literal("facing").then(Commands.literal("entity").then(Commands.argument("facingEntity", EntityArgument.entity()).executes((context) -> {
-            return teleportToPos(context.getSource(), EntityArgument.getEntities(context, "targets"), context.getSource().getLevel(), Vec3Argument.getCoordinates(context, "location"), (Coordinates)null, new TeleportCommand.LookAt(EntityArgument.getEntity(context, "facingEntity"), EntityAnchorArgument.Anchor.FEET));
-        }).then(Commands.argument("facingAnchor", EntityAnchorArgument.anchor()).executes((context) -> {
-            return teleportToPos(context.getSource(), EntityArgument.getEntities(context, "targets"), context.getSource().getLevel(), Vec3Argument.getCoordinates(context, "location"), (Coordinates)null, new TeleportCommand.LookAt(EntityArgument.getEntity(context, "facingEntity"), EntityAnchorArgument.getAnchor(context, "facingAnchor")));
-        })))).then(Commands.argument("facingLocation", Vec3Argument.vec3()).executes((context) -> {
-            return teleportToPos(context.getSource(), EntityArgument.getEntities(context, "targets"), context.getSource().getLevel(), Vec3Argument.getCoordinates(context, "location"), (Coordinates)null, new TeleportCommand.LookAt(Vec3Argument.getVec3(context, "facingLocation")));
-        })))).then(Commands.argument("destination", EntityArgument.entity()).executes((context) -> {
-            return teleportToEntity(context.getSource(), EntityArgument.getEntities(context, "targets"), EntityArgument.getEntity(context, "destination"));
+        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.LookAt(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.LookAt(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.LookAt(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(Commands.literal("tp").requires((source) -> {
-            return source.hasPermission(2);
-        }).redirect(literalCommandNode));
+
+        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(), (TeleportCommand.LookAt)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(() -> {
-                return Component.translatable("commands.teleport.success.entity.single", targets.iterator().next().getDisplayName(), destination.getDisplayName());
+                return Component.translatable("commands.teleport.success.entity.single", ((Entity) targets.iterator().next()).getDisplayName(), destination.getDisplayName());
             }, true);
         } else {
             source.sendSuccess(() -> {
@@ -78,9 +94,10 @@
     }
 
     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);
+        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);
         }
@@ -106,21 +123,25 @@
             }
         }
 
-        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(() -> {
-                return Component.translatable("commands.teleport.success.location.single", targets.iterator().next().getDisplayName(), formatDouble(vec3.x), formatDouble(vec3.y), formatDouble(vec3.z));
+                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(() -> {
-                return Component.translatable("commands.teleport.success.location.multiple", targets.size(), formatDouble(vec3.x), formatDouble(vec3.y), formatDouble(vec3.z));
+                return Component.translatable("commands.teleport.success.location.multiple", targets.size(), TeleportCommand.formatDouble(vec3d.x), TeleportCommand.formatDouble(vec3d.y), TeleportCommand.formatDouble(vec3d.z));
             }, true);
         }
 
@@ -132,21 +153,48 @@
     }
 
     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();
+        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()) {
+                    return;
+                }
+
+                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);
                 }
 
-                label23: {
+                label23:
+                {
                     if (target instanceof LivingEntity) {
-                        LivingEntity livingEntity = (LivingEntity)target;
-                        if (livingEntity.isFallFlying()) {
+                        LivingEntity entityliving = (LivingEntity) target;
+
+                        if (entityliving.isFallFlying()) {
                             break label23;
                         }
                     }
@@ -156,15 +204,17 @@
                 }
 
                 if (target instanceof PathfinderMob) {
-                    PathfinderMob pathfinderMob = (PathfinderMob)target;
-                    pathfinderMob.getNavigation().stop();
+                    PathfinderMob entitycreature = (PathfinderMob) target;
+
+                    entitycreature.getNavigation().stop();
                 }
 
             }
         }
     }
 
-    static class LookAt {
+    private static class LookAt {
+
         private final Vec3 position;
         private final Entity entity;
         private final EntityAnchorArgument.Anchor anchor;
@@ -184,7 +234,7 @@
         public void perform(CommandSourceStack source, Entity entity) {
             if (this.entity != null) {
                 if (entity instanceof ServerPlayer) {
-                    ((ServerPlayer)entity).lookAt(source.getAnchor(), this.entity, this.anchor);
+                    ((ServerPlayer) entity).lookAt(source.getAnchor(), this.entity, this.anchor);
                 } else {
                     entity.lookAt(source.getAnchor(), this.position);
                 }
