I've been trying to program a Minecraft plugin for some time now, but I'm just stuck on the timer. I would like it to be able to pause the timer and restart at a later time (without server restart / reload between).
My current code is this:
My problem, however, is that if I pause the timer and start again, it will run twice. : /
I'm thankful for every answer.
There are different approaches to what you can do. For example, in your timer, you can query a boolean that you set outside the class, as appropriate, depending on whether the timer should run or not.
Otherwise, you can also terminate the scheduler from outside and instantiate it again when called.
Hope I could help you.
Thank you for the fast answer.
How exactly do you terminate scheduler?
Save your scheduler in a variable
BukkitRunnable consumptionScheduler = new ChangeValueScheduler (port, itemName, consumptionRate);
then you make the desired call
consumptionScheduler.runTaskTimer (Clerks.INSTANCE, 20 * 20, 20 * consumptionFrequency);
Finally, you can finish the scheduler again:
consumptionScheduler.cancel ();
Please note: The examples are code snippets of my code and will not work in your code.
Hope I could help you.