Paper/patches/server/0496-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 4c0f7741e199e4bb03767effda669bbbc9f0d233..7b10bb9cbf6f2b4a70ddaa0ba4bc7409a17f3f09 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
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: 69fa4695 Add some missing deprecation annotations f850da2e Update Maven plugins/versions 8d8400db Use regular compiler seeing as ECJ doesn't support Java 21 JRE c29e1688 Revert "BUILDTOOLS-676: Downgrade Maven compiler version" 07bce714 SPIGOT-7355: More field renames and fixes 6a8ea764 Fix bad merge in penultimate commit 50a7920c Fix imports in previous commit 83640dd1 PR-995: Add required feature to MinecraftExperimental for easy lookups fc1f96cf BUILDTOOLS-676: Downgrade Maven compiler version CraftBukkit Changes: 90f1059ba Fix item placement 661afb43c SPIGOT-7633: Clearer error message for missing particle data 807b465b3 SPIGOT-7634: Armadillo updates infrequently 590cf09a8 Fix unit tests always seeing Mojang server as unavailable 7c7ac5eb2 SPIGOT-7636: Fix clearing ItemMeta 4a72905cf SPIGOT-7635: Fix Player#transfer and cookie methods ebb50e136 Fix incorrect Vault implementation b33fed8b7 Update Maven plugins/versions 6f00f0608 SPIGOT-7632: Control middle clicking chest does not copy contents db821f405 Use regular compiler seeing as ECJ doesn't support Java 21 JRE 8a2976737 Revert "BUILDTOOLS-676: Downgrade Maven compiler version" 0297f87bb SPIGOT-7355: More field renames and fixes 2d03bdf6a SPIGOT-7629: Fix loading banner patterns e77951fac Fix equality of deserialized display names c66f3e4fd SPIGOT-7631: Fix deserialisation of BlockStateMeta 9c2c7be8d SPIGOT-7630: Fix crash saving unticked leashed entities 8c1e7c841 PR-1384: Disable certain PlayerProfile tests, if Mojang's services or internet are not available ced93d572 SPIGOT-7626: sendSignChange() has no effect c77362cae SPIGOT-7625: ItemStack with lore cannot be serialized in 1.20.5 ff2004387 SPIGOT-7620: Fix server crash when hoppers transfer items to double chests 8b4abeb03 BUILDTOOLS-676: Downgrade Maven compiler version
2024-04-25 23:21:18 +02:00
@@ -1431,12 +1431,15 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Targeti
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
2024-04-24 15:46:45 +02:00
+ org.bukkit.event.player.PlayerUnleashEntityEvent event = CraftEventFactory.callPlayerUnleashEntityEvent(this, player, hand, !player.hasInfiniteMaterials());
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
2024-04-24 15:46:45 +02:00
- this.dropLeash(true, !player.hasInfiniteMaterials());
+ 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 {
@@ -1605,8 +1608,11 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Targeti
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
}
}
@@ -1674,8 +1680,11 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Targeti
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;
@@ -1852,8 +1861,11 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Targeti
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
2024-04-24 15:46:45 +02:00
index e92831739603ef1b5678c9d44e85ab70d62be0e7..cdd07093342521ff9944bf7a342bbf142ba3f0b7 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
2024-04-24 15:46:45 +02:00
@@ -72,8 +72,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;
2024-04-24 15:46:45 +02:00
@@ -81,8 +84,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 dfb0db42e335fd7334b752ac62f8adb7bffbb2ef..65d140a3e3c42763ce4d162f8c9f5b9d79d4e501 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
@@ -121,11 +121,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
2024-04-24 15:46:45 +02:00
index e6bb82928af3378847722421ce3bad7f5b994890..dadb4f13ec6b9915108603aa34d4112c47337c44 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
2024-04-24 15:46:45 +02:00
@@ -1565,8 +1565,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;
}