aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0654-Add-back-EntityPortalExitEvent.patch
blob: 97155b3279cebc6c5d430c5a4d0ca7f2f14bd424 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Sun, 16 May 2021 09:39:46 -0700
Subject: [PATCH] Add back EntityPortalExitEvent


diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 6889b02637178db2caad58e5513847fb96e04ecb..6f023b22a1051baaa5310d8c5a1aa6d8b76d8992 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -3373,6 +3373,28 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
             } else {
                 // CraftBukkit start
                 worldserver = shapedetectorshape.world;
+                // Paper start - Call EntityPortalExitEvent
+                CraftEntity bukkitEntity = this.getBukkitEntity();
+                Vec3 position = shapedetectorshape.pos;
+                float yaw = shapedetectorshape.yRot;
+                float pitch = bukkitEntity.getLocation().getPitch(); // Keep entity pitch as per moveTo line below
+                Vec3 velocity = shapedetectorshape.speed;
+                org.bukkit.event.entity.EntityPortalExitEvent event = new org.bukkit.event.entity.EntityPortalExitEvent(bukkitEntity,
+                    bukkitEntity.getLocation(), new Location(worldserver.getWorld(), position.x, position.y, position.z, yaw, pitch),
+                    bukkitEntity.getVelocity(), org.bukkit.craftbukkit.util.CraftVector.toBukkit(shapedetectorshape.speed));
+                event.callEvent();
+                if (this.isRemoved()) {
+                    return null;
+                }
+
+                if (!event.isCancelled() && event.getTo() != null) {
+                    worldserver = ((CraftWorld) event.getTo().getWorld()).getHandle();
+                    position = new Vec3(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ());
+                    yaw = event.getTo().getYaw();
+                    pitch = event.getTo().getPitch();
+                    velocity = org.bukkit.craftbukkit.util.CraftVector.toNMS(event.getAfter());
+                }
+                // Paper end
                 if (worldserver == this.level) {
                     // SPIGOT-6782: Just move the entity if a plugin changed the world to the one the entity is already in
                     this.moveTo(shapedetectorshape.pos.x, shapedetectorshape.pos.y, shapedetectorshape.pos.z, shapedetectorshape.yRot, shapedetectorshape.xRot);
@@ -3392,8 +3414,8 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
 
                 if (entity != null) {
                     entity.restoreFrom(this);
-                    entity.moveTo(shapedetectorshape.pos.x, shapedetectorshape.pos.y, shapedetectorshape.pos.z, shapedetectorshape.yRot, entity.getXRot());
-                    entity.setDeltaMovement(shapedetectorshape.speed);
+                    entity.moveTo(position.x, position.y, position.z, yaw, pitch); // Paper - use EntityPortalExitEvent values
+                    entity.setDeltaMovement(velocity); // Paper - use EntityPortalExitEvent values
                     // CraftBukkit start - Don't spawn the new entity if the current entity isn't spawned
                     if (this.inWorld) {
                         worldserver.addDuringTeleport(entity);