use of com.faforever.client.chat.ChatColorMode.CUSTOM in project downlords-faf-client by FAForever.
the class PircBotXChatService method postConstruct.
@PostConstruct
void postConstruct() {
eventBus.register(this);
fafService.addOnMessageListener(SocialMessage.class, this::onSocialMessage);
connectionState.addListener((observable, oldValue, newValue) -> {
switch(newValue) {
case DISCONNECTED:
case CONNECTING:
onDisconnected();
break;
}
});
addEventListener(NoticeEvent.class, this::onNotice);
addEventListener(ConnectEvent.class, event -> connectionState.set(ConnectionState.CONNECTED));
addEventListener(DisconnectEvent.class, event -> connectionState.set(ConnectionState.DISCONNECTED));
addEventListener(UserListEvent.class, event -> onChatUserList(event.getChannel().getName(), chatUsers(event.getUsers())));
addEventListener(JoinEvent.class, event -> onUserJoinedChannel(event.getChannel().getName(), getOrCreateChatUser(event.getUser())));
addEventListener(PartEvent.class, event -> onChatUserLeftChannel(event.getChannel().getName(), event.getUser().getNick()));
addEventListener(QuitEvent.class, event -> onChatUserQuit(event.getUser().getNick()));
addEventListener(TopicEvent.class, event -> getOrCreateChannel(event.getChannel().getName()).setTopic(event.getTopic()));
addEventListener(MessageEvent.class, this::onMessage);
addEventListener(ActionEvent.class, this::onAction);
addEventListener(PrivateMessageEvent.class, this::onPrivateMessage);
addEventListener(MotdEvent.class, this::onMotd);
addEventListener(OpEvent.class, event -> {
User recipient = event.getRecipient();
if (recipient != null) {
onModeratorSet(event.getChannel().getName(), recipient.getNick());
}
});
ChatPrefs chatPrefs = preferencesService.getPreferences().getChat();
chatPrefs.userToColorProperty().addListener((MapChangeListener<? super String, ? super Color>) change -> preferencesService.store());
chatPrefs.chatColorModeProperty().addListener((observable, oldValue, newValue) -> {
synchronized (chatUsersByName) {
switch(newValue) {
case CUSTOM:
chatUsersByName.values().stream().filter(chatUser -> chatPrefs.getUserToColor().containsKey(chatUser.getUsername().toLowerCase(US))).forEach(chatUser -> chatUser.setColor(chatPrefs.getUserToColor().get(chatUser.getUsername().toLowerCase(US))));
break;
case RANDOM:
for (ChatUser chatUser : chatUsersByName.values()) {
chatUser.setColor(ColorGeneratorUtil.generateRandomColor(chatUser.getUsername().hashCode()));
}
break;
default:
for (ChatUser chatUser : chatUsersByName.values()) {
chatUser.setColor(null);
}
}
}
});
}
Aggregations