mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-11 09:23:42 +01:00
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.
This commit is contained in:
parent
1192f2a53a
commit
e88cea8402
1 changed files with 16 additions and 10 deletions
|
@ -24,7 +24,6 @@ import org.bukkit.craftbukkit.util.Waitable;
|
||||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||||
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event;
|
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.InventoryAction;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.inventory.InventoryCreativeEvent;
|
import org.bukkit.event.inventory.InventoryCreativeEvent;
|
||||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
|
||||||
import org.bukkit.event.inventory.InventoryType.SlotType;
|
import org.bukkit.event.inventory.InventoryType.SlotType;
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
import org.bukkit.event.player.PlayerAnimationEvent;
|
import org.bukkit.event.player.PlayerAnimationEvent;
|
||||||
|
@ -1083,18 +1081,26 @@ public class PlayerConnection extends Connection {
|
||||||
ItemStack itemInHand = this.player.inventory.getItemInHand(); // CraftBukkit
|
ItemStack itemInHand = this.player.inventory.getItemInHand(); // CraftBukkit
|
||||||
if (packet7useentity.action == 0) {
|
if (packet7useentity.action == 0) {
|
||||||
// CraftBukkit start
|
// 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());
|
PlayerInteractEntityEvent event = new PlayerInteractEntityEvent((Player) this.getPlayer(), entity.getBukkitEntity());
|
||||||
this.server.getPluginManager().callEvent(event);
|
this.server.getPluginManager().callEvent(event);
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
if (triggerLeashUpdate && (event.isCancelled() || this.player.inventory.getItemInHand() == null || this.player.inventory.getItemInHand().id != Item.LEASH.id)) {
|
||||||
if (itemInHand != null && itemInHand.id == Item.LEASH.id && entity instanceof EntityInsentient) {
|
|
||||||
// Refresh the current leash state
|
// Refresh the current leash state
|
||||||
this.sendPacket(new Packet39AttachEntity(1, entity, ((EntityInsentient) entity).bI()));
|
this.sendPacket(new Packet39AttachEntity(1, entity, ((EntityInsentient) entity).bI()));
|
||||||
}
|
}
|
||||||
if (itemInHand != null && itemInHand.id == Item.NAME_TAG.id && entity instanceof EntityInsentient) {
|
|
||||||
|
if (triggerTagUpdate && (event.isCancelled() || this.player.inventory.getItemInHand() == null || this.player.inventory.getItemInHand().id != Item.NAME_TAG.id)) {
|
||||||
// Refresh the current entity metadata
|
// Refresh the current entity metadata
|
||||||
this.sendPacket(new Packet40EntityMetadata(entity.id, entity.datawatcher, true));
|
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()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
|
|
Loading…
Reference in a new issue