CauseStackManager called from off main thread

After Cause refactoring many plugins should be updated.

Howto fix this code:

    		  CommandManager cmdManager = Sponge.getCommandManager();
    		  try {
			    	cmdManager.process(this, command);

    		  
    		  }
    		  catch (Exception e) {
    			  System.out.println(e);
    		  }

Before cause refactor works without problem, now get:

java.lang.IllegalStateException: CauseStackManager called from off main thread!

Howto fix? I have nothing with cause input. Im just want run command and get output.

Minecraft is single threaded, so any processes that interact with the server directly need to be on the main server thread.

If you’re running code asynchronously that must work with the server, you need to transfer it to the main thread. The easiest way to do this is simply to submit a synchronous Task - Sponge takes care of it from there.

Task.builder()
    .executor(t -> Sponge.getCommandManager().process(source, command))
    .submit(plugin);

Now, I have no idea what the context of what you’re doing is, but it seems unlikely that this is an instance of a CommandSource (and if so, you’re probably not going about something in the right way).

As for why you get an error with the CauseStackManager even though you never used it, process has an internal call to push and pop the source - it’s presumed that you’re calling it synchronously, which you should be.