use of org.javacord.api.event.user.UserChangeStatusEvent in project Javacord by BtoBastian.
the class PresenceUpdateHandler method dispatchUserStatusChangeEventIfChangeDetected.
private void dispatchUserStatusChangeEventIfChangeDetected(long userId, UserStatus newStatus, UserStatus oldStatus, Map<DiscordClient, UserStatus> newClientStatus, Map<DiscordClient, UserStatus> oldClientStatus) {
UserImpl user = api.getCachedUserById(userId).map(UserImpl.class::cast).orElse(null);
// Only dispatch the event if something changed
boolean shouldDispatch = false;
if (newClientStatus != oldClientStatus) {
shouldDispatch = true;
}
for (DiscordClient client : DiscordClient.values()) {
if (newClientStatus.get(client) != oldClientStatus.get(client)) {
shouldDispatch = true;
}
}
if (!shouldDispatch) {
return;
}
UserChangeStatusEvent event = new UserChangeStatusEventImpl(api, userId, newStatus, oldStatus, newClientStatus, oldClientStatus);
api.getEventDispatcher().dispatchUserChangeStatusEvent(api, user == null ? Collections.emptySet() : user.getMutualServers(), user == null ? Collections.emptySet() : Collections.singleton(user), event);
}
Aggregations