Where chest is a Chest blockstate:
chest.setCustomName(ChatColor.translateAlternateColorCodes('&', "here is &rsomething"));
chest.update();For printing to file and broadcasting to chat:
@EventHandler
private void chestName(PlayerInteractEvent event)
{
if (event.getAction() != Action.LEFT_CLICK_BLOCK)
return;
Chest chest = (Chest)event.getClickedBlock().getState();
String name = chest.getCustomName();
getConfig().set("yolo", name);
saveConfig();
Bukkit.broadcastMessage(name);
} In the config, you'll see: here is §0something
In chat, something will appear in black.
What I expect to see in the config is: here is §rsomething
I don't mind if it shows up in chat as black, but I wish the original string kept the §r instead of converting when retrieving the custom name. It's obviously stored in the server since this changes depending on if it's an item or block, but if this is difficult to do (retrieving how it's stored vs. how it's displayed, since what I infer from your comment is that CB is reading and converting the displayed json representation; I'm not familiar with what the server does with this stuff), then probably not worth "fixing."
Also printing the item's custom name will print
§fin config in place of the §0.