Solved IllegalStateException: Asynchronous command dispatch!

Discussion in 'Spigot Plugin Help' started by Acoder, Jun 14, 2021.

  1. Hi,

    I am coding a Spigot plugin for 1.16.5 but I get an exception when I dispatch a command in the AsyncPlayerChatEvent. I don't understand why this is happening.
    How do I fix it?

    Exception :

    [10:00:56] [Async Chat Thread - #0/ERROR]: Could not pass event AsyncPlayerChatEvent to MC-GameMaker v1.0
    org.bukkit.event.EventException: null
    at$1.execute( ~[spigot-1.16.5.jar:3059-Spigot-4225eac-7ea8b96]
    at org.bukkit.plugin.RegisteredListener.callEvent( ~[spigot-1.16.5.jar:3059-Spigot-4225eac-7ea8b96]
    at org.bukkit.plugin.SimplePluginManager.fireEvent( [spigot-1.16.5.jar:3059-Spigot-4225eac-7ea8b96]
    at org.bukkit.plugin.SimplePluginManager.callEvent( [spigot-1.16.5.jar:3059-Spigot-4225eac-7ea8b96]
    at [spigot-1.16.5.jar:3059-Spigot-4225eac-7ea8b96]
    at net.minecraft.server.v1_16_R3.PlayerConnection.c( [spigot-1.16.5.jar:3059-Spigot-4225eac-7ea8b96]
    at net.minecraft.server.v1_16_R3.PlayerConnection.a( [spigot-1.16.5.jar:3059-Spigot-4225eac-7ea8b96]
    at net.minecraft.server.v1_16_R3.PacketPlayInChat$ [spigot-1.16.5.jar:3059-Spigot-4225eac-7ea8b96]
    at java.util.concurrent.Executors$ [?:?]
    at [?:?]
    at java.util.concurrent.ThreadPoolExecutor.runWorker( [?:?]
    at java.util.concurrent.ThreadPoolExecutor$ [?:?]
    at [?:?]
    Caused by: java.lang.IllegalStateException: Asynchronous command dispatch!
    at org.spigotmc.AsyncCatcher.catchOp( ~[spigot-1.16.5.jar:3059-Spigot-4225eac-7ea8b96]
    at org.bukkit.craftbukkit.v1_16_R3.CraftServer.dispatchCommand( ~[spigot-1.16.5.jar:3059-Spigot-4225eac-7ea8b96]
    at org.bukkit.Bukkit.dispatchCommand( ~[spigot-1.16.5.jar:3059-Spigot-4225eac-7ea8b96]
    at name.sgriffeth.MCGameMaker.Command.executeCommands( ~[?:?]
    at name.sgriffeth.MCGameMaker.Main.event( ~[?:?]
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke( ~[?:?]
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke( ~[?:?]
    at java.lang.reflect.Method.invoke( ~[?:?]
    at$1.execute( ~[spigot-1.16.5.jar:3059-Spigot-4225eac-7ea8b96]
    ... 12 more
  2. Please write your code so we can help you
  3. What is your code? You are running something that cannot be run async, so you will have to run that part of the code in sync.
    • Agree Agree x 1
  4. Is there a better way to post code than just uploading a text file? (It seems i cant upload .java files)

    Attached Files:

    #4 Acoder, Jun 14, 2021
    Last edited: Jun 14, 2021
  5. SteelPhoenix


    fam why are you listening to all events and why did you squash everything into one class?!?

    Anyways you can't dispatch commands from async context. Use the BukkitScheduler.
    • Agree Agree x 1
  6. Code (Text):
    Bukkit.getScheduler().runTask(plugin, () -> {
    //Your code here
  7. I have 6 other classes but i only post my Main class. I am listening to all events because i want players to be able to listen to any event in game and also run commands when those events are called.
  8. You will have problems with it. Why would you want for example to run a command every time a players move? Your tps will be on the ground.
  9. You have the option to run a command on the PlayerMoveEvent. But if there are no commands scheduled for PlayerMoveEvent then no commands will run on the PlayerMoveEvent. Something you could do is schedule /tellraw @s {"text":"Hello welcome to the Server'',"color":''blue"} to run on PlayerJoinEvent and then whenever a player joins he will get a message saying "Hello welcome to the Server''. And you can do this in game.
  10. Ok, did you solved your problem? If you have an async problem, just use what i write before
  11. Yes. Its working now thanks.