#1129: Fix state corruption while handling explosion damage on EntityComplexPart

An IllegalStateException may occur when an entity is damaged by fire or a potion effect immediately after an EntityComplexPart is damaged by an explosion.

This is fixed by performing the instanceof EntityComplexPart check prior to setting CraftEventFactory.entityDamage.

By: Jacob Martin <jjm_223@hotmail.com>
This commit is contained in:
CraftBukkit/Spigot 2022-12-29 14:06:51 +11:00
parent b718d5f0b0
commit a5b2050ee5

View file

@ -45,14 +45,12 @@
this.level.gameEvent(this.source, GameEvent.EXPLODE, new Vec3D(this.x, this.y, this.z));
Set<BlockPosition> set = Sets.newHashSet();
boolean flag = true;
@@ -211,7 +226,35 @@
@@ -211,7 +226,36 @@
double d12 = (double) getSeenPercent(vec3d, entity);
double d13 = (1.0D - d7) * d12;
- entity.hurt(this.getDamageSource(), (float) ((int) ((d13 * d13 + d13) / 2.0D * 7.0D * (double) f2 + 1.0D)));
+ // CraftBukkit start
+ CraftEventFactory.entityDamage = source;
+ entity.lastDamageCancelled = false;
+
+ // Special case ender dragon only give knockback if no damage is cancelled
+ // Thinks to note:
@ -64,6 +62,9 @@
+ continue;
+ }
+
+ CraftEventFactory.entityDamage = source;
+ entity.lastDamageCancelled = false;
+
+ if (entity instanceof EntityEnderDragon) {
+ for (EntityComplexPart entityComplexPart : ((EntityEnderDragon) entity).subEntities) {
+ if (list.contains(entityComplexPart)) {
@ -82,7 +83,7 @@
double d14 = d13;
if (entity instanceof EntityLiving) {
@@ -254,6 +297,51 @@
@@ -254,6 +298,51 @@
SystemUtils.shuffle(this.toBlow, this.level.random);
ObjectListIterator objectlistiterator = this.toBlow.iterator();
@ -134,7 +135,7 @@
while (objectlistiterator.hasNext()) {
BlockPosition blockposition = (BlockPosition) objectlistiterator.next();
@@ -272,8 +360,8 @@
@@ -272,8 +361,8 @@
TileEntity tileentity = iblockdata.hasBlockEntity() ? this.level.getBlockEntity(blockposition) : null;
LootTableInfo.Builder loottableinfo_builder = (new LootTableInfo.Builder(worldserver)).withRandom(this.level.random).withParameter(LootContextParameters.ORIGIN, Vec3D.atCenterOf(blockposition)).withParameter(LootContextParameters.TOOL, ItemStack.EMPTY).withOptionalParameter(LootContextParameters.BLOCK_ENTITY, tileentity).withOptionalParameter(LootContextParameters.THIS_ENTITY, this.source);
@ -145,7 +146,7 @@
}
iblockdata.spawnAfterBreak(worldserver, blockposition, ItemStack.EMPTY, flag2);
@@ -305,7 +393,11 @@
@@ -305,7 +394,11 @@
BlockPosition blockposition2 = (BlockPosition) objectlistiterator1.next();
if (this.random.nextInt(3) == 0 && this.level.getBlockState(blockposition2).isAir() && this.level.getBlockState(blockposition2.below()).isSolidRender(this.level, blockposition2.below())) {
@ -158,7 +159,7 @@
}
}
}
@@ -317,6 +409,7 @@
@@ -317,6 +410,7 @@
}
private static void addBlockDrops(ObjectArrayList<Pair<ItemStack, BlockPosition>> objectarraylist, ItemStack itemstack, BlockPosition blockposition) {