Timed events

Discussion in 'Plugin Development' started by PrivateAlpha, Feb 27, 2011.

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

    PrivateAlpha

    if i want something to happen every 10 sec what should i use?

    is it safe to manipulate blocks like a furnace or craftbench from a seperate thread?
     
  2. Offline

    Edward Hand

  3. Offline

    PrivateAlpha

    Thanks
    --- merged: Feb 28, 2011 7:36 AM ---
    Can someone provide an example of how to use this?

    i have:
    Code:
    scheduleSyncRepeatingTask(this,FurnaceChecker,200, timeToWait);
    where FurnaceChecker is the class i want to run.... i'm a lil new to all this (^^,)
     
  4. Offline

    Raphfrk

    This would be how you declare the Runnable:

    Code:
    public class FurnaceChecker implements Runnable {
        public void run() {
            <your code>
        }
    }
    
    This assumes that you are running it in your main class:

    Code:
    int furnaceId = getServer().scheduleSyncRepeatingTask(this, new FurnaceChecker(), 200, timeToWait());
    
    You can also inline declare the Runnable. However, all variables used in the Runnable must be declared as final.

    Code:
    final String finalInputString = inputString;
    
    int furnaceId = getServer().scheduleSyncRepeatingTask(this, new Runnable() {
        public void run() {
            System.out.println(finalInputString);
        }
    }, 200, timeToWait());
    
    Finally, you can cancel the task with

    Code:
    getServer().getScheduler().cancelTask(furnaceId);
    
     
  5. Offline

    PrivateAlpha

    Code:
    The method scheduleSyncRepeatingTask(Plugin Runnable,long,long) is undefined for the type factory furnace)
    i get this error even though it is right?

    FurnaceChecker declaration:
    Code:
    public class FurnaceChecker implements Runnable
    Where am i going wrong?
    --- merged: Feb 28, 2011 12:02 PM ---
    anyone?
     
  6. Offline

    Raphfrk

    You need to call the server.

    Code:
    getServer().schedule....
    
    More of the code would make it easier to find the issue.

    getServer() only works in your main plugin class.

    Normally what people do is pass their main plugin class to all sub-classes that they use in the constructor.

    This was you can just say

    p.getServer()....

    (assuming p is the variable storing the reference to your plugin's main class)
     
  7. Offline

    PrivateAlpha

    You, dear sir, are awesome! =]
     
Thread Status:
Not open for further replies.

Share This Page