The code below works great, except when I type % in chat, the event doesn't run at all... Code: @EventHandler public void chat(AsyncPlayerChatEvent event) { event.setFormat(event.getPlayer().getDisplayName() + format("&f: " + event.getMessage())); } Code: public static String format(String input) { return ChatColor.translateAlternateColorCodes('&', input.replace("(heart)", "❤")); } Could anyone tell me why this happens...? and maybe how to fix it? Thanks
I'm not really experienced with #translateAlternateColorCodes. The format(String input) needs to be called.
@Eos UnknownFormatConversionException Code: @EventHandler public void chat(AsyncPlayerChatEvent event) { event.setFormat(event.getPlayer().getDisplayName() + ": " + event.getMessage()); } It doesn't have to do with the other thing, the code above returns the same error...
@Meatiex Set the format like it's intended, don't put the player's name or message in there, just a format.
@Meatiex The reason it doesn't work is because you are using a character that doesn't work inside the Formatter. Bukkit is taking that input string and using it in a Formatter. In a Formatter, the % sign means that a formatting instruction follows. There are 2 variables in the default message format. One is "%1$s" which means the player's name. The other is "%2$s" which means the message they typed. The default message format is "<%1$s> %2$s". Just remember you can't use % because the Formatter uses that as a variable to format the string. To solve the problem, don't use event.getMessage() in the format string, wherever you want their message to appear, use the string "%2$s" EDIT: To format their message using your format method, you can use this line. Code: event.setMessage(format(event.getMessage()));