Solved java.util.UnknownFormatConversionException: Conversion = '%'

Discussion in 'Spigot Plugin Development' started by Plochem, Sep 9, 2018.

  1. I get that error whenever a player sends a message containing a '%'

    Here's the error: rip.PNG
    And here's my line 23:
    rip.PNG
    Also, what is line 100 of AsyncPlayerChatEvent#setFormat() since that's where the error is thrown?
     
  2. Don't use
    Code (Text):
    e.setFormat(player.getPlayerListName() + "§r: " + e.getMessage();
    use this instead
    Code (Text):
    e.setFormat(player.getPlayerListName() + ChatColor.RESET + ": " + e.getMessage();
    Edit: never use § for colors in plugins, Use ChatColor.COLOR
     
  3. That doesn't solve my problem though.
     
    • Like Like x 1
  4. md_5

    Administrator Developer

    STOP PUTTING THE MESSAGE IN THE FORMAT

    The format is the format, the message is the message.

    Don't mix them....
     
    • Informative Informative x 2
    • Winner Winner x 1
  5. Code (Text):
    e.setFormat(player.getPlayerListName() + ChatColor.RESET + ": ");
    e.setMessage(e.getMesssage.replaceAll("%", "%%"));
    If I do that, the message won't appear in chat.
     
    #7 Plochem, Sep 9, 2018
    Last edited: Sep 9, 2018
  6. You need to use %1$ for the player displayname and %2$ for the message

    So you can do something like this
    Code (Java):
    e.setFormat("%1$§r: %2$");