Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. package me.nl.YourPalJake.GameAPI.Spigot.Time;
  2.  
  3. import me.nl.YourPalJake.GameAPI.Spigot.Callback;
  4. import org.bukkit.plugin.Plugin;
  5. import org.bukkit.scheduler.BukkitRunnable;
  6. import org.bukkit.scheduler.BukkitScheduler;
  7.  
  8. import java.util.HashMap;
  9.  
  10. public abstract class BungeeTimer {
  11.  
  12. private HashMap<Integer, Callback> doaction = new HashMap<>();
  13. private HashMap<Integer, String> objective1 = new HashMap<>();
  14.  
  15.  
  16.  
  17. private String nextobjectivename;
  18. private int nextobjective = 1;
  19. private int amountOfObjectives = 0;
  20. private int time = 0;
  21. private int taskId;
  22.  
  23. public Integer getTime(){
  24. return time;
  25. }
  26.  
  27. public void addAction(Integer time, Callback action){
  28. doaction.put(time, action);
  29. }
  30.  
  31. public void addObjective(String name){
  32. amountOfObjectives++;
  33. objective1.put(amountOfObjectives, name);
  34. }
  35.  
  36. public String getNextObjectiveName() {
  37. return nextobjectivename;
  38. }
  39.  
  40. public abstract void onPrepare();
  41.  
  42. @SuppressWarnings("deprecation")
  43. public void startTimer(Plugin p){
  44. onPrepare();
  45. BukkitScheduler scheduler = p.getServer().getScheduler();
  46. Integer id = scheduler.scheduleSyncRepeatingTask(p, new BukkitRunnable() {
  47. @Override
  48. public void run() {
  49. if(doaction.containsKey(time)){
  50. doaction.get(time).run();
  51. }
  52. if(amountOfObjectives >= 1){
  53. if(objective1.containsKey(nextobjective)){
  54. nextobjectivename = objective1.get(nextobjective);
  55. nextobjective++;
  56. }
  57. }
  58. time++;
  59. }
  60. }, 0L, 20L);
  61. taskId = id;
  62. }
  63.  
  64.  
  65. public void stopTimer(Plugin p){
  66. p.getServer().getScheduler().cancelTask(taskId);
  67. }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement