Is Bukkit.dispatchCommand() synchonous?

Discussion in 'Spigot Plugin Development' started by hjk321, Sep 3, 2019.

  1. I want to display a message output after dispatching a command, but make sure it appears *after* any message output from the dispatched command. Is the method synchronous, meaning I can directly send my message in the same thread as the dispatchCommand call? Or should I wait 2 ticks before sending the message (as theoretically an asynchronous implementation of dispatchCommand would run after one tick)

    The docs say nothing about any of this, so how can I tell in the future what is synchronous and asynchronous?

  2. Since it calls commands in the main thread, it is synchronous.
    • Agree Agree x 2
  3. Just for the question if you need to check this in future:
    I always compare the returned value of Thread#getCurrentThread() with a saved instance of the main Thread that calls my plugins onEnable(). If it returns true, its the main Thread.
  4. Most of the bukkit/spigot API is synchronous, unless specified otherwise in the docs.

    You can also check directly with Bukkit.isPrimaryThread() - if it returns true, then the current thread is the server's main thread.
    • Like Like x 1
  5. Even simpler, seems like i overlooked that method.
    Thanks for letting me know! :)
    • Like Like x 1