summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/NetServerHandler.java
diff options
context:
space:
mode:
authordurron597 <martin.jared@gmail.com>2011-01-08 05:49:42 -0500
committerdurron597 <martin.jared@gmail.com>2011-01-08 05:50:35 -0500
commit65c8df24b60443ee2c7932fd68d498694ec5ede2 (patch)
tree34865b5bffb40e1ea7f9a3b2f985776e6a24de11 /src/main/java/net/minecraft/server/NetServerHandler.java
parentf71e2b4ed3c6877b1a622d33afd80838d2fa9f35 (diff)
downloadcraftbukkit-65c8df24b60443ee2c7932fd68d498694ec5ede2.tar
craftbukkit-65c8df24b60443ee2c7932fd68d498694ec5ede2.tar.gz
craftbukkit-65c8df24b60443ee2c7932fd68d498694ec5ede2.tar.lz
craftbukkit-65c8df24b60443ee2c7932fd68d498694ec5ede2.tar.xz
craftbukkit-65c8df24b60443ee2c7932fd68d498694ec5ede2.zip
Partial Player Item, Block RightClick, Block Place
Diffstat (limited to 'src/main/java/net/minecraft/server/NetServerHandler.java')
-rw-r--r--src/main/java/net/minecraft/server/NetServerHandler.java119
1 files changed, 74 insertions, 45 deletions
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;