Fix DamageSource API

Uses the correct entity in the EntityDamageByEntity event
Returns the correct entity for API's DamageSource#getCausingEntity
This commit is contained in:
Jake Potrebic
2024-03-09 14:13:04 -08:00
parent a87a5e10d9
commit d42ef390ea
12 changed files with 36 additions and 50 deletions

View File

@@ -41,13 +41,13 @@ public class CraftDamageSource implements DamageSource {
@Override
public org.bukkit.entity.Entity getCausingEntity() {
net.minecraft.world.entity.Entity entity = this.getHandle().getCausingDamager();
net.minecraft.world.entity.Entity entity = this.getHandle().getEntity(); // Paper - fix DamageSource API - revert to vanilla
return (entity != null) ? entity.getBukkitEntity() : null;
}
@Override
public org.bukkit.entity.Entity getDirectEntity() {
net.minecraft.world.entity.Entity entity = this.getHandle().getDamager();
net.minecraft.world.entity.Entity entity = this.getHandle().getDirectEntity(); // Paper - fix DamageSource API
return (entity != null) ? entity.getBukkitEntity() : null;
}
@@ -65,7 +65,7 @@ public class CraftDamageSource implements DamageSource {
@Override
public boolean isIndirect() {
return this.getHandle().getCausingDamager() != this.getHandle().getDamager();
return !this.getHandle().isDirect(); // Paper - fix DamageSource API
}
@Override

View File

@@ -41,6 +41,11 @@ public class CraftDamageSourceBuilder implements DamageSource.Builder {
@Override
public DamageSource build() {
// Paper start - fix DamageCause API
if (this.causingEntity != null && this.directEntity == null) {
throw new IllegalArgumentException("Direct entity must be set if causing entity is set");
}
// Paper end - fix DamageCause API
return CraftDamageSource.buildFromBukkit(this.damageType, this.causingEntity, this.directEntity, this.damageLocation);
}
}