Chat Message Error

Discussion in 'Spigot Plugin Development' started by Enderaura, May 29, 2017.

  1. My plugin formats a chat message according to the players rank (set through that plugin).

    But I get this error when putting a '%' in chat and it unformats the chat message, it's fine with all other symbols

    Code (Text):

    [09:23:49 ERROR]: Could not pass event AsyncPlayerChatEvent to Permissions v1.0
    org.bukkit.event.EventException
      at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:310) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
      at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
      at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:502) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
      at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:484) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
      at net.minecraft.server.v1_8_R3.PlayerConnection.chat(PlayerConnection.j
    ava:1084) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
      at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java
    :1022) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
      at net.minecraft.server.v1_8_R3.PacketPlayInChat$1.run(PacketPlayInChat.
    java:39) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
      at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.8.0_101]
      at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_101]
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:
    1.8.0_101]
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?
    :1.8.0_101]
      at java.lang.Thread.run(Unknown Source) [?:1.8.0_101]
    Caused by: java.util.UnknownFormatConversionException: Conversion = '%'
      at org.bukkit.event.player.AsyncPlayerChatEvent.setFormat(AsyncPlayerCha
    tEvent.java:100) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
      at com.xenderaura.perms.Main.onPlayerChat(Main.java:39) ~[?:?]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0
    _101]
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0
    _101]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .8.0_101]
      at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_101]
      at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:306) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
      ... 11 more
    [09:23:49 INFO]: <Enderqura> %
    [09:23:56 INFO]: Owner Enderqura >> hi
    [09:24:53 INFO]: Owner Enderqura >> !
    [09:24:56 INFO]: Owner Enderqura >> "
    [09:24:58 INFO]: Owner Enderqura >> ú
    [09:24:59 INFO]: Owner Enderqura >> $
    [09:25:01 INFO]: Owner Enderqura >> ^
    [09:25:04 INFO]: Owner Enderqura >> &
    [09:25:06 INFO]: Owner Enderqura >> *
    [09:25:08 INFO]: Owner Enderqura >> (
    [09:25:09 INFO]: Owner Enderqura >> )
     
    Here is my method for the chat format.
    Code (Java):

    @EventHandler
       public void onPlayerChat(AsyncPlayerChatEvent e){
         
         Player p = e.getPlayer();
         Rank r = getRank(p);
         
         String prefix = r.getPrefix();
         String message = e.getMessage();
         
         ChatColor color = r.getColor();
         
         e.setFormat(prefix + p.getName() + " §b>> §7" + color + message);
       }
     
  2. MiniDigger

    Supporter

  3. I tried setMessage but that only modified the actual message text, so it was like: <Enderqura> Owner Enderqura >> message
     
  4. electronicboy

    IRC Staff

    The format and the message itself are separate components and will be merged by the server later by running String.format(format, ...) with several components being passed to that, as noted in the javadocs
     
  5. So could you give me a better way of modifying the format? Do I do set message as well?

    Sent from my SM-G900F using Tapatalk
     
  6. Mas

    Mas

    In #setFormat, instead of p.getName() and e.getMessage() replace them both with "%s"