Solved java.lang.IllegalStateException: Asynchronous entity add!

Discussion in 'Spigot Plugin Development' started by SCPKeter, Jun 26, 2018.

  1. Sup!

    Dunno why does this exception keeps occuring, because I simply execute command (using dispatchCommand on Server object), and I don't use any Threads for that, even Spigot's schedule(A)SyncTask.

    Used code:
    Code (Java):

    getServer().dispatchCommand(getServer().getConsoleSender(),applyPlaceholders(command, placeholders));
     

    Stacktrace
     
  2. Can i see the applyPlaceholders thing?
     
  3. md_5

    Administrator Developer

    AsyncChatEvent is async.
    Would you believe?
     
    • Funny Funny x 1
  4. FrostedSnowman

    Resource Staff

    What makes you say that?
     
  5. oh, right
     
  6. Sure.
    Code (Text):
    private String applyPlaceholders(String input, Map<String, String> values) {
            for (Map.Entry<String, String> entry : values.entrySet()) {
                input = input.replaceFirst(entry.getKey(), entry.getValue());
            }

            input = ChatColor.translateAlternateColorCodes('&', input);
            return input;
        }
     
  7. Whatever. What's the fix for that?
     
  8. md_5

    Administrator Developer

    Commands must be dispatched sync via the scheduler
     
  9. Thanks, I'll try it
     
  10. That worked, thanks y'all!