So I’m working with a plugin that listens for InteractBlockEvent.Primary as well as the ChangeBlockEvent.Break event. It works fine for normal players, but for players using creative, both events will be triggered at the same time when the player hits a block. Having both events triggered is causing problems because the action is being done twice.
So what I’d like to do is set up a system that can add the necessary actions to a queue, then execute that queue on tick end. This way, when InteractBlockEvent fires, it adds the action, then ChangeBlockEvent can come along, check to see if the action already exists in the queue, and if so, just don’t bother to add it again.
The problem here is I don’t know how to figure out when the tick ends. I could use the Scheduler system to run a function every tick, but then I don’t know exactly when that function will be run.
I could also do something similar, and have the InteractBlockEvent flag that it’s done the action, then have the ChangeBlockEvent look for that flag before it runs the action, but then I still need to know when the tick ends so I can clear that flag.
I could also use some other code to check the game state to see if the action has already happened but that is prone to bugs.
Does anybody know how to figure out either what tick the game is current on, or what event is fired for ticks? Or barring that, any better ideas for how to accomplish what I’m trying to do? Note that any alternatives to InteractBlockEvent would be fine, I’m just trying to find out when the player hit a block (In Bukkit this was done via BlockDamageEvent, which doesn’t seem to have an alternative in Sponge).