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/item/EntityItem.java
+++ b/net/minecraft/world/entity/item/EntityItem.java
@@ -31,6 +31,14 @@
@@ -31,6 +31,15 @@
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.Vec3D;
@@ -9,13 +9,14 @@
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.entity.Player;
+import org.bukkit.event.entity.EntityPickupItemEvent;
+import org.bukkit.event.entity.EntityRemoveEvent;
+import org.bukkit.event.player.PlayerPickupItemEvent;
+// CraftBukkit end
+
public class EntityItem extends Entity implements TraceableEntity {
private static final DataWatcherObject<ItemStack> DATA_ITEM = DataWatcher.defineId(EntityItem.class, DataWatcherRegistry.ITEM_STACK);
@@ -47,6 +55,7 @@
@@ -47,6 +56,7 @@
@Nullable
public UUID target;
public final float bobOffs;
@@ -23,8 +24,12 @@
public EntityItem(EntityTypes<? extends EntityItem> entitytypes, World world) {
super(entitytypes, world);
@@ -128,9 +137,12 @@
this.discard();
@@ -125,12 +135,15 @@
@Override
public void tick() {
if (this.getItem().isEmpty()) {
- this.discard();
+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
} else {
super.tick();
- if (this.pickupDelay > 0 && this.pickupDelay != 32767) {
@@ -39,7 +44,7 @@
this.xo = this.getX();
this.yo = this.getY();
@@ -180,9 +192,11 @@
@@ -180,9 +193,11 @@
this.mergeWithNeighbours();
}
@@ -51,20 +56,22 @@
this.hasImpulse |= this.updateInWaterStateAndDoFluidPushing();
if (!this.level().isClientSide) {
@@ -194,6 +208,12 @@
@@ -194,7 +209,13 @@
}
if (!this.level().isClientSide && this.age >= 6000) {
- this.discard();
+ // CraftBukkit start - fire ItemDespawnEvent
+ if (CraftEventFactory.callItemDespawnEvent(this).isCancelled()) {
+ this.age = 0;
+ return;
+ }
+ // CraftBukkit end
this.discard();
+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
}
@@ -277,6 +297,11 @@
}
@@ -277,11 +298,16 @@
}
private static void merge(EntityItem entityitem, ItemStack itemstack, EntityItem entityitem1, ItemStack itemstack1) {
@@ -76,7 +83,13 @@
merge(entityitem, itemstack, itemstack1);
entityitem.pickupDelay = Math.max(entityitem.pickupDelay, entityitem1.pickupDelay);
entityitem.age = Math.min(entityitem.age, entityitem1.age);
@@ -302,6 +327,11 @@
if (itemstack1.isEmpty()) {
- entityitem1.discard();
+ entityitem1.discard(EntityRemoveEvent.Cause.MERGE); // CraftBukkit - add Bukkit remove cause);
}
}
@@ -302,12 +328,17 @@
} else if (this.level().isClientSide) {
return true;
} else {
@@ -88,7 +101,23 @@
this.markHurt();
this.health = (int) ((float) this.health - f);
this.gameEvent(GameEvent.ENTITY_DAMAGE, damagesource.getEntity());
@@ -366,6 +396,46 @@
if (this.health <= 0) {
this.getItem().onDestroyed(this);
- this.discard();
+ this.discard(EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause
}
return true;
@@ -354,7 +385,7 @@
this.setItem(ItemStack.of(nbttagcompound1));
if (this.getItem().isEmpty()) {
- this.discard();
+ this.discard(null); // CraftBukkit - add Bukkit remove cause
}
}
@@ -366,10 +397,50 @@
Item item = itemstack.getItem();
int i = itemstack.getCount();
@@ -135,3 +164,8 @@
if (this.pickupDelay == 0 && (this.target == null || this.target.equals(entityhuman.getUUID())) && entityhuman.getInventory().add(itemstack)) {
entityhuman.take(this, i);
if (itemstack.isEmpty()) {
- this.discard();
+ this.discard(EntityRemoveEvent.Cause.PICKUP); // CraftBukkit - add Bukkit remove cause
itemstack.setCount(i);
}