PaperMC/patches/unapplied/server/0516-Expand-EntityUnleashEvent.patch

141 lines
9.9 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Nassim Jahnke <nassim@njahnke.dev>
2021-06-11 14:02:28 +02:00
Date: Fri, 29 Jan 2021 15:13:11 +0100
Subject: [PATCH] Expand EntityUnleashEvent
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 3e6706671b3dc06b376eaa9d6d463c6a098104d1..d1833dcc92b1570e62a1941bbea6d66ff0b2ee5f 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -1300,12 +1300,15 @@ public abstract class Mob extends LivingEntity implements Targeting {
2021-06-11 14:02:28 +02:00
return InteractionResult.PASS;
} else if (this.getLeashHolder() == player) {
// CraftBukkit start - fire PlayerUnleashEntityEvent
- if (CraftEventFactory.callPlayerUnleashEntityEvent(this, player, hand).isCancelled()) {
+ // Paper start - Expand EntityUnleashEvent
+ org.bukkit.event.player.PlayerUnleashEntityEvent event = CraftEventFactory.callPlayerUnleashEntityEvent(this, player, hand, !player.getAbilities().instabuild);
2021-06-11 14:02:28 +02:00
+ if (event.isCancelled()) {
+ // Paper end - Expand EntityUnleashEvent
2021-06-11 14:02:28 +02:00
((ServerPlayer) player).connection.send(new ClientboundSetEntityLinkPacket(this, this.getLeashHolder()));
return InteractionResult.PASS;
}
// CraftBukkit end
2021-06-14 21:58:32 +02:00
- this.dropLeash(true, !player.getAbilities().instabuild);
+ this.dropLeash(true, event.isDropLeash()); // Paper - Expand EntityUnleashEvent
2023-03-14 21:25:13 +01:00
this.gameEvent(GameEvent.ENTITY_INTERACT, player);
2023-06-08 02:54:54 +02:00
return InteractionResult.sidedSuccess(this.level().isClientSide);
2021-06-11 14:02:28 +02:00
} else {
@@ -1473,8 +1476,11 @@ public abstract class Mob extends LivingEntity implements Targeting {
2021-06-11 14:02:28 +02:00
if (this.leashHolder != null) {
if (!this.isAlive() || !this.leashHolder.isAlive()) {
2023-06-08 02:54:54 +02:00
- this.level().getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), (!this.isAlive()) ? UnleashReason.PLAYER_UNLEASH : UnleashReason.HOLDER_GONE)); // CraftBukkit
2023-12-06 04:00:14 +01:00
- this.dropLeash(true, !this.leashHolder.pluginRemoved);// CraftBukkit - SPIGOT-7487: Don't drop leash, when the holder was removed by a plugin
+ // Paper start - Expand EntityUnleashEvent
2023-12-06 04:00:14 +01:00
+ EntityUnleashEvent event = new EntityUnleashEvent(this.getBukkitEntity(), (!this.isAlive()) ? EntityUnleashEvent.UnleashReason.PLAYER_UNLEASH : EntityUnleashEvent.UnleashReason.HOLDER_GONE, !this.leashHolder.pluginRemoved);
2023-06-08 02:54:54 +02:00
+ this.level().getCraftServer().getPluginManager().callEvent(event); // CraftBukkit
2021-06-11 14:02:28 +02:00
+ this.dropLeash(true, event.isDropLeash());
+ // Paper end - Expand EntityUnleashEvent
2021-06-11 14:02:28 +02:00
}
}
@@ -1537,8 +1543,11 @@ public abstract class Mob extends LivingEntity implements Targeting {
2021-06-11 14:02:28 +02:00
boolean flag1 = super.startRiding(entity, force);
if (flag1 && this.isLeashed()) {
2023-06-08 02:54:54 +02:00
- this.level().getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN)); // CraftBukkit
2021-06-11 14:02:28 +02:00
- this.dropLeash(true, true);
+ // Paper start - Expand EntityUnleashEvent
2023-06-08 02:54:54 +02:00
+ EntityUnleashEvent event = new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.UNKNOWN, true);
+ if (!event.callEvent()) { return flag1; }
2021-06-11 14:02:28 +02:00
+ this.dropLeash(true, event.isDropLeash());
+ // Paper end - Expand EntityUnleashEvent
2021-06-11 14:02:28 +02:00
}
return flag1;
@@ -1728,8 +1737,11 @@ public abstract class Mob extends LivingEntity implements Targeting {
2021-06-11 14:02:28 +02:00
@Override
protected void removeAfterChangingDimensions() {
super.removeAfterChangingDimensions();
2023-06-08 02:54:54 +02:00
- this.level().getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN)); // CraftBukkit
2021-06-11 14:02:28 +02:00
- this.dropLeash(true, false);
+ // Paper start - Expand EntityUnleashEvent
2023-06-08 02:54:54 +02:00
+ EntityUnleashEvent event = new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.UNKNOWN, false);
+ this.level().getCraftServer().getPluginManager().callEvent(event); // CraftBukkit
2021-06-11 14:02:28 +02:00
+ this.dropLeash(true, event.isDropLeash());
+ // Paper end - Expand EntityUnleashEvent
2021-06-14 21:58:32 +02:00
this.getAllSlots().forEach((itemstack) -> {
2023-06-08 02:54:54 +02:00
if (!itemstack.isEmpty()) {
itemstack.setCount(0);
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/entity/PathfinderMob.java b/src/main/java/net/minecraft/world/entity/PathfinderMob.java
index 85a9bcbd229b56317c2de15670a04c6d0eb51e18..d6393210cfee53685f83c8491bea8b9c13b01eea 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/PathfinderMob.java
+++ b/src/main/java/net/minecraft/world/entity/PathfinderMob.java
@@ -56,8 +56,11 @@ public abstract class PathfinderMob extends Mob {
2021-06-11 14:02:28 +02:00
if (this instanceof TamableAnimal && ((TamableAnimal) this).isInSittingPose()) {
if (f > entity.level().paperConfig().misc.maxLeashDistance) { // Paper - Configurable max leash distance
2023-06-08 02:54:54 +02:00
- this.level().getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.DISTANCE)); // CraftBukkit
2021-06-11 14:02:28 +02:00
- this.dropLeash(true, true);
+ // Paper start - Expand EntityUnleashEvent
2021-06-11 14:02:28 +02:00
+ EntityUnleashEvent event = new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.DISTANCE, true);
+ if (!event.callEvent()) return;
2021-06-11 14:02:28 +02:00
+ this.dropLeash(true, event.isDropLeash());
+ // Paper end - Expand EntityUnleashEvent
2021-06-11 14:02:28 +02:00
}
return;
@@ -65,8 +68,11 @@ public abstract class PathfinderMob extends Mob {
2021-06-11 14:02:28 +02:00
this.onLeashDistance(f);
if (f > entity.level().paperConfig().misc.maxLeashDistance) { // Paper - Configurable max leash distance
2023-06-08 02:54:54 +02:00
- this.level().getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.DISTANCE)); // CraftBukkit
2021-06-11 14:02:28 +02:00
- this.dropLeash(true, true);
+ // Paper start - Expand EntityUnleashEvent
2021-06-11 14:02:28 +02:00
+ EntityUnleashEvent event = new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.DISTANCE, true);
+ if (!event.callEvent()) return;
2021-06-11 14:02:28 +02:00
+ this.dropLeash(true, event.isDropLeash());
+ // Paper end - Expand EntityUnleashEvent
2021-06-11 14:02:28 +02:00
this.goalSelector.disableControlFlag(Goal.Flag.MOVE);
} else if (f > 6.0F) {
double d0 = (entity.getX() - this.getX()) / (double) f;
diff --git a/src/main/java/net/minecraft/world/entity/decoration/LeashFenceKnotEntity.java b/src/main/java/net/minecraft/world/entity/decoration/LeashFenceKnotEntity.java
index 6a6526b7b1b578e08a41f85c0443c5f04177efb0..0b88bd258c4f2bce100bf96bcbe61c20493f8e40 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/decoration/LeashFenceKnotEntity.java
+++ b/src/main/java/net/minecraft/world/entity/decoration/LeashFenceKnotEntity.java
@@ -127,11 +127,14 @@ public class LeashFenceKnotEntity extends HangingEntity {
2023-03-14 21:25:13 +01:00
if (entityinsentient1.isLeashed() && entityinsentient1.getLeashHolder() == this) {
2021-06-11 14:02:28 +02:00
// CraftBukkit start
2023-03-14 21:25:13 +01:00
- if (CraftEventFactory.callPlayerUnleashEntityEvent(entityinsentient1, player, hand).isCancelled()) {
+ // Paper start - Expand EntityUnleashEvent
2023-03-14 21:25:13 +01:00
+ org.bukkit.event.player.PlayerUnleashEntityEvent event = CraftEventFactory.callPlayerUnleashEntityEvent(entityinsentient1, player, hand, !player.getAbilities().instabuild);
2021-06-11 14:02:28 +02:00
+ if (event.isCancelled()) {
+ // Paper end - Expand EntityUnleashEvent
2021-06-11 14:02:28 +02:00
die = false;
continue;
}
2023-03-14 21:25:13 +01:00
- entityinsentient1.dropLeash(true, !player.getAbilities().instabuild); // false -> survival mode boolean
+ entityinsentient1.dropLeash(true, event.isDropLeash()); // false -> survival mode boolean // Paper - Expand EntityUnleashEvent
2021-06-11 14:02:28 +02:00
// CraftBukkit end
2023-03-14 21:25:13 +01:00
flag1 = true;
2021-06-11 14:02:28 +02:00
}
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
Updated Upstream (Bukkit/CraftBukkit) (#10379) Updated Upstream (Bukkit/CraftBukkit) 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: f02baa38 PR-988: Add World#getIntersectingChunks(BoundingBox) 9321d665 Move getItemInUse up to LivingEntity 819eef73 PR-959: Add access to current item's remaining ticks c4fdadb0 SPIGOT-7601: Add AbstractArrow#getItem be8261ca Add support for Java 22 26119676 PR-979: Add more translation keys 66753362 PR-985: Correct book maximum pages and characters per page documentation c8be92fa PR-980: Improve getArmorContents() documentation f1120ee2 PR-983: Expose riptide velocity to PlayerRiptideEvent CraftBukkit Changes: dfaa89bbe PR-1369: Add World#getIntersectingChunks(BoundingBox) 51bbab2b9 Move getItemInUse up to LivingEntity 668e09602 PR-1331: Add access to current item's remaining ticks a639406d1 SPIGOT-7601: Add AbstractArrow#getItem 0398930fc SPIGOT-7602: Allow opening in-world horse and related inventories ffd15611c SPIGOT-7608: Allow empty lists to morph to any PDT list 2188dcfa9 Add support for Java 22 45d6a609f SPIGOT-7604: Revert "SPIGOT-7365: DamageCause blocked by shield should trigger invulnerableTime" 06d915943 SPIGOT-7365: DamageCause blocked by shield should trigger invulnerableTime ca3bc3707 PR-1361: Add more translation keys 366c3ca80 SPIGOT-7600: EntityChangeBlockEvent is not fired for frog eggs 06d0f9ba8 SPIGOT-7593: Fix sapling growth physics / client-side updates 45c2608e4 PR-1366: Expose riptide velocity to PlayerRiptideEvent 29b6bb79b SPIGOT-7587: Remove fixes for now-resolved MC-142590 and MC-109346
2024-04-06 21:53:39 +02:00
index ec6bbab9787e5568e2be7d0a0004d8103ec38ff3..ca0cb9ad99992ef2602781adf16da94ca56975f8 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
Updated Upstream (Bukkit/CraftBukkit) (#10379) Updated Upstream (Bukkit/CraftBukkit) 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: f02baa38 PR-988: Add World#getIntersectingChunks(BoundingBox) 9321d665 Move getItemInUse up to LivingEntity 819eef73 PR-959: Add access to current item's remaining ticks c4fdadb0 SPIGOT-7601: Add AbstractArrow#getItem be8261ca Add support for Java 22 26119676 PR-979: Add more translation keys 66753362 PR-985: Correct book maximum pages and characters per page documentation c8be92fa PR-980: Improve getArmorContents() documentation f1120ee2 PR-983: Expose riptide velocity to PlayerRiptideEvent CraftBukkit Changes: dfaa89bbe PR-1369: Add World#getIntersectingChunks(BoundingBox) 51bbab2b9 Move getItemInUse up to LivingEntity 668e09602 PR-1331: Add access to current item's remaining ticks a639406d1 SPIGOT-7601: Add AbstractArrow#getItem 0398930fc SPIGOT-7602: Allow opening in-world horse and related inventories ffd15611c SPIGOT-7608: Allow empty lists to morph to any PDT list 2188dcfa9 Add support for Java 22 45d6a609f SPIGOT-7604: Revert "SPIGOT-7365: DamageCause blocked by shield should trigger invulnerableTime" 06d915943 SPIGOT-7365: DamageCause blocked by shield should trigger invulnerableTime ca3bc3707 PR-1361: Add more translation keys 366c3ca80 SPIGOT-7600: EntityChangeBlockEvent is not fired for frog eggs 06d0f9ba8 SPIGOT-7593: Fix sapling growth physics / client-side updates 45c2608e4 PR-1366: Expose riptide velocity to PlayerRiptideEvent 29b6bb79b SPIGOT-7587: Remove fixes for now-resolved MC-142590 and MC-109346
2024-04-06 21:53:39 +02:00
@@ -1570,8 +1570,10 @@ public class CraftEventFactory {
Bukkit.getPluginManager().callEvent(new PlayerRecipeBookSettingsChangeEvent(player.getBukkitEntity(), bukkitType, open, filter));
2021-06-11 14:02:28 +02:00
}
- public static PlayerUnleashEntityEvent callPlayerUnleashEntityEvent(Mob entity, net.minecraft.world.entity.player.Player player, InteractionHand enumhand) {
- PlayerUnleashEntityEvent event = new PlayerUnleashEntityEvent(entity.getBukkitEntity(), (Player) player.getBukkitEntity(), CraftEquipmentSlot.getHand(enumhand));
+ // Paper start - Expand EntityUnleashEvent
+ public static PlayerUnleashEntityEvent callPlayerUnleashEntityEvent(Mob entity, net.minecraft.world.entity.player.Player player, InteractionHand enumhand, boolean dropLeash) {
+ PlayerUnleashEntityEvent event = new PlayerUnleashEntityEvent(entity.getBukkitEntity(), (Player) player.getBukkitEntity(), CraftEquipmentSlot.getHand(enumhand), dropLeash);
+ // Paper end - Expand EntityUnleashEvent
2023-06-08 02:54:54 +02:00
entity.level().getCraftServer().getPluginManager().callEvent(event);
2021-06-11 14:02:28 +02:00
return event;
}