Archiviert
13
0

SPIGOT-4597: Make BlockDropItemEvent use a list

Dieser Commit ist enthalten in:
md_5 2019-01-30 11:20:39 +11:00
Ursprung 1734f378f7
Commit ed274c517f
2 geänderte Dateien mit 26 neuen und 30 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

@ -10,6 +10,7 @@ import javax.annotation.Nullable;
import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.collect.Lists;
import net.minecraft.server.*;
@ -198,11 +199,15 @@ public class CraftEventFactory {
return event;
}
public static BlockDropItemEvent callBlockDropItemEvent(Block block, BlockState state, EntityPlayer player, EntityItem item) {
BlockDropItemEvent event = new BlockDropItemEvent(block, state, player.getBukkitEntity(), (org.bukkit.entity.Item) item.getBukkitEntity());
public static void handleBlockDropItemEvent(Block block, BlockState state, EntityPlayer player, List<EntityItem> items) {
BlockDropItemEvent event = new BlockDropItemEvent(block, state, player.getBukkitEntity(), Lists.transform(items, (item) -> (org.bukkit.entity.Item) item.getBukkitEntity()));
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) {