Solved Why does this runnable not work?

Discussion in 'Spigot Plugin Development' started by BourneDev, Apr 17, 2017.

  1. To cancel it inside itself you need to use the BukkitRunnable. Otherwise you have to store the Scheduler Process ID in an Integer and cancel it by calling Bukkit.getScheduler().cancel(pScheduler);
     
    • Agree Agree x 2
  2. Try it without the scheduler like this:
    Code (Java):

    new BukkitRunnable(){

         @Override
          public void run() {
               Bukkit.getConsoleSender().sendMessage(" running");
               cancel();
          }
    }.runTaskTimerAsynchronously(plugin, 20, 20);
     
  3. First off that method is deprecated use this
    https://hub.spigotmc.org/javadocs/spigot/org/bukkit/scheduler/BukkitRunnable.html#runTaskTimer(org.bukkit.plugin.Plugin, long, long)

    Second thing it clearly states
    Asynchronous tasks should never access any API in Bukkit. Great care should be taken to assure the thread-safety of asynchronous tasks.

    And there you are using Bukkit.broascastMessage. Use the link for the right thing
     
  4. Choco

    Moderator

    When it comes to broadcasting a message, thread safety is not of concern. The only real concerns is when you start interacting with entities and components regarding the world. As long as you're not modifying anything asynchronously, you're fine. Broadcasting a message is simply sending a packet. No biggy