Update PlayerConnection method to latest spigot (Fixes right click bug, caused from old spigot code)

This commit is contained in:
Shaun Bennett 2014-09-02 20:33:00 -05:00
parent 08e6b73b1f
commit 9168de20da

View File

@ -736,25 +736,18 @@ public class PlayerConnection implements PacketPlayInListener
WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension);
// CraftBukkit start
if (this.player.dead)
return;
if (this.player.dead) return;
// This is a horrible hack needed because the client sends 2 packets on
// 'right mouse click'
// aimed at a block. We shouldn't need to get the second packet if the
// data is handled
// This is a horrible hack needed because the client sends 2 packets on 'right mouse click'
// aimed at a block. We shouldn't need to get the second packet if the data is handled
// but we cannot know what the client will do, so we might still get it
//
// If the time between packets is small enough, and the 'signature'
// similar, we discard the
// second one. This sadly has to remain until Mojang makes their packets
// saner. :(
// -- Grum
// If the time between packets is small enough, and the 'signature' similar, we discard the
// second one. This sadly has to remain until Mojang makes their packets saner. :(
// -- Grum
if (packetplayinblockplace.getFace() == 255)
{
if (packetplayinblockplace.getItemStack() != null
&& packetplayinblockplace.getItemStack().getItem() == this.lastMaterial && this.lastPacket != null
&& packetplayinblockplace.timestamp - this.lastPacket < 100)
if (packetplayinblockplace.getItemStack() != null && packetplayinblockplace.getItemStack().getItem() == this.lastMaterial && this.lastPacket != null && packetplayinblockplace.timestamp - this.lastPacket < 100)
{
this.lastPacket = null;
return;
@ -762,23 +755,14 @@ public class PlayerConnection implements PacketPlayInListener
}
else
{
this.lastMaterial = packetplayinblockplace.getItemStack() == null ? null : packetplayinblockplace
.getItemStack().getItem();
this.lastMaterial = packetplayinblockplace.getItemStack() == null ? null : packetplayinblockplace.getItemStack().getItem();
this.lastPacket = packetplayinblockplace.timestamp;
}
// 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
// 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.
boolean always = false;
// CraftBukkit end
// Spigot start
if (player.activeContainer != player.defaultContainer)
{
getPlayer().closeInventory();
}
// Spigot end
ItemStack itemstack = this.player.inventory.getItemInHand();
boolean flag = false;
@ -800,8 +784,7 @@ public class PlayerConnection implements PacketPlayInListener
// Spigot start - skip the event if throttled
if (!throttled)
{
org.bukkit.event.player.PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(
this.player, Action.RIGHT_CLICK_AIR, itemstack);
org.bukkit.event.player.PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.RIGHT_CLICK_AIR, itemstack);
if (event.useItemInHand() != Event.Result.DENY)
{
this.player.playerInteractManager.useItem(this.player, this.player.world, itemstack);
@ -809,20 +792,15 @@ public class PlayerConnection implements PacketPlayInListener
}
// Spigot end
// 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 doesn't
// cause the
// 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 doesn't cause the
// inventory update packet to get sent
always = (itemstack.count != itemstackAmount) || itemstack.getItem() == Item.getItemOf(Blocks.WATER_LILY);
// CraftBukkit end
}
else if (packetplayinblockplace.d() >= this.minecraftServer.getMaxBuildHeight() - 1
&& (packetplayinblockplace.getFace() == 1 || packetplayinblockplace.d() >= this.minecraftServer
.getMaxBuildHeight()))
else if (packetplayinblockplace.d() >= this.minecraftServer.getMaxBuildHeight() - 1 && (packetplayinblockplace.getFace() == 1 || packetplayinblockplace.d() >= this.minecraftServer.getMaxBuildHeight()))
{
ChatMessage chatmessage = new ChatMessage("build.tooHigh",
new Object[] { Integer.valueOf(this.minecraftServer.getMaxBuildHeight()) });
ChatMessage chatmessage = new ChatMessage("build.tooHigh", new Object[]{Integer.valueOf(this.minecraftServer.getMaxBuildHeight())});
chatmessage.getChatModifier().setColor(EnumChatFormat.RED);
this.player.playerConnection.sendPacket(new PacketPlayOutChat(chatmessage));
@ -830,23 +808,17 @@ public class PlayerConnection implements PacketPlayInListener
}
else
{
// CraftBukkit start - Check if we can actually do something over
// this large a distance
// CraftBukkit start - Check if we can actually do something over this large a distance
Location eyeLoc = this.getPlayer().getEyeLocation();
double reachDistance = NumberConversions.square(eyeLoc.getX() - i)
+ NumberConversions.square(eyeLoc.getY() - j) + NumberConversions.square(eyeLoc.getZ() - k);
if (reachDistance > (this.getPlayer().getGameMode() == org.bukkit.GameMode.CREATIVE ? CREATIVE_PLACE_DISTANCE_SQUARED
: SURVIVAL_PLACE_DISTANCE_SQUARED))
double reachDistance = NumberConversions.square(eyeLoc.getX() - i) + NumberConversions.square(eyeLoc.getY() - j) + NumberConversions.square(eyeLoc.getZ() - k);
if (reachDistance > (this.getPlayer().getGameMode() == org.bukkit.GameMode.CREATIVE ? CREATIVE_PLACE_DISTANCE_SQUARED : SURVIVAL_PLACE_DISTANCE_SQUARED))
{
return;
}
if (throttled
|| !this.player.playerInteractManager.interact(this.player, worldserver, itemstack, i, j, k, l,
packetplayinblockplace.h(), packetplayinblockplace.i(), packetplayinblockplace.j()))
if (throttled || !this.player.playerInteractManager.interact(this.player, worldserver, itemstack, i, j, k, l, packetplayinblockplace.h(), packetplayinblockplace.i(), packetplayinblockplace.j()))
{ // Spigot - skip the event if throttled
always = true; // force PacketPlayOutSetSlot to be sent to
// client to update ItemStack count
always = true; // force PacketPlayOutSetSlot to be sent to client to update ItemStack count
}
// CraftBukkit end
@ -899,21 +871,15 @@ public class PlayerConnection implements PacketPlayInListener
if (itemstack == null || itemstack.n() == 0)
{
this.player.g = true;
this.player.inventory.items[this.player.inventory.itemInHandIndex] = ItemStack
.b(this.player.inventory.items[this.player.inventory.itemInHandIndex]);
Slot slot = this.player.activeContainer.getSlot((IInventory) this.player.inventory,
this.player.inventory.itemInHandIndex);
this.player.inventory.items[this.player.inventory.itemInHandIndex] = ItemStack.b(this.player.inventory.items[this.player.inventory.itemInHandIndex]);
Slot slot = this.player.activeContainer.getSlot((IInventory) this.player.inventory, this.player.inventory.itemInHandIndex);
this.player.activeContainer.b();
this.player.g = false;
// CraftBukkit - TODO CHECK IF NEEDED -- new if structure might not
// need 'always'. Kept it in for now, but may be able to remove in
// future
if (!ItemStack.matches(this.player.inventory.getItemInHand(), packetplayinblockplace.getItemStack())
|| always)
// CraftBukkit - TODO CHECK IF NEEDED -- new if structure might not need 'always'. Kept it in for now, but may be able to remove in future
if (!ItemStack.matches(this.player.inventory.getItemInHand(), packetplayinblockplace.getItemStack()) || always)
{
this.sendPacket(new PacketPlayOutSetSlot(this.player.activeContainer.windowId, slot.rawSlotIndex,
this.player.inventory.getItemInHand()));
this.sendPacket(new PacketPlayOutSetSlot(this.player.activeContainer.windowId, slot.rawSlotIndex, this.player.inventory.getItemInHand()));
}
}
}