Paper/patches/unapplied/server/0285-force-entity-dismount-during-teleportation.patch

114 lines
5.8 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
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
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;
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!
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index c46ad2013439f043145fb7fc67bbcd80728e3c16..f746829f1e94ee58821e56ec4192269add00395b 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -2570,11 +2570,16 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
2021-06-11 14:02:28 +02:00
}
2021-11-24 01:44:41 +01:00
public void removeVehicle() {
+ // Paper start - Force entity dismount during teleportation
2021-11-24 01:44:41 +01:00
+ stopRiding(false);
+ }
2021-06-11 14:02:28 +02:00
+ public void stopRiding(boolean suppressCancellation) {
+ // Paper end - Force entity dismount during teleportation
2021-06-11 14:02:28 +02:00
if (this.vehicle != null) {
Entity entity = this.vehicle;
this.vehicle = null;
- if (!entity.removePassenger(this)) this.vehicle = entity; // CraftBukkit
+ if (!entity.removePassenger(this, suppressCancellation)) this.vehicle = entity; // CraftBukkit // Paper - Force entity dismount during teleportation
2021-06-11 14:02:28 +02:00
}
}
@@ -2605,7 +2610,10 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#9440) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 01aa02eb PR-858: Add LivingEntity#playHurtAnimation() 9421320f PR-884: Refinements to new ban API for improved compatibility and correctness 37a60b45 SPIGOT-6455, SPIGOT-7030, PR-750: Improve ban API 4eeb174b All smithing inventories are now the new smithing inventory f2bb168e PR-880: Add methods to get/set FallingBlock CancelDrop e7a807fa PR-879: Add Player#sendHealthUpdate() 692b8e96 SPIGOT-7370: Remove float value conversion in plugin.yml 2d033390 SPIGOT-7403: Add direct API for waxed signs 16a08373 PR-876: Add missing Raider API and 'no action ticks' CraftBukkit Changes: b60a95c8c PR-1189: Add LivingEntity#playHurtAnimation() 95c335c63 PR-1226: Fix VehicleEnterEvent not being called for certain entities 0a0fc3bee PR-1227: Refinements to new ban API for improved compatibility and correctness 0d0b1e5dc Revert bad change to PathfinderGoalSit causing all cats to sit 648196070 SPIGOT-6455, SPIGOT-7030, PR-1054: Improve ban API 31fe848d6 All smithing inventories are now the new smithing inventory 9a919a143 SPIGOT-7416: SmithItemEvent not firing in Smithing Table 9f64f0d22 PR-1221: Add methods to get/set FallingBlock CancelDrop 3be9ac171 PR-1220: Add Player#sendHealthUpdate() c1279f775 PR-1209: Clean up various patches c432e4397 Fix Raider#setCelebrating() implementation 504d96665 SPIGOT-7403: Add direct API for waxed signs c68c1f1b3 PR-1216: Add missing Raider API and 'no action ticks' 85b89c3dd Increase outdated build delay Spigot Changes: 9ebce8af Rebuild patches 64b565e6 Rebuild patches
2023-07-04 10:22:56 +02:00
}
2021-06-11 14:02:28 +02:00
}
- protected boolean removePassenger(Entity entity) { // CraftBukkit
+ // Paper start - Force entity dismount during teleportation
2021-06-11 14:02:28 +02:00
+ protected boolean removePassenger(Entity entity) { return removePassenger(entity, false);}
+ protected boolean removePassenger(Entity entity, boolean suppressCancellation) { // CraftBukkit
+ // Paper end - Force entity dismount during teleportation
2021-06-11 14:02:28 +02:00
if (entity.getVehicle() == this) {
throw new IllegalStateException("Use x.stopRiding(y), not y.removePassenger(x)");
} else {
@@ -2615,7 +2623,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
2021-06-13 10:26:58 +02:00
if (this.getBukkitEntity() instanceof Vehicle && entity.getBukkitEntity() instanceof LivingEntity) {
2021-06-11 14:02:28 +02:00
VehicleExitEvent event = new VehicleExitEvent(
2021-06-13 10:26:58 +02:00
(Vehicle) this.getBukkitEntity(),
2021-06-11 14:02:28 +02:00
- (LivingEntity) entity.getBukkitEntity()
+ (LivingEntity) entity.getBukkitEntity(), !suppressCancellation // Paper - Force entity dismount during teleportation
2021-06-11 14:02:28 +02:00
);
// Suppress during worldgen
if (this.valid) {
@@ -2628,7 +2636,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10164) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 63c208dd Remove no longer used import 70be76c7 PR-958: Further clarify deprecation of TAG_CONTAINER_ARRAY ae21f4ac PR-955: Add methods to place structures with block/entity transformers e3d960f2 SPIGOT-7547: Remark that Damageable#setAbsorptionAmount() is capped to a specific value b125516c Fix typo in RecipeChoice.ExactChoice docs 309497c1 Add EntityMountEvent and EntityDismount Event 2fd45ae3 Improve ItemFactory#enchantItem consistency 2b198268 PR-933: Define native persistent data types for lists CraftBukkit Changes: 771182f70 PR-1327: Add methods to place structures with block/entity transformers e41ad4c82 SPIGOT-7567: SpawnReason for SNOWMAN is reported as BUILD_IRONGOLEM 76931e8bd Add EntityMountEvent and EntityDismount Event 9b29b21c7 PR-1183: Better handle lambda expression and renaming of classes in Commodore 1462ebe85 Reformat Commodore.java 9fde4c037 PR-1324: Improve ItemFactory#enchantItem consistency 4e419c774 PR-1295: Define native persistent data types for lists dd8cca388 SPIGOT-7562: Fix Score#getScore and Score#isScoreSet 690278200 Only fetch an online UUID in online mode 1da8d9a53 Fire PreLogin events even in offline mode 2e88514ad PR-1325: Use CraftBlockType and CraftItemType instead of CraftMagicNumbers to convert between minecraft and bukkit block / item representation Spigot Changes: 864e4acc Restore accidentally removed package-info.java f91a10d5 Remove obsolete EntityMountEvent and EntityDismountEvent 828f0593 SPIGOT-7558: Deprecate silenceable lightning API as sound is now client-side and cannot be removed cdc4e035 Remove obsolete patch fetching correct mode UUIDs 49e36b8e Merge related BungeeCord patches 6e87b9ab Remove obsolete firing of PreLogin events in offline mode 5c76b183 Remove redundant patch dealing with exceptions in the crash reporter 3a2219d1 Remove redundant patch logging cause of unexpected exception
2024-01-14 10:46:04 +01:00
}
2021-06-11 14:02:28 +02:00
}
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10164) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 63c208dd Remove no longer used import 70be76c7 PR-958: Further clarify deprecation of TAG_CONTAINER_ARRAY ae21f4ac PR-955: Add methods to place structures with block/entity transformers e3d960f2 SPIGOT-7547: Remark that Damageable#setAbsorptionAmount() is capped to a specific value b125516c Fix typo in RecipeChoice.ExactChoice docs 309497c1 Add EntityMountEvent and EntityDismount Event 2fd45ae3 Improve ItemFactory#enchantItem consistency 2b198268 PR-933: Define native persistent data types for lists CraftBukkit Changes: 771182f70 PR-1327: Add methods to place structures with block/entity transformers e41ad4c82 SPIGOT-7567: SpawnReason for SNOWMAN is reported as BUILD_IRONGOLEM 76931e8bd Add EntityMountEvent and EntityDismount Event 9b29b21c7 PR-1183: Better handle lambda expression and renaming of classes in Commodore 1462ebe85 Reformat Commodore.java 9fde4c037 PR-1324: Improve ItemFactory#enchantItem consistency 4e419c774 PR-1295: Define native persistent data types for lists dd8cca388 SPIGOT-7562: Fix Score#getScore and Score#isScoreSet 690278200 Only fetch an online UUID in online mode 1da8d9a53 Fire PreLogin events even in offline mode 2e88514ad PR-1325: Use CraftBlockType and CraftItemType instead of CraftMagicNumbers to convert between minecraft and bukkit block / item representation Spigot Changes: 864e4acc Restore accidentally removed package-info.java f91a10d5 Remove obsolete EntityMountEvent and EntityDismountEvent 828f0593 SPIGOT-7558: Deprecate silenceable lightning API as sound is now client-side and cannot be removed cdc4e035 Remove obsolete patch fetching correct mode UUIDs 49e36b8e Merge related BungeeCord patches 6e87b9ab Remove obsolete firing of PreLogin events in offline mode 5c76b183 Remove redundant patch dealing with exceptions in the crash reporter 3a2219d1 Remove redundant patch logging cause of unexpected exception
2024-01-14 10:46:04 +01:00
- EntityDismountEvent event = new EntityDismountEvent(entity.getBukkitEntity(), this.getBukkitEntity());
+ EntityDismountEvent event = new EntityDismountEvent(entity.getBukkitEntity(), this.getBukkitEntity(), !suppressCancellation); // Paper - Force entity dismount during teleportation
2021-06-11 14:02:28 +02:00
// Suppress during worldgen
if (this.valid) {
Bukkit.getPluginManager().callEvent(event);
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 1a328de32b69b69814e11a5b6bc55bfccf408d6b..4be7b136dd2b35b0637a1455985ab99bbd3af0a5 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -3492,9 +3492,15 @@ public abstract class LivingEntity extends Entity implements Attackable {
2021-06-11 14:02:28 +02:00
2021-11-24 01:44:41 +01:00
@Override
public void stopRiding() {
+ // Paper start - Force entity dismount during teleportation
2021-11-24 01:44:41 +01:00
+ stopRiding(false);
+ }
+ @Override
+ public void stopRiding(boolean suppressCancellation) {
+ // Paper end - Force entity dismount during teleportation
2021-06-11 14:02:28 +02:00
Entity entity = this.getVehicle();
- super.stopRiding();
+ super.stopRiding(suppressCancellation); // Paper - Force entity dismount during teleportation
if (entity != null && entity != this.getVehicle() && !this.level().isClientSide) {
2021-06-11 14:02:28 +02:00
this.dismountVehicle(entity);
}
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
index 83c7ba56900ce40f71d98062bf15110a76597dce..3c3c953f05c18279d3245fe6bc8afef83cd62cd1 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
@@ -1141,7 +1141,13 @@ public abstract class Player extends LivingEntity {
2021-06-11 14:02:28 +02:00
2021-11-24 01:44:41 +01:00
@Override
public void removeVehicle() {
2021-06-11 14:02:28 +02:00
- super.removeVehicle();
+ // Paper start - Force entity dismount during teleportation
2021-11-24 01:44:41 +01:00
+ stopRiding(false);
+ }
+ @Override
+ public void stopRiding(boolean suppressCancellation) {
+ super.stopRiding(suppressCancellation);
+ // Paper end - Force entity dismount during teleportation
2021-06-11 14:02:28 +02:00
this.boardingCooldown = 0;
}