From 5c4a9d5f139462124ed5fb54e284662e845b2f72 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Tue, 21 May 2019 12:07:56 +1000 Subject: [PATCH] SPIGOT-4966: Provide access to Entity in PortalCreateEvent By: md_5 --- .../event/entity/EntityCreatePortalEvent.java | 4 ++++ .../bukkit/event/world/PortalCreateEvent.java | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/paper-api/src/main/java/org/bukkit/event/entity/EntityCreatePortalEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/EntityCreatePortalEvent.java index 35cae8978b..397baaefd2 100644 --- a/paper-api/src/main/java/org/bukkit/event/entity/EntityCreatePortalEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/entity/EntityCreatePortalEvent.java @@ -6,11 +6,15 @@ import org.bukkit.block.BlockState; import org.bukkit.entity.LivingEntity; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; +import org.bukkit.event.world.PortalCreateEvent; import org.jetbrains.annotations.NotNull; /** * Thrown when a Living Entity creates a portal in a world. + * + * @deprecated Use {@link PortalCreateEvent} */ +@Deprecated public class EntityCreatePortalEvent extends EntityEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); private final List blocks; diff --git a/paper-api/src/main/java/org/bukkit/event/world/PortalCreateEvent.java b/paper-api/src/main/java/org/bukkit/event/world/PortalCreateEvent.java index 291ae48dcd..579f017474 100644 --- a/paper-api/src/main/java/org/bukkit/event/world/PortalCreateEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/world/PortalCreateEvent.java @@ -3,9 +3,11 @@ package org.bukkit.event.world; import java.util.List; import org.bukkit.World; import org.bukkit.block.BlockState; +import org.bukkit.entity.Entity; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * Called when a portal is created @@ -14,12 +16,19 @@ public class PortalCreateEvent extends WorldEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); private boolean cancel = false; private final List blocks; + private final Entity entity; private final CreateReason reason; + @Deprecated public PortalCreateEvent(@NotNull final List blocks, @NotNull final World world, @NotNull CreateReason reason) { + this(blocks, world, null, reason); + } + + public PortalCreateEvent(@NotNull final List blocks, @NotNull final World world, @Nullable Entity entity, @NotNull CreateReason reason) { super(world); this.blocks = blocks; + this.entity = entity; this.reason = reason; } @@ -33,6 +42,16 @@ public class PortalCreateEvent extends WorldEvent implements Cancellable { return this.blocks; } + /** + * Returns the Entity that triggered this portal creation (if available) + * + * @return Entity involved in this event + */ + @Nullable + public Entity getEntity() { + return entity; + } + @Override public boolean isCancelled() { return cancel;