-
Notifications
You must be signed in to change notification settings - Fork 0
/
0004-Add-EntityTeleportHinderedEvent.patch
198 lines (177 loc) · 10.4 KB
/
0004-Add-EntityTeleportHinderedEvent.patch
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Mariell Hoversholm <proximyst@proximyst.com>
Date: Sun, 3 May 2020 13:31:01 -0300
Subject: [PATCH] Add EntityTeleportHinderedEvent
---
.../java/net/minecraft/server/BlockBase.java | 1 +
.../minecraft/server/BlockEnderPortal.java | 20 ++++++++++++++++-
.../net/minecraft/server/BlockPortal.java | 20 ++++++++++++++++-
.../server/TileEntityEndGateway.java | 22 +++++++++++++++++++
.../craftbukkit/entity/CraftEntity.java | 12 +++++++++-
.../craftbukkit/entity/CraftPlayer.java | 6 +++++
6 files changed, 78 insertions(+), 3 deletions(-)
diff --git a/src/main/java/net/minecraft/server/BlockBase.java b/src/main/java/net/minecraft/server/BlockBase.java
index 2760b377d1f68ac5f66e7274317379e2dda8288a..ec69ca4ebcd94d8dcea8d0157fb870eed6a606f3 100644
--- a/src/main/java/net/minecraft/server/BlockBase.java
+++ b/src/main/java/net/minecraft/server/BlockBase.java
@@ -250,6 +250,7 @@ public abstract class BlockBase {
return 0;
}
+ public final void collideWithBlock(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { this.a(iblockdata, world, blockposition, entity); } // Papercut - OBFHELPER
@Deprecated
public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {}
diff --git a/src/main/java/net/minecraft/server/BlockEnderPortal.java b/src/main/java/net/minecraft/server/BlockEnderPortal.java
index e731b6d811d179f07f84278d2cce75e0d98092ab..dcd4447dc8252ffdba69a9b8e52fd944accf6e38 100644
--- a/src/main/java/net/minecraft/server/BlockEnderPortal.java
+++ b/src/main/java/net/minecraft/server/BlockEnderPortal.java
@@ -1,8 +1,11 @@
package net.minecraft.server;
// CraftBukkit start
+
import org.bukkit.event.entity.EntityPortalEnterEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
+import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
+import us.minevict.papercut.event.entity.EntityTeleportHinderedEvent;
// CraftBukkit end
public class BlockEnderPortal extends BlockTileEntity {
@@ -25,7 +28,22 @@ public class BlockEnderPortal extends BlockTileEntity {
@Override
public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
- if (world instanceof WorldServer && !entity.isPassenger() && !entity.isVehicle() && entity.canPortal() && VoxelShapes.c(VoxelShapes.a(entity.getBoundingBox().d((double) (-blockposition.getX()), (double) (-blockposition.getY()), (double) (-blockposition.getZ()))), iblockdata.getShape(world, blockposition), OperatorBoolean.AND)) {
+ // Papercut start
+ if (world instanceof WorldServer && /*!entity.isPassenger() && !entity.isVehicle() &&*/ entity.canPortal() && VoxelShapes.c(VoxelShapes.a(entity.getBoundingBox().d((double) (-blockposition.getX()), (double) (-blockposition.getY()), (double) (-blockposition.getZ()))), iblockdata.getShape(world, blockposition), OperatorBoolean.AND)) {
+ if (entity.isPassenger()) { // Moved down from wrapping statement
+ if (new EntityTeleportHinderedEvent(entity.getBukkitEntity(), EntityTeleportHinderedEvent.Reason.IS_PASSENGER, TeleportCause.END_PORTAL).callEvent()) {
+ this.collideWithBlock(iblockdata, world, blockposition, entity);
+ }
+ return;
+ }
+
+ if (entity.isVehicle()) {
+ if (new EntityTeleportHinderedEvent(entity.getBukkitEntity(), EntityTeleportHinderedEvent.Reason.IS_VEHICLE, PlayerTeleportEvent.TeleportCause.END_PORTAL).callEvent()) {
+ this.collideWithBlock(iblockdata, world, blockposition, entity);
+ }
+ return;
+ }
+ // Papercut end
ResourceKey<World> resourcekey = world.getTypeKey() == DimensionManager.THE_END ? World.OVERWORLD : World.THE_END; // CraftBukkit - SPIGOT-6152: send back to main overworld in custom ends
WorldServer worldserver = ((WorldServer) world).getMinecraftServer().getWorldServer(resourcekey);
diff --git a/src/main/java/net/minecraft/server/BlockPortal.java b/src/main/java/net/minecraft/server/BlockPortal.java
index 4132cd4c6f13cfa1c0cda43daaa908ff3c07f32b..f2abb014cee279216df5f83f075a992a109d64d3 100644
--- a/src/main/java/net/minecraft/server/BlockPortal.java
+++ b/src/main/java/net/minecraft/server/BlockPortal.java
@@ -8,6 +8,8 @@ import org.bukkit.craftbukkit.block.CraftBlockState;
import org.bukkit.event.entity.EntityPortalEnterEvent;
import org.bukkit.event.world.PortalCreateEvent;
// CraftBukkit end
+import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; // Papercut
+import us.minevict.papercut.event.entity.EntityTeleportHinderedEvent; // Papercut
public class BlockPortal extends Block {
@@ -63,7 +65,23 @@ public class BlockPortal extends Block {
@Override
public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
- if (!entity.isPassenger() && !entity.isVehicle() && entity.canPortal()) {
+ // Papercut start
+ if (entity.canPortal()) {
+ if (entity.isPassenger()) { // Moved down from wrapping statement
+ if (new EntityTeleportHinderedEvent(entity.getBukkitEntity(), EntityTeleportHinderedEvent.Reason.IS_PASSENGER, TeleportCause.NETHER_PORTAL).callEvent()) {
+ a(iblockdata, world, blockposition, entity);
+ }
+ return;
+ }
+
+ if (entity.isVehicle()) {
+ if (new EntityTeleportHinderedEvent(entity.getBukkitEntity(), EntityTeleportHinderedEvent.Reason.IS_VEHICLE, TeleportCause.NETHER_PORTAL).callEvent()) {
+ a(iblockdata, world, blockposition, entity);
+ }
+ return;
+ }
+ // Papercut end
+
// 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);
diff --git a/src/main/java/net/minecraft/server/TileEntityEndGateway.java b/src/main/java/net/minecraft/server/TileEntityEndGateway.java
index e0118a971e1ea3c52a1380f519146b8f46a425ea..f19edc0cc658e6739d57dc729669a16f637754c6 100644
--- a/src/main/java/net/minecraft/server/TileEntityEndGateway.java
+++ b/src/main/java/net/minecraft/server/TileEntityEndGateway.java
@@ -12,6 +12,8 @@ import org.bukkit.Location;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.event.player.PlayerTeleportEvent;
// CraftBukkit end
+import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; // Papercut
+import us.minevict.papercut.event.entity.EntityTeleportHinderedEvent; // Papercut
public class TileEntityEndGateway extends TileEntityEnderPortal implements ITickable {
@@ -126,6 +128,26 @@ public class TileEntityEndGateway extends TileEntityEnderPortal implements ITick
}
public void b(Entity entity) {
+ // Papercut start
+ if (!entity.canPortal()) {
+ return;
+ }
+
+ if (entity.isVehicle()) {
+ if (new EntityTeleportHinderedEvent(entity.getBukkitEntity(), EntityTeleportHinderedEvent.Reason.IS_VEHICLE, TeleportCause.END_PORTAL).callEvent()) {
+ a(entity);
+ }
+ return;
+ }
+
+ if (entity.isPassenger()) {
+ if (new EntityTeleportHinderedEvent(entity.getBukkitEntity(), EntityTeleportHinderedEvent.Reason.IS_PASSENGER, TeleportCause.END_PORTAL).callEvent()) {
+ a(entity);
+ }
+ return;
+ }
+ // Papercut end
+
if (this.world instanceof WorldServer && !this.f()) {
this.c = 100;
if (this.exitPortal == null && this.world.getTypeKey() == DimensionManager.THE_END) { // CraftBukkit - work in alternate worlds
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index 1fe253bc7261a6077747addf8d9023ca94525999..1a72ab6d2424df9e25f98646712f4468bc70bc88 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -172,6 +172,7 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.util.BoundingBox;
import org.bukkit.util.NumberConversions;
import org.bukkit.util.Vector;
+import us.minevict.papercut.event.entity.EntityTeleportHinderedEvent; // Papercut
public abstract class CraftEntity implements org.bukkit.entity.Entity {
private static PermissibleBase perm;
@@ -515,7 +516,16 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
Preconditions.checkArgument(location != null, "location");
location.checkFinite();
- if (entity.isVehicle() || entity.dead) {
+ if (entity.dead) { // Papercut
+ return false;
+ }
+
+ if (entity.isVehicle()) {
+ // Papercut start
+ if (new EntityTeleportHinderedEvent(this, EntityTeleportHinderedEvent.Reason.IS_VEHICLE, cause).callEvent()) {
+ return teleport(location, cause);
+ }
+ // Papercut end
return false;
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 018afcd420035672a5a29f0aeb4c314ff13ba7ee..98d99af9d8f16bf4ded7b01e5e38b495f971f06f 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -127,6 +127,7 @@ import org.bukkit.plugin.messaging.StandardMessenger;
import org.bukkit.scoreboard.Scoreboard;
import net.md_5.bungee.api.chat.BaseComponent; // Spigot
+import us.minevict.papercut.event.entity.EntityTeleportHinderedEvent; // Papercut
@DelegateDeserialization(CraftOfflinePlayer.class)
public class CraftPlayer extends CraftHumanEntity implements Player {
@@ -791,6 +792,11 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
if (entity.isVehicle()) {
+ // Papercut start
+ if (new EntityTeleportHinderedEvent(this, EntityTeleportHinderedEvent.Reason.IS_VEHICLE, cause).callEvent()) {
+ return teleport(location, cause);
+ }
+ // Papercut end
return false;
}