Search in sources :

Example 1 with CUSTOM

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);
                    }
            }
        }
    });
}
Also used : UserOfflineEvent(com.faforever.client.player.UserOfflineEvent) GenericEvent(org.pircbotx.hooks.types.GenericEvent) FXCollections.observableHashMap(javafx.collections.FXCollections.observableHashMap) StringUtils.containsIgnoreCase(org.apache.commons.lang3.StringUtils.containsIgnoreCase) TopicEvent(org.pircbotx.hooks.events.TopicEvent) LoggerFactory(org.slf4j.LoggerFactory) Irc(com.faforever.client.config.ClientProperties.Irc) ConnectionState(com.faforever.client.net.ConnectionState) HIGH(com.faforever.client.task.CompletableTask.Priority.HIGH) SocialMessage(com.faforever.client.remote.domain.SocialMessage) MotdEvent(org.pircbotx.hooks.events.MotdEvent) PreDestroy(javax.annotation.PreDestroy) Task(javafx.concurrent.Task) CUSTOM(com.faforever.client.chat.ChatColorMode.CUSTOM) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) Map(java.util.Map) RANDOM(com.faforever.client.chat.ChatColorMode.RANDOM) ChatPrefs(com.faforever.client.preferences.ChatPrefs) PircBotX(org.pircbotx.PircBotX) PlayerService(com.faforever.client.player.PlayerService) ClientProperties(com.faforever.client.config.ClientProperties) LoggedOutEvent(com.faforever.client.user.event.LoggedOutEvent) FafClientApplication(com.faforever.client.FafClientApplication) UserOnlineEvent(com.faforever.client.player.UserOnlineEvent) NoticeEvent(org.pircbotx.hooks.events.NoticeEvent) MapChangeListener(javafx.collections.MapChangeListener) MethodHandles(java.lang.invoke.MethodHandles) UpdateApplicationBadgeEvent(com.faforever.client.ui.tray.event.UpdateApplicationBadgeEvent) JoinEvent(org.pircbotx.hooks.events.JoinEvent) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ObservableMap(javafx.collections.ObservableMap) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Player(com.faforever.client.player.Player) CountDownLatch(java.util.concurrent.CountDownLatch) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) DisconnectEvent(org.pircbotx.hooks.events.DisconnectEvent) ReadOnlyIntegerProperty(javafx.beans.property.ReadOnlyIntegerProperty) UserHostmask(org.pircbotx.UserHostmask) PostConstruct(javax.annotation.PostConstruct) Lazy(org.springframework.context.annotation.Lazy) NotNull(org.jetbrains.annotations.NotNull) User(org.pircbotx.User) Event(org.pircbotx.hooks.Event) ActionEvent(org.pircbotx.hooks.events.ActionEvent) TaskService(com.faforever.client.task.TaskService) PreferencesService(com.faforever.client.preferences.PreferencesService) LoginSuccessEvent(com.faforever.client.user.event.LoginSuccessEvent) IrcException(org.pircbotx.exception.IrcException) ReadOnlyObjectProperty(javafx.beans.property.ReadOnlyObjectProperty) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) CompletableTask(com.faforever.client.task.CompletableTask) US(java.util.Locale.US) Hashing(com.google.common.hash.Hashing) CompletableFuture(java.util.concurrent.CompletableFuture) UserService(com.faforever.client.user.UserService) MessageEvent(org.pircbotx.hooks.events.MessageEvent) ArrayList(java.util.ArrayList) EventBus(com.google.common.eventbus.EventBus) PartEvent(org.pircbotx.hooks.events.PartEvent) Inject(javax.inject.Inject) OpEvent(org.pircbotx.hooks.events.OpEvent) Service(org.springframework.stereotype.Service) UtilSSLSocketFactory(org.pircbotx.UtilSSLSocketFactory) Subscribe(com.google.common.eventbus.Subscribe) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Color(javafx.scene.paint.Color) ObjectProperty(javafx.beans.property.ObjectProperty) Logger(org.slf4j.Logger) UTF_8(java.nio.charset.StandardCharsets.UTF_8) IOException(java.io.IOException) ChatMessageEvent(com.faforever.client.chat.event.ChatMessageEvent) Profile(org.springframework.context.annotation.Profile) FafService(com.faforever.client.remote.FafService) QuitEvent(org.pircbotx.hooks.events.QuitEvent) Configuration(org.pircbotx.Configuration) UserListEvent(org.pircbotx.hooks.events.UserListEvent) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) PrivateMessageEvent(org.pircbotx.hooks.events.PrivateMessageEvent) ConnectEvent(org.pircbotx.hooks.events.ConnectEvent) VisibleForTesting(com.google.common.annotations.VisibleForTesting) I18n(com.faforever.client.i18n.I18n) NoCatch.noCatch(com.github.nocatch.NoCatch.noCatch) User(org.pircbotx.User) ChatPrefs(com.faforever.client.preferences.ChatPrefs) PostConstruct(javax.annotation.PostConstruct)

Aggregations

FafClientApplication (com.faforever.client.FafClientApplication)1 CUSTOM (com.faforever.client.chat.ChatColorMode.CUSTOM)1 RANDOM (com.faforever.client.chat.ChatColorMode.RANDOM)1 ChatMessageEvent (com.faforever.client.chat.event.ChatMessageEvent)1 ClientProperties (com.faforever.client.config.ClientProperties)1 Irc (com.faforever.client.config.ClientProperties.Irc)1 I18n (com.faforever.client.i18n.I18n)1 ConnectionState (com.faforever.client.net.ConnectionState)1 Player (com.faforever.client.player.Player)1 PlayerService (com.faforever.client.player.PlayerService)1 UserOfflineEvent (com.faforever.client.player.UserOfflineEvent)1 UserOnlineEvent (com.faforever.client.player.UserOnlineEvent)1 ChatPrefs (com.faforever.client.preferences.ChatPrefs)1 PreferencesService (com.faforever.client.preferences.PreferencesService)1 FafService (com.faforever.client.remote.FafService)1 SocialMessage (com.faforever.client.remote.domain.SocialMessage)1 CompletableTask (com.faforever.client.task.CompletableTask)1 HIGH (com.faforever.client.task.CompletableTask.Priority.HIGH)1 TaskService (com.faforever.client.task.TaskService)1 UpdateApplicationBadgeEvent (com.faforever.client.ui.tray.event.UpdateApplicationBadgeEvent)1