Executing console command

Discussion in 'Spigot Plugin Development' started by Random_Cow, Jun 1, 2016.

  1. I'm just wondering, is it bad to execute a console command on an async method? Eg, a Bukkit runnable async or a playerpreloginevent async. like command executor( command, consolesender). Also how will this affect login times if I were to run it on main thread vs asynchronous.
  2. Asynchronous won't block the main thread if you're making long operations in the player login event. However, you won't be able to call some of the bukkit API.
  3. Is the command executor considered apart of the Bukkit API? Also how will this affect the player login times if it's a long query
  4. Depends on how long the query is, and depends on what you mean by command executor? You can always call Bukkit.dispatchCommand AFAIK
  5. It's the dispatchcommand() just with console as sender as the sender. The query shouldn't be too long, it's just Obtain a true or false value
  6. Don't run database queries in the main thread, like ever.
  7. Code (Java):
    BukkitServer#dispatchCommand(ConsoleCommandSender console, String command);
  9. I know the method, it's just that I read that you shouldn't run the Bukkit API in asynchronous. There's 2 more things: (which out of the 3 options are more effective)
    Run method on asyncplayerlogin event
    Run method on player login event with the Bukkit async runnable.
    Run method on asyncplayerlogin event with Bukkit async runnable.
    What would running it in async + async result in?
  10. Were you not talking about a query earlier?
    You should try running Bukkit.dispatchCommand() from inside the asyncplayerlogin event, it should work and is your best option. If it doesn't work, then do every query / operations you need inside the asyncplayerlogin, and then, still in the asyncplayerlogin schedule a runnable (not an async runnable) that should execute in 0 ticks.
    The general rule is that if you're making somewhat complex operations that takes a considerable amount of time to run (more than a millisecond let's say), you should be running them in asynchronous so the players can still interact with the server without it being unresponsive.
  11. @Ferdz running commands off the main thread is fine. But I think what @Random_Cow is afraid of is that some commands might break the server if ran from an async thread. Like you said, just execute a sync runnable and then execute the command.
    • Agree Agree x 1