Caused by: java.util.IllegalFormatFlagsException: Flags = ' '

Discussion in 'Spigot Plugin Development' started by BremiWorld, Aug 9, 2018.

  1. Code (Text):
    Caused by: java.util.IllegalFormatFlagsException: Flags = ' '
            at org.bukkit.event.player.AsyncPlayerChatEvent.setFormat(AsyncPlayerChatEvent.java:100) ~[server.jar:git-Bukkit-d27e6d0]
            at me.bremiworld.events.chatt.modifyChat(chatt.java:54) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_181]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_181]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_181]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_181]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:300) ~[server.jar:git-Bukkit-d27e6d0]
            ... 36 more
    What does that mean, I don't understand this. It says there's an error in this line:

    Code (Text):
    event.setFormat(ChatColor.translateAlternateColorCodes('&', format.replace("%player%", player.getName())+format.replace("%group%", plugin.getChat().getPlayerPrefix(player))+message));
    That's the line 54.
     
  2. Why did you start a new thread?
    BTW, that's not how formatter works. In the prev thread i linked you the formatter documentation.

    And if you give up, try this...
    Code (Java):

    e.setCancelled(true);
    for(Player p : Bukkit.getOnlinePlayers()) {
        p.sendMessage(/* Your things */);
    }
     
     
  3. because it's not the same error, but it's from the same line
     
  4. The main problem is, i think that you not using the formatter correctly.

    As i saw in the bukkit's code, e.setFormat() represents the String.format(format, new Object[] {e.getPlayer(), e.getMessage()});
    So in conclusion, the format variable should be something like a keyword or something, but definetly not the entire message.

    Are there a method like e.setMessage()?
    That would be better for your problem
     
  5. The problem is the format.replace("%group%", plugin.getChat().getPlayerPrefix(player)) because when I remove that it works, and I suppose it's because it can't get the prefix properly, but idk how to fix it and I tried lots of things.
     
  6. Firestar311

    Supporter

    The problem comes from using the % sign to symbolize a variable, try to use a different symbol
     
  7. now it throws that error (i changed the symbol)
    Code (Text):
    Caused by: java.util.UnknownFormatConversionException: Conversion = 'ยบ'
            at org.bukkit.event.player.AsyncPlayerChatEvent.setFormat(AsyncPlayerChatEvent.java:100) ~[server.jar:git-Bukkit-d27e6d0]
            at me.bremiworld.events.chatt.modifyChat(chatt.java:54) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_181]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_181]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_181]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_181]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:300) ~[server.jar:git-Bukkit-d27e6d0]
     
  8. You can also try split down that line into multiple variables, and check them
     
  9. no. Use %s in place of the player and in place of the message when changing the format of the AsyncPlayerChatEvent. You shouldn't even need to use String#format
     
  10. how? i've never done that. and wht's the difference between doing it like this and with variables? i'm a beginner, so thanks for the patience,
     
  11. but i've got that
    Code (Text):
    Player player = event.getPlayer();
    and i need the format thing because i take that text from my config file:
    Code (Text):
    String format = config.getString("Config.chat-format.format");
                event.setFormat(ChatColor.translateAlternateColorCodes('&', format.replace("%player%", player.getName())+format.replace("$group$", plugin.getChat().getPlayerPrefix(player))+message));
     
  12. That's not what I mean. The default message format is something like this "<%s>: %s"
    Those symbols are placeholders, first for the player name, then the player's message. Using the % sign without using those two placeholders can cause format/plugin breaking.
     
  13. But if I put it as that, eclipse tells me that it's wrong.
    Code (Text):
    format.replace("%player%", <%s>)
    also ,the player thing works well, the error is caused because of the group thing.
     
  14. You're getting the wrong idea. There should be no "%player%" in the default format. You're not replacing anything with that part. What is the look that you're going for? Just show me a screenshot or something of what you want it to look like.
     
  15. Ok, I want it to look like EssentialsChat, so you know, customize the chat. So I want it to be like $group$ &c$player$ &7>> so it displays like that in the server chat. So I want to replace the $player$ with the username and that works, but then $group$ isn't working.
     
  16. You have nothing telling you what to replace $group$ with. It isn't done automatically. You need to pass that information to your AsyncPlayerChatEvent listener and format it in. I'd think it would look something like this:
    Code (Java):
    @EventHandler
    public void onPlayerChat(AsyncPlayerChatEvent event) {
        String format = "$GROUP$ "+ChatColor.RED+"%s "+ChatColor.GRAY+">> %s";
        // The first %s is automatically formatted as the player's displayname, the second being the message
        event.setFormat(format.replace("$GROUP$", playerprefix);
    }
     
  17. But the playerprefix doesnt work. What should I do if I want it to work?