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,17 @@
--- a/net/minecraft/world/level/block/entity/TileEntityBeehive.java
+++ b/net/minecraft/world/level/block/entity/TileEntityBeehive.java
@@ -43,6 +43,7 @@
@@ -27,6 +27,10 @@
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.level.gameevent.GameEvent;
+// CraftBukkit start
+import org.bukkit.event.entity.EntityRemoveEvent;
+// CraftBukkit end
+
public class TileEntityBeehive extends TileEntity {
public static final String TAG_FLOWER_POS = "FlowerPos";
@@ -43,6 +47,7 @@
private final List<TileEntityBeehive.HiveBee> stored = Lists.newArrayList();
@Nullable
public BlockPosition savedFlowerPos;
@@ -8,7 +19,7 @@
public TileEntityBeehive(BlockPosition blockposition, IBlockData iblockdata) {
super(TileEntityTypes.BEEHIVE, blockposition, iblockdata);
@@ -82,7 +83,7 @@
@@ -82,7 +87,7 @@
}
public boolean isFull() {
@@ -17,7 +28,7 @@
}
public void emptyAllLivingFromHive(@Nullable EntityHuman entityhuman, IBlockData iblockdata, TileEntityBeehive.ReleaseStatus tileentitybeehive_releasestatus) {
@@ -99,7 +100,7 @@
@@ -99,7 +104,7 @@
if (entityhuman.position().distanceToSqr(entity.position()) <= 16.0D) {
if (!this.isSedated()) {
@@ -26,7 +37,7 @@
} else {
entitybee.setStayOutOfHiveCountdown(400);
}
@@ -111,10 +112,16 @@
@@ -111,10 +116,16 @@
}
private List<Entity> releaseAllOccupants(IBlockData iblockdata, TileEntityBeehive.ReleaseStatus tileentitybeehive_releasestatus) {
@@ -44,7 +55,7 @@
});
if (!list.isEmpty()) {
super.setChanged();
@@ -142,7 +149,19 @@
@@ -142,7 +153,19 @@
}
public void addOccupantWithPresetTicks(Entity entity, boolean flag, int i) {
@@ -65,7 +76,16 @@
entity.stopRiding();
entity.ejectPassengers();
NBTTagCompound nbttagcompound = new NBTTagCompound();
@@ -174,7 +193,13 @@
@@ -164,7 +187,7 @@
this.level.gameEvent(GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(entity, this.getBlockState()));
}
- entity.discard();
+ entity.discard(EntityRemoveEvent.Cause.ENTER_BLOCK); // CraftBukkit - add Bukkit remove cause
super.setChanged();
}
}
@@ -174,7 +197,13 @@
}
private static boolean releaseOccupant(World world, BlockPosition blockposition, IBlockData iblockdata, TileEntityBeehive.HiveBee tileentitybeehive_hivebee, @Nullable List<Entity> list, TileEntityBeehive.ReleaseStatus tileentitybeehive_releasestatus, @Nullable BlockPosition blockposition1) {
@@ -80,7 +100,7 @@
return false;
} else {
NBTTagCompound nbttagcompound = tileentitybeehive_hivebee.entityData.copy();
@@ -197,6 +222,18 @@
@@ -197,6 +226,18 @@
if (!entity.getType().is(TagsEntity.BEEHIVE_INHABITORS)) {
return false;
} else {
@@ -99,7 +119,7 @@
if (entity instanceof EntityBee) {
EntityBee entitybee = (EntityBee) entity;
@@ -228,6 +265,7 @@
@@ -228,6 +269,7 @@
list.add(entitybee);
}
@@ -107,7 +127,7 @@
float f = entity.getBbWidth();
double d0 = flag ? 0.0D : 0.55D + (double) (f / 2.0F);
double d1 = (double) blockposition.getX() + 0.5D + d0 * (double) enumdirection.getStepX();
@@ -235,11 +273,12 @@
@@ -235,11 +277,12 @@
double d3 = (double) blockposition.getZ() + 0.5D + d0 * (double) enumdirection.getStepZ();
entity.moveTo(d1, d2, d3, entity.getYRot(), entity.getXRot());
@@ -121,7 +141,7 @@
}
} else {
return false;
@@ -288,6 +327,10 @@
@@ -288,6 +331,10 @@
if (releaseOccupant(world, blockposition, iblockdata, tileentitybeehive_hivebee, (List) null, tileentitybeehive_releasestatus, blockposition1)) {
flag = true;
iterator.remove();
@@ -132,7 +152,7 @@
}
}
}
@@ -329,6 +372,11 @@
@@ -329,6 +376,11 @@
this.savedFlowerPos = GameProfileSerializer.readBlockPos(nbttagcompound.getCompound("FlowerPos"));
}
@@ -144,7 +164,7 @@
}
@Override
@@ -338,6 +386,7 @@
@@ -338,6 +390,7 @@
if (this.hasSavedFlowerPos()) {
nbttagcompound.put("FlowerPos", GameProfileSerializer.writeBlockPos(this.savedFlowerPos));
}

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/world/level/block/entity/TileEntityEndGateway.java
+++ b/net/minecraft/world/level/block/entity/TileEntityEndGateway.java
@@ -33,6 +33,14 @@
@@ -33,6 +33,15 @@
import net.minecraft.world.phys.Vec3D;
import org.slf4j.Logger;
@@ -9,13 +9,14 @@
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.entity.CraftPlayer;
+import org.bukkit.craftbukkit.util.CraftLocation;
+import org.bukkit.event.entity.EntityRemoveEvent;
+import org.bukkit.event.player.PlayerTeleportEvent;
+// CraftBukkit end
+
public class TileEntityEndGateway extends TileEntityEnderPortal {
private static final Logger LOGGER = LogUtils.getLogger();
@@ -169,7 +177,7 @@
@@ -169,7 +178,7 @@
tileentityendgateway.teleportCooldown = 100;
BlockPosition blockposition1;
@@ -24,7 +25,16 @@
blockposition1 = findOrCreateValidTeleportPos(worldserver, blockposition);
blockposition1 = blockposition1.above(10);
TileEntityEndGateway.LOGGER.debug("Creating portal at {}", blockposition1);
@@ -198,8 +206,34 @@
@@ -190,7 +199,7 @@
if (entity2 != null) {
entity1 = entity2;
- entity.discard();
+ entity.discard(EntityRemoveEvent.Cause.HIT); // CraftBukkit - add Bukkit remove cause
} else {
entity1 = entity;
}
@@ -198,8 +207,34 @@
entity1 = entity.getRootVehicle();
}

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/world/level/block/entity/TileEntityHopper.java
+++ b/net/minecraft/world/level/block/entity/TileEntityHopper.java
@@ -32,6 +32,21 @@
@@ -32,6 +32,22 @@
import net.minecraft.world.phys.shapes.OperatorBoolean;
import net.minecraft.world.phys.shapes.VoxelShapes;
@@ -13,6 +13,7 @@
+import org.bukkit.craftbukkit.inventory.CraftInventory;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.event.entity.EntityRemoveEvent;
+import org.bukkit.event.inventory.HopperInventorySearchEvent;
+import org.bukkit.event.inventory.InventoryMoveItemEvent;
+import org.bukkit.event.inventory.InventoryPickupItemEvent;
@@ -22,7 +23,7 @@
public class TileEntityHopper extends TileEntityLootable implements IHopper {
public static final int MOVE_ITEM_SPEED = 8;
@@ -40,6 +55,36 @@
@@ -40,6 +56,36 @@
private int cooldownTime;
private long tickedGameTime;
@@ -59,7 +60,7 @@
public TileEntityHopper(BlockPosition blockposition, IBlockData iblockdata) {
super(TileEntityTypes.HOPPER, blockposition, iblockdata);
this.items = NonNullList.withSize(5, ItemStack.EMPTY);
@@ -113,7 +158,7 @@
@@ -113,7 +159,7 @@
boolean flag = false;
if (!tileentityhopper.isEmpty()) {
@@ -68,7 +69,7 @@
}
if (!tileentityhopper.inventoryFull()) {
@@ -147,7 +192,7 @@
@@ -147,7 +193,7 @@
return false;
}
@@ -77,7 +78,7 @@
IInventory iinventory1 = getAttachedContainer(world, blockposition, iblockdata);
if (iinventory1 == null) {
@@ -161,7 +206,30 @@
@@ -161,7 +207,30 @@
for (int i = 0; i < iinventory.getContainerSize(); ++i) {
if (!iinventory.getItem(i).isEmpty()) {
ItemStack itemstack = iinventory.getItem(i).copy();
@@ -109,7 +110,7 @@
if (itemstack1.isEmpty()) {
iinventory1.setChanged();
@@ -226,7 +294,34 @@
@@ -226,7 +295,34 @@
if (!itemstack.isEmpty() && canTakeItemFromContainer(ihopper, iinventory, itemstack, i, enumdirection)) {
ItemStack itemstack1 = itemstack.copy();
@@ -145,7 +146,7 @@
if (itemstack2.isEmpty()) {
iinventory.setChanged();
@@ -241,6 +336,13 @@
@@ -241,13 +337,20 @@
public static boolean addItem(IInventory iinventory, EntityItem entityitem) {
boolean flag = false;
@@ -159,7 +160,15 @@
ItemStack itemstack = entityitem.getItem().copy();
ItemStack itemstack1 = addItem((IInventory) null, iinventory, itemstack, (EnumDirection) null);
@@ -367,16 +469,40 @@
if (itemstack1.isEmpty()) {
flag = true;
entityitem.setItem(ItemStack.EMPTY);
- entityitem.discard();
+ entityitem.discard(EntityRemoveEvent.Cause.PICKUP); // CraftBukkit - add Bukkit remove cause
} else {
entityitem.setItem(itemstack1);
}
@@ -367,16 +470,40 @@
return itemstack;
}