Expand EntityUnleashEvent

This commit is contained in:
Nassim Jahnke 2021-01-29 15:13:11 +01:00
parent 1292627c18
commit a85863338c
6 changed files with 161 additions and 108 deletions

View file

@ -18,7 +18,7 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.FenceGateBlock;
@@ -138,9 +138,142 @@
@@ -138,8 +138,141 @@
import net.minecraft.world.scores.ScoreHolder;
import net.minecraft.world.scores.Team;
import org.slf4j.Logger;
@ -61,7 +61,7 @@
+// CraftBukkit end
public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess, ScoreHolder {
+
+ // CraftBukkit start
+ private static final int CURRENT_LEVEL = 2;
+ public boolean preserveMotion = true; // Paper - Fix Entity Teleportation and cancel velocity if teleported; keep initial motion on first setPositionRotation
@ -157,10 +157,9 @@
+ return Entity.TOTAL_AIR_SUPPLY;
+ }
+ // CraftBukkit end
+
private static final Logger LOGGER = LogUtils.getLogger();
public static final String ID_TAG = "id";
public static final String PASSENGERS_TAG = "Passengers";
@@ -224,7 +357,7 @@
private static final EntityDataAccessor<Boolean> DATA_CUSTOM_NAME_VISIBLE = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.BOOLEAN);
private static final EntityDataAccessor<Boolean> DATA_SILENT = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.BOOLEAN);
@ -170,7 +169,7 @@
private static final EntityDataAccessor<Integer> DATA_TICKS_FROZEN = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.INT);
private EntityInLevelCallback levelCallback;
private final VecDeltaCodec packetPositionCodec;
@@ -253,7 +386,65 @@
@@ -253,6 +386,64 @@
private final List<Entity.Movement> movementThisTick;
private final Set<BlockState> blocksInside;
private final LongSet visitedBlocks;
@ -203,7 +202,7 @@
+ private org.bukkit.util.Vector origin;
+ @javax.annotation.Nullable
+ private UUID originWorld;
+
+ public void setOrigin(@javax.annotation.Nonnull Location location) {
+ this.origin = location.toVector();
+ this.originWorld = location.getWorld().getUID();
@ -232,10 +231,9 @@
+ return this.dimensions.makeBoundingBox(x, y, z);
+ }
+ // Paper end
+
public Entity(EntityType<?> type, Level world) {
this.id = Entity.ENTITY_COUNTER.incrementAndGet();
this.passengers = ImmutableList.of();
@@ -261,7 +452,7 @@
this.bb = Entity.INITIAL_AABB;
this.stuckSpeedMultiplier = Vec3.ZERO;
@ -485,15 +483,15 @@
}
}
@@ -587,9 +874,25 @@
@@ -587,7 +874,23 @@
}
public final void igniteForSeconds(float seconds) {
- this.igniteForTicks(Mth.floor(seconds * 20.0F));
+ // CraftBukkit start
+ this.igniteForSeconds(seconds, true);
}
+ }
+
+ public final void igniteForSeconds(float f, boolean callEvent) {
+ if (callEvent) {
+ EntityCombustEvent event = new EntityCombustEvent(this.getBukkitEntity(), f);
@ -507,11 +505,9 @@
+ }
+ // CraftBukkit end
+ this.igniteForTicks(Mth.floor(f * 20.0F));
+ }
+
}
public void igniteForTicks(int ticks) {
if (this.remainingFireTicks < ticks) {
this.setRemainingFireTicks(ticks);
@@ -610,7 +913,7 @@
}
@ -541,12 +537,12 @@
+ bl = bl.getRelative(BlockFace.SOUTH);
+ } else if (movement.z < vec3d1.z) {
+ bl = bl.getRelative(BlockFace.NORTH);
}
+ }
+
+ if (!bl.getType().isAir()) {
+ VehicleBlockCollisionEvent event = new VehicleBlockCollisionEvent(vehicle, bl);
+ this.level.getCraftServer().getPluginManager().callEvent(event);
+ }
}
}
+ // CraftBukkit end
@ -958,20 +954,25 @@
world.addFreshEntity(entityitem);
return entityitem;
}
@@ -2184,6 +2714,12 @@
@@ -2184,7 +2714,16 @@
if (this.isAlive() && this instanceof Leashable leashable) {
if (leashable.getLeashHolder() == player) {
if (!this.level().isClientSide()) {
- if (player.hasInfiniteMaterials()) {
+ // 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.hasInfiniteMaterials());
+ if (event.isCancelled()) {
+ // Paper end - Expand EntityUnleashEvent
+ ((ServerPlayer) player).connection.send(new ClientboundSetEntityLinkPacket(this, leashable.getLeashHolder()));
+ return InteractionResult.PASS;
+ }
+ // CraftBukkit end
if (player.hasInfiniteMaterials()) {
+ if (!event.isDropLeash()) { // Paper - Expand EntityUnleashEvent
leashable.removeLeash();
} else {
@@ -2200,6 +2736,13 @@
leashable.dropLeash();
@@ -2200,6 +2739,13 @@
if (itemstack.is(Items.LEAD) && leashable.canHaveALeashAttachedToIt()) {
if (!this.level().isClientSide()) {
@ -985,7 +986,7 @@
leashable.setLeashedTo(player, true);
}
@@ -2265,7 +2808,7 @@
@@ -2265,7 +2811,7 @@
}
public boolean showVehicleHealth() {
@ -994,7 +995,7 @@
}
public boolean startRiding(Entity entity, boolean force) {
@@ -2273,7 +2816,7 @@
@@ -2273,7 +2819,7 @@
return false;
} else if (!entity.couldAcceptPassenger()) {
return false;
@ -1003,7 +1004,7 @@
return false;
} else {
for (Entity entity1 = entity; entity1.vehicle != null; entity1 = entity1.vehicle) {
@@ -2285,11 +2828,32 @@
@@ -2285,11 +2831,32 @@
if (!force && (!this.canRide(entity) || !entity.canAddPassenger(this))) {
return false;
} else {
@ -1037,7 +1038,7 @@
this.vehicle = entity;
this.vehicle.addPassenger(this);
entity.getIndirectPassengersStream().filter((entity2) -> {
@@ -2314,19 +2878,30 @@
@@ -2314,19 +2881,30 @@
}
public void removeVehicle() {
@ -1070,7 +1071,7 @@
protected void addPassenger(Entity passenger) {
if (passenger.getVehicle() != this) {
throw new IllegalStateException("Use x.startRiding(y), not y.addPassenger(x)");
@@ -2349,21 +2924,53 @@
@@ -2349,21 +2927,53 @@
}
}
@ -1130,7 +1131,7 @@
}
protected boolean canAddPassenger(Entity passenger) {
@@ -2464,7 +3071,7 @@
@@ -2464,7 +3074,7 @@
if (teleporttransition != null) {
ServerLevel worldserver1 = teleporttransition.newLevel();
@ -1139,7 +1140,7 @@
this.teleport(teleporttransition);
}
}
@@ -2547,7 +3154,7 @@
@@ -2547,7 +3157,7 @@
}
public boolean isCrouching() {
@ -1148,7 +1149,7 @@
}
public boolean isSprinting() {
@@ -2563,7 +3170,7 @@
@@ -2563,7 +3173,7 @@
}
public boolean isVisuallySwimming() {
@ -1157,7 +1158,7 @@
}
public boolean isVisuallyCrawling() {
@@ -2571,6 +3178,13 @@
@@ -2571,6 +3181,13 @@
}
public void setSwimming(boolean swimming) {
@ -1171,7 +1172,7 @@
this.setSharedFlag(4, swimming);
}
@@ -2609,6 +3223,7 @@
@@ -2609,6 +3226,7 @@
@Nullable
public PlayerTeam getTeam() {
@ -1179,7 +1180,7 @@
return this.level().getScoreboard().getPlayersTeam(this.getScoreboardName());
}
@@ -2624,8 +3239,12 @@
@@ -2624,8 +3242,12 @@
return this.getTeam() != null ? this.getTeam().isAlliedTo(team) : false;
}
@ -1193,7 +1194,7 @@
}
public boolean getSharedFlag(int index) {
@@ -2644,7 +3263,7 @@
@@ -2644,7 +3266,7 @@
}
public int getMaxAirSupply() {
@ -1202,7 +1203,7 @@
}
public int getAirSupply() {
@@ -2652,7 +3271,18 @@
@@ -2652,7 +3274,18 @@
}
public void setAirSupply(int air) {
@ -1222,18 +1223,19 @@
}
public int getTicksFrozen() {
@@ -2679,11 +3309,40 @@
@@ -2679,11 +3312,40 @@
public void thunderHit(ServerLevel world, LightningBolt lightning) {
this.setRemainingFireTicks(this.remainingFireTicks + 1);
- if (this.remainingFireTicks == 0) {
- this.igniteForSeconds(8.0F);
+ // CraftBukkit start
+ final org.bukkit.entity.Entity thisBukkitEntity = this.getBukkitEntity();
+ final org.bukkit.entity.Entity stormBukkitEntity = lightning.getBukkitEntity();
+ final PluginManager pluginManager = Bukkit.getPluginManager();
+ // CraftBukkit end
+
if (this.remainingFireTicks == 0) {
- this.igniteForSeconds(8.0F);
+ if (this.remainingFireTicks == 0) {
+ // CraftBukkit start - Call a combust event when lightning strikes
+ EntityCombustByEntityEvent entityCombustEvent = new EntityCombustByEntityEvent(stormBukkitEntity, thisBukkitEntity, 8.0F);
+ pluginManager.callEvent(entityCombustEvent);
@ -1265,7 +1267,7 @@
}
public void onAboveBubbleCol(boolean drag) {
@@ -2713,7 +3372,7 @@
@@ -2713,7 +3375,7 @@
this.resetFallDistance();
}
@ -1274,7 +1276,7 @@
return true;
}
@@ -2818,7 +3477,7 @@
@@ -2818,7 +3480,7 @@
public String toString() {
String s = this.level() == null ? "~NULL~" : this.level().toString();
@ -1283,7 +1285,7 @@
}
public final boolean isInvulnerableToBase(DamageSource damageSource) {
@@ -2850,8 +3509,34 @@
@@ -2850,8 +3512,34 @@
public Entity teleport(TeleportTransition teleportTarget) {
Level world = this.level();
@ -1318,7 +1320,7 @@
ServerLevel worldserver1 = teleportTarget.newLevel();
boolean flag = worldserver1.dimension() != worldserver.dimension();
@@ -2918,10 +3603,19 @@
@@ -2918,10 +3606,19 @@
gameprofilerfiller.pop();
return null;
} else {
@ -1339,7 +1341,7 @@
Iterator iterator1 = list1.iterator();
while (iterator1.hasNext()) {
@@ -2947,7 +3641,7 @@
@@ -2947,7 +3644,7 @@
}
private void sendTeleportTransitionToRidingPlayers(TeleportTransition teleportTarget) {
@ -1348,18 +1350,27 @@
Iterator iterator = this.getIndirectPassengers().iterator();
while (iterator.hasNext()) {
@@ -2995,8 +3689,9 @@
@@ -2995,22 +3692,45 @@
}
protected void removeAfterChangingDimensions() {
- this.setRemoved(Entity.RemovalReason.CHANGED_DIMENSION);
- if (this instanceof Leashable leashable) {
- leashable.removeLeash();
+ this.setRemoved(Entity.RemovalReason.CHANGED_DIMENSION, null); // CraftBukkit - add Bukkit remove cause
if (this instanceof Leashable leashable) {
+ this.level().getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN)); // CraftBukkit
leashable.removeLeash();
+ if (this instanceof Leashable leashable && leashable.isLeashed()) { // Paper - only call if it is leashed
+ // Paper start - Expand EntityUnleashEvent
+ final EntityUnleashEvent event = new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN, false); // CraftBukkit
+ event.callEvent();
+ if (!event.isDropLeash()) {
+ leashable.removeLeash();
+ } else {
+ leashable.dropLeash();
+ }
+ // Paper end - Expand EntityUnleashEvent
}
@@ -3004,13 +3699,28 @@
}
public Vec3 getRelativePortalPosition(Direction.Axis portalAxis, BlockUtil.FoundRectangle portalRect) {
return PortalShape.getRelativePosition(portalRect, portalAxis, this.position(), this.getDimensions(this.getPose()));
@ -1388,7 +1399,7 @@
if (from.dimension() == Level.END && to.dimension() == Level.OVERWORLD) {
Iterator iterator = this.getPassengers().iterator();
@@ -3134,10 +3844,16 @@
@@ -3134,9 +3854,15 @@
return (Boolean) this.entityData.get(Entity.DATA_CUSTOM_NAME_VISIBLE);
}
@ -1399,16 +1410,15 @@
+ public final boolean teleportTo(ServerLevel world, double destX, double destY, double destZ, Set<Relative> flags, float yaw, float pitch, boolean resetCamera) {
+ return this.teleportTo(world, destX, destY, destZ, flags, yaw, pitch, resetCamera, PlayerTeleportEvent.TeleportCause.UNKNOWN);
+ }
+
+ public boolean teleportTo(ServerLevel worldserver, double d0, double d1, double d2, Set<Relative> set, float f, float f1, boolean flag, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause) {
+ float f2 = Mth.clamp(f1, -90.0F, 90.0F);
+ Entity entity = this.teleport(new TeleportTransition(worldserver, new Vec3(d0, d1, d2), Vec3.ZERO, f, f2, set, TeleportTransition.DO_NOTHING, cause));
+ // CraftBukkit end
+
return entity != null;
}
@@ -3187,7 +3903,7 @@
@@ -3187,7 +3913,7 @@
/** @deprecated */
@Deprecated
protected void fixupDimensions() {
@ -1417,7 +1427,7 @@
EntityDimensions entitysize = this.getDimensions(entitypose);
this.dimensions = entitysize;
@@ -3196,7 +3912,7 @@
@@ -3196,7 +3922,7 @@
public void refreshDimensions() {
EntityDimensions entitysize = this.dimensions;
@ -1426,7 +1436,7 @@
EntityDimensions entitysize1 = this.getDimensions(entitypose);
this.dimensions = entitysize1;
@@ -3258,10 +3974,29 @@
@@ -3258,10 +3984,29 @@
}
public final void setBoundingBox(AABB boundingBox) {
@ -1458,7 +1468,7 @@
return this.getDimensions(pose).eyeHeight();
}
@@ -3335,7 +4070,7 @@
@@ -3335,7 +4080,7 @@
}
@Nullable
@ -1467,7 +1477,7 @@
return null;
}
@@ -3435,7 +4170,7 @@
@@ -3435,7 +4180,7 @@
}
public boolean isControlledByLocalInstance() {
@ -1476,7 +1486,7 @@
if (entityliving instanceof Player entityhuman) {
return entityhuman.isLocalPlayer();
@@ -3445,7 +4180,7 @@
@@ -3445,7 +4190,7 @@
}
public boolean isControlledByClient() {
@ -1485,7 +1495,7 @@
return entityliving != null && entityliving.isControlledByClient();
}
@@ -3463,7 +4198,7 @@
@@ -3463,7 +4208,7 @@
return new Vec3((double) f1 * d2 / (double) f3, 0.0D, (double) f2 * d2 / (double) f3);
}
@ -1494,7 +1504,7 @@
return new Vec3(this.getX(), this.getBoundingBox().maxY, this.getZ());
}
@@ -3489,8 +4224,37 @@
@@ -3489,8 +4234,37 @@
return 1;
}
@ -1533,7 +1543,7 @@
}
public void lookAt(EntityAnchorArgument.Anchor anchorPoint, Vec3 target) {
@@ -3551,6 +4315,11 @@
@@ -3551,6 +4325,11 @@
vec3d = vec3d.add(vec3d1);
++k1;
}
@ -1545,7 +1555,7 @@
}
}
}
@@ -3613,7 +4382,7 @@
@@ -3613,7 +4392,7 @@
return new ClientboundAddEntityPacket(this, entityTrackerEntry);
}
@ -1554,7 +1564,7 @@
return this.type.getDimensions();
}
@@ -3713,8 +4482,40 @@
@@ -3713,8 +4492,40 @@
public double getRandomZ(double widthScale) {
return this.getZ((2.0D * this.random.nextDouble() - 1.0D) * widthScale);
}
@ -1595,7 +1605,7 @@
if (this.position.x != x || this.position.y != y || this.position.z != z) {
this.position = new Vec3(x, y, z);
int i = Mth.floor(x);
@@ -3732,6 +4533,12 @@
@@ -3732,6 +4543,12 @@
this.levelCallback.onMove();
}
@ -1608,7 +1618,7 @@
}
public void checkDespawn() {}
@@ -3818,8 +4625,16 @@
@@ -3818,8 +4635,16 @@
@Override
public final void setRemoved(Entity.RemovalReason reason) {
@ -1626,7 +1636,7 @@
}
if (this.removalReason.shouldDestroy()) {
@@ -3827,8 +4642,8 @@
@@ -3827,8 +4652,8 @@
}
this.getPassengers().forEach(Entity::stopRiding);
@ -1637,7 +1647,7 @@
}
public void unsetRemoved() {
@@ -3887,7 +4702,7 @@
@@ -3887,7 +4712,7 @@
}
public Vec3 getKnownMovement() {
@ -1646,7 +1656,7 @@
if (entityliving instanceof Player entityhuman) {
if (this.isAlive()) {
@@ -3962,4 +4777,14 @@
@@ -3962,4 +4787,14 @@
void accept(Entity entity, double x, double y, double z);
}

View file

@ -75,17 +75,20 @@
}
if (sendPacket) {
@@ -171,7 +184,8 @@
@@ -171,7 +184,11 @@
if (leashable_a != null && leashable_a.leashHolder != null) {
if (!entity.isAlive() || !leashable_a.leashHolder.isAlive()) {
- if (world.getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) {
+ world.getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(entity.getBukkitEntity(), (!entity.isAlive()) ? UnleashReason.PLAYER_UNLEASH : UnleashReason.HOLDER_GONE)); // CraftBukkit
+ if (world.getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS) && !entity.pluginRemoved) { // CraftBukkit - SPIGOT-7487: Don't drop leash, when the holder was removed by a plugin
+ // Paper start - Expand EntityUnleashEvent
+ final EntityUnleashEvent event = new EntityUnleashEvent(entity.getBukkitEntity(), (!entity.isAlive()) ? UnleashReason.PLAYER_UNLEASH : UnleashReason.HOLDER_GONE, world.getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS) && !entity.pluginRemoved);
+ event.callEvent();
+ if (event.isDropLeash()) { // CraftBukkit - SPIGOT-7487: Don't drop leash, when the holder was removed by a plugin
+ // Paper end - Expand EntityUnleashEvent
((Leashable) entity).dropLeash();
} else {
((Leashable) entity).removeLeash();
@@ -187,7 +201,7 @@
@@ -187,7 +204,7 @@
return;
}
@ -94,16 +97,26 @@
((Leashable) entity).leashTooFarBehaviour();
} else if ((double) f > 6.0D) {
((Leashable) entity).elasticRangeLeashBehaviour(entity1, f);
@@ -205,13 +219,18 @@
@@ -205,13 +222,27 @@
}
default void leashTooFarBehaviour() {
- this.dropLeash();
+ // CraftBukkit start
+ boolean dropLeash = true; // Paper
+ if (this instanceof Entity entity) {
+ entity.level().getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(entity.getBukkitEntity(), EntityUnleashEvent.UnleashReason.DISTANCE));
+ // Paper start - Expand EntityUnleashEvent
+ final EntityUnleashEvent event = new EntityUnleashEvent(entity.getBukkitEntity(), EntityUnleashEvent.UnleashReason.DISTANCE, true);
+ if (!event.callEvent()) return;
+ dropLeash = event.isDropLeash();
+ }
+ // CraftBukkit end
this.dropLeash();
+ if (dropLeash) {
+ this.dropLeash();
+ } else {
+ this.removeLeash();
+ }
+ // Paper end - Expand EntityUnleashEvent
}
default void closeRangeLeashBehaviour(Entity entity) {}
@ -114,7 +127,7 @@
}
private static <E extends Entity & Leashable> void legacyElasticRangeLeashBehaviour(E entity, Entity leashHolder, float distance) {
@@ -223,7 +242,7 @@
@@ -223,7 +254,7 @@
}
default void setLeashedTo(Entity leashHolder, boolean sendPacket) {
@ -123,7 +136,7 @@
}
private static <E extends Entity & Leashable> void setLeashedTo(E entity, Entity leashHolder, boolean sendPacket) {
@@ -254,7 +273,7 @@
@@ -254,7 +285,7 @@
@Nullable
default Entity getLeashHolder() {

View file

@ -35,19 +35,21 @@
protected Mob(EntityType<? extends Mob> type, Level world) {
super(type, world);
this.handItems = NonNullList.withSize(2, ItemStack.EMPTY);
@@ -160,6 +174,12 @@
}
@@ -157,8 +171,14 @@
if (world instanceof ServerLevel) {
this.registerGoals();
}
+
+ }
+ // CraftBukkit start
+ public void setPersistenceRequired(boolean persistenceRequired) {
+ this.persistenceRequired = persistenceRequired;
+ }
}
+ // CraftBukkit end
+
protected void registerGoals() {}
public static AttributeSupplier.Builder createMobAttributes() {
@@ -264,11 +284,42 @@
@Nullable
@ -93,19 +95,20 @@
}
@Override
@@ -399,6 +450,12 @@
@@ -397,7 +448,13 @@
@Nullable
protected SoundEvent getAmbientSound() {
return null;
}
+ }
+
+ // CraftBukkit start - Add delegate method
+ public SoundEvent getAmbientSound0() {
+ return this.getAmbientSound();
+ }
}
+ // CraftBukkit end
+
@Override
public void addAdditionalSaveData(CompoundTag nbt) {
super.addAdditionalSaveData(nbt);
@@ -473,13 +530,25 @@
nbt.putBoolean("NoAI", this.isNoAi());
}
@ -279,19 +282,20 @@
ProfilerFiller gameprofilerfiller = Profiler.get();
gameprofilerfiller.push("sensing");
@@ -1011,6 +1117,12 @@
}
@@ -1009,7 +1115,13 @@
this.onEquipItem(slot, itemstack1, stack);
}
+ }
+
+ // Paper start
+ protected boolean shouldSkipLoot(EquipmentSlot slot) { // method to avoid to fallback into the global mob loot logic (i.e fox)
+ return false;
+ }
}
+ // Paper end
+
@Override
protected void dropCustomDeathLoot(ServerLevel world, DamageSource source, boolean causedByPlayer) {
super.dropCustomDeathLoot(world, source, causedByPlayer);
@@ -1018,6 +1130,7 @@
while (iterator.hasNext()) {
@ -356,13 +360,13 @@
+ conversionparams.type().convert(this, t0, conversionparams);
+ if (!conversionparams_a.finalizeConversionOrCancel(t0)) return null; // Paper - entity zap event - return null if conversion was cancelled
Level world = this.level();
+
+ // CraftBukkit start
+ if (transformReason == null) {
+ // Special handling for slime split and pig lightning
+ return t0;
+ }
+
+ if (CraftEventFactory.callEntityTransformEvent(this, t0, transformReason).isCancelled()) {
+ return null;
+ }
@ -405,15 +409,24 @@
@Override
public Leashable.LeashData getLeashData() {
return this.leashData;
@@ -1458,6 +1612,7 @@
@@ -1458,7 +1612,15 @@
boolean flag1 = super.startRiding(entity, force);
if (flag1 && this.isLeashed()) {
+ this.level().getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN)); // CraftBukkit
this.dropLeash();
- this.dropLeash();
+ // Paper start - Expand EntityUnleashEvent
+ EntityUnleashEvent event = new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.UNKNOWN, true);
+ if (!event.callEvent()) { return flag1; }
+ if (event.isDropLeash()) {
+ this.dropLeash();
+ } else {
+ this.removeLeash();
+ }
+ // Paper end - Expand EntityUnleashEvent
}
@@ -1542,7 +1697,7 @@
return flag1;
@@ -1542,7 +1704,7 @@
if (f1 > 0.0F && target instanceof LivingEntity) {
entityliving = (LivingEntity) target;

View file

@ -12,16 +12,26 @@
public abstract class TamableAnimal extends Animal implements OwnableEntity {
@@ -96,7 +101,7 @@
@@ -96,8 +101,16 @@
@Override
public boolean handleLeashAtDistance(Entity leashHolder, float distance) {
if (this.isInSittingPose()) {
- if (distance > 10.0F) {
- this.dropLeash();
+ if (distance > (float) this.level().paperConfig().misc.maxLeashDistance.or(Leashable.LEASH_TOO_FAR_DIST)) { // Paper - Configurable max leash distance
this.dropLeash();
+ // Paper start - Expand EntityUnleashEvent
+ org.bukkit.event.entity.EntityUnleashEvent event = new org.bukkit.event.entity.EntityUnleashEvent(this.getBukkitEntity(), org.bukkit.event.entity.EntityUnleashEvent.UnleashReason.DISTANCE, true);
+ if (!event.callEvent()) return false;
+ if (event.isDropLeash()) {
+ this.dropLeash();
+ } else {
+ this.removeLeash();
+ }
+ // Paper end - Expand EntityUnleashEvent
}
@@ -295,7 +300,14 @@
return false;
@@ -295,7 +308,14 @@
if (!this.canTeleportTo(new BlockPos(x, y, z))) {
return false;
} else {

View file

@ -38,7 +38,7 @@
leashable.setLeashedTo(this, true);
flag = true;
}
@@ -93,18 +107,38 @@
@@ -93,18 +107,43 @@
boolean flag1 = false;
if (!flag) {
@ -57,13 +57,18 @@
if (leashable1.isLeashed() && leashable1.getLeashHolder() == this) {
- leashable1.removeLeash();
+ // CraftBukkit start
+ boolean dropLeash = !player.hasInfiniteMaterials();
+ if (leashable1 instanceof Entity leashed) {
+ if (CraftEventFactory.callPlayerUnleashEntityEvent(leashed, player, hand).isCancelled()) {
+ // Paper start - Expand EntityUnleashEvent
+ org.bukkit.event.player.PlayerUnleashEntityEvent event = CraftEventFactory.callPlayerUnleashEntityEvent(leashed, player, hand, dropLeash);
+ dropLeash = event.isDropLeash();
+ if (event.isCancelled()) {
+ // Paper end - Expand EntityUnleashEvent
+ die = false;
+ continue;
+ }
+ }
+ if (player.getAbilities().instabuild){
+ if (!dropLeash) { // Paper - Expand EntityUnleashEvent
+ leashable1.removeLeash();
+ } else {
+ leashable1.dropLeash();

View file

@ -1596,8 +1596,10 @@ public class CraftEventFactory {
Bukkit.getPluginManager().callEvent(new PlayerRecipeBookSettingsChangeEvent(player.getBukkitEntity(), bukkitType, open, filter));
}
public static PlayerUnleashEntityEvent callPlayerUnleashEntityEvent(Entity 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(Entity 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
entity.level().getCraftServer().getPluginManager().callEvent(event);
return event;
}