2020-05-06 09:48:49 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2018-11-15 14:29:04 +00:00
From: Shane Freeder <theboyetronic@gmail.com>
Date: Thu, 15 Nov 2018 13:38:37 +0000
Subject: [PATCH] force entity dismount during teleportation
Entities must be dismounted before teleportation in order to avoid
2018-11-18 15:39:28 +00:00
multiple issues in the server with regards to teleportation, shamefully,
too many plugins rely on the events firing, which means that not firing
these events caues more issues than it solves;
2018-11-15 14:29:04 +00:00
2018-11-18 15:39:28 +00:00
In order to counteract this, Entity dismount/exit vehicle events have
been modified to supress cancellation (and has a method to allow plugins
to check if this has been set), noting that cancellation will be silently
surpressed given that plugins are not expecting this event to not be cancellable.
This is a far from ideal scenario, however: given the current state of this
event and other alternatives causing issues elsewhere, I believe that
this is going to be the best soultion all around.
Improvements/suggestions welcome!
2018-11-15 14:29:04 +00:00
2021-03-16 07:19:45 +00:00
diff --git a/src/main/java/net/minecraft/server/level/EntityPlayer.java b/src/main/java/net/minecraft/server/level/EntityPlayer.java
2021-05-15 21:10:57 +00:00
index ae5fe4f71ea1cc231e5d87920c2243f4f4f581f1..bea8dd578cfd5532dd1b679a4ee4e6c74a416bba 100644
2021-03-16 07:19:45 +00:00
--- a/src/main/java/net/minecraft/server/level/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/level/EntityPlayer.java
2021-05-15 21:10:57 +00:00
@@ -1252,11 +1252,13 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
2021-03-16 07:19:45 +00:00
}
}
- @Override
- public void stopRiding() {
+ // Paper start
+ @Override public void stopRiding() { stopRiding(false); }
+ @Override public void stopRiding(boolean suppressCancellation) {
+ // paper end
Entity entity = this.getVehicle();
- super.stopRiding();
+ super.stopRiding(suppressCancellation); // Paper
Entity entity1 = this.getVehicle();
if (entity1 != entity && this.playerConnection != null) {
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
2021-05-15 21:10:57 +00:00
index f102ecb56ac04a5b840fa52e6d1ff9604598d58d..f0c18a55900774ba67eaf094f175a9e37c16e56c 100644
2021-03-16 07:19:45 +00:00
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
2021-03-16 13:04:28 +00:00
@@ -2040,12 +2040,15 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
2018-11-15 14:29:04 +00:00
}
2020-11-03 02:22:15 +00:00
- public void bf() {
2018-11-15 14:29:04 +00:00
+ // Paper start
2020-11-03 02:22:15 +00:00
+ public void bf() { stopRiding(false); }
2018-11-18 15:39:28 +00:00
+ public void stopRiding(boolean suppressCancellation) {
2018-11-15 14:29:04 +00:00
+ // Paper end
if (this.vehicle != null) {
Entity entity = this.vehicle;
this.vehicle = null;
- if (!entity.removePassenger(this)) this.vehicle = entity; // CraftBukkit
2018-11-18 15:39:28 +00:00
+ if (!entity.removePassenger(this, suppressCancellation)) this.vehicle = entity; // CraftBukkit // Paper
2018-11-15 14:29:04 +00:00
}
}
2021-03-16 13:04:28 +00:00
@@ -2100,7 +2103,10 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
2018-11-15 14:29:04 +00:00
return true; // CraftBukkit
}
- protected boolean removePassenger(Entity entity) { // CraftBukkit
+ // Paper start
+ protected boolean removePassenger(Entity entity) { return removePassenger(entity, false);}
2018-11-18 15:39:28 +00:00
+ protected boolean removePassenger(Entity entity, boolean suppressCancellation) { // CraftBukkit
2018-11-15 14:29:04 +00:00
+ // Paper end
if (entity.getVehicle() == this) {
throw new IllegalStateException("Use x.stopRiding(y), not y.removePassenger(x)");
} else {
2021-03-16 13:04:28 +00:00
@@ -2110,7 +2116,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
2018-11-18 15:39:28 +00:00
if (getBukkitEntity() instanceof Vehicle && entity.getBukkitEntity() instanceof LivingEntity) {
VehicleExitEvent event = new VehicleExitEvent(
(Vehicle) getBukkitEntity(),
- (LivingEntity) entity.getBukkitEntity()
+ (LivingEntity) entity.getBukkitEntity(), !suppressCancellation // Paper
);
2020-06-30 05:20:29 +00:00
// Suppress during worldgen
if (this.valid) {
2021-03-16 13:04:28 +00:00
@@ -2124,7 +2130,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
2018-11-18 15:39:28 +00:00
}
// CraftBukkit end
// Spigot start
- org.spigotmc.event.entity.EntityDismountEvent event = new org.spigotmc.event.entity.EntityDismountEvent(entity.getBukkitEntity(), this.getBukkitEntity());
+ org.spigotmc.event.entity.EntityDismountEvent event = new org.spigotmc.event.entity.EntityDismountEvent(entity.getBukkitEntity(), this.getBukkitEntity(), !suppressCancellation); // Paper
2020-06-30 05:20:29 +00:00
// Suppress during worldgen
if (this.valid) {
Bukkit.getPluginManager().callEvent(event);
2021-03-16 07:19:45 +00:00
diff --git a/src/main/java/net/minecraft/world/entity/EntityLiving.java b/src/main/java/net/minecraft/world/entity/EntityLiving.java
2021-05-15 21:10:57 +00:00
index c189a7051240bb357acf5075c98206a258409b0c..58270f45de665b5c1cfd9fc548eadb263ad230e9 100644
2021-03-16 07:19:45 +00:00
--- a/src/main/java/net/minecraft/world/entity/EntityLiving.java
+++ b/src/main/java/net/minecraft/world/entity/EntityLiving.java
@@ -3015,11 +3015,13 @@ public abstract class EntityLiving extends Entity {
2020-08-25 02:22:08 +00:00
return ((Byte) this.datawatcher.get(EntityLiving.ag) & 4) != 0;
2018-11-28 04:18:34 +00:00
}
2019-05-05 11:12:32 +00:00
- @Override
2018-11-28 04:18:34 +00:00
- public void stopRiding() {
+ // Paper start
2019-05-05 11:12:32 +00:00
+ @Override public void stopRiding() { stopRiding(false); }
+ @Override public void stopRiding(boolean suppressCancellation) {
2018-11-28 04:18:34 +00:00
+ // Paper end
Entity entity = this.getVehicle();
- super.stopRiding();
+ super.stopRiding(suppressCancellation); // Paper - suppress
if (entity != null && entity != this.getVehicle() && !this.world.isClientSide) {
2019-12-12 16:20:43 +00:00
this.a(entity);
2018-11-28 04:18:34 +00:00
}
2021-03-16 07:19:45 +00:00
diff --git a/src/main/java/net/minecraft/world/entity/player/EntityHuman.java b/src/main/java/net/minecraft/world/entity/player/EntityHuman.java
2021-03-16 13:04:28 +00:00
index 87374174dcbf9e7ee448a1cdd9a3528557c3a2ea..564dfa98c166fde509044e6e1938efb321ece53d 100644
2021-03-16 07:19:45 +00:00
--- a/src/main/java/net/minecraft/world/entity/player/EntityHuman.java
+++ b/src/main/java/net/minecraft/world/entity/player/EntityHuman.java
2021-03-16 13:04:28 +00:00
@@ -1039,9 +1039,11 @@ public abstract class EntityHuman extends EntityLiving {
2021-03-16 07:19:45 +00:00
return -0.35D;
2018-11-15 14:29:04 +00:00
}
2019-05-05 11:12:32 +00:00
- @Override
2021-03-16 07:19:45 +00:00
- public void bf() {
- super.bf();
2018-11-15 14:29:04 +00:00
+ // Paper start
2021-03-16 07:19:45 +00:00
+ @Override public void bf() { stopRiding(false); }
2019-05-05 11:12:32 +00:00
+ @Override public void stopRiding(boolean suppressCancellation) {
2021-03-16 07:19:45 +00:00
+ // Paper end
+ super.stopRiding(suppressCancellation); // Paper - suppress
this.j = 0;
}
2018-11-15 14:29:04 +00:00