Skip to content

Commit 0193a9d

Browse files
Add EntityPortalReadyEvent (#5619)
1 parent 5deafd1 commit 0193a9d

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Jake Potrebic <jake.m.potrebic@gmail.com>
3+
Date: Wed, 12 May 2021 04:30:53 -0700
4+
Subject: [PATCH] Add EntityPortalReadyEvent
5+
6+
7+
diff --git a/src/main/java/io/papermc/paper/event/entity/EntityPortalReadyEvent.java b/src/main/java/io/papermc/paper/event/entity/EntityPortalReadyEvent.java
8+
new file mode 100644
9+
index 0000000000000000000000000000000000000000..3c6c1d7e97a0c9813bbc585fd209cc63f498e0d4
10+
--- /dev/null
11+
+++ b/src/main/java/io/papermc/paper/event/entity/EntityPortalReadyEvent.java
12+
@@ -0,0 +1,89 @@
13+
+package io.papermc.paper.event.entity;
14+
+
15+
+import org.bukkit.PortalType;
16+
+import org.bukkit.World;
17+
+import org.bukkit.entity.Entity;
18+
+import org.bukkit.event.Cancellable;
19+
+import org.bukkit.event.HandlerList;
20+
+import org.bukkit.event.entity.EntityEvent;
21+
+import org.jetbrains.annotations.NotNull;
22+
+import org.jetbrains.annotations.Nullable;
23+
+
24+
+/**
25+
+ * Called when an entity is ready to be teleported by a plugin.
26+
+ * Currently this is only called after the required
27+
+ * ticks have passed for a Nether Portal.
28+
+ * <p>
29+
+ * Cancelling this event resets the entity's readiness
30+
+ * regarding the current portal.
31+
+ */
32+
+public class EntityPortalReadyEvent extends EntityEvent implements Cancellable {
33+
+
34+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
35+
+
36+
+ private World targetWorld;
37+
+ private final PortalType portalType;
38+
+ private boolean cancelled;
39+
+
40+
+ public EntityPortalReadyEvent(final @NotNull Entity entity, final @Nullable World targetWorld, final @NotNull PortalType portalType) {
41+
+ super(entity);
42+
+ this.targetWorld = targetWorld;
43+
+ this.portalType = portalType;
44+
+ }
45+
+
46+
+ /**
47+
+ * Gets the world this portal will teleport to.
48+
+ * Can be null if "allow-nether" is false in server.properties
49+
+ * or if there is another situation where there is no world to teleport to.
50+
+ * <p>
51+
+ * This world may be modified by later events such as {@link org.bukkit.event.player.PlayerPortalEvent}
52+
+ * or {@link org.bukkit.event.entity.EntityPortalEvent}.
53+
+ *
54+
+ * @return the world the portal will teleport the entity to.
55+
+ */
56+
+ public @Nullable World getTargetWorld() {
57+
+ return targetWorld;
58+
+ }
59+
+
60+
+ /**
61+
+ * Sets the world this portal will teleport to. A null value
62+
+ * will essentially cancel the teleport and prevent further events
63+
+ * such as {@link org.bukkit.event.player.PlayerPortalEvent} from firing.
64+
+ * <p>
65+
+ * This world may be modified by later events such as {@link org.bukkit.event.player.PlayerPortalEvent}
66+
+ * or {@link org.bukkit.event.entity.EntityPortalEvent}.
67+
+ *
68+
+ * @param targetWorld the world
69+
+ */
70+
+ public void setTargetWorld(final @Nullable World targetWorld) {
71+
+ this.targetWorld = targetWorld;
72+
+ }
73+
+
74+
+ /**
75+
+ * Gets the portal type for this event.
76+
+ *
77+
+ * @return the portal type
78+
+ */
79+
+ public @NotNull PortalType getPortalType() {
80+
+ return portalType;
81+
+ }
82+
+
83+
+ @Override
84+
+ public boolean isCancelled() {
85+
+ return cancelled;
86+
+ }
87+
+
88+
+ @Override
89+
+ public void setCancelled(final boolean cancel) {
90+
+ this.cancelled = cancel;
91+
+ }
92+
+
93+
+ @Override
94+
+ public @NotNull HandlerList getHandlers() {
95+
+ return HANDLER_LIST;
96+
+ }
97+
+
98+
+ public static @NotNull HandlerList getHandlerList() {
99+
+ return HANDLER_LIST;
100+
+ }
101+
+}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Jake Potrebic <jake.m.potrebic@gmail.com>
3+
Date: Wed, 12 May 2021 04:30:42 -0700
4+
Subject: [PATCH] Add EntityPortalReadyEvent
5+
6+
7+
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
8+
index 19a64b582bc042e426220e080d9c21b3a82cf3f7..cff8490a2f08215fdd8c5d819ec76cafd8a8cb90 100644
9+
--- a/src/main/java/net/minecraft/world/entity/Entity.java
10+
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
11+
@@ -2856,6 +2856,13 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
12+
if (true && !this.isPassenger() && this.portalTime++ >= i) { // CraftBukkit
13+
this.level.getProfiler().push("portal");
14+
this.portalTime = i;
15+
+ // Paper start
16+
+ io.papermc.paper.event.entity.EntityPortalReadyEvent event = new io.papermc.paper.event.entity.EntityPortalReadyEvent(this.getBukkitEntity(), worldserver1 == null ? null : worldserver.getWorld(), org.bukkit.PortalType.NETHER);
17+
+ if (!event.callEvent()) {
18+
+ this.portalTime = 0;
19+
+ } else {
20+
+ worldserver1 = event.getTargetWorld() == null ? null : ((CraftWorld) event.getTargetWorld()).getHandle();
21+
+ // Paper end
22+
this.setPortalCooldown();
23+
// CraftBukkit start
24+
if (this instanceof ServerPlayer) {
25+
@@ -2863,6 +2870,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
26+
} else {
27+
this.changeDimension(worldserver1);
28+
}
29+
+ } // Paper
30+
// CraftBukkit end
31+
this.level.getProfiler().pop();
32+
}

0 commit comments

Comments
 (0)