Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.nl.YourPalJake.GameAPI.Spigot.Time;
- import me.nl.YourPalJake.GameAPI.Spigot.Callback;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.scheduler.BukkitRunnable;
- import org.bukkit.scheduler.BukkitScheduler;
- import java.util.HashMap;
- public abstract class BungeeTimer {
- private HashMap<Integer, Callback> doaction = new HashMap<>();
- private HashMap<Integer, String> objective1 = new HashMap<>();
- private String nextobjectivename;
- private int nextobjective = 1;
- private int amountOfObjectives = 0;
- private int time = 0;
- private int taskId;
- public Integer getTime(){
- return time;
- }
- public void addAction(Integer time, Callback action){
- doaction.put(time, action);
- }
- public void addObjective(String name){
- amountOfObjectives++;
- objective1.put(amountOfObjectives, name);
- }
- public String getNextObjectiveName() {
- return nextobjectivename;
- }
- public abstract void onPrepare();
- @SuppressWarnings("deprecation")
- public void startTimer(Plugin p){
- onPrepare();
- BukkitScheduler scheduler = p.getServer().getScheduler();
- Integer id = scheduler.scheduleSyncRepeatingTask(p, new BukkitRunnable() {
- @Override
- public void run() {
- if(doaction.containsKey(time)){
- doaction.get(time).run();
- }
- if(amountOfObjectives >= 1){
- if(objective1.containsKey(nextobjective)){
- nextobjectivename = objective1.get(nextobjective);
- nextobjective++;
- }
- }
- time++;
- }
- }, 0L, 20L);
- taskId = id;
- }
- public void stopTimer(Plugin p){
- p.getServer().getScheduler().cancelTask(taskId);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement