1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package me.km.scheduler;
- import me.km.KajetansMod;
- public class SnuviTask
- {
- private final int id;
- private final long rtimer;
- private final Runnable r;
- private long timer;
-
- public SnuviTask(int id, Runnable r, long delay, long rtimer)
- {
- this.rtimer = rtimer << 1; // server ticks seems to be 1/40 of a second
- this.timer = delay << 1;
- this.r = r;
- this.id = id;
- }
- public int getId()
- {
- return id;
- }
-
- public long getRepeatTimer()
- {
- return rtimer;
- }
-
- public boolean isRepeating()
- {
- return rtimer > 0;
- }
-
- public boolean tick(boolean noRepeat)
- {
- timer -= 1;
- if(timer <= 0)
- {
- try
- {
- r.run();
- }
- catch(Exception ex)
- {
- KajetansMod.scripts.getSnuviParser().getLogger().print(ex.getLocalizedMessage(), ex, null, null, null, -1);
- }
- if(rtimer <= 0 || noRepeat)
- {
- return true;
- }
- timer = rtimer;
- }
- return false;
- }
- }
|