java.lang.IllegalStateException: Asynchronous command dispatch!

Discussion in 'Spigot Plugin Development' started by uncovery, Oct 31, 2018.

  1. I am trying to update this plugin here to 1.13: https://github.com/uncovery/Websend

    It allows to have a 2-way communication between PHP and Minecraft.
    Minecraft t p PHP works fine, but since 1.13, the other way around is broken.

    By adding additional debug outputs, I nailed it down to this line here:

    https://github.com/uncovery/Websend.../github/websend/server/PacketParser.java#L108

    running the command

    success = Main.getBukkitServer().dispatchCommand(sender, command);

    and returning this error:

    java.lang.IllegalStateException: Asynchronous command dispatch!
    at org.spigotmc.AsyncCatcher.catchOp(AsyncCatcher.java:14)
    at org.bukkit.craftbukkit.v1_13_R2.CraftServer.dispatchCommand(CraftServer.java:697)
    at com.github.websend.server.PacketParser.parseDoCommandAsConsole(PacketParser.java:108)
    at com.github.websend.server.CommunicationServer.startServer(CommunicationServer.java:115)
    at com.github.websend.server.CommunicationServer.run(CommunicationServer.java:52)

    Can someone help me with this? Is there a way to fix this?
    Are Asynchronous tasks prevented since 1.13?
    what's the right way to do this now?
     
  2. #2 SystemEncryption, Oct 31, 2018
    Last edited: Oct 31, 2018
  3. You can use BukkitScheduler#callSyncMethod
    Code (Java):
    boolean success = Bukkit.getScheduler().callSyncMethod( this, () -> Bukkit.dispatchCommand( sender, command ) ).get();
    The Bukkit API is NOT thread safe, almost everything in the API can't be used async
     
    • Informative Informative x 1
  4. @FrozenLegend : Thanks a lot for this!

    When I use this code, I get an error that Lambda expressions are not supported in 1.7 code, and when I switch to 1.8, the code is supported but the build fails with

    Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.2:shade (default) on project Websend: Error creating shaded jar: 19556 -> [Help 1]

    Could you kindly tell me how to write the above without Lambda expressions until I figure out why the code won't compile with 1.8 sources? Thanks!

    Sorry, I am quite a noob in Java (obviously)....
     
  5. Code (Java):
    boolean success = Bukkit.getScheduler().callSyncMethod( this, new Callable<Boolean>() {
        @Override
        public Boolean call() {
            return Bukkit.dispatchCommand( sender, command );
        }
    } ).get();
    But i suggest you to find a solution and use java 8, your build probably fail because dependency used by your plugin are probably using java 7 and you are creating a shaded jar using java 8, you should take a look and update all the dependency if you can and the shading should be ok.
     
    #5 FrozenLegend, Nov 1, 2018
    Last edited: Nov 1, 2018
    • Useful Useful x 1
  6. Thanks, will do my best!
     
  7. Btw if you do not succeed to update your plugin, I can look quickly and if it's not too long i can do it for you.
     
    • Friendly Friendly x 2
  8. Thanks a lot for the offer! it's highly appreciated!

    I (think) now fixed all dependencies to use 1.8 versions. I changed the project version to 1.8, and, using your new (non-lambda) code, it compiles fine. However, if I use the lambda-verstion code, it suddenly fails with the error:

    Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.2:shade (default) on project Websend: Error creating shaded jar: 21724 -> [Help 1]

    So it seems that only for the fact that I use the lambda code, it tries to create a shaded jar, but not without? Is that logical?

    Anyhow, without the lambda code, it seems that the plugin is working as far as I can tell so far. If I run into any other issues, I will make a new post!
     

Share This Page