simple timer

Discussion in 'Plugin Development' started by michidk, May 27, 2012.

Thread Status:
Not open for further replies.
  1. Hi,
    how to do a simple timer? (countdown)
    Yes i know with bukkit Scheduler...But how?

    But i search about 4 Hours and found nothing...

    It should look like this:
    Code:
    System.out.println(Wait 30 Sekonds);
    timer(30);
    System.out.println(Finished!);

    Greetz
    -michidk
     
  2. Offline

    Coryf88

    Code:java
    1. System.out.println("Wait 30 Sekonds");
    2. this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    3. public void run() {
    4. System.out.println("Finished!");
    5. }
    6. }, 600L); // (30 seconds * 20 ticks/second = 600)
     
  3. Coryf88
    The Problem is, iam in the Playerlistner.
    If i use it it looks like this: (eclipse says it must look like this)
    Code:java
    1.  
    2. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask((Plugin) this, new Runnable() {
    3. public void run() {
    4. System.out.println("Finished!");
    5. }
    6. }, 600L); // (30 seconds * 20 ticks/second = 600)


    But this make that error:
    Code:
    [SEVERE] Could not pass event PlayerCommandPreprocessEvent to myplugin
    org.bukkit.event.EventException
    anyone a Idea??

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  4. Why do you cast 'this' to plugin? When you're in the main class you don't need it, otherwise you'll need the instance of your main.

    Also, please provide THE WHOLE stacktrace
     
  5. It isnt in the Main Class..

    But now it works:
    Code:java
    1. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    2. public void run() {
    3. System.out.println("Finished!");
    4. }
    5. }, 600L); // (30 seconds * 20 ticks/second = 600)


    My fail was there:
    public class playerListener implements Listener,
    And so it Works:
    public class playerListener implements Listener, Plugin
     
  6. But that's not what you want to do. You don't want to create a 'separate plugin', hence you should use the instance of your main class.
     
Thread Status:
Not open for further replies.

Share This Page