SPIGOT-4597: Make BlockDropItemEvent use a list

This commit is contained in:
md_5 2019-01-30 11:20:39 +11:00
parent 1734f378f7
commit ed274c517f
2 changed files with 26 additions and 30 deletions

View file

@ -82,8 +82,8 @@
f = iblockdata.getDamage(this.player, this.player.world, blockposition); f = iblockdata.getDamage(this.player, this.player.world, blockposition);
+ // Allow fire punching to be blocked + // Allow fire punching to be blocked
+ this.world.douseFire((EntityHuman) null, blockposition, enumdirection); + this.world.douseFire((EntityHuman) null, blockposition, enumdirection);
} + }
+
+ if (event.useItemInHand() == Event.Result.DENY) { + if (event.useItemInHand() == Event.Result.DENY) {
+ // If we 'insta destroyed' then the client needs to be informed. + // If we 'insta destroyed' then the client needs to be informed.
+ if (f > 1.0f) { + if (f > 1.0f) {
@ -97,8 +97,8 @@
+ // Let the client know the block still exists + // Let the client know the block still exists
+ ((EntityPlayer) this.player).playerConnection.sendPacket(new PacketPlayOutBlockChange(this.world, blockposition)); + ((EntityPlayer) this.player).playerConnection.sendPacket(new PacketPlayOutBlockChange(this.world, blockposition));
+ return; + return;
+ } }
+
+ if (blockEvent.getInstaBreak()) { + if (blockEvent.getInstaBreak()) {
+ f = 2.0f; + f = 2.0f;
+ } + }
@ -126,7 +126,7 @@
} }
} }
@@ -190,13 +252,97 @@ @@ -190,13 +252,93 @@
public boolean breakBlock(BlockPosition blockposition) { public boolean breakBlock(BlockPosition blockposition) {
IBlockData iblockdata = this.world.getType(blockposition); IBlockData iblockdata = this.world.getType(blockposition);
@ -175,13 +175,13 @@
+ } + }
+ // Let the client know the block still exists + // Let the client know the block still exists
+ ((EntityPlayer) this.player).playerConnection.sendPacket(new PacketPlayOutBlockChange(this.world, blockposition)); + ((EntityPlayer) this.player).playerConnection.sendPacket(new PacketPlayOutBlockChange(this.world, blockposition));
+
- if (!this.player.getItemInMainHand().getItem().a(iblockdata, this.world, blockposition, (EntityHuman) this.player)) {
+ // Brute force all possible updates + // Brute force all possible updates
+ for (EnumDirection dir : EnumDirection.values()) { + for (EnumDirection dir : EnumDirection.values()) {
+ ((EntityPlayer) this.player).playerConnection.sendPacket(new PacketPlayOutBlockChange(world, blockposition.shift(dir))); + ((EntityPlayer) this.player).playerConnection.sendPacket(new PacketPlayOutBlockChange(world, blockposition.shift(dir)));
+ } + }
+
- if (!this.player.getItemInMainHand().getItem().a(iblockdata, this.world, blockposition, (EntityHuman) this.player)) {
+ // Update any tile entity data for this block + // Update any tile entity data for this block
+ TileEntity tileentity = this.world.getTileEntity(blockposition); + TileEntity tileentity = this.world.getTileEntity(blockposition);
+ if (tileentity != null) { + if (tileentity != null) {
@ -210,11 +210,7 @@
+ boolean flag = this.c(blockposition); + boolean flag = this.c(blockposition);
+ +
+ if (event.isDropItems()) { + if (event.isDropItems()) {
+ for (EntityItem item : world.captureDrops) { + org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockDropItemEvent(bblock, state, this.player, world.captureDrops);
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callBlockDropItemEvent(bblock, state, this.player, item).isCancelled()) {
+ world.addEntity(item);
+ }
+ }
+ } + }
+ +
+ world.captureDrops = null; + world.captureDrops = null;
@ -225,7 +221,7 @@
if ((block instanceof BlockCommand || block instanceof BlockStructure) && !this.player.isCreativeAndOp()) { if ((block instanceof BlockCommand || block instanceof BlockStructure) && !this.player.isCreativeAndOp()) {
this.world.notify(blockposition, iblockdata, iblockdata, 3); this.world.notify(blockposition, iblockdata, iblockdata, 3);
return false; return false;
@@ -221,6 +367,10 @@ @@ -221,6 +363,10 @@
} }
} }
@ -236,7 +232,7 @@
boolean flag = this.c(blockposition); boolean flag = this.c(blockposition);
if (!this.isCreative()) { if (!this.isCreative()) {
@@ -228,13 +378,31 @@ @@ -228,12 +374,26 @@
boolean flag1 = this.player.hasBlock(iblockdata); boolean flag1 = this.player.hasBlock(iblockdata);
itemstack1.a(this.world, iblockdata, blockposition, this.player); itemstack1.a(this.world, iblockdata, blockposition, this.player);
@ -248,15 +244,11 @@
iblockdata.getBlock().a(this.world, this.player, blockposition, iblockdata, tileentity, itemstack2); iblockdata.getBlock().a(this.world, this.player, blockposition, iblockdata, tileentity, itemstack2);
} }
+ // CraftBukkit end + // CraftBukkit end
} + }
+
+ if (event.isDropItems()) { + if (event.isDropItems()) {
+ for (EntityItem item : world.captureDrops) { + org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockDropItemEvent(bblock, state, this.player, world.captureDrops);
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callBlockDropItemEvent(bblock, state, this.player, item).isCancelled()) { }
+ world.addEntity(item);
+ }
+ }
+ }
+ world.captureDrops = null; + world.captureDrops = null;
+ // CraftBukkit end + // CraftBukkit end
+ +
@ -265,11 +257,10 @@
+ iblockdata.getBlock().dropExperience(this.world, blockposition, event.getExpToDrop()); + iblockdata.getBlock().dropExperience(this.world, blockposition, event.getExpToDrop());
+ } + }
+ // CraftBukkit end + // CraftBukkit end
+
return flag; return flag;
} }
} @@ -277,11 +437,40 @@
@@ -277,11 +445,40 @@
} }
} }
@ -310,7 +301,7 @@
if (tileentity instanceof ITileInventory) { if (tileentity instanceof ITileInventory) {
Block block = iblockdata.getBlock(); Block block = iblockdata.getBlock();
@@ -305,24 +502,26 @@ @@ -305,24 +494,26 @@
boolean flag = !entityhuman.getItemInMainHand().isEmpty() || !entityhuman.getItemInOffHand().isEmpty(); boolean flag = !entityhuman.getItemInMainHand().isEmpty() || !entityhuman.getItemInOffHand().isEmpty();
boolean flag1 = entityhuman.isSneaking() && flag; boolean flag1 = entityhuman.isSneaking() && flag;

View file

@ -10,6 +10,7 @@ import javax.annotation.Nullable;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Functions; import com.google.common.base.Functions;
import com.google.common.collect.Lists;
import net.minecraft.server.*; import net.minecraft.server.*;
@ -198,11 +199,15 @@ public class CraftEventFactory {
return event; return event;
} }
public static BlockDropItemEvent callBlockDropItemEvent(Block block, BlockState state, EntityPlayer player, EntityItem item) { public static void handleBlockDropItemEvent(Block block, BlockState state, EntityPlayer player, List<EntityItem> items) {
BlockDropItemEvent event = new BlockDropItemEvent(block, state, player.getBukkitEntity(), (org.bukkit.entity.Item) item.getBukkitEntity()); BlockDropItemEvent event = new BlockDropItemEvent(block, state, player.getBukkitEntity(), Lists.transform(items, (item) -> (org.bukkit.entity.Item) item.getBukkitEntity()));
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
return event; if (!event.isCancelled()) {
for (EntityItem item : items) {
item.world.addEntity(item);
}
}
} }
public static EntityPlaceEvent callEntityPlaceEvent(ItemActionContext itemactioncontext, Entity entity) { public static EntityPlaceEvent callEntityPlaceEvent(ItemActionContext itemactioncontext, Entity entity) {