ChatMessageManager { @Subscribe(priority = -1) public void onChatMessage(ChatMessage chatMessage) { MessageNode messageNode = chatMessage.getMessageNode(); ChatMessageType chatMessageType = chatMessage.getType(); boolean isChatboxTransparent = client.isResized() && client.getVar(Varbits.TRANSPARENT_CHATBOX) == 1; Color usernameColor = null; Color senderColor = null; switch (chatMessageType) { case TRADEREQ: case AUTOTYPER: case PUBLICCHAT: case MODCHAT: { boolean isFriend = client.isFriended(chatMessage.getName(), true) && !client.getLocalPlayer().getName().equals(chatMessage.getName()); if (isFriend) { usernameColor = isChatboxTransparent ? chatColorConfig.transparentPublicFriendUsernames() : chatColorConfig.opaquePublicFriendUsernames(); } if (usernameColor == null) { usernameColor = isChatboxTransparent ? chatColorConfig.transparentUsername() : chatColorConfig.opaqueUsername(); } break; } case FRIENDSCHAT: usernameColor = isChatboxTransparent ? chatColorConfig.transparentFriendsChatUsernames() : chatColorConfig.opaqueFriendsChatUsernames(); break; } senderColor = isChatboxTransparent ? chatColorConfig.transparentFriendsChatChannelName() : chatColorConfig.opaqueFriendsChatChannelName(); if (usernameColor != null) { messageNode.setName(ColorUtil.wrapWithColorTag(messageNode.getName(), usernameColor)); } String sender = messageNode.getSender(); if (senderColor != null && !Strings.isNullOrEmpty(sender)) { messageNode.setSender(ColorUtil.wrapWithColorTag(sender, senderColor)); } final Collection<ChatColor> chatColors = colorCache.get(chatMessageType); for (ChatColor chatColor : chatColors) { if (chatColor.isTransparent() != isChatboxTransparent || chatColor.getType() != ChatColorType.NORMAL || chatColor.isDefault()) { continue; } final Color color = chatColor.getColor(); messageNode.setValue(ColorUtil.wrapWithColorTag( messageNode.getValue().replace(ColorUtil.CLOSING_COLOR_TAG, ColorUtil.colorTag(color)), color)); break; } } @Inject private  ChatMessageManager(
		Client client,
		ChatColorConfig chatColorConfig,
		ClientThread clientThread); @Subscribe void onVarbitChanged(VarbitChanged event); @Subscribe void onResizeableChanged(ResizeableChanged event); @Subscribe void onConfigChanged(ConfigChanged event); @Subscribe(priority = -1) // run after all plugins void onChatMessage(ChatMessage chatMessage); @Subscribe void onScriptCallbackEvent(ScriptCallbackEvent scriptCallbackEvent); void loadColors(); void queue(QueuedMessage message); void process(); void update(final MessageNode target);  }
@Test public void onChatMessage() { when(chatColorConfig.opaquePublicChat()).thenReturn(Color.decode("#b20000")); chatMessageManager.loadColors(); ChatMessage chatMessage = new ChatMessage(); chatMessage.setType(ChatMessageType.PUBLICCHAT); MessageNode messageNode = mock(MessageNode.class); chatMessage.setMessageNode(messageNode); when(messageNode.getValue()).thenReturn("Your dodgy necklace protects you. It has <col=ff0000>1</col> charge left."); chatMessageManager.onChatMessage(chatMessage); verify(messageNode).setValue(eq("<col=b20000>Your dodgy necklace protects you. It has <col=ff0000>1<col=b20000> charge left.</col>")); }