--- 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;
@@ -32,42 +34,55 @@
 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_19_R2.CraftWorld;
+import org.bukkit.event.entity.EntityTeleportEvent;
+// 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(ClientboundPlayerPositionPacket.RelativeArgument.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(ClientboundPlayerPositionPacket.RelativeArgument.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(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);
         }
@@ -76,9 +91,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<ClientboundPlayerPositionPacket.RelativeArgument> set = EnumSet.noneOf(ClientboundPlayerPositionPacket.RelativeArgument.class);
+
         if (location.isXRelative()) {
             set.add(ClientboundPlayerPositionPacket.RelativeArgument.X);
         }
@@ -104,18 +120,22 @@
             }
         }
 
-        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(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(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();
@@ -126,44 +146,64 @@
     }
 
     private static void performTeleport(CommandSourceStack source, Entity target, ServerLevel world, double x, double y, double z, Set<ClientboundPlayerPositionPacket.RelativeArgument> movementFlags, float yaw, float pitch, @Nullable TeleportCommand.LookAt facingLocation) throws CommandSyntaxException {
-        BlockPos blockPos = new BlockPos(x, y, z);
-        if (!Level.isInSpawnableBounds(blockPos)) {
-            throw INVALID_POSITION.create();
+        BlockPos blockposition = new BlockPos(x, y, z);
+
+        if (!Level.isInSpawnableBounds(blockposition)) {
+            throw TeleportCommand.INVALID_POSITION.create();
         } else {
-            float f = Mth.wrapDegrees(yaw);
-            float g = Mth.wrapDegrees(pitch);
+            float f2 = Mth.wrapDegrees(yaw);
+            float f3 = Mth.wrapDegrees(pitch);
+
             if (target instanceof ServerPlayer) {
-                ChunkPos chunkPos = new ChunkPos(new BlockPos(x, y, z));
-                world.getChunkSource().addRegionTicket(TicketType.POST_TELEPORT, chunkPos, 1, target.getId());
+                ChunkPos chunkcoordintpair = new ChunkPos(new BlockPos(x, y, z));
+
+                world.getChunkSource().addRegionTicket(TicketType.POST_TELEPORT, chunkcoordintpair, 1, target.getId());
                 target.stopRiding();
-                if (((ServerPlayer)target).isSleeping()) {
-                    ((ServerPlayer)target).stopSleepInBed(true, true);
+                if (((ServerPlayer) target).isSleeping()) {
+                    ((ServerPlayer) target).stopSleepInBed(true, true);
                 }
 
                 if (world == target.level) {
-                    ((ServerPlayer)target).connection.teleport(x, y, z, f, g, movementFlags);
+                    ((ServerPlayer) target).connection.teleport(x, y, z, f2, f3, movementFlags, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.COMMAND); // CraftBukkit
                 } else {
-                    ((ServerPlayer)target).teleportTo(world, x, y, z, f, g);
+                    ((ServerPlayer) target).teleportTo(world, x, y, z, f2, f3, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.COMMAND); // CraftBukkit
                 }
 
-                target.setYHeadRot(f);
+                target.setYHeadRot(f2);
             } else {
-                float h = Mth.clamp(g, -90.0F, 90.0F);
+                float f4 = Mth.clamp(f3, -90.0F, 90.0F);
+                // CraftBukkit start - Teleport event
+                Location to = new Location(world.getWorld(), x, y, z, f2, f4);
+                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();
+                f4 = to.getPitch();
+                world = ((CraftWorld) to.getWorld()).getHandle();
+                // CraftBukkit end
+
                 if (world == target.level) {
-                    target.moveTo(x, y, z, f, h);
-                    target.setYHeadRot(f);
+                    target.moveTo(x, y, z, f2, f4);
+                    target.setYHeadRot(f2);
                 } else {
                     target.unRide();
-                    Entity entity = target;
+                    Entity entity1 = target;
+
                     target = target.getType().create(world);
                     if (target == null) {
                         return;
                     }
 
-                    target.restoreFrom(entity);
-                    target.moveTo(x, y, z, f, h);
-                    target.setYHeadRot(f);
-                    entity.setRemoved(Entity.RemovalReason.CHANGED_DIMENSION);
+                    target.restoreFrom(entity1);
+                    target.moveTo(x, y, z, f2, f4);
+                    target.setYHeadRot(f2);
+                    entity1.setRemoved(Entity.RemovalReason.CHANGED_DIMENSION);
                     world.addDuringTeleport(target);
                 }
             }
@@ -172,19 +212,20 @@
                 facingLocation.perform(source, target);
             }
 
-            if (!(target instanceof LivingEntity) || !((LivingEntity)target).isFallFlying()) {
+            if (!(target instanceof LivingEntity) || !((LivingEntity) target).isFallFlying()) {
                 target.setDeltaMovement(target.getDeltaMovement().multiply(1.0D, 0.0D, 1.0D));
                 target.setOnGround(true);
             }
 
             if (target instanceof PathfinderMob) {
-                ((PathfinderMob)target).getNavigation().stop();
+                ((PathfinderMob) target).getNavigation().stop();
             }
 
         }
     }
 
-    static class LookAt {
+    private static class LookAt {
+
         private final Vec3 position;
         private final Entity entity;
         private final EntityAnchorArgument.Anchor anchor;
@@ -204,7 +245,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);
                 }
