2021-06-11 14:02:28 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2022-08-01 16:01:20 +02:00
|
|
|
From: Nassim Jahnke <nassim@njahnke.dev>
|
2021-06-11 14:02:28 +02:00
|
|
|
Date: Fri, 29 Jan 2021 15:13:11 +0100
|
2024-01-19 13:22:30 +01:00
|
|
|
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
|
2024-06-13 17:45:43 +02:00
|
|
|
index 2d2f2f8320df7650a6fc746d7071c9ffdbb8e2d4..5b169de9c2a34044dcf46c613291ae56a83ad5d2 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
|
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
|
2022-10-02 09:56:36 +02:00
|
|
|
- if (CraftEventFactory.callPlayerUnleashEntityEvent(this, player, hand).isCancelled()) {
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // 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()) {
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // 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());
|
2024-01-19 22:13:42 +01:00
|
|
|
+ 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 {
|
2024-04-28 03:00:01 +02:00
|
|
|
@@ -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
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // 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());
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // Paper end - Expand EntityUnleashEvent
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2024-04-28 03:00:01 +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);
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // Paper start - Expand EntityUnleashEvent
|
2023-06-08 02:54:54 +02:00
|
|
|
+ EntityUnleashEvent event = new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.UNKNOWN, true);
|
2024-01-19 13:22:30 +01:00
|
|
|
+ if (!event.callEvent()) { return flag1; }
|
2021-06-11 14:02:28 +02:00
|
|
|
+ this.dropLeash(true, event.isDropLeash());
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // Paper end - Expand EntityUnleashEvent
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return flag1;
|
2024-04-28 03:00:01 +02:00
|
|
|
@@ -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);
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // Paper start - Expand EntityUnleashEvent
|
2023-06-08 02:54:54 +02:00
|
|
|
+ EntityUnleashEvent event = new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.UNKNOWN, false);
|
2024-01-19 17:54:05 +01:00
|
|
|
+ this.level().getCraftServer().getPluginManager().callEvent(event); // CraftBukkit
|
2021-06-11 14:02:28 +02:00
|
|
|
+ this.dropLeash(true, event.isDropLeash());
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // 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()) {
|
2024-01-19 22:13:42 +01:00
|
|
|
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);
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // Paper start - Expand EntityUnleashEvent
|
2021-06-11 14:02:28 +02:00
|
|
|
+ EntityUnleashEvent event = new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.DISTANCE, true);
|
2024-01-19 17:54:05 +01:00
|
|
|
+ if (!event.callEvent()) return;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ this.dropLeash(true, event.isDropLeash());
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // 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);
|
2024-01-19 22:13:42 +01:00
|
|
|
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);
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // Paper start - Expand EntityUnleashEvent
|
2021-06-11 14:02:28 +02:00
|
|
|
+ EntityUnleashEvent event = new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.DISTANCE, true);
|
2024-01-19 17:54:05 +01:00
|
|
|
+ if (!event.callEvent()) return;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ this.dropLeash(true, event.isDropLeash());
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // 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
|
2024-04-28 03:00:01 +02:00
|
|
|
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
|
2024-04-28 03:00:01 +02:00
|
|
|
@@ -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()) {
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // 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()) {
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // 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
|
2024-01-19 22:13:42 +01:00
|
|
|
+ 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-06-13 17:45:43 +02:00
|
|
|
index 676528008a90d9af916a96c3f3518f8d1bd090fb..54635efbc71c3c80b44342bf5fb213bfb66408c4 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-05-11 23:48:37 +02:00
|
|
|
@@ -1567,8 +1567,10 @@ public class CraftEventFactory {
|
2023-11-11 21:25:45 +01:00
|
|
|
Bukkit.getPluginManager().callEvent(new PlayerRecipeBookSettingsChangeEvent(player.getBukkitEntity(), bukkitType, open, filter));
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
2022-10-02 09:56:36 +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));
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // Paper start - Expand EntityUnleashEvent
|
2022-10-02 09:56:36 +02:00
|
|
|
+ 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);
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // 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;
|
|
|
|
}
|