[SPIGOT-4697] PlayerInteractEvent#hasItem returns false for shovel Created: 12/Apr/19  Updated: 14/Apr/19  Resolved: 14/Apr/19

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Alex Kingston Assignee: Unassigned
Resolution: Cannot Reproduce Votes: 0
Labels: PlayerInteractEvent, bug, hasItem, shovel

Version: git-Spigot-f09662d-7c395d4
Guidelines Read: Yes

 Description   

It is really weird:

PlayerInteractEvent#hasItem returns false for stone shovel while Material#STONE_SHOVEL#isItem returns true. See my code for clearer understanding.

if (!e.getAction().equals(Action.RIGHT_CLICK_BLOCK) || !e.hasBlock() || !e.hasItem())

{ new DebugMessage("Event cancelled because of no right-click/block/item"); #fired if (e.hasBlock()) new DebugMessage("Event got block!"); #fired if (e.hasItem()) new DebugMessage("Event got item!"); #did not fire if (Material.STONE_SHOVEL.isItem()) new DebugMessage("Stone_Shovel is item!"); #fired }

 

I added comments on which fired and which not (new DebugMessage is just a console message)

 

Please note that this bug persists for all other shovel types.

 



 Comments   
Comment by md_5 [ 14/Apr/19 ]

You are likely forgetting about each hand.

See the below debug:
[12:38:48 INFO]: true org.bukkit.event.player.PlayerInteractEvent@7eed54fa[item=ItemStack

{STONE_SHOVEL x 1}

,action=RIGHT_CLICK_BLOCK,blockClicked=CraftBlock{pos=BlockPosition

{x=71, y=1, z=-125},type=STONE_BRICKS,data=Block{minecraft:stone_bricks},fluid=net.minecraft.server.FluidTypeEmpty@2c5d601e},blockFace=UP,useClickedBlock=ALLOW,useItemInHand=DEFAULT,hand=HAND,player=CraftPlayer{name=md_5},name=<null>,async=false]
[12:38:48 INFO]: false org.bukkit.event.player.PlayerInteractEvent@4432ce57[item=<null>,action=RIGHT_CLICK_BLOCK,blockClicked=CraftBlock{pos=BlockPosition{x=71, y=1, z=-125}

,type=STONE_BRICKS,data=Block

{minecraft:stone_bricks}

,fluid=net.minecraft.server.FluidTypeEmpty@2c5d601e},blockFace=UP,useClickedBlock=ALLOW,useItemInHand=DEFAULT,hand=OFF_HAND,player=CraftPlayer

{name=md_5}

,name=<null>,async=false]

Note I only have an item in my main hand, so it is true for that and false for the off hand.

Comment by Alex Kingston [ 12/Apr/19 ]

wow I even formatted the code but unfortunately it seems to not help at all.

Generated at Tue Apr 22 04:20:17 UTC 2025 using Jira 10.3.5#10030005-sha1:190c783f2bd6c69cd5accdb70f97e48812a78d14.