--- a/net/minecraft/world/level/block/BlockEnderPortal.java
+++ b/net/minecraft/world/level/block/BlockEnderPortal.java
@@ -26,6 +26,19 @@
 import net.minecraft.world.phys.shapes.VoxelShape;
 import net.minecraft.world.phys.shapes.VoxelShapeCollision;
 
+// CraftBukkit start
+import java.util.List;
+import net.minecraft.server.level.EntityPlayer;
+import net.minecraft.world.level.dimension.WorldDimension;
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.craftbukkit.event.CraftPortalEvent;
+import org.bukkit.craftbukkit.util.CraftLocation;
+import org.bukkit.event.entity.EntityPortalEnterEvent;
+import org.bukkit.event.player.PlayerRespawnEvent;
+import org.bukkit.event.player.PlayerTeleportEvent;
+// CraftBukkit end
+
 public class BlockEnderPortal extends BlockTileEntity implements Portal {
 
     public static final MapCodec<BlockEnderPortal> CODEC = simpleCodec(BlockEnderPortal::new);
@@ -58,6 +71,10 @@
     @Override
     protected void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
         if (entity.canUsePortal(false)) {
+            // CraftBukkit start - Entity in portal
+            EntityPortalEnterEvent event = new EntityPortalEnterEvent(entity.getBukkitEntity(), new org.bukkit.Location(world.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+            world.getCraftServer().getPluginManager().callEvent(event);
+            // CraftBukkit end
             if (!world.isClientSide && world.dimension() == World.END && entity instanceof EntityPlayer) {
                 EntityPlayer entityplayer = (EntityPlayer) entity;
 
@@ -74,11 +91,11 @@
 
     @Override
     public TeleportTransition getPortalDestination(WorldServer worldserver, Entity entity, BlockPosition blockposition) {
-        ResourceKey<World> resourcekey = worldserver.dimension() == World.END ? World.OVERWORLD : World.END;
+        ResourceKey<World> resourcekey = worldserver.getTypeKey() == WorldDimension.END ? World.OVERWORLD : World.END; // CraftBukkit - SPIGOT-6152: send back to main overworld in custom ends
         WorldServer worldserver1 = worldserver.getServer().getLevel(resourcekey);
 
         if (worldserver1 == null) {
-            return null;
+            return new TeleportTransition(PlayerTeleportEvent.TeleportCause.END_PORTAL); // CraftBukkit- always fire event in case plugins wish to change it
         } else {
             boolean flag = resourcekey == World.END;
             BlockPosition blockposition1 = flag ? WorldServer.END_SPAWN_POINT : worldserver1.getSharedSpawnPos();
@@ -87,7 +104,7 @@
             Set set;
 
             if (flag) {
-                EndPlatformFeature.createEndPlatform(worldserver1, BlockPosition.containing(vec3d).below(), true);
+                EndPlatformFeature.createEndPlatform(worldserver1, BlockPosition.containing(vec3d).below(), true, entity); // CraftBukkit
                 f = EnumDirection.WEST.toYRot();
                 set = Relative.union(Relative.DELTA, Set.of(Relative.X_ROT));
                 if (entity instanceof EntityPlayer) {
@@ -99,13 +116,21 @@
                 if (entity instanceof EntityPlayer) {
                     EntityPlayer entityplayer = (EntityPlayer) entity;
 
-                    return entityplayer.findRespawnPositionAndUseSpawnBlock(false, TeleportTransition.DO_NOTHING);
+                    return entityplayer.findRespawnPositionAndUseSpawnBlock(false, TeleportTransition.DO_NOTHING, PlayerRespawnEvent.RespawnReason.END_PORTAL); // CraftBukkit
                 }
 
                 vec3d = entity.adjustSpawnLocation(worldserver1, blockposition1).getBottomCenter();
             }
 
-            return new TeleportTransition(worldserver1, vec3d, Vec3D.ZERO, f, 0.0F, set, TeleportTransition.PLAY_PORTAL_SOUND.then(TeleportTransition.PLACE_PORTAL_TICKET));
+            // CraftBukkit start
+            CraftPortalEvent event = entity.callPortalEvent(entity, CraftLocation.toBukkit(vec3d, worldserver1.getWorld(), f, entity.getXRot()), PlayerTeleportEvent.TeleportCause.END_PORTAL, 0, 0);
+            if (event == null) {
+                return null;
+            }
+            Location to = event.getTo();
+
+            return new TeleportTransition(((CraftWorld) to.getWorld()).getHandle(), CraftLocation.toVec3D(to), entity.getDeltaMovement(), to.getYaw(), to.getPitch(), set, TeleportTransition.PLAY_PORTAL_SOUND.then(TeleportTransition.PLACE_PORTAL_TICKET), PlayerTeleportEvent.TeleportCause.END_PORTAL);
+            // CraftBukkit end
         }
     }
 
