I tried alot, almost ate my keyboard for rage but couldnt get the timer to work.. code (Move your mouse to reveal the content) code (open) code (close) import org.bukkit.scheduler.BukkitScheduler; callSyncMethod(this, doTasks()); public static void doTasks() { //TODO. } error (Move your mouse to reveal the content) error (open) error (close) The method callSyncMethod(plgInf, void) is undefined for the type plgInf /me wonders why Java doesn't just have a SetTimer(amount, loop) and Timer() function.
http://javadoc.lukegb.com/Bukkit/df/dfa/interfaceorg_1_1bukkit_1_1scheduler_1_1BukkitScheduler.html Using one of the first 6 methods always works for me.
Tried all of them, all giving the same error.. Any examples please, examples are the best way for me to learn using something. Thanks!
Oh, sorry. I should have payed more attention to your code/error. It should be this: Code: getServer().getScheduler().scheduleSyncTask(.....
An instance of a class that implements Runnable eg : Code: public class AClass implements Runnable { @Override public void run(){ //Do whatever every tick } }
Got it, but getting error at 'Tasks tasks = new Tasks();', I have no idea how to otherwisely use it.. code (Move your mouse to reveal the content) code (open) code (close) Tasks tasks = new Tasks(); public void onEnable() { PluginManager pm = getServer().getPluginManager(); pm.registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_RESPAWN, playerListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_DAMAGED, blockListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.CREATURE_SPAWN, entityListener, Event.Priority.Normal, this); getServer().getScheduler().scheduleSyncDelayedTask(this, tasks); PluginDescriptionFile pdfFile = this.getDescription(); System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled" ); } Below I have the same error at the plgInf line. code (Move your mouse to reveal the content) code (open) code (close) public class Tasks implements Runnable { plgInf plugin = new plgInf(); @Override public void run(){ //Doing something with plugin plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, this); } }
If you're going to pass this in for the first one then it needs to implement Runnable and it needs to specialize the run method and I also think you want it to repeat so use scheduleSyncRepeatingTask. For your second one, I don't know why you're calling the schedule method... Code: public class PluginWhatever extends JavaPlugin implements Runnable { @Override public void onEnable(){ ... getServer().getScheduler().scheduleSyncRepeatingTask(this, this, 0, ticks);//ticks = how many ticks before it gets executed again } @Override public void onDisable(){ ... } @Override public void run(){ //Your code to get repeatedly executed after the period } }
One thing that I've never had the chance to wrap my finger around is the ticks, what unit is it given in ? seconds or microseconds i guess but I'm not sure.
Thank you very much, going to try now, i'll post back if it didn't work! And also, I assume it was milliseconds. (1s = 1000ms) <-- forget about that, it's not milliseconds, 20 ticks = 1 sec