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));
}
}
Aggregations