[Unsolved] Timed Events

Discussion in 'Plugin Development' started by HotelManager24, Nov 30, 2011.

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


    Hey, I'm trying to code a plugin for a server, but I need some help. Could anyone supply me with the source code for a broadcast happening every 30 minutes? If you could, that would be highly appreciated.
  2. Offline


    there is no way to get it precisely at 30 minutes, but a hint would be you should assume there are roughly 1200 ticks per minute, so you would want to create a repeating task using the scheduler that repeats every 30 minutes (or 36000 ticks). This should be a good base to start you off with. Also here is an article on the wiki about programming using the scheduler, http://wiki.bukkit.org/Scheduler_Programming
  3. Offline


    This much, I knew. But I'm having a confused time with it. I was wondering if you could write me some code for it.


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


    The link showed a perfectly good example, but the repeat period was a little bit different.

    myPlugin.getServer().getScheduler().scheduleSyncRepeatingTask(myPlugin, new Runnable() {
        public void run() {
            System.out.println("This message is printed by a synchronous task");
    }, 1L, 30*60*20L);
    I changed it from "Async" to "Sync" because only experienced multi-threaded programming folks should even be attempting Async threads.

    I made the inital delay 1 tick, so it happens almost immediately after this setup code runs.

    I made the repeating delay 30 minutes. Thirty minutes is 30*60 seconds, and thirty minutes worth of ticks is 30*60*20.

    Of course, you should put something else in the middle... if you wanted a broadcast message, myPlugin.getServer().broadcastMessage() might be useful.
  5. Offline


    Alrighty, thanks. But what should I be replacing "myPlugin" with?
  6. Offline


  7. Offline


  8. Offline


    I had meant what to replace this one with:

    ..scheduleSyncRepeatingTask(myPlugin, new Runnable() {..
  9. Offline


    That depends where in your code your putting that line, are you putting it in a listener, or in your main class?

    If it's going in your main class, replace it with "this"
    If it's going in a listener, replace it with "plugin"
  10. Offline


    Ok, thanks!
Thread Status:
Not open for further replies.

Share This Page