SPIGOT-5794: Only skip interact event if position, hand and itemstack are equal

This commit is contained in:
Brokkonaut 2020-09-12 08:36:10 +10:00 committed by md_5
parent bf3d720714
commit 6f55306c44
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
2 changed files with 13 additions and 7 deletions

View File

@ -717,14 +717,14 @@
+ org.bukkit.event.player.PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.RIGHT_CLICK_AIR, itemstack, enumhand);
+ cancelled = event.useItemInHand() == Event.Result.DENY;
+ } else {
+ if (player.playerInteractManager.firedInteract) {
+ player.playerInteractManager.firedInteract = false;
+ MovingObjectPositionBlock movingobjectpositionblock = (MovingObjectPositionBlock) movingobjectposition;
+ if (player.playerInteractManager.firedInteract && player.playerInteractManager.interactPosition.equals(movingobjectpositionblock.getBlockPosition()) && player.playerInteractManager.interactHand == enumhand && ItemStack.equals(player.playerInteractManager.interactItemStack, itemstack)) {
+ cancelled = player.playerInteractManager.interactResult;
+ } else {
+ MovingObjectPositionBlock movingobjectpositionblock = (MovingObjectPositionBlock) movingobjectposition;
+ org.bukkit.event.player.PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, movingobjectpositionblock.getBlockPosition(), movingobjectpositionblock.getDirection(), itemstack, true, enumhand);
+ cancelled = event.useItemInHand() == Event.Result.DENY;
+ }
+ player.playerInteractManager.firedInteract = false;
+ }
+
+ if (cancelled) {

View File

@ -243,13 +243,16 @@
}
}
}
@@ -287,12 +423,40 @@
@@ -287,12 +423,46 @@
}
}
+ // CraftBukkit start - whole method
+ public boolean interactResult = false;
+ public boolean firedInteract = false;
+ public BlockPosition interactPosition;
+ public EnumHand interactHand;
+ public ItemStack interactItemStack;
public EnumInteractionResult a(EntityPlayer entityplayer, World world, ItemStack itemstack, EnumHand enumhand, MovingObjectPositionBlock movingobjectpositionblock) {
BlockPosition blockposition = movingobjectpositionblock.getBlockPosition();
IBlockData iblockdata = world.getType(blockposition);
@ -268,6 +271,9 @@
+ PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(entityplayer, Action.RIGHT_CLICK_BLOCK, blockposition, movingobjectpositionblock.getDirection(), itemstack, cancelledBlock, enumhand);
+ firedInteract = true;
+ interactResult = event.useItemInHand() == Event.Result.DENY;
+ interactPosition = blockposition.immutableCopy();
+ interactHand = enumhand;
+ interactItemStack = itemstack.cloneItemStack();
+
+ if (event.useInteractedBlock() == Event.Result.DENY) {
+ // If we denied a door from opening, we need to send a correcting update to the client, as it already opened the door.
@ -284,7 +290,7 @@
if (itileinventory != null) {
entityplayer.openContainer(itileinventory);
@@ -306,7 +470,7 @@
@@ -306,7 +476,7 @@
ItemStack itemstack1 = itemstack.cloneItemStack();
if (!flag1) {
@ -293,7 +299,7 @@
if (enuminteractionresult.a()) {
CriterionTriggers.M.a(entityplayer, blockposition, itemstack1);
@@ -314,17 +478,17 @@
@@ -314,17 +484,17 @@
}
}
@ -314,7 +320,7 @@
}
if (enuminteractionresult1.a()) {
@@ -332,10 +496,10 @@
@@ -332,10 +502,10 @@
}
return enuminteractionresult1;