[SPIGOT-1132] PlayerInteractEvent being called twice when using minecarts Created: 15/Aug/15  Updated: 30/Jun/16  Resolved: 30/Jun/16

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

Type: Bug Priority: Minor
Reporter: Ryan Barry Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: PlayerInteractEvent, minecart

Attachments: PNG File 2015-08-15_16.04.49.png    

 Description   

If a minecart is placed on a rail, any PlayerInteractEvents are called twice. If "event.setCancelled(true)" is called in the second iteration, it also cancels the first.

I have attached a screenshot of what happens after clicking once on rails with a minecart. The code for which is simply:

@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerInteract(PlayerInteractEvent event)
{
   Player player = event.getPlayer();
   Block block = event.getClickedBlock();
   if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK))
   {
      player.sendMessage("Event called");
   }
}


 Comments   
Comment by md_5 [ 30/Jun/16 ]

Nope, it was related to Minecarts

Comment by Matthew Steglinski [ 14/Mar/16 ]

This is not an issue related to minecarts. The event is called twice in 1.9 due to an interact occurring for both hands. See SPIGOT-1744/SPIGOT-1604/SPIGOT-1570/SPIGOT-1793.

Comment by Ryan Barry [ 14/Mar/16 ]
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerInteract(PlayerInteractEvent event)
{		
   Player player = event.getPlayer();
   Block block = event.getClickedBlock();
   ItemStack item = player.getItemInHand();
   if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK))
   {
      player.sendMessage(event.getClass().getName());
   }
}

This code displays the message "org.bukkit.event.player.PlayerInteractEvent" twice, and so it would appear it's not calling the event due to event subclasses also triggering it.

Comment by Matthew Steglinski [ 14/Mar/16 ]

I believe this is related to SPIGOT-32

Comment by Ryan Barry [ 14/Mar/16 ]

Still present in latest version git-Spigot-6f291ea-55a8535 (MC: 1.9)

Comment by Ryan Barry [ 31/Aug/15 ]

Apart from the onEnable method to register the listener once, this is the only thing in the code.

Comment by Janmm14 [ 31/Aug/15 ]

Please ensure you did not registered your listener twice.

Generated at Sat Dec 13 15:20:30 UTC 2025 using Jira 10.3.13#10030013-sha1:56dd970ae30ebfeda3a697d25be1f6388b68a422.