hey all, how would I stop someone from doing MAGIC e.g. &k in an arg. (Doing a nickname plugin) but allow reg colour codes e.g. &a (green)
Doesn't work. Tried player.sendMessage("New nickname: " + ChatColor.translateAlternateColorCodes('&', args[0]).replace("&k", "")); and player.sendMessage("New nickname: " + ChatColor.translateAlternateColorCodes('&', args[0]).replace("&k", " "));
It needs to be Code (Text): player.sendMessage("New nickname: " + ChatColor.translateAlternateColorCodes('&k', args[0].replace("&k", ""))); Note the replace method is inside the translateAlternateColorCodes(). Edit: Godammit, ninj'd by @_Cory_
That is the same as Code (Java): text = text.replace("&k", ""); String#replace will already replace all occurrences in the String.
You could try this: Code (Text): ChatColor.translateAlternateColorCodes('&', input).replace(ChatColor.MAGIC, "");
Look into the Pattern and Matcher classes if you want to handle it efficiently. If you don't require efficiency and want simple code, look into String#replaceAll.