Scheduler help?

Discussion in 'Plugin Development' started by LazerAspect, Nov 19, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    LazerAspect

    Hi there! I'm fairly new to bukkit. Here is what I'm trying to do : I'm trying to make something in another class run every 60 seconds, so I put something in my on enable to do whatever is in my GameLoop class. That works fine. The problem is that in this :

    GameLoop :

    Code:
    // this is the gameloop class! (Second class)
     
    public class GameLoop implements Runnable {
     
     
     
     
     
        public void run(){
     
            Bukkit.getServer().getScheduler().scheduleAsyncDelayedTask(this, new Runnable(){
                public void run(){
                    Bukkit.getServer().broadcastMessage(ChatColor.GRAY + "[" + ChatColor.DARK_AQUA + "Countdown" + ChatColor.GRAY + "]" + ChatColor.YELLOW + "");
                }
            }, 20L);
     
        }
    }
     
     
     
     
     
    
    Alrighty, so I get an error on "scheduleAsyncDelayedTask". The error on eclipse is the method scheduleAsyncDelayedTask(plugin, runnable, long) is not applicable for the arguements (GameLoop, new Runnable(){}, long) Thank you if you can help!

    Here's my onEnable to make it run every 60 seconds if you need it :)

    Code:
    public void onEnable() {
       
       
     
            getServer().getScheduler().scheduleSyncRepeatingTask(this,
                    new GameLoop(), 20l, 20*60l);
     
    }
     
  2. Offline

    Mmarz11

    LazerAspect That is because GameLoop is not a Plugin.
     
  3. Offline

    CubieX

    Do you really want to run the GameLoop task asynchronously?
    Be sure to not use the BukkitAPI within this task then.

    And you need to replace "this" in your async scheduler method in GameLoop class with a reference to your main class.
     
  4. Offline

    AaronL98

    CubieX I'm also stuck with something similar to this. I have another class(Event.java) with my .scheduleAsyncRepeatingTask
    Code:
    Code:java
    1.  
    2. public void run(){
    3. Bukkit.broadcastMessage("Debug 1");
    4. if(Main.countdown != -1){
    5. Bukkit.broadcastMessage("Debug 2");
    6. if(Main.countdown != 0){
    7. Bukkit.broadcastMessage(""+Main.countdown);
    8. Main.countdown--;
    9. for(Player all : Bukkit.getServer().getOnlinePlayers()){
    10. BarAPI.setMessage(all, ChatColor.LIGHT_PURPLE + "Game Starting in " + ChatColor.DARK_GRAY +"["+ChatColor.DARK_AQUA+ Main.countdown + ChatColor.DARK_GRAY+"]"+ChatColor.LIGHT_PURPLE+"seconds");
    11. BarAPI.setHealth(all, 100);
    12. }
    13.  
    14. }else{
    15. Bukkit.broadcastMessage(ChatColor.DARK_GRAY+"["+ChatColor.DARK_AQUA+"ML"+ChatColor.DARK_GRAY+"]"+ChatColor.GRAY+"The has begun");
    16. startGame.gameStart();
    17. Bukkit.broadcastMessage("Debug 3");
    18. Main.countdown--;
    19. }
    20. }
    21. }
    22.  
    23. }, 0L, 20L);


    All of the code i have pasted is underlined yellow by eclipse, telling me that i should add suppress warnings, as it is depricated? Not too sure what it means.

    I have this code in my Event.java class reference my main:
    Code:java
    1. public Event(Main plugin){
    2. this.plugin = plugin;
    3. }
     
  5. Offline

    mydeblob

    AaronL98
    2 things, firstly make your own thread. No one likes thread jackers, secondly you are using a deprecated method. Can you post your full code instead of just the run() method?
     
  6. Offline

    CubieX

    .scheduleAsyncRepeatingTask is deprecated.
    Use .runTaskTimerAsynchrounously instead.

    Also, you are using BukkitAPI calls.
    Don't do this in async tasks. I can't see why this should be done async anyway. So better use .runTaskTimer to run it synchrounously.
     
Thread Status:
Not open for further replies.

Share This Page