Solved CountDown

Discussion in 'Plugin Development' started by bubblefat_, May 27, 2015.

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

    bubblefat_

    I am wanted to make something where when you die it puts you in spectator mode for 3 seconds then teleports you somewhere. I know how to do everything but one thing, and thats waiting 3 seconds. So how can I make it so once the code if run, it waits 3 seconds and then does something.
     
  2. Offline

    scrollbar

    You can use bukkit scheduleSyncDelayedTask method for delayed tasks.

    Code:
    myPlugin.getServer().getScheduler().scheduleSyncDelayedTask(myPlugin, new Runnable() {
      public void run() {
          //This will be executed after 3 seconds.
      }
    }, 60L);
    //20L = 1 second.
    
     
  3. Make a new delayed task:
    Code:java
    1. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    2. public void run() {
    3. //Do something
    4. }
    5. }, 3 * 20);
     
  4. Offline

    Agentleader1

    They beat me to it lol, but if you're doing this in another class, use the JavaPlugin class INSTANCE.

    For example:
    In other class(es) (open)
    Code:
    Main.instance


    For Main Plugin Class (open)

    Code:
    public static Main instance; //Main is the name of the Main class plugin that extends JavaPlugin
    
    @Override
    public void onEnable(){
            instance = this;
    }
     
  5. @Agentleader1 Don't forget to set the instance to null in onDisable or you get memory leaks
     
  6. Offline

    Agentleader1

Thread Status:
Not open for further replies.

Share This Page