1.15.2 Handle Mouse Held Down and Released

Discussion in 'Spigot Plugin Development' started by xMakerx, Mar 30, 2020.

  1. Hi there!

    I'm trying to make a power bar of sorts where how far an object goes depends on how long the player's right mouse button is down. I've pretty much implemented a prototype, but I was wondering if there was a less hacky way to do this. I used a BukkitRunnable that runs as a task timer every tick to update a progress bar, do calculations, and determine if the mouse button was released. It appears that PlayerInteractEvent is fired every 4 ticks (~200ms), so in my runnable I see if ~200 milliseconds has passed since the last mouse button down time was recorded. That begs the question: what do I do if the server or the client is experiencing lag? I think my system will break down then. Are there any other ways to implement this into my plugin?

  2. It will probably break. But you can change design. Instead of registering every click you can register only 2 clicks (one for starting prograss bar and second for ending it). Also i guess when you reach maximum of that progress bar it will end automatically. You will not hold button but just click to start and click to end. Also you should add small time when to ignore this event because i think event is fired for both hands.