From 612f3e137a533ff7fc286ad5089c3b7a1fe76568 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Fri, 4 Jun 2021 17:58:45 -0400 Subject: [PATCH] Fix dangerous end portal logic (#5776) Co-authored-by: Spottedleaf --- .../Fix-dangerous-end-portal-logic.patch | 99 +++++++++++++++++++ Spigot-Server-Patches/added-Wither-API.patch | 2 +- 2 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 Spigot-Server-Patches/Fix-dangerous-end-portal-logic.patch diff --git a/Spigot-Server-Patches/Fix-dangerous-end-portal-logic.patch b/Spigot-Server-Patches/Fix-dangerous-end-portal-logic.patch new file mode 100644 index 0000000000..9eda02348c --- /dev/null +++ b/Spigot-Server-Patches/Fix-dangerous-end-portal-logic.patch @@ -0,0 +1,99 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Spottedleaf +Date: Fri, 4 Jun 2021 17:06:52 -0400 +Subject: [PATCH] Fix dangerous end portal logic + +End portals could teleport entities during move calls. Stupid +logic given the caller will never expect that kind of thing, +and will result in all kinds of dupes. + +Move the tick logic into the post tick, where portaling was +designed to happen in the first place. + +diff --git a/src/main/java/net/minecraft/server/level/EntityPlayer.java b/src/main/java/net/minecraft/server/level/EntityPlayer.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/level/EntityPlayer.java ++++ b/src/main/java/net/minecraft/server/level/EntityPlayer.java +@@ -0,0 +0,0 @@ public class EntityPlayer extends EntityHuman implements ICrafting { + return b(worldserver, TeleportCause.UNKNOWN); + } + ++ @Nullable public final Entity changeDimension(WorldServer worldserver, PlayerTeleportEvent.TeleportCause cause) { return this.b(worldserver, cause); } // Paper - OBFHELPER + @Nullable + public Entity b(WorldServer worldserver, PlayerTeleportEvent.TeleportCause cause) { + // CraftBukkit end +diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/entity/Entity.java ++++ b/src/main/java/net/minecraft/world/entity/Entity.java +@@ -0,0 +0,0 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne + } + // Paper end - optimise entity tracking + ++ // Paper start - make end portalling safe ++ public BlockPosition portalBlock; ++ public WorldServer portalWorld; ++ public void tickEndPortal() { ++ BlockPosition pos = this.portalBlock; ++ WorldServer world = this.portalWorld; ++ this.portalBlock = null; ++ this.portalWorld = null; ++ ++ if (pos == null || world == null || world != this.world) { ++ return; ++ } ++ ++ if (this.isPassenger() || this.isVehicle() || !this.canPortal() || this.dead || !this.valid || !this.isAlive()) { ++ return; ++ } ++ ++ ResourceKey resourcekey = world.getTypeKey() == DimensionManager.THE_END ? World.OVERWORLD : World.THE_END; // CraftBukkit - SPIGOT-6152: send back to main overworld in custom ends ++ WorldServer worldserver = world.getMinecraftServer().getWorldServer(resourcekey); ++ ++ org.bukkit.event.entity.EntityPortalEnterEvent event = new org.bukkit.event.entity.EntityPortalEnterEvent(this.getBukkitEntity(), new org.bukkit.Location(world.getWorld(), pos.getX(), pos.getY(), pos.getZ())); ++ event.callEvent(); ++ ++ if (this instanceof EntityPlayer) { ++ ((EntityPlayer)this).changeDimension(worldserver, PlayerTeleportEvent.TeleportCause.END_PORTAL); ++ return; ++ } ++ this.teleportTo(worldserver, null); ++ } ++ // Paper end - make end portalling safe ++ + public Entity(EntityTypes entitytypes, World world) { + this.id = Entity.entityCount.incrementAndGet(); + this.passengers = Lists.newArrayList(); +@@ -0,0 +0,0 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne + } + + this.E(); ++ this.tickEndPortal(); // Paper - make end portalling safe + } + } + +diff --git a/src/main/java/net/minecraft/world/level/block/BlockEnderPortal.java b/src/main/java/net/minecraft/world/level/block/BlockEnderPortal.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/level/block/BlockEnderPortal.java ++++ b/src/main/java/net/minecraft/world/level/block/BlockEnderPortal.java +@@ -0,0 +0,0 @@ public class BlockEnderPortal extends BlockTileEntity { + // return; // CraftBukkit - always fire event in case plugins wish to change it + } + +- // CraftBukkit start - Entity in portal +- EntityPortalEnterEvent event = new EntityPortalEnterEvent(entity.getBukkitEntity(), new org.bukkit.Location(world.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ())); +- world.getServer().getPluginManager().callEvent(event); +- +- if (entity instanceof EntityPlayer) { +- ((EntityPlayer) entity).b(worldserver, PlayerTeleportEvent.TeleportCause.END_PORTAL); +- return; +- } +- // CraftBukkit end +- entity.b(worldserver); ++ // Paper start - move all of this logic into portal tick ++ entity.portalWorld = ((WorldServer)world); ++ entity.portalBlock = blockposition.immutableCopy(); ++ // Paper end - move all of this logic into portal tick + } + + } diff --git a/Spigot-Server-Patches/added-Wither-API.patch b/Spigot-Server-Patches/added-Wither-API.patch index 130b4d777d..4473f7889e 100644 --- a/Spigot-Server-Patches/added-Wither-API.patch +++ b/Spigot-Server-Patches/added-Wither-API.patch @@ -33,7 +33,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 @Override public boolean canPortal() { - return false; -+ return canPortal; // Paper ++ return super.canPortal() && canPortal; // Paper } @Override