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