[SPIGOT-7811] Enchantments are applied on sweeping attack even if damage event is cancelled Created: 02/Jul/24  Updated: 25/Dec/24  Resolved: 03/Jul/24

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: PureGero Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None

Version: This server is running CraftBukkit version 4248-Spigot-491f367-ae4f5a0 (MC: 1.21) (Implementing API version 1.21-R0.1-SNAPSHOT)
Guidelines Read: Yes

 Description   

When a player attacks an entity with a sword, nearby entities are also attacked with a sweeping mechanic. The damage event for these sweeping entity targets can be cancelled individually. However, if the sword has an enchantment on it, this enchantment will still apply to the sweeping entity targets even if their damage event is cancelled. For example, fire aspect will still set them on fire.

The current code in EntityHuman.java under `void attack(Entity)` is:
 

// CraftBukkit start - Only apply knockback if the damage hits
if (entityliving2.hurt(this.damageSources().playerAttack(this).sweep(), f7)) {
    entityliving2.knockback(0.4000000059604645D, (double) MathHelper.sin(this.getYRot() * 0.017453292F), (double) (-MathHelper.cos(this.getYRot() * 0.017453292F)), this, EntityKnockbackEvent.KnockbackCause.SWEEP_ATTACK); // CraftBukkit
}
// CraftBukkit end
World world = this.level();

if (world instanceof WorldServer) {
    WorldServer worldserver = (WorldServer) world;

    EnchantmentManager.doPostAttackEffects(worldserver, entityliving2, damagesource);
}

The fix this issue, it should be replaced with the following. This will run the enchantment effects only if the damage successfully hit and was not cancelled:

// CraftBukkit start - Only apply knockback if the damage hits
if (entityliving2.hurt(this.damageSources().playerAttack(this).sweep(), f7)) {
    entityliving2.knockback(0.4000000059604645D, (double) MathHelper.sin(this.getYRot() * 0.017453292F), (double) (-MathHelper.cos(this.getYRot() * 0.017453292F)), this, EntityKnockbackEvent.KnockbackCause.SWEEP_ATTACK); // CraftBukkit

    World world = this.level();
    if (world instanceof WorldServer) {
        WorldServer worldserver = (WorldServer) world;

        EnchantmentManager.doPostAttackEffects(worldserver, entityliving2, damagesource);
    }
}
// CraftBukkit end

 


Generated at Sat Dec 13 15:19:18 UTC 2025 using Jira 10.3.13#10030013-sha1:56dd970ae30ebfeda3a697d25be1f6388b68a422.