Schelduler in Schelduler

Discussion in 'Plugin Development' started by TomTheDeveloper, Mar 20, 2013.

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

    TomTheDeveloper

    Code:java
    1. public void GameRounds(){
    2. this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
    3.  
    4. public void run(){
    5.  
    6. }
    7.  
    8. }, 1200L, 2400L);
    9.  
    10.  
    11.  
    12.  
    13. }


    How can i put a delayed schelduler in this repeating schelduler, i know it sounds weird, but i will add serveral delayed tasks into the repeating task.

    I can't do this:
    in the public void run():
    this.getServer()....

    This gives me an error at .getServer()
     
  2. Offline

    Sayshal

    Spelled syntax wrong. Lol.
     
    RyanJF1 likes this.
  3. Offline

    TomTheDeveloper

    Not anymore :p
     
  4. Offline

    Minecrell

    I think it should work if you remove "this." before getServer in the scheduler.
     
  5. Offline

    Barinade

    Why do you want to put a delayed task in a repeating task?
     
  6. Offline

    TomTheDeveloper

    For rounds in a minigame, every round there will be spawning new zombies

    Minecrell
    Nope doesn't work, but i can solve it without using schelduler in schelduler, but i am interested in this solution

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  7. Offline

    Scizzr

    I'm assuming he's using the repeating task as the timer and the delayed tasks for the counters and whatnot.

    Anyways, you get an error because the second 'this' refers to the repeating task. In order to use your plugin globally, you can create a Plugin variable like so:

    Code:
    package com.example.test;
     
    import org.bukkit.Server;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitScheduler;
     
    public class TestPlugin extends JavaPlugin {
        TestPlugin plugin;
        Server server;
        BukkitScheduler sched;
     
        public void onEnable() {
            plugin = this;
            server = plugin.getServer();
            sched = server.getScheduler();
        }
     
        public void GameRounds() {
            sched.scheduleSyncRepeatingTask(this, new Runnable() {
                public void run() {
                    sched.scheduleSyncDelayedTask(plugin, new Runnable() {
                        public void run() {
                            //blah
                        }
                    }, 100L);
                }
            }, 1200L, 2400L);
        }
    }
    
    As I have done, I also would recommend that you create variables for the Server and BukkitScheduler, as it cuts down on resources since you're not constantly asking Bukkit what the server is and what the scheduler is.

    Good luck!
     
  8. Offline

    Barinade

    Why not increment a number ever time?
    int i = 0
    5 minute scheduler -> increase i by 1, if i = ? do whatever, if i = maxi do i = 0

    I just fail to see any need for a delayed task in a repeating task...
     
Thread Status:
Not open for further replies.

Share This Page