Hello Bukkit. I'm having some trouble decoding an invisible String. I make the String invisible by adding the ChatColor COLOR_CHAR before each letter. I then decode it by replacing all the characters § with nothing. This works for the EntityDamageByEntityEvent when hitting someone, but does not work when trying to get an ItemStacks lore and then trying to decode it. On the last line, I set the decoded name (and this obviously works on the EntityDamageByEntityEvent), but when I try to get it from an itemstack by doing so: Code: public static MoreItemsItem castToMoreItem(ItemStack itemStack, Player player){ if(itemStack != null && itemStack.getItemMeta() != null && itemStack.getItemMeta().hasLore()) { String itemName = itemStack.getItemMeta().getLore().get(itemStack.getItemMeta().getLore().size() - 1) .replaceAll("§", ""); player.sendMessage(itemName); ItemManager itemManager = new ItemManager(itemName); if(itemManager.exists()) {//This just checks if the item is found in the config. return new MoreItemsItem(itemName); } } return null; } It does not seem to work. As you can see, I've tried debugging and the line returns empty. I have checked if it's the correct line and it is.. If I try to print it to the console it prints a lot of weird characters. Thanks in advance for helping me.
I don't believe it will help, as it works with when damaging entities, but here you go: Code: public String convertToInvisibleString(String s) { String hidden = ""; for (char c : s.toCharArray()) hidden += ChatColor.COLOR_CHAR+""+c; return hidden; }
@khave Use String#replace(ChatColor.COLOR_CHAR + "", "") And if your text contains characters from "g" to "z" or capital letters, they'll be visible. Maybe you should use something like a "key" that you save in the config only containing 0-9 and a-f characters...