From 65c8df24b60443ee2c7932fd68d498694ec5ede2 Mon Sep 17 00:00:00 2001 From: durron597 Date: Sat, 8 Jan 2011 05:49:42 -0500 Subject: Partial Player Item, Block RightClick, Block Place --- .../net/minecraft/server/NetServerHandler.java | 119 +++++++++++++-------- 1 file changed, 74 insertions(+), 45 deletions(-) (limited to 'src/main/java/net/minecraft/server/NetServerHandler.java') diff --git a/src/main/java/net/minecraft/server/NetServerHandler.java b/src/main/java/net/minecraft/server/NetServerHandler.java index 0bdaa965..57eb5c46 100644 --- a/src/main/java/net/minecraft/server/NetServerHandler.java +++ b/src/main/java/net/minecraft/server/NetServerHandler.java @@ -2,13 +2,15 @@ package net.minecraft.server; import java.util.*; import java.util.logging.Logger; + +import org.bukkit.BlockFace; import org.bukkit.Location; import org.bukkit.craftbukkit.CraftBlock; import org.bukkit.craftbukkit.CraftItemStack; import org.bukkit.craftbukkit.CraftPlayer; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.event.Event.Type; -import org.bukkit.event.player.PlayerBlockItemEvent; +import org.bukkit.event.block.BlockRightClickedEvent; import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerItemEvent; import org.bukkit.event.player.PlayerMoveEvent; @@ -293,10 +295,40 @@ implements ICommandListener { d.e.B = false; } + // Craftbukkit start - store the last block right clicked and what type it was + CraftBlock lastRightClicked; + int lastMaterial; + public void a(Packet15Place packet15place) { ItemStack itemstack = e.an.e(); - boolean flag = d.e.B = d.f.g(e.aw); + // Craftbukkit we don't check spawn protection here anymore + /* boolean flag = */d.e.B = d.f.g(e.aw); + CraftBlock blockClicked = null; + BlockFace blockFace = null; + + if (packet15place.d == 255) { + // Craftbukkit ITEM_USE -- if we have a lastRightClicked then it could be a usable location + if (packet15place.e != null && packet15place.e.c == lastMaterial) { + blockClicked = lastRightClicked; + } else if (lastMaterial == 0) { + blockClicked = lastRightClicked; + } + lastRightClicked = null; + lastMaterial = 0; + } else { + // Craftbukkit RIGHTCLICK or BLOCK_PLACE .. or nothing + blockClicked = (CraftBlock) d.e.getWorld().getBlockAt(packet15place.a, packet15place.b, packet15place.c); + lastRightClicked = blockClicked; + lastMaterial = (packet15place.e == null) ? 0 : packet15place.e.c; + } + + if (blockClicked != null && itemstack != null) { + blockFace = CraftBlock.notchToBlockFace(packet15place.d); + } else { + blockFace = BlockFace.Self; + } + // Craftbukkit if rightclick decremented the item, always send the update packet. // this is not here for Craftbukkit's own functionality; rather it is to fix // a notch bug where the item doesn't update correctly. @@ -309,15 +341,24 @@ implements ICommandListener { CraftItemStack craftItem = new CraftItemStack(itemstack); CraftPlayer player = new CraftPlayer(server, e); - PlayerItemEvent pie = new PlayerItemEvent(Type.PLAYER_ITEM, player, craftItem); - - // We still call this event even in spawn protection. - server.getPluginManager().callEvent(pie); + PlayerItemEvent pie = new PlayerItemEvent(Type.PLAYER_ITEM, player, craftItem, blockClicked, blockFace); + // Craftbukkit We still call this event even in spawn protection. + // Don't call this event if using Buckets / signs + switch (craftItem.getType()) { + case Sign: + case Bucket: + case WaterBucket: + case LavaBucket: + server.getPluginManager().callEvent(pie); + } + if (!pie.isCancelled()) { int itemstackAmount = itemstack.a; e.c.a(e, d.e, itemstack); - // Craftbukkit notch decrements the counter by 1 in the above method with food, snowballs and so forth + // Craftbukkit notch decrements the counter by 1 in the above method with food, + // snowballs and so forth, but he does it in a place that doesnt cause the + // inventory update packet to get sent always = (itemstack.a != itemstackAmount); } } else { @@ -335,46 +376,34 @@ implements ICommandListener { // Craftbukkit start CraftItemStack craftItem = new CraftItemStack(itemstack); CraftPlayer player = new CraftPlayer(server, e); - CraftBlock blockClicked = (CraftBlock) d.e.getWorld().getBlockAt(l, i1, j1); - boolean canBuild = (i2 > 16) || flag; - PlayerBlockItemEvent pbie = new PlayerBlockItemEvent(Type.PLAYER_BLOCKITEM, player, craftItem, blockClicked, CraftBlock.notchToBlockFace(k1), canBuild); - - // We still call this event even in spawn protection. - server.getPluginManager().callEvent(pbie); +// boolean canBuild = (i2 > 16) || flag; + BlockRightClickedEvent brce = new BlockRightClickedEvent(Type.BLOCK_RIGHTCLICKED, blockClicked, blockFace, craftItem, player); + server.getPluginManager().callEvent(brce); - if (!pbie.isCancelled()) { - // Note: this is the spawn protection check - if (pbie.canBuild()) { - e.c.a(e, d.e, itemstack, l, i1, j1, k1); - } else { - // Craftbukkit This fixes another notch bug. No point in - // sending the block update packets when you weren't allowed to place! - d.e.B = false; - return; - } - - // These are the response packets back to the client - e.a.b(new Packet53BlockChange(l, i1, j1, d.e)); - if (k1 == 0) { - i1--; - } - if (k1 == 1) { - i1++; - } - if (k1 == 2) { - j1--; - } - if (k1 == 3) { - j1++; - } - if (k1 == 4) { - l--; - } - if (k1 == 5) { - l++; - } - e.a.b(new Packet53BlockChange(l, i1, j1, d.e)); + // Craftbukkit WE HAVE MOVED THE SPAWN PROTECTION CHECK DOWN INTO CLASS ItemBlock!!! + e.c.a(e, d.e, itemstack, l, i1, j1, k1); + + // These are the response packets back to the client + e.a.b(new Packet53BlockChange(l, i1, j1, d.e)); + if (k1 == 0) { + i1--; + } + if (k1 == 1) { + i1++; + } + if (k1 == 2) { + j1--; + } + if (k1 == 3) { + j1++; + } + if (k1 == 4) { + l--; + } + if (k1 == 5) { + l++; } + e.a.b(new Packet53BlockChange(l, i1, j1, d.e)); } if (itemstack != null && itemstack.a == 0) { e.an.a[e.an.c] = null; -- cgit v1.2.3