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,6 +1,6 @@
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -126,8 +126,67 @@
@@ -126,8 +126,68 @@
import org.joml.Vector3f;
import org.slf4j.Logger;
@@ -33,6 +33,7 @@
+import org.bukkit.event.entity.EntityMountEvent;
+import org.bukkit.event.entity.EntityPortalEvent;
+import org.bukkit.event.entity.EntityPoseChangeEvent;
+import org.bukkit.event.entity.EntityRemoveEvent;
+import org.bukkit.event.player.PlayerTeleportEvent;
+import org.bukkit.plugin.PluginManager;
+// CraftBukkit end
@@ -68,7 +69,7 @@
private static final Logger LOGGER = LogUtils.getLogger();
public static final String ID_TAG = "id";
public static final String PASSENGERS_TAG = "Passengers";
@@ -242,6 +301,29 @@
@@ -242,6 +302,29 @@
public boolean hasVisualFire;
@Nullable
private IBlockData feetBlockState;
@@ -98,7 +99,41 @@
public Entity(EntityTypes<?> entitytypes, World world) {
this.id = Entity.ENTITY_COUNTER.incrementAndGet();
@@ -375,6 +457,12 @@
@@ -346,12 +429,18 @@
}
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);
}
public final void discard() {
- this.remove(Entity.RemovalReason.DISCARDED);
+ // CraftBukkit start - add Bukkit remove cause
+ this.discard(null);
+ }
+
+ public final void discard(EntityRemoveEvent.Cause cause) {
+ this.remove(Entity.RemovalReason.DISCARDED, cause);
+ // CraftBukkit end
}
protected abstract void defineSynchedData();
@@ -369,12 +458,24 @@
}
public void remove(Entity.RemovalReason entity_removalreason) {
- this.setRemoved(entity_removalreason);
+ // CraftBukkit start - add Bukkit remove cause
+ this.setRemoved(entity_removalreason, null);
+ }
+
+ public void remove(Entity.RemovalReason entity_removalreason, EntityRemoveEvent.Cause cause) {
+ this.setRemoved(entity_removalreason, cause);
+ // CraftBukkit end
}
public void onClientRemoval() {}
public void setPose(EntityPose entitypose) {
@@ -111,7 +146,7 @@
this.entityData.set(Entity.DATA_POSE, entitypose);
}
@@ -399,6 +487,33 @@
@@ -399,6 +500,33 @@
}
protected void setRot(float f, float f1) {
@@ -145,7 +180,7 @@
this.setYRot(f % 360.0F);
this.setXRot(f1 % 360.0F);
}
@@ -440,6 +555,15 @@
@@ -440,6 +568,15 @@
this.baseTick();
}
@@ -161,7 +196,7 @@
public void baseTick() {
this.level().getProfiler().push("entityBaseTick");
this.feetBlockState = null;
@@ -454,7 +578,7 @@
@@ -454,7 +591,7 @@
this.walkDistO = this.walkDist;
this.xRotO = this.getXRot();
this.yRotO = this.getYRot();
@@ -170,7 +205,7 @@
if (this.canSpawnSprintParticle()) {
this.spawnSprintParticle();
}
@@ -489,6 +613,10 @@
@@ -489,6 +626,10 @@
if (this.isInLava()) {
this.lavaHurt();
this.fallDistance *= 0.5F;
@@ -181,7 +216,7 @@
}
this.checkBelowWorld();
@@ -540,15 +668,47 @@
@@ -540,15 +681,47 @@
public void lavaHurt() {
if (!this.fireImmune()) {
@@ -231,7 +266,16 @@
int j = i * 20;
if (this instanceof EntityLiving) {
@@ -699,6 +859,28 @@
@@ -574,7 +747,7 @@
}
protected void onBelowWorld() {
- this.discard();
+ this.discard(EntityRemoveEvent.Cause.OUT_OF_WORLD); // CraftBukkit - add Bukkit remove cause
}
public boolean isFree(double d0, double d1, double d2) {
@@ -699,6 +872,28 @@
block.updateEntityAfterFallOn(this.level(), this);
}
@@ -260,7 +304,7 @@
if (this.onGround()) {
block.stepOn(this.level(), blockposition, iblockdata, this);
}
@@ -1026,6 +1208,20 @@
@@ -1026,6 +1221,20 @@
return SoundEffects.GENERIC_SPLASH;
}
@@ -281,7 +325,7 @@
protected void checkInsideBlocks() {
AxisAlignedBB axisalignedbb = this.getBoundingBox();
BlockPosition blockposition = BlockPosition.containing(axisalignedbb.minX + 1.0E-7D, axisalignedbb.minY + 1.0E-7D, axisalignedbb.minZ + 1.0E-7D);
@@ -1440,6 +1636,7 @@
@@ -1440,6 +1649,7 @@
this.yo = d1;
this.zo = d4;
this.setPos(d3, d1, d4);
@@ -289,7 +333,7 @@
}
public void moveTo(Vec3D vec3d) {
@@ -1634,6 +1831,12 @@
@@ -1634,6 +1844,12 @@
return false;
}
@@ -302,7 +346,7 @@
public void awardKillScore(Entity entity, int i, DamageSource damagesource) {
if (entity instanceof EntityPlayer) {
CriterionTriggers.ENTITY_KILLED_PLAYER.trigger((EntityPlayer) entity, this, damagesource);
@@ -1662,16 +1865,22 @@
@@ -1662,16 +1878,22 @@
}
public boolean saveAsPassenger(NBTTagCompound nbttagcompound) {
@@ -327,7 +371,7 @@
return true;
}
}
@@ -1682,16 +1891,38 @@
@@ -1682,16 +1904,38 @@
}
public NBTTagCompound saveWithoutId(NBTTagCompound nbttagcompound) {
@@ -370,7 +414,7 @@
nbttagcompound.put("Rotation", this.newFloatList(this.getYRot(), this.getXRot()));
nbttagcompound.putFloat("FallDistance", this.fallDistance);
nbttagcompound.putShort("Fire", (short) this.remainingFireTicks);
@@ -1699,7 +1930,28 @@
@@ -1699,7 +1943,28 @@
nbttagcompound.putBoolean("OnGround", this.onGround());
nbttagcompound.putBoolean("Invulnerable", this.invulnerable);
nbttagcompound.putInt("PortalCooldown", this.portalCooldown);
@@ -400,7 +444,7 @@
IChatBaseComponent ichatbasecomponent = this.getCustomName();
if (ichatbasecomponent != null) {
@@ -1748,7 +2000,7 @@
@@ -1748,7 +2013,7 @@
nbttagcompound.put("Tags", nbttaglist);
}
@@ -409,7 +453,7 @@
if (this.isVehicle()) {
nbttaglist = new NBTTagList();
iterator = this.getPassengers().iterator();
@@ -1757,7 +2009,7 @@
@@ -1757,7 +2022,7 @@
Entity entity = (Entity) iterator.next();
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
@@ -418,7 +462,7 @@
nbttaglist.add(nbttagcompound1);
}
}
@@ -1767,6 +2019,11 @@
@@ -1767,6 +2032,11 @@
}
}
@@ -430,7 +474,7 @@
return nbttagcompound;
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT");
@@ -1850,6 +2107,45 @@
@@ -1850,6 +2120,45 @@
} else {
throw new IllegalStateException("Entity has invalid position");
}
@@ -476,7 +520,7 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Loading entity NBT");
CrashReportSystemDetails crashreportsystemdetails = crashreport.addCategory("Entity being loaded");
@@ -1871,6 +2167,12 @@
@@ -1871,6 +2180,12 @@
return entitytypes.canSerialize() && minecraftkey != null ? minecraftkey.toString() : null;
}
@@ -489,7 +533,7 @@
protected abstract void readAdditionalSaveData(NBTTagCompound nbttagcompound);
protected abstract void addAdditionalSaveData(NBTTagCompound nbttagcompound);
@@ -1925,9 +2227,22 @@
@@ -1925,9 +2240,22 @@
} else if (this.level().isClientSide) {
return null;
} else {
@@ -512,7 +556,7 @@
this.level().addFreshEntity(entityitem);
return entityitem;
}
@@ -2025,6 +2340,27 @@
@@ -2025,6 +2353,27 @@
if (!flag && (!this.canRide(entity) || !entity.canAddPassenger(this))) {
return false;
} else {
@@ -540,7 +584,7 @@
if (this.isPassenger()) {
this.stopRiding();
}
@@ -2058,7 +2394,7 @@
@@ -2058,7 +2407,7 @@
Entity entity = this.vehicle;
this.vehicle = null;
@@ -549,7 +593,7 @@
}
}
@@ -2089,10 +2425,38 @@
@@ -2089,10 +2438,38 @@
}
}
@@ -589,7 +633,7 @@
if (this.passengers.size() == 1 && this.passengers.get(0) == entity) {
this.passengers = ImmutableList.of();
} else {
@@ -2104,6 +2468,7 @@
@@ -2104,6 +2481,7 @@
entity.boardingCooldown = 60;
this.gameEvent(GameEvent.ENTITY_DISMOUNT, entity);
}
@@ -597,7 +641,7 @@
}
protected boolean canAddPassenger(Entity entity) {
@@ -2190,14 +2555,20 @@
@@ -2190,14 +2568,20 @@
if (this.isInsidePortal) {
MinecraftServer minecraftserver = worldserver.getServer();
@@ -621,7 +665,7 @@
this.level().getProfiler().pop();
}
@@ -2321,6 +2692,13 @@
@@ -2321,6 +2705,13 @@
}
public void setSwimming(boolean flag) {
@@ -635,7 +679,7 @@
this.setSharedFlag(4, flag);
}
@@ -2370,8 +2748,12 @@
@@ -2370,8 +2761,12 @@
return this.getTeam() != null ? this.getTeam().isAlliedTo(scoreboardteambase) : false;
}
@@ -649,7 +693,7 @@
}
public boolean getSharedFlag(int i) {
@@ -2390,7 +2772,7 @@
@@ -2390,7 +2785,7 @@
}
public int getMaxAirSupply() {
@@ -658,7 +702,7 @@
}
public int getAirSupply() {
@@ -2398,7 +2780,18 @@
@@ -2398,7 +2793,18 @@
}
public void setAirSupply(int i) {
@@ -678,7 +722,7 @@
}
public int getTicksFrozen() {
@@ -2425,11 +2818,40 @@
@@ -2425,11 +2831,40 @@
public void thunderHit(WorldServer worldserver, EntityLightning entitylightning) {
this.setRemainingFireTicks(this.remainingFireTicks + 1);
@@ -721,7 +765,7 @@
}
public void onAboveBubbleCol(boolean flag) {
@@ -2594,15 +3016,38 @@
@@ -2594,15 +3029,38 @@
@Nullable
public Entity changeDimension(WorldServer worldserver) {
@@ -762,7 +806,7 @@
this.level().getProfiler().popPush("reloading");
Entity entity = this.getType().create(worldserver);
@@ -2610,10 +3055,22 @@
@@ -2610,10 +3068,22 @@
entity.restoreFrom(this);
entity.moveTo(shapedetectorshape.pos.x, shapedetectorshape.pos.y, shapedetectorshape.pos.z, shapedetectorshape.yRot, entity.getXRot());
entity.setDeltaMovement(shapedetectorshape.speed);
@@ -788,7 +832,13 @@
}
this.removeAfterChangingDimensions();
@@ -2634,20 +3091,34 @@
@@ -2629,25 +3099,39 @@
}
protected void removeAfterChangingDimensions() {
- this.setRemoved(Entity.RemovalReason.CHANGED_DIMENSION);
+ this.setRemoved(Entity.RemovalReason.CHANGED_DIMENSION, null); // CraftBukkit - add Bukkit remove cause
}
@Nullable
protected ShapeDetectorShape findDimensionEntryPoint(WorldServer worldserver) {
@@ -828,7 +878,7 @@
IBlockData iblockdata = this.level().getBlockState(this.portalEntrancePos);
EnumDirection.EnumAxis enumdirection_enumaxis;
Vec3D vec3d;
@@ -2664,8 +3135,8 @@
@@ -2664,8 +3148,8 @@
vec3d = new Vec3D(0.5D, 0.0D, 0.0D);
}
@@ -839,7 +889,7 @@
}
} else {
BlockPosition blockposition1;
@@ -2675,8 +3146,14 @@
@@ -2675,8 +3159,14 @@
} else {
blockposition1 = worldserver.getHeightmapPos(HeightMap.Type.MOTION_BLOCKING_NO_LEAVES, worldserver.getSharedSpawnPos());
}
@@ -855,7 +905,7 @@
}
}
@@ -2684,8 +3161,23 @@
@@ -2684,8 +3174,23 @@
return BlockPortalShape.getRelativePosition(blockutil_rectangle, enumdirection_enumaxis, this.position(), this.getDimensions(this.getPose()));
}
@@ -881,7 +931,7 @@
}
public boolean canChangeDimensions() {
@@ -2806,6 +3298,12 @@
@@ -2806,6 +3311,12 @@
}
}
@@ -894,11 +944,13 @@
public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set<RelativeMovement> set, float f, float f1) {
float f2 = MathHelper.clamp(f1, -90.0F, 90.0F);
@@ -2825,7 +3323,11 @@
@@ -2824,8 +3335,12 @@
entity.restoreFrom(this);
entity.moveTo(d0, d1, d2, f, f2);
entity.setYHeadRot(f);
this.setRemoved(Entity.RemovalReason.CHANGED_DIMENSION);
- this.setRemoved(Entity.RemovalReason.CHANGED_DIMENSION);
- worldserver.addDuringTeleport(entity);
+ this.setRemoved(Entity.RemovalReason.CHANGED_DIMENSION, null); // CraftBukkit - add Bukkit remove cause
+ // CraftBukkit start - Don't spawn the new entity if the current entity isn't spawned
+ if (inWorld) {
+ worldserver.addDuringTeleport(entity);
@@ -907,7 +959,7 @@
}
return true;
@@ -2931,7 +3433,26 @@
@@ -2931,7 +3446,26 @@
}
public final void setBoundingBox(AxisAlignedBB axisalignedbb) {
@@ -935,7 +987,7 @@
}
protected float getEyeHeight(EntityPose entitypose, EntitySize entitysize) {
@@ -3246,6 +3767,11 @@
@@ -3246,6 +3780,11 @@
vec3d = vec3d.add(vec3d1);
++k1;
}
@@ -947,3 +999,18 @@
}
}
}
@@ -3517,6 +4056,14 @@
@Override
public final void setRemoved(Entity.RemovalReason entity_removalreason) {
+ // CraftBukkit start - add Bukkit remove cause
+ setRemoved(entity_removalreason, null);
+ }
+
+ @Override
+ public final void setRemoved(Entity.RemovalReason entity_removalreason, EntityRemoveEvent.Cause cause) {
+ CraftEventFactory.callEntityRemoveEvent(this, cause);
+ // CraftBukkit end
if (this.removalReason == null) {
this.removalReason = entity_removalreason;
}