Check if PlayerInteractEvent is repeated? Repeated left click triggers action

Discussion in 'Spigot Plugin Development' started by pokemonzr, Jun 18, 2016.

  1. I'm trying to create a plugin that does something when a player repeatedly left clicks a block (i.e, mines it). The issue is that I want the player to continuously left click the block for x amount of seconds before the action executes. How would I go about doing this?

    Thank you!
  2. Err, when you're holding down click I believe it fires an interactevent when you first click and then it fires one when you break the block. Actually it might only fire one when you break the block.
  3. What's happening for me is it fires on the first right click, and it executes the action 5 seconds later. I scheduled a syncDelayedTask for 5 seconds after the left click, but it's meant so that a player is mining the block and the action executes.

    Is there any way I could only execute it the player holds down left click for 5 seconds?
  4. You could try BlockDamageEvent.
  5. Does BlockDamageEvent work for bedrock?
  6. Any block will work with it :p

    public final Block getBlock()
    Gets the block involved in this event.
  7. Is there a way to check if a player stops mining the block, so I can cancel the scheduler? The action I want to happen is scheduled for 5 seconds after the BlockDamageEvent, so if a player damages a block once, and then stops, it still executes 5 seconds later.
  8. check if the event of them breaking the block was cancelled.
  9. Would that be the same BlockDamageEvent? Or would it be BlockBreakEvent?

    Edit: I checked if the BlockDamageEvent is cancelled, and if it isn't to schedule the syncDelayedTask. However, if I stop mining the block and wait 5 seconds, it still disappears. Could there be another way to check if the player aborted the block breaking?
    #9 pokemonzr, Jun 19, 2016
    Last edited: Jun 19, 2016