Search in sources :

Example 1 with UserUpdateNameEvent

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

the class EntityBuilder method updateUser.

public void updateUser(UserImpl userObj, DataObject user) {
    String oldName = userObj.getName();
    String newName = user.getString("username");
    String oldDiscriminator = userObj.getDiscriminator();
    String newDiscriminator = user.get("discriminator").toString();
    String oldAvatar = userObj.getAvatarId();
    String newAvatar = user.getString("avatar", null);
    int oldFlags = userObj.getFlagsRaw();
    int newFlags = user.getInt("public_flags", 0);
    JDAImpl jda = getJDA();
    long responseNumber = jda.getResponseTotal();
    if (!oldName.equals(newName)) {
        userObj.setName(newName);
        jda.handleEvent(new UserUpdateNameEvent(jda, responseNumber, userObj, oldName));
    }
    if (!oldDiscriminator.equals(newDiscriminator)) {
        userObj.setDiscriminator(newDiscriminator);
        jda.handleEvent(new UserUpdateDiscriminatorEvent(jda, responseNumber, userObj, oldDiscriminator));
    }
    if (!Objects.equals(oldAvatar, newAvatar)) {
        userObj.setAvatarId(newAvatar);
        jda.handleEvent(new UserUpdateAvatarEvent(jda, responseNumber, userObj, oldAvatar));
    }
    if (oldFlags != newFlags) {
        userObj.setFlags(newFlags);
        jda.handleEvent(new UserUpdateFlagsEvent(jda, responseNumber, userObj, User.UserFlag.getFlags(oldFlags)));
    }
}
Also used : UserUpdateNameEvent(net.dv8tion.jda.api.events.user.update.UserUpdateNameEvent) UserUpdateFlagsEvent(net.dv8tion.jda.api.events.user.update.UserUpdateFlagsEvent) JDAImpl(net.dv8tion.jda.internal.JDAImpl) UserUpdateDiscriminatorEvent(net.dv8tion.jda.api.events.user.update.UserUpdateDiscriminatorEvent) UserUpdateAvatarEvent(net.dv8tion.jda.api.events.user.update.UserUpdateAvatarEvent)

Aggregations

UserUpdateAvatarEvent (net.dv8tion.jda.api.events.user.update.UserUpdateAvatarEvent)1 UserUpdateDiscriminatorEvent (net.dv8tion.jda.api.events.user.update.UserUpdateDiscriminatorEvent)1 UserUpdateFlagsEvent (net.dv8tion.jda.api.events.user.update.UserUpdateFlagsEvent)1 UserUpdateNameEvent (net.dv8tion.jda.api.events.user.update.UserUpdateNameEvent)1 JDAImpl (net.dv8tion.jda.internal.JDAImpl)1