mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-01 00:10:32 +01:00
141 lines
9.2 KiB
Diff
141 lines
9.2 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Nassim Jahnke <jahnke.nassim@gmail.com>
|
|
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 78e28d40292ec99ac0a22bd7f834c30c68c00098..2f347a0687e592bf00ef7e5a031a5dde5177ba3b 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Mob.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
|
|
@@ -1233,12 +1233,15 @@ public abstract class Mob extends LivingEntity {
|
|
return InteractionResult.PASS;
|
|
} else if (this.getLeashHolder() == player) {
|
|
// CraftBukkit start - fire PlayerUnleashEntityEvent
|
|
- if (CraftEventFactory.callPlayerUnleashEntityEvent(this, player).isCancelled()) {
|
|
+ // Paper start - drop leash variable
|
|
+ org.bukkit.event.player.PlayerUnleashEntityEvent event = CraftEventFactory.callPlayerUnleashEntityEvent(this, player, !player.getAbilities().instabuild);
|
|
+ if (event.isCancelled()) {
|
|
+ // Paper end
|
|
((ServerPlayer) player).connection.send(new ClientboundSetEntityLinkPacket(this, this.getLeashHolder()));
|
|
return InteractionResult.PASS;
|
|
}
|
|
// CraftBukkit end
|
|
- this.dropLeash(true, !player.getAbilities().instabuild);
|
|
+ this.dropLeash(true, event.isDropLeash()); // Paper - drop leash variable
|
|
return InteractionResult.sidedSuccess(this.level.isClientSide);
|
|
} else {
|
|
InteractionResult enuminteractionresult = this.checkAndHandleImportantInteractions(player, hand);
|
|
@@ -1396,8 +1399,11 @@ public abstract class Mob extends LivingEntity {
|
|
|
|
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
|
|
}
|
|
|
|
}
|
|
@@ -1460,8 +1466,11 @@ public abstract class Mob extends LivingEntity {
|
|
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;
|
|
@@ -1633,8 +1642,11 @@ public abstract class Mob extends LivingEntity {
|
|
@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
|
|
this.getAllSlots().forEach((itemstack) -> {
|
|
if (!itemstack.isEmpty()) itemstack.setCount(0); // CraftBukkit
|
|
});
|
|
diff --git a/src/main/java/net/minecraft/world/entity/PathfinderMob.java b/src/main/java/net/minecraft/world/entity/PathfinderMob.java
|
|
index 999d18610666ec442bb038da5c452e3cd77e7428..5f256c1ac5d49e19cfccf174dd55506313c493e0 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/PathfinderMob.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/PathfinderMob.java
|
|
@@ -49,8 +49,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;
|
|
@@ -58,8 +61,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
|
|
index ae277032a8748b13cca6ab7892691732e78b6752..6daee9cc30fef287df81d949b6fa0b91fa21d759 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/decoration/LeashFenceKnotEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/decoration/LeashFenceKnotEntity.java
|
|
@@ -122,11 +122,14 @@ public class LeashFenceKnotEntity extends HangingEntity {
|
|
entityinsentient = (Mob) iterator.next();
|
|
if (entityinsentient.isLeashed() && entityinsentient.getLeashHolder() == this) {
|
|
// CraftBukkit start
|
|
- if (CraftEventFactory.callPlayerUnleashEntityEvent(entityinsentient, player).isCancelled()) {
|
|
+ // Paper start - drop leash variable
|
|
+ org.bukkit.event.player.PlayerUnleashEntityEvent event = CraftEventFactory.callPlayerUnleashEntityEvent(entityinsentient, player, !player.getAbilities().instabuild);
|
|
+ if (event.isCancelled()) {
|
|
+ // Paper end
|
|
die = false;
|
|
continue;
|
|
}
|
|
- entityinsentient.dropLeash(true, !player.getAbilities().instabuild); // false -> survival mode boolean
|
|
+ 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 30bf86f0f22b783273286b4372541f8a2def0eb2..dbe2d218aa2561b404519245d3ef09b9a1e234e3 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
@@ -1524,8 +1524,10 @@ public class CraftEventFactory {
|
|
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;
|
|
}
|