#1390: Improve internal handling of damage sources

By: Doc <nachito94@msn.com>
This commit is contained in:
CraftBukkit/Spigot
2024-05-04 08:15:51 +10:00
parent f01e218606
commit 066665a979
12 changed files with 72 additions and 48 deletions

View File

@@ -28,7 +28,7 @@
public static DamageSource getDefaultDamageSource(World world, @Nullable Entity entity) {
return world.damageSources().explosion(entity, getIndirectSourceEntityInternal(entity));
@@ -86,17 +100,18 @@
@@ -86,7 +100,7 @@
this.hitPlayers = Maps.newHashMap();
this.level = world;
this.source = entity;
@@ -37,11 +37,7 @@
this.x = d0;
this.y = d1;
this.z = d2;
this.fire = flag;
this.blockInteraction = explosion_effect;
- this.damageSource = damagesource == null ? world.damageSources().explosion(this) : damagesource;
+ this.damageSource = damagesource == null ? world.damageSources().explosion(this).customCausingEntity(entity) : damagesource.customCausingEntity(entity); // CraftBukkit - handle source entity
this.damageCalculator = explosiondamagecalculator == null ? this.makeDamageCalculator(entity) : explosiondamagecalculator;
@@ -97,6 +111,7 @@
this.smallExplosionParticles = particleparam;
this.largeExplosionParticles = particleparam1;
this.explosionSound = holder;
@@ -144,7 +140,7 @@
+ this.yield = event.getYield();
+ } else {
+ org.bukkit.block.Block block = location.getBlock();
+ org.bukkit.block.BlockState blockState = (damageSource.blockState != null) ? damageSource.blockState : block.getState();
+ org.bukkit.block.BlockState blockState = (damageSource.getDirectBlockState() != null) ? damageSource.getDirectBlockState() : block.getState();
+ BlockExplodeEvent event = new BlockExplodeEvent(block, blockState, blockList, this.yield);
+ this.level.getCraftServer().getPluginManager().callEvent(event);
+ this.wasCanceled = event.isCancelled();