UnknownFormatConversionException

Discussion in 'Spigot Plugin Development' started by Christophe6, May 21, 2016.

  1. Hello, I'm trying to replace strings! But when I change the prefix tag (%prefix%) to %prfix% it gives me this error:
    Code (Java):
    [12:22:09 ERROR]: Could not pass event AsyncPlayerChatEvent to Kingdom v2.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-1.9.2.jar:git-Spigot-a1b8bf3-048849c]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.9.2.jar:git-Spigot-a1b8bf3-048849c]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.9.2.jar:git-Spigot-a1b8bf3-048849c]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:484) [spigot-1.9.2.jar:git-Spigot-a1b8bf3-048849c]
        at net.minecraft.server.v1_9_R1.PlayerConnection.chat(PlayerConnection.java:1272) [spigot-1.9.2.jar:git-Spigot-a1b8bf3-048849c]
        at net.minecraft.server.v1_9_R1.PlayerConnection.a(PlayerConnection.java:1210) [spigot-1.9.2.jar:git-Spigot-a1b8bf3-048849c]
        at net.minecraft.server.v1_9_R1.PacketPlayInChat$1.run(PacketPlayInChat.java:39) [spigot-1.9.2.jar:git-Spigot-a1b8bf3-048849c]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_91]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_91]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_91]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_91]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_91]
    Caused by: java.util.UnknownFormatConversionException: Conversion = 'p'
        at org.bukkit.event.player.AsyncPlayerChatEvent.setFormat(AsyncPlayerChatEvent.java:100) ~[spigot-1.9.2.jar:git-Spigot-a1b8bf3-048849c]
        at me.christophe6.kingdom.ChatListener.onPlayerChat(ChatListener.java:78) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_91]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.9.2.jar:git-Spigot-a1b8bf3-048849c]
        ... 11 more
    This is my code:
    Code (Java):
                        if(SettingsManager.getInstance().getConfig().getString("no_kingdom_msg") == null) {
                            SettingsManager.getInstance().getConfig().addDefault("no_kingdom_msg", "&c[&r%prefix%&c]&r &c[&r%playerdisplayname%&c]&r&0>&r %message%");
                        }
                       
                        message = SettingsManager.getInstance().getConfig().getString("no_kingdom_msg");
                       
                        //Replacing tags
                        if(message.contains("%player%")) {
                            message = message.replaceAll("%player%", player.getName());
                        }
                       
                        if(message.contains("%playerdisplayname%")) {
                            message = message.replaceAll("%playerdisplayname%", player.getDisplayName());
                        }
                       
                        if(message.contains("%message%")) {
                            message = message.replaceAll("%message%", e.getMessage());
                        }
                       
                        if(message.contains("%prefix%")) {
                            message = message.replaceAll("%prefix%", KingdomHandler.getInstance().getPrefix(player));
                        }
                       
                        message = ChatColor.translateAlternateColorCodes('&', message);
                       
                        e.setFormat(message);
     
  2. U should save the config after doing this. And don't forget to do SettingsManager.getInstance().getConfig().options().copyDeafults(true);
     
  3. @Mr_Minecraft15
    Where do I need to put SettingsManager.getInstance().getConfig().options().copyDeafults(true);? Every time I use SettingsManager.getInstance().getConfig().addDefault();?
     
  4. simply use

    Code (Java):
    message.replace("%player%", #Player.getName());
    there is no need to use replaceAll