Search in sources :

Example 1 with UserUpdateActivitiesEvent

use of net.dv8tion.jda.api.events.user.update.UserUpdateActivitiesEvent in project JDA by DV8FromTheWorld.

the class PresenceUpdateHandler method handleActivities.

private void handleActivities(List<Activity> newActivities, @Nullable MemberImpl member, MemberPresenceImpl presence) {
    List<Activity> oldActivities = presence.getActivities();
    presence.setActivities(newActivities);
    if (member == null)
        return;
    boolean unorderedEquals = Helpers.deepEqualsUnordered(oldActivities, newActivities);
    if (unorderedEquals) {
        boolean deepEquals = Helpers.deepEquals(oldActivities, newActivities);
        if (!deepEquals) {
            getJDA().handleEvent(new UserUpdateActivityOrderEvent(getJDA(), responseNumber, oldActivities, member));
        }
    } else {
        getJDA().getEntityBuilder().updateMemberCache(member);
        // create modifiable copy
        List<Activity> stoppedActivities = new ArrayList<>(oldActivities);
        List<Activity> startedActivities = new ArrayList<>();
        for (Activity activity : newActivities) {
            if (!stoppedActivities.remove(activity))
                startedActivities.add(activity);
        }
        for (Activity activity : startedActivities) {
            getJDA().handleEvent(new UserActivityStartEvent(getJDA(), responseNumber, member, activity));
        }
        for (Activity activity : stoppedActivities) {
            getJDA().handleEvent(new UserActivityEndEvent(getJDA(), responseNumber, member, activity));
        }
        getJDA().handleEvent(new UserUpdateActivitiesEvent(getJDA(), responseNumber, member, oldActivities));
    }
}
Also used : UserActivityEndEvent(net.dv8tion.jda.api.events.user.UserActivityEndEvent) ArrayList(java.util.ArrayList) UserUpdateActivitiesEvent(net.dv8tion.jda.api.events.user.update.UserUpdateActivitiesEvent) Activity(net.dv8tion.jda.api.entities.Activity) UserUpdateActivityOrderEvent(net.dv8tion.jda.api.events.user.update.UserUpdateActivityOrderEvent) UserActivityStartEvent(net.dv8tion.jda.api.events.user.UserActivityStartEvent)

Aggregations

ArrayList (java.util.ArrayList)1 Activity (net.dv8tion.jda.api.entities.Activity)1 UserActivityEndEvent (net.dv8tion.jda.api.events.user.UserActivityEndEvent)1 UserActivityStartEvent (net.dv8tion.jda.api.events.user.UserActivityStartEvent)1 UserUpdateActivitiesEvent (net.dv8tion.jda.api.events.user.update.UserUpdateActivitiesEvent)1 UserUpdateActivityOrderEvent (net.dv8tion.jda.api.events.user.update.UserUpdateActivityOrderEvent)1