Skip to content

Commit

Permalink
Call EntityPortalEnterEvent on endgateways and make cancellable (#10892)
Browse files Browse the repository at this point in the history
  • Loading branch information
Machine-Maker authored Jun 23, 2024
1 parent 5ae4758 commit 897ece4
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 23 deletions.
79 changes: 79 additions & 0 deletions patches/api/0384-Improve-PortalEvents.patch
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,85 @@ Date: Thu, 15 Dec 2022 10:33:34 -0800
Subject: [PATCH] Improve PortalEvents


diff --git a/src/main/java/org/bukkit/PortalType.java b/src/main/java/org/bukkit/PortalType.java
index 427cfbb8b542215c5d9993056e0cadf18ab9bd4b..e6120b83259c15189bbbf6b6dd13fbe7ccdf073d 100644
--- a/src/main/java/org/bukkit/PortalType.java
+++ b/src/main/java/org/bukkit/PortalType.java
@@ -14,6 +14,12 @@ public enum PortalType {
* This is an Ender portal.
*/
ENDER,
+ // Paper start
+ /**
+ * This is an end gateway
+ */
+ END_GATEWAY,
+ // Paper end

/**
* This is a custom Plugin portal.
diff --git a/src/main/java/org/bukkit/event/entity/EntityPortalEnterEvent.java b/src/main/java/org/bukkit/event/entity/EntityPortalEnterEvent.java
index 6818e9f0ba32ca1a1e612703f7526b29f5a6438f..d3724db0a5a67cde15b05fecd32b2ca370cca998 100644
--- a/src/main/java/org/bukkit/event/entity/EntityPortalEnterEvent.java
+++ b/src/main/java/org/bukkit/event/entity/EntityPortalEnterEvent.java
@@ -7,14 +7,25 @@ import org.jetbrains.annotations.NotNull;

/**
* Called when an entity comes into contact with a portal
+ * <p>
+ * Cancelling this event prevents any further processing of the portal for that tick.
+ * @see io.papermc.paper.event.entity.EntityInsideBlockEvent
*/
-public class EntityPortalEnterEvent extends EntityEvent {
+public class EntityPortalEnterEvent extends EntityEvent implements org.bukkit.event.Cancellable { // Paper
private static final HandlerList handlers = new HandlerList();
private final Location location;

+ @Deprecated(since = "1.21") @io.papermc.paper.annotation.DoNotUse // Paper
public EntityPortalEnterEvent(@NotNull final Entity entity, @NotNull final Location location) {
+ // Paper start
+ this(entity, location, org.bukkit.PortalType.CUSTOM);
+ }
+ @org.jetbrains.annotations.ApiStatus.Internal
+ public EntityPortalEnterEvent(@NotNull final Entity entity, @NotNull final Location location, @NotNull final org.bukkit.PortalType portalType) {
+ // Paper end
super(entity);
this.location = location;
+ this.portalType = portalType; // Paper
}

/**
@@ -27,6 +38,30 @@ public class EntityPortalEnterEvent extends EntityEvent {
return location;
}

+ // Paper start
+ private boolean cancelled = false;
+ private final org.bukkit.PortalType portalType;
+
+ /**
+ * Get the portal type.
+ *
+ * @return the portal type
+ */
+ public org.bukkit.@NotNull PortalType getPortalType() {
+ return this.portalType;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return this.cancelled;
+ }
+
+ @Override
+ public void setCancelled(final boolean cancel) {
+ this.cancelled = cancel;
+ }
+ // Paper end
+
@NotNull
@Override
public HandlerList getHandlers() {
diff --git a/src/main/java/org/bukkit/event/entity/EntityPortalEvent.java b/src/main/java/org/bukkit/event/entity/EntityPortalEvent.java
index 67fb9d93e808e907fa980f3004d415ae5d0a53fc..97e36c7f6e09276fbae20eaeee0965566332ca46 100644
--- a/src/main/java/org/bukkit/event/entity/EntityPortalEvent.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ index 099efafa14c10910e4ed04abb1823f0c1a96b6a6..8506fa03293c575c35b55b0522248074

/**
diff --git a/src/main/java/org/bukkit/event/entity/EntityPortalEnterEvent.java b/src/main/java/org/bukkit/event/entity/EntityPortalEnterEvent.java
index 6818e9f0ba32ca1a1e612703f7526b29f5a6438f..e4e3d2e22c28ef251d76c48ade267b4eb3749e7d 100644
index d3724db0a5a67cde15b05fecd32b2ca370cca998..8b2caf665b9e829ceefc89bf41b192f53f3d5773 100644
--- a/src/main/java/org/bukkit/event/entity/EntityPortalEnterEvent.java
+++ b/src/main/java/org/bukkit/event/entity/EntityPortalEnterEvent.java
@@ -24,7 +24,7 @@ public class EntityPortalEnterEvent extends EntityEvent {
@@ -35,7 +35,7 @@ public class EntityPortalEnterEvent extends EntityEvent implements org.bukkit.ev
*/
@NotNull
public Location getLocation() {
- return location;
+ return location.clone(); // Paper - clone to avoid changes
}

@NotNull
// Paper start
diff --git a/src/main/java/org/bukkit/event/entity/ItemDespawnEvent.java b/src/main/java/org/bukkit/event/entity/ItemDespawnEvent.java
index 6fc66197eb2c5d59c70d8d028b7963748371edbe..2bb29fa449cd6c90b52d2786ed15b6154d591607 100644
--- a/src/main/java/org/bukkit/event/entity/ItemDespawnEvent.java
Expand Down
50 changes: 48 additions & 2 deletions patches/server/0789-Improve-PortalEvents.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Improve PortalEvents


diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index f52d394c90bc326c2a58c4f623df632235e0c599..b58a83b9e7a7c9253b0091f271823bf821e90c19 100644
index f52d394c90bc326c2a58c4f623df632235e0c599..ec386450f9808c724c1b2b97c6e14fc5292caafc 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -3528,7 +3528,14 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -3528,7 +3528,15 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
org.bukkit.entity.Entity bukkitEntity = entity.getBukkitEntity();
Location enter = bukkitEntity.getLocation();

Expand All @@ -17,10 +17,56 @@ index f52d394c90bc326c2a58c4f623df632235e0c599..b58a83b9e7a7c9253b0091f271823bf8
+ final org.bukkit.PortalType portalType = switch (cause) {
+ case END_PORTAL -> org.bukkit.PortalType.ENDER;
+ case NETHER_PORTAL -> org.bukkit.PortalType.NETHER;
+ case END_GATEWAY -> org.bukkit.PortalType.END_GATEWAY; // not actually used yet
+ default -> org.bukkit.PortalType.CUSTOM;
+ };
+ EntityPortalEvent event = new EntityPortalEvent(bukkitEntity, enter, exit, searchRadius, portalType);
+ // Paper end
event.getEntity().getServer().getPluginManager().callEvent(event);
if (event.isCancelled() || event.getTo() == null || event.getTo().getWorld() == null || !entity.isAlive()) {
return null;
diff --git a/src/main/java/net/minecraft/world/level/block/EndGatewayBlock.java b/src/main/java/net/minecraft/world/level/block/EndGatewayBlock.java
index 11486419dd98a013c7387d3d73f322a95a18c574..3f5bb5c9ceb5b31fcc9ef0a7a6157e1e1cb2a09f 100644
--- a/src/main/java/net/minecraft/world/level/block/EndGatewayBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/EndGatewayBlock.java
@@ -92,6 +92,10 @@ public class EndGatewayBlock extends BaseEntityBlock implements Portal {
protected void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) {
if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, pos)).callEvent()) { return; } // Paper - Add EntityInsideBlockEvent
if (entity.canUsePortal(false)) {
+ // Paper start - call EntityPortalEnterEvent
+ org.bukkit.event.entity.EntityPortalEnterEvent event = new org.bukkit.event.entity.EntityPortalEnterEvent(entity.getBukkitEntity(), new org.bukkit.Location(world.getWorld(), pos.getX(), pos.getY(), pos.getZ()), org.bukkit.PortalType.END_GATEWAY); // Paper - add portal type
+ if (!event.callEvent()) return;
+ // Paper end - call EntityPortalEnterEvent
BlockEntity tileentity = world.getBlockEntity(pos);

if (!world.isClientSide && tileentity instanceof TheEndGatewayBlockEntity) {
diff --git a/src/main/java/net/minecraft/world/level/block/EndPortalBlock.java b/src/main/java/net/minecraft/world/level/block/EndPortalBlock.java
index cff3e9869340f1ffb7093431cbe1ac5e67792a4e..01333f69b622141b2eb53441c6cbd69e4a059d55 100644
--- a/src/main/java/net/minecraft/world/level/block/EndPortalBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/EndPortalBlock.java
@@ -66,8 +66,9 @@ public class EndPortalBlock extends BaseEntityBlock implements Portal {
if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, pos)).callEvent()) { return; } // Paper - Add EntityInsideBlockEvent
if (entity.canUsePortal(false) && Shapes.joinIsNotEmpty(Shapes.create(entity.getBoundingBox().move((double) (-pos.getX()), (double) (-pos.getY()), (double) (-pos.getZ()))), state.getShape(world, pos), BooleanOp.AND)) {
// CraftBukkit start - Entity in portal
- EntityPortalEnterEvent event = new EntityPortalEnterEvent(entity.getBukkitEntity(), new org.bukkit.Location(world.getWorld(), pos.getX(), pos.getY(), pos.getZ()));
+ EntityPortalEnterEvent event = new EntityPortalEnterEvent(entity.getBukkitEntity(), new org.bukkit.Location(world.getWorld(), pos.getX(), pos.getY(), pos.getZ()), org.bukkit.PortalType.ENDER); // Paper - add portal type
world.getCraftServer().getPluginManager().callEvent(event);
+ if (event.isCancelled()) return; // Paper - make cancellable
// CraftBukkit end
if (!world.isClientSide && world.dimension() == Level.END && entity instanceof ServerPlayer) {
ServerPlayer entityplayer = (ServerPlayer) entity;
diff --git a/src/main/java/net/minecraft/world/level/block/NetherPortalBlock.java b/src/main/java/net/minecraft/world/level/block/NetherPortalBlock.java
index a530276b0123dee5680d7e09ad3d2f0414909c91..ddab7de1d376e9e486e2f920174397ea8804aa29 100644
--- a/src/main/java/net/minecraft/world/level/block/NetherPortalBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/NetherPortalBlock.java
@@ -110,8 +110,9 @@ public class NetherPortalBlock extends Block implements Portal {
if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, pos)).callEvent()) { return; } // Paper - Add EntityInsideBlockEvent
if (entity.canUsePortal(false)) {
// CraftBukkit start - Entity in portal
- EntityPortalEnterEvent event = new EntityPortalEnterEvent(entity.getBukkitEntity(), new org.bukkit.Location(world.getWorld(), pos.getX(), pos.getY(), pos.getZ()));
+ EntityPortalEnterEvent event = new EntityPortalEnterEvent(entity.getBukkitEntity(), new org.bukkit.Location(world.getWorld(), pos.getX(), pos.getY(), pos.getZ()), org.bukkit.PortalType.NETHER); // Paper - add portal type
world.getCraftServer().getPluginManager().callEvent(event);
+ if (event.isCancelled()) return; // Paper - make cancellable
// CraftBukkit end
entity.setAsInsidePortal(this, pos);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Subject: [PATCH] Expose pre-collision moving velocity to


diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index b58a83b9e7a7c9253b0091f271823bf821e90c19..deee2eebebb415115c5566057ac626f35e9472e1 100644
index ec386450f9808c724c1b2b97c6e14fc5292caafc..011a869c2eac551fe15fca34eee11ff928af52e2 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -943,6 +943,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ clearing the owner.
Co-authored-by: Warrior <[email protected]>

diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index deee2eebebb415115c5566057ac626f35e9472e1..6d18b9a0b65c62de3f134d3d6dda6e4a988a64dc 100644
index 011a869c2eac551fe15fca34eee11ff928af52e2..fa32b32fb5e6b546cb73b43e59db408404797cb5 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -391,6 +391,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subject: [PATCH] Don't load chunks for supporting block checks


diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 6d18b9a0b65c62de3f134d3d6dda6e4a988a64dc..33ecda938359e07607ceacd0b8e8fca7e33e2ee2 100644
index fa32b32fb5e6b546cb73b43e59db408404797cb5..1d5d477b0b689167742c2f2edff263be40a991c8 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -1186,7 +1186,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ index 2ea29c9491186d7a25ed3eed99ee4a488bcaa272..de96d7df65713f2fa7b8f2dd068856bb
this.players.remove(entityplayer);
this.playersByName.remove(entityplayer.getScoreboardName().toLowerCase(java.util.Locale.ROOT)); // Spigot
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 33ecda938359e07607ceacd0b8e8fca7e33e2ee2..309dab6900543bf04ae371d7278bdf1b87a8a3c4 100644
index 1d5d477b0b689167742c2f2edff263be40a991c8..aebe9cb97776bb833221a0f11285696c266b752b 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -255,11 +255,23 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
Expand Down Expand Up @@ -1213,15 +1213,15 @@ index 33ecda938359e07607ceacd0b8e8fca7e33e2ee2..309dab6900543bf04ae371d7278bdf1b
@Override
public CommandSender getBukkitSender(CommandSourceStack wrapper) {
return this.getBukkitEntity();
@@ -4484,6 +4496,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4485,6 +4497,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
public final void setRemoved(Entity.RemovalReason entity_removalreason, EntityRemoveEvent.Cause cause) {
CraftEventFactory.callEntityRemoveEvent(this, cause);
// CraftBukkit end
+ final boolean alreadyRemoved = this.removalReason != null; // Paper - Folia schedulers
if (this.removalReason == null) {
this.removalReason = entity_removalreason;
}
@@ -4494,12 +4507,28 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4495,12 +4508,28 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess

this.getPassengers().forEach(Entity::stopRiding);
this.levelCallback.onRemove(entity_removalreason);
Expand Down
2 changes: 1 addition & 1 deletion patches/server/0874-Expand-Pose-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subject: [PATCH] Expand Pose API


diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 309dab6900543bf04ae371d7278bdf1b87a8a3c4..d56d1426a9be2f22fac458f8302bad04b3f257c2 100644
index aebe9cb97776bb833221a0f11285696c266b752b..80a29f4818cda4255c82fcd47f0da2235a02da23 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -426,6 +426,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
Expand Down
2 changes: 1 addition & 1 deletion patches/server/0881-Fix-inventory-desync.patch
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ index 9d6c6a979fb1751ca90c9c1210ec52bbf12495f4..46d6fb2591f47c245446db210a00cbaa
this.containerMenu.findSlot(this.getInventory(), this.getInventory().selected).ifPresent(s -> {
this.containerSynchronizer.sendSlotChange(this.containerMenu, s, this.getMainHandItem());
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index d56d1426a9be2f22fac458f8302bad04b3f257c2..eebb2ad39c1363ab2c3bd6d1efbd5c70b4700f42 100644
index 80a29f4818cda4255c82fcd47f0da2235a02da23..23442e0f887cec3c3a65b3dd3d0f4f40db0e54b1 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -2639,8 +2639,9 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ index 8b5eabea1a0926c22b58ef8761caee3a06aa5ee0..53fdf4e104f36a2bd88fdf26d8c68cd3
if (entity.valid) {
MinecraftServer.LOGGER.error("Attempted Double World add on {}", entity, new Throwable());
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index eebb2ad39c1363ab2c3bd6d1efbd5c70b4700f42..fb1b19bb748a97465af2b9f1de89df9f5165b7cc 100644
index 23442e0f887cec3c3a65b3dd3d0f4f40db0e54b1..24aacf9997c9ea0bd68ef3803f4a3ee4a920ab44 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -625,7 +625,11 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ index 184f3c7a1304f4f9d2aaeae27172be9d853c30de..3cbb59df34156479d24a8251f2b3acbb
if (entityitem == null) {
return null;
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index fb1b19bb748a97465af2b9f1de89df9f5165b7cc..bebb39beaba51bf19448d572b08efd25560c6e5a 100644
index 24aacf9997c9ea0bd68ef3803f4a3ee4a920ab44..363fe1aff439983199f5137547cef9516fbab2a8 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -2563,6 +2563,25 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
Expand Down
2 changes: 1 addition & 1 deletion patches/server/0950-Fix-DamageSource-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ index caf1d79e2bbdd257a5439e2973653747e678805f..e34584e4780f343d6c946af5377088d5

public DamageSource sonicBoom(Entity attacker) {
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index bebb39beaba51bf19448d572b08efd25560c6e5a..e0a3efc65b407084bdf2ef5be2cea86572858435 100644
index 363fe1aff439983199f5137547cef9516fbab2a8..2e2101274f3afebbae783fa119f5cae8104de45d 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -3263,7 +3263,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
Expand Down
Loading

0 comments on commit 897ece4

Please sign in to comment.