SnuviTask.java 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package me.km.scheduler;
  2. import me.km.KajetansMod;
  3. public class SnuviTask
  4. {
  5. private final int id;
  6. private final long rtimer;
  7. private final Runnable r;
  8. private long timer;
  9. public SnuviTask(int id, Runnable r, long delay, long rtimer)
  10. {
  11. this.rtimer = rtimer << 1; // server ticks seems to be 1/40 of a second
  12. this.timer = delay << 1;
  13. this.r = r;
  14. this.id = id;
  15. }
  16. public int getId()
  17. {
  18. return id;
  19. }
  20. public long getRepeatTimer()
  21. {
  22. return rtimer;
  23. }
  24. public boolean isRepeating()
  25. {
  26. return rtimer > 0;
  27. }
  28. public boolean tick(boolean noRepeat)
  29. {
  30. timer -= 1;
  31. if(timer <= 0)
  32. {
  33. try
  34. {
  35. r.run();
  36. }
  37. catch(Exception ex)
  38. {
  39. KajetansMod.scripts.getSnuviParser().getLogger().print(ex.getLocalizedMessage(), ex, null, null, null, -1);
  40. }
  41. if(rtimer <= 0 || noRepeat)
  42. {
  43. return true;
  44. }
  45. timer = rtimer;
  46. }
  47. return false;
  48. }
  49. }