3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-16 13:00:06 +01:00
Paper/patches/server/0612-Add-dropLeash-variable-to-EntityUnleashEvent.patch

141 Zeilen
9.2 KiB
Diff

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2021-07-07 19:18:05 +02:00
From: kennytv <jahnke.nassim@gmail.com>
2021-06-11 14:02:28 +02:00
Date: Fri, 29 Jan 2021 15:13:11 +0100
Subject: [PATCH] Add dropLeash variable to EntityUnleashEvent
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 976dbf40292b10364f9e80bebe96ec9c4dfb657e..c375081e02925da6085a2d433bfc2c3719770f78 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
@@ -1213,12 +1213,15 @@ public abstract class Mob extends LivingEntity {
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).isCancelled()) {
+ // Paper start - drop leash variable
2021-06-14 21:58:32 +02:00
+ org.bukkit.event.player.PlayerUnleashEntityEvent event = CraftEventFactory.callPlayerUnleashEntityEvent(this, player, !player.getAbilities().instabuild);
2021-06-11 14:02:28 +02:00
+ if (event.isCancelled()) {
+ // Paper end
((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);
2021-06-11 14:02:28 +02:00
+ this.dropLeash(true, event.isDropLeash()); // Paper - drop leash variable
return InteractionResult.sidedSuccess(this.level.isClientSide);
} else {
InteractionResult enuminteractionresult = this.checkAndHandleImportantInteractions(player, hand);
@@ -1376,8 +1379,11 @@ public abstract class Mob extends LivingEntity {
2021-06-11 14:02:28 +02:00
if (this.leashHolder != null) {
if (!this.isAlive() || !this.leashHolder.isAlive()) {
- this.level.getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), (!this.isAlive()) ? UnleashReason.PLAYER_UNLEASH : UnleashReason.HOLDER_GONE)); // CraftBukkit
- this.dropLeash(true, true);
+ // Paper start - drop leash variable
+ EntityUnleashEvent event = new EntityUnleashEvent(this.getBukkitEntity(), (!this.isAlive()) ? UnleashReason.PLAYER_UNLEASH : UnleashReason.HOLDER_GONE, true);
+ this.level.getCraftServer().getPluginManager().callEvent(event); // CraftBukkit
+ this.dropLeash(true, event.isDropLeash());
+ // Paper end
}
}
@@ -1440,8 +1446,11 @@ public abstract class Mob extends LivingEntity {
2021-06-11 14:02:28 +02:00
boolean flag1 = super.startRiding(entity, force);
if (flag1 && this.isLeashed()) {
- this.level.getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN)); // CraftBukkit
- this.dropLeash(true, true);
+ // Paper start - drop leash variable
+ EntityUnleashEvent event = new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN, true);
+ this.level.getCraftServer().getPluginManager().callEvent(event); // CraftBukkit
+ this.dropLeash(true, event.isDropLeash());
+ // Paper end
}
return flag1;
@@ -1611,8 +1620,11 @@ public abstract class Mob extends LivingEntity {
2021-06-11 14:02:28 +02:00
@Override
protected void removeAfterChangingDimensions() {
super.removeAfterChangingDimensions();
- this.level.getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN)); // CraftBukkit
- this.dropLeash(true, false);
+ // Paper start - drop leash variable
+ EntityUnleashEvent event = new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN, false);
+ this.level.getCraftServer().getPluginManager().callEvent(event); // CraftBukkit
+ this.dropLeash(true, event.isDropLeash());
+ // Paper end
2021-06-14 21:58:32 +02:00
this.getAllSlots().forEach((itemstack) -> {
if (!itemstack.isEmpty()) itemstack.setCount(0); // CraftBukkit
});
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 a884940cc576704951d42c6b0d00f5a319297c29..d16a7bab5495d58ea9e6811d4b507667cfa3d264 100644
--- a/src/main/java/net/minecraft/world/entity/PathfinderMob.java
+++ b/src/main/java/net/minecraft/world/entity/PathfinderMob.java
@@ -47,8 +47,11 @@ public abstract class PathfinderMob extends Mob {
if (this instanceof TamableAnimal && ((TamableAnimal) this).isInSittingPose()) {
if (f > entity.level.paperConfig.maxLeashDistance) { // Paper
- this.level.getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.DISTANCE)); // CraftBukkit
- this.dropLeash(true, true);
+ // Paper start - drop leash variable
+ EntityUnleashEvent event = new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.DISTANCE, true);
+ this.level.getCraftServer().getPluginManager().callEvent(event); // CraftBukkit
+ this.dropLeash(true, event.isDropLeash());
+ // Paper end
}
return;
@@ -56,8 +59,11 @@ public abstract class PathfinderMob extends Mob {
this.onLeashDistance(f);
if (f > entity.level.paperConfig.maxLeashDistance) { // Paper
- this.level.getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.DISTANCE)); // CraftBukkit
- this.dropLeash(true, true);
+ // Paper start - drop leash variable
+ EntityUnleashEvent event = new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.DISTANCE, true);
+ this.level.getCraftServer().getPluginManager().callEvent(event); // CraftBukkit
+ this.dropLeash(true, event.isDropLeash());
+ // Paper end
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
2021-06-14 21:58:32 +02:00
index b9b67134f02fd7484ed19905c9ae1f9b8a26ce26..c05f173b7642380900fdd77ce5d2c020468b5fc0 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
2021-06-14 21:58:32 +02:00
@@ -123,11 +123,14 @@ public class LeashFenceKnotEntity extends HangingEntity {
2021-06-11 14:02:28 +02:00
entityinsentient = (Mob) iterator.next();
if (entityinsentient.isLeashed() && entityinsentient.getLeashHolder() == this) {
// CraftBukkit start
- if (CraftEventFactory.callPlayerUnleashEntityEvent(entityinsentient, player).isCancelled()) {
+ // Paper start - drop leash variable
2021-06-14 21:58:32 +02:00
+ org.bukkit.event.player.PlayerUnleashEntityEvent event = CraftEventFactory.callPlayerUnleashEntityEvent(entityinsentient, player, !player.getAbilities().instabuild);
2021-06-11 14:02:28 +02:00
+ if (event.isCancelled()) {
+ // Paper end
die = false;
continue;
}
2021-06-14 21:58:32 +02:00
- entityinsentient.dropLeash(true, !player.getAbilities().instabuild); // false -> survival mode boolean
2021-06-11 14:02:28 +02:00
+ entityinsentient.dropLeash(true, event.isDropLeash()); // false -> survival mode boolean // Paper - drop leash variable
// CraftBukkit end
}
}
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index b06d92fa7c1d7cb7a9637e9c435f95b8c18d0581..7c68b15c432084adf069797cfccb0526055796cb 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
@@ -1484,8 +1484,10 @@ public class CraftEventFactory {
2021-06-11 14:02:28 +02:00
return itemInHand;
}
- public static PlayerUnleashEntityEvent callPlayerUnleashEntityEvent(Mob entity, net.minecraft.world.entity.player.Player player) {
- PlayerUnleashEntityEvent event = new PlayerUnleashEntityEvent(entity.getBukkitEntity(), (Player) player.getBukkitEntity());
+ // Paper start - drop leash variable
+ public static PlayerUnleashEntityEvent callPlayerUnleashEntityEvent(Mob entity, net.minecraft.world.entity.player.Player player, boolean dropLeash) {
+ PlayerUnleashEntityEvent event = new PlayerUnleashEntityEvent(entity.getBukkitEntity(), (Player) player.getBukkitEntity(), dropLeash);
+ // Paper end
entity.level.getCraftServer().getPluginManager().callEvent(event);
return event;
}