sendPluginMessage inside schedular

Discussion in 'BungeeCord Plugin Development' started by Irantwomiles, May 25, 2016.

  1. How can I have my sendPluginMessage inside of a schedular? I get an error message in eclipse.
     
  2. What error do you get? Can you send us that part of the code?
     
  3. If you use async scheduler, it can be done like this:

    Code (Java):
    Bukkit.getScheduler().scheduleAsyncRepeatingTask(Core.plugin, new Runnable() {
                public void run() {
                    // some code

                    new BukkitRunnable() {
                        public void run() {
                            // sendPluginMessage here
                        }
                    }.runTask(Core.plugin);

                }
    }, 0, 20);
     
  4. except spoonfed you can also explain him about this
    Code (Java):
    }, 0, 20);
     
  5. What I should explain about this? It is two long vars - 1) delay before task start 2) delay between repeatings
     
  6. @EnervateD code example about the }, 0, 20); at the end
    0 = delay - the ticks to wait before running the task for the first time
    20= period - the ticks to wait between runs
     
  7. he might not know that thing.
     
  8. What I said before? Don't you read the entire message?
     
  9. Sorry mate posted it before knowing that you've posted that thing before.
     
  10. Haha, it happens ;)
     
  11. Why do you have a task inside a task. It's totally unnecessary. Just use 1 async repeating task.
     
  12. huh ? have a look at spigot javadocs.
     
  13. Didnt know you could have a runnable inside a runnable. How does th At even work, also I know that with async you need to do threading and I don't know how to do that.
     
  14. what the :p BukkitScheduler has this method

    Code (Java):
    scheduleAsyncRepeatingTask(Plugin plugin, Runnable run, long delay, long period);
    what's the matter about runnable inside another runnable ?
     
  15. There's not something wrong with a runnable inside a runnable, but you just created an async task to create a sync task to send a plugin message, that doesn't make sence to me.
     
  16. well if you'd know how it works and what it says in spigot javadoc you'll know a reason that makes sense.
     
  17. Sending chat messages is thread-safe.
     
  18. It says that you shouldn't use bukkit api in an async task. I know that, and it's because bukkit isn't thread-safe, but that doesn't mean that all methods aren't thread-safe, there are thread-safe methods, and then you can call it from async tasks. and as far as I know, plugin messaging is thread-safe, so then it's not that necessary, yes it's a bit less safe, because you need to know what methods are thread-safe but if it works in an async thread, then I think that not having to register another task is better, but it always depends on the programmer.
     
  19. You don't need to do smth else. Just use this code, it will work.