SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, #1008: Add EntityRemoveEvent

By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
CraftBukkit/Spigot
2024-02-21 20:55:34 +11:00
parent 6dc11b5d28
commit 64cd2b148a
81 changed files with 2037 additions and 475 deletions

View File

@@ -1,18 +1,19 @@
--- a/net/minecraft/world/entity/boss/enderdragon/EntityEnderCrystal.java
+++ b/net/minecraft/world/entity/boss/enderdragon/EntityEnderCrystal.java
@@ -20,6 +20,11 @@
@@ -20,6 +20,12 @@
import net.minecraft.world.level.block.BlockFireAbstract;
import net.minecraft.world.level.dimension.end.EnderDragonBattle;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityRemoveEvent;
+import org.bukkit.event.entity.ExplosionPrimeEvent;
+// CraftBukkit end
+
public class EntityEnderCrystal extends Entity {
private static final DataWatcherObject<Optional<BlockPosition>> DATA_BEAM_TARGET = DataWatcher.defineId(EntityEnderCrystal.class, DataWatcherRegistry.OPTIONAL_BLOCK_POS);
@@ -55,7 +60,11 @@
@@ -55,7 +61,11 @@
BlockPosition blockposition = this.blockPosition();
if (((WorldServer) this.level()).getDragonFight() != null && this.level().getBlockState(blockposition).isAir()) {
@@ -25,16 +26,16 @@
}
}
@@ -95,11 +104,23 @@
@@ -95,12 +105,26 @@
return false;
} else {
if (!this.isRemoved() && !this.level().isClientSide) {
- this.remove(Entity.RemovalReason.KILLED);
+ // CraftBukkit start - All non-living entities need this
+ if (CraftEventFactory.handleNonLivingEntityDamageEvent(this, damagesource, f, false)) {
+ return false;
+ }
+ // CraftBukkit end
this.remove(Entity.RemovalReason.KILLED);
if (!damagesource.is(DamageTypeTags.IS_EXPLOSION)) {
DamageSource damagesource1 = damagesource.getEntity() != null ? this.damageSources().explosion(this, damagesource.getEntity()) : null;
@@ -42,11 +43,15 @@
+ // CraftBukkit start
+ ExplosionPrimeEvent event = CraftEventFactory.callExplosionPrimeEvent(this, 6.0F, false);
+ if (event.isCancelled()) {
+ this.unsetRemoved();
+ return false;
+ }
+
+ this.remove(Entity.RemovalReason.KILLED, EntityRemoveEvent.Cause.EXPLODE); // CraftBukkit - add Bukkit remove cause
+ this.level().explode(this, damagesource1, (ExplosionDamageCalculator) null, this.getX(), this.getY(), this.getZ(), event.getRadius(), event.getFire(), World.a.BLOCK);
+ // CraftBukkit end
+ } else {
+ this.remove(Entity.RemovalReason.KILLED, EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause
}
+ // CraftBukkit end
this.onDestroyedBy(damagesource);
}

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/world/entity/boss/enderdragon/EntityEnderDragon.java
+++ b/net/minecraft/world/entity/boss/enderdragon/EntityEnderDragon.java
@@ -53,6 +53,19 @@
@@ -53,6 +53,20 @@
import org.joml.Vector3f;
import org.slf4j.Logger;
@@ -15,12 +15,13 @@
+import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.event.entity.EntityExplodeEvent;
+import org.bukkit.event.entity.EntityRegainHealthEvent;
+import org.bukkit.event.entity.EntityRemoveEvent;
+// CraftBukkit end
+
public class EntityEnderDragon extends EntityInsentient implements IMonster {
private static final Logger LOGGER = LogUtils.getLogger();
@@ -90,6 +103,7 @@
@@ -90,6 +104,7 @@
private final PathPoint[] nodes;
private final int[] nodeAdjacency;
private final Path openSet;
@@ -28,7 +29,7 @@
public EntityEnderDragon(EntityTypes<? extends EntityEnderDragon> entitytypes, World world) {
super(EntityTypes.ENDER_DRAGON, world);
@@ -111,6 +125,7 @@
@@ -111,6 +126,7 @@
this.noPhysics = true;
this.noCulling = true;
this.phaseManager = new DragonControllerManager(this);
@@ -36,7 +37,7 @@
}
public void setDragonFight(EnderDragonBattle enderdragonbattle) {
@@ -258,7 +273,7 @@
@@ -258,7 +274,7 @@
Vec3D vec3d1 = idragoncontroller.getFlyTargetLocation();
@@ -45,7 +46,7 @@
double d0 = vec3d1.x - this.getX();
double d1 = vec3d1.y - this.getY();
double d2 = vec3d1.z - this.getZ();
@@ -399,7 +414,14 @@
@@ -399,7 +415,14 @@
if (this.nearestCrystal.isRemoved()) {
this.nearestCrystal = null;
} else if (this.tickCount % 10 == 0 && this.getHealth() < this.getMaxHealth()) {
@@ -61,7 +62,7 @@
}
}
@@ -474,6 +496,9 @@
@@ -474,6 +497,9 @@
int j1 = MathHelper.floor(axisalignedbb.maxZ);
boolean flag = false;
boolean flag1 = false;
@@ -71,7 +72,7 @@
for (int k1 = i; k1 <= l; ++k1) {
for (int l1 = j; l1 <= i1; ++l1) {
@@ -483,7 +508,11 @@
@@ -483,7 +509,11 @@
if (!iblockdata.isAir() && !iblockdata.is(TagsBlock.DRAGON_TRANSPARENT)) {
if (this.level().getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) && !iblockdata.is(TagsBlock.DRAGON_IMMUNE)) {
@@ -84,7 +85,7 @@
} else {
flag = true;
}
@@ -492,6 +521,51 @@
@@ -492,6 +522,51 @@
}
}
@@ -136,7 +137,16 @@
if (flag1) {
BlockPosition blockposition1 = new BlockPosition(i + this.random.nextInt(l - i + 1), j + this.random.nextInt(i1 - j + 1), k + this.random.nextInt(j1 - k + 1));
@@ -556,6 +630,21 @@
@@ -547,7 +622,7 @@
@Override
public void kill() {
- this.remove(Entity.RemovalReason.KILLED);
+ this.remove(Entity.RemovalReason.KILLED, EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause
this.gameEvent(GameEvent.ENTITY_DIE);
if (this.dragonFight != null) {
this.dragonFight.updateDragon(this);
@@ -556,6 +631,21 @@
}
@@ -158,7 +168,7 @@
@Override
protected void tickDeath() {
if (this.dragonFight != null) {
@@ -571,15 +660,20 @@
@@ -571,15 +661,20 @@
this.level().addParticle(Particles.EXPLOSION_EMITTER, this.getX() + (double) f, this.getY() + 2.0D + (double) f1, this.getZ() + (double) f2, 0.0D, 0.0D, 0.0D);
}
@@ -180,7 +190,7 @@
EntityExperienceOrb.award((WorldServer) this.level(), this.position(), MathHelper.floor((float) short0 * 0.08F));
}
@@ -590,7 +684,7 @@
@@ -590,7 +685,7 @@
this.move(EnumMoveType.SELF, new Vec3D(0.0D, 0.10000000149011612D, 0.0D));
if (this.dragonDeathTime == 200 && this.level() instanceof WorldServer) {
@@ -189,7 +199,16 @@
EntityExperienceOrb.award((WorldServer) this.level(), this.position(), MathHelper.floor((float) short0 * 0.2F));
}
@@ -811,6 +905,7 @@
@@ -598,7 +693,7 @@
this.dragonFight.setDragonKilled(this);
}
- this.remove(Entity.RemovalReason.KILLED);
+ this.remove(Entity.RemovalReason.KILLED, EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause
this.gameEvent(GameEvent.ENTITY_DIE);
}
@@ -811,6 +906,7 @@
super.addAdditionalSaveData(nbttagcompound);
nbttagcompound.putInt("DragonPhase", this.phaseManager.getCurrentPhase().getPhase().getId());
nbttagcompound.putInt("DragonDeathTime", this.dragonDeathTime);
@@ -197,7 +216,7 @@
}
@Override
@@ -824,6 +919,11 @@
@@ -824,6 +920,11 @@
this.dragonDeathTime = nbttagcompound.getInt("DragonDeathTime");
}

View File

@@ -0,0 +1,22 @@
--- a/net/minecraft/world/entity/boss/enderdragon/phases/DragonControllerLandedFlame.java
+++ b/net/minecraft/world/entity/boss/enderdragon/phases/DragonControllerLandedFlame.java
@@ -10,6 +10,10 @@
import net.minecraft.world.entity.boss.enderdragon.EntityEnderDragon;
import net.minecraft.world.phys.Vec3D;
+// CraftBukkit start
+import org.bukkit.event.entity.EntityRemoveEvent;
+// CraftBukkit end
+
public class DragonControllerLandedFlame extends AbstractDragonControllerLanded {
private static final int FLAME_DURATION = 200;
@@ -99,7 +103,7 @@
@Override
public void end() {
if (this.flame != null) {
- this.flame.discard();
+ this.flame.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
this.flame = null;
}

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/world/entity/boss/wither/EntityWither.java
+++ b/net/minecraft/world/entity/boss/wither/EntityWither.java
@@ -55,6 +55,17 @@
@@ -55,6 +55,18 @@
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.phys.Vec3D;
@@ -11,6 +11,7 @@
+import net.minecraft.world.level.block.Blocks;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityRegainHealthEvent;
+import org.bukkit.event.entity.EntityRemoveEvent;
+import org.bukkit.event.entity.EntityTargetEvent;
+import org.bukkit.event.entity.ExplosionPrimeEvent;
+// CraftBukkit end
@@ -18,7 +19,7 @@
public class EntityWither extends EntityMonster implements PowerableMob, IRangedEntity {
private static final DataWatcherObject<Integer> DATA_TARGET_A = DataWatcher.defineId(EntityWither.class, DataWatcherRegistry.INT);
@@ -248,15 +259,40 @@
@@ -248,15 +260,40 @@
i = this.getInvulnerableTicks() - 1;
this.bossEvent.setProgress(1.0F - (float) i / 220.0F);
if (i <= 0) {
@@ -62,7 +63,7 @@
}
} else {
@@ -301,6 +337,7 @@
@@ -301,6 +338,7 @@
if (!list.isEmpty()) {
EntityLiving entityliving1 = (EntityLiving) list.get(this.random.nextInt(list.size()));
@@ -70,7 +71,7 @@
this.setAlternativeTarget(i, entityliving1.getId());
}
}
@@ -331,6 +368,11 @@
@@ -331,6 +369,11 @@
IBlockData iblockdata = this.level().getBlockState(blockposition);
if (canDestroy(iblockdata)) {
@@ -82,7 +83,7 @@
flag = this.level().destroyBlock(blockposition, true, this) || flag;
}
}
@@ -344,7 +386,7 @@
@@ -344,7 +387,7 @@
}
if (this.tickCount % 20 == 0) {
@@ -91,3 +92,12 @@
}
this.bossEvent.setProgress(this.getHealth() / this.getMaxHealth());
@@ -498,7 +541,7 @@
@Override
public void checkDespawn() {
if (this.level().getDifficulty() == EnumDifficulty.PEACEFUL && this.shouldDespawnInPeaceful()) {
- this.discard();
+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
} else {
this.noActionTime = 0;
}