-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Minor
-
None
-
Affects Version/s: None
-
None
-
This server is running CraftBukkit version 4248-Spigot-491f367-ae4f5a0 (MC: 1.21) (Implementing API version 1.21-R0.1-SNAPSHOT)
-
Yes
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