summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorWesley Wolfe <weswolf@aol.com>2013-07-23 21:39:30 -0500
committerWesley Wolfe <weswolf@aol.com>2013-07-23 21:52:31 -0500
commite88cea8402eb1ab94249c10e298c43875ac8b17f (patch)
tree36256e18946d7e8fc3350bd3e6e523976a236681 /src/main
parent1192f2a53a20354e7d2292a1c710d6bfe779b600 (diff)
downloadcraftbukkit-e88cea8402eb1ab94249c10e298c43875ac8b17f.tar
craftbukkit-e88cea8402eb1ab94249c10e298c43875ac8b17f.tar.gz
craftbukkit-e88cea8402eb1ab94249c10e298c43875ac8b17f.tar.lz
craftbukkit-e88cea8402eb1ab94249c10e298c43875ac8b17f.tar.xz
craftbukkit-e88cea8402eb1ab94249c10e298c43875ac8b17f.zip
Check interactable items before event. Fixes BUKKIT-4576
Items that cause entities to change state, including tags, chest, and leashes, do not update the client properly following the firing of PlayerInteractEntityEvent. This change makes the item checks occur before the event fires, to concur with the client's assumptions.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/net/minecraft/server/PlayerConnection.java26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
index ff685d59..6aa7a21b 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -24,7 +24,6 @@ import org.bukkit.craftbukkit.util.Waitable;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.craftbukkit.event.CraftEventFactory;
-import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
@@ -35,7 +34,6 @@ import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCreativeEvent;
-import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryType.SlotType;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerAnimationEvent;
@@ -1083,18 +1081,26 @@ public class PlayerConnection extends Connection {
ItemStack itemInHand = this.player.inventory.getItemInHand(); // CraftBukkit
if (packet7useentity.action == 0) {
// CraftBukkit start
+ boolean triggerTagUpdate = itemInHand != null && itemInHand.id == Item.NAME_TAG.id && entity instanceof EntityInsentient;
+ boolean triggerChestUpdate = itemInHand != null && itemInHand.id == Block.CHEST.id && entity instanceof EntityHorse;
+ boolean triggerLeashUpdate = itemInHand != null && itemInHand.id == Item.LEASH.id && entity instanceof EntityInsentient;
PlayerInteractEntityEvent event = new PlayerInteractEntityEvent((Player) this.getPlayer(), entity.getBukkitEntity());
this.server.getPluginManager().callEvent(event);
+ if (triggerLeashUpdate && (event.isCancelled() || this.player.inventory.getItemInHand() == null || this.player.inventory.getItemInHand().id != Item.LEASH.id)) {
+ // Refresh the current leash state
+ this.sendPacket(new Packet39AttachEntity(1, entity, ((EntityInsentient) entity).bI()));
+ }
+
+ if (triggerTagUpdate && (event.isCancelled() || this.player.inventory.getItemInHand() == null || this.player.inventory.getItemInHand().id != Item.NAME_TAG.id)) {
+ // Refresh the current entity metadata
+ this.sendPacket(new Packet40EntityMetadata(entity.id, entity.datawatcher, true));
+ }
+ if (triggerChestUpdate && (event.isCancelled() || this.player.inventory.getItemInHand() == null || this.player.inventory.getItemInHand().id != Block.CHEST.id)) {
+ this.sendPacket(new Packet40EntityMetadata(entity.id, entity.datawatcher, true));
+ }
+
if (event.isCancelled()) {
- if (itemInHand != null && itemInHand.id == Item.LEASH.id && entity instanceof EntityInsentient) {
- // Refresh the current leash state
- this.sendPacket(new Packet39AttachEntity(1, entity, ((EntityInsentient) entity).bI()));
- }
- if (itemInHand != null && itemInHand.id == Item.NAME_TAG.id && entity instanceof EntityInsentient) {
- // Refresh the current entity metadata
- this.sendPacket(new Packet40EntityMetadata(entity.id, entity.datawatcher, true));
- }
return;
}
// CraftBukkit end