Guest User

Untitled

a guest
May 20th, 2015
387
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public abstract class Task {
  2.  
  3. //Static Objects
  4. public static int DELAYED = 0;
  5. public static int REPEATING = 1;
  6.  
  7. public static Plugin plugin = Main.getPlugin();
  8.  
  9. //Objects
  10. private int tickRate;
  11. private int tick;
  12. private int totalTick;
  13. private int autoCancel;
  14.  
  15. public int count = 0;
  16.  
  17. private boolean isCancelled;
  18.  
  19. //Constructors
  20. public Task(int i, int tickRate) {
  21. this.tickRate = tickRate;
  22. tick = 0;
  23. totalTick = 0;
  24. autoCancel = 0;
  25. isCancelled = false;
  26.  
  27. if (i == DELAYED) {
  28. Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
  29. @Override
  30. public void run() {
  31. update();
  32. cancel();
  33. }
  34. }, tickRate);
  35.  
  36. return;
  37. }
  38.  
  39. TaskManager.getInstance().addTask(this);
  40. }
  41.  
  42. public Task(int i, int tickRate, int autoCancel) {
  43. this.tickRate = tickRate;
  44. tick = 0;
  45. totalTick = 0;
  46. this.autoCancel = autoCancel;
  47. isCancelled = false;
  48.  
  49. if (i == DELAYED) {
  50. Bukkit.getScheduler().scheduleSyncDelayedTask(TunnelsHub.getPlugin(), new Runnable() {
  51. @Override
  52. public void run() {
  53. update();
  54. cancel();
  55. }
  56. }, tickRate);
  57.  
  58. return;
  59. }
  60.  
  61. TaskManager.getInstance().addTask(this);
  62. }
  63.  
  64. //Abstract Methods
  65. public abstract void update();
  66.  
  67. //Object Methods
  68. public void updateTicks() {
  69. tick++;
  70. totalTick++;
  71.  
  72. if (tick >= tickRate) {
  73. tick = 0;
  74. count++;
  75. update();
  76. }
  77.  
  78. if (autoCancel > 0 && totalTick >= autoCancel) {
  79. cancel();
  80. }
  81. }
  82.  
  83. public void setAutoCancel(int autoCancel) {
  84. this.autoCancel = autoCancel;
  85. }
  86.  
  87. public void cancel() {
  88. isCancelled = true;
  89.  
  90. TaskManager.getInstance().removeTask(this);
  91. }
  92. }
RAW Paste Data