Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public String execute(String args, CommandObject command) {
- for (CharacterObject c: command.characters.getCharacters()){
- if (c.getUserID().equals(command.authorID)){
- List<IRole> userRoles = command.guild.getRolesForUser(command.author);
- int roleCount = 0;
- int postRoleCount =0;
- //resets User roles back to scratch.
- for (int i = 0; i < userRoles.size();i++){
- if (command.guildConfig.isRoleCosmetic(userRoles.get(i).getID())){
- userRoles.remove(i);
- } else if (userRoles.get(i).isEveryoneRole()) {
- userRoles.remove(i);
- } else if (userRoles.get(i) != null){
- roleCount++;
- }
- }
- //loads new roles.
- for (RoleTypeObject r: c.getRoles()){
- userRoles.add(command.guild.getRoleByID(r.getRoleID()));
- }
- for (IRole role: command.guild.getRolesForUser(command.author)){
- if (!command.guildConfig.isRoleCosmetic(role.getID())){
- postRoleCount++;
- }
- }
- //validates only if non cosmetic roles were not removed.
- logger.debug("Prior to Edit Role Count :" + roleCount);
- logger.debug("Post Edit Role Count :" + postRoleCount);
- if (postRoleCount >= roleCount){
- Utility.roleManagement(command.author,command.guild,userRoles);
- Utility.updateUserNickName(command.author,command.guild,c.getNickname());
- return "> Character " + c.getNickname() + " Loaded.";
- }else {
- return "> An error occurred while attempting to load your character.";
- }
- }
- }
- return Constants.ERROR_CHAR_NOT_FOUND;
- }
- public static RequestBuffer.RequestFuture<Boolean> roleManagement(IUser author, IGuild guild, List<IRole> userRoles) {
- return RequestBuffer.request(() -> {
- try {
- IRole[] roles = new IRole[userRoles.size()];
- int i = 0;
- for (IRole r : userRoles) {
- if (r == null) {
- logger.error("ROLE RETURNED NULL");
- }
- roles[i] = r;
- i++;
- }
- guild.editUserRoles(author, roles);
- } catch (MissingPermissionsException e) {
- if (e.getMessage().contains("Edited roles hierarchy is too high.")) {
- logger.debug("Error Editing roles of user with id: " + author.getID() + " on guild with id: " + guild.getID() +
- ".\n" + Constants.PREFIX_EDT_LOGGER_INDENT + "Reason: Edited roles hierarchy is too high.");
- return true;
- } else {
- e.printStackTrace();
- return true;
- }
- } catch (DiscordException e) {
- if (e.getMessage().contains("CloudFlare")) {
- roleManagement(author, guild, userRoles);
- } else {
- e.printStackTrace();
- return true;
- }
- }
- return false;
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment