public RoleUpdatePositionEvent(JDA api, long responseNumber, Role role, int oldPosition, int oldPositionRaw) { super(api, responseNumber, role, oldPosition, role.getPosition(), IDENTIFIER); this.oldPositionRaw = oldPositionRaw; this.newPositionRaw = role.getPositionRaw(); }
/** * Checks if one given Role can interact with a 2nd given Role - in a permission sense (kick/ban/modify perms). * This only checks the Role-Position and does not check the actual permission (kick/ban/manage_role/...) * * @param issuer * The role that tries to interact with 2nd role * @param target * The role that is the target of the interaction * * @throws IllegalArgumentException * if any of the provided parameters is {@code null} * or the provided entities are not from the same guild * * @return True, if issuer can interact with target */ public static boolean canInteract(Role issuer, Role target) { Checks.notNull(issuer, "Issuer Role"); Checks.notNull(target, "Target Role"); if(!issuer.getGuild().equals(target.getGuild())) throw new IllegalArgumentException("The 2 Roles are not from same Guild!"); return target.getPosition() < issuer.getPosition(); }
final int initialPos = role.getPosition(); if (initialPos != i && !isOwner && !self.canInteract(role))
/** * Checks if the given hierarchy position is lower than all roles given in the list. * * @param roles The list to compare the position to. * @param hierarchyPosition The position that should be compared with the list. * @return True if the given position is lower than any of the roles in the list, false otherwise. */ public static boolean isRoleHierarchyLower(@Nonnull List<Role> roles, int hierarchyPosition) { for (Role role : roles) { if (role.getPosition() < hierarchyPosition) { return false; } } return true; }
/** * Checks if the given hierarchy position is higher than all roles given in the list. * * @param roles The list to compare the position to. * @param hierarchyPosition The position that should be compared with the list. * @return True if the given position is higher than any of the roles in the list, false otherwise. */ public static boolean isRolePositionHigher(@Nonnull List<Role> roles, int hierarchyPosition) { for (Role role : roles) { if (role.getPosition() > hierarchyPosition) { return false; } } return true; }
/** * Get the role that is position highest in the role hierarchy for the given member. * * @param member The member whos roles should be used. * @return Possibly-null, if the user has any roles the role that is ranked highest in the role hierarchy will be returned. */ public static Role getHighestFrom(@Nonnull Member member) { Checks.notNull(member, "Member object can not be null"); List<Role> roles = member.getRoles(); if (roles.isEmpty()) { return null; } return roles.stream().sorted((first, second) -> { if (first.getPosition() == second.getPosition()) { return 0; } return first.getPosition() > second.getPosition() ? -1 : 1; }).findFirst().orElseGet(null); }
/** * Checks if the given roles hierarchy position is lower than all roles given in the list. * * @param roles The list to compare the role position to. * @param matchRole The role which position should be used in the comparison. * @return True if the given position is lower than any of the roles in the list, false otherwise. */ public static boolean isRoleHierarchyLower(@Nonnull List<Role> roles, @Nonnull Role matchRole) { Checks.notNull(matchRole, "Match roles can not be null"); return isRoleHierarchyLower(roles, matchRole.getPosition()); }
/** * Checks if the given roles hierarchy position is higher than all roles given in the list. * * @param roles The list to compare the role position to. * @param matchRole The role which position should be used in the comparison. * @return True if the given position is higher than any of the roles in the list, false otherwise. */ public static boolean isRoleHierarchyHigher(@Nonnull List<Role> roles, @Nonnull Role matchRole) { Checks.notNull(matchRole, "Match roles can not be null"); return isRolePositionHigher(roles, matchRole.getPosition()); }
public static String buildRoleData(List<Role> roles) { List<Map<String, Object>> rolesMap = new ArrayList<>(); for (Role role : roles) { if (role.isPublicRole()) { continue; } Map<String, Object> item = new HashMap<>(); item.put("id", role.getId()); item.put("name", role.getName()); item.put("position", role.getPosition()); item.put("permissions", role.getPermissionsRaw()); item.put("color", role.getColor() == null ? null : Integer.toHexString(role.getColor().getRGB()).substring(2) ); rolesMap.add(item); } return AvaIre.gson.toJson(rolesMap); }
private boolean canInteract(Member sender, Member target, GuildWrapper wrapper) { if (target.isOwner() || target.hasPermission(Permission.ADMINISTRATOR)) return true; if (target.getRoles().isEmpty() || sender.getRoles().isEmpty()) { return true; } Role muteRole = wrapper.getMutedRole(); Role topMemberRole = sender.getRoles().get(0); Role topTargetRole = target.getRoles().get(0); if (muteRole != null) { if (topMemberRole.getIdLong() == muteRole.getIdLong() && sender.getRoles().size() > 1) topMemberRole = sender.getRoles().get(1); if (topTargetRole.getIdLong() == muteRole.getIdLong() && target.getRoles().size() > 1) topTargetRole = target.getRoles().get(1); } return topMemberRole.getPosition() > topTargetRole.getPosition(); } }
if (!getGuild().getSelfMember().getRoles().isEmpty()) getGuild().getController().modifyRolePositions().selectPosition(mutedRole) .moveTo(getGuild().getSelfMember().getRoles().get(0).getPosition() - 1).queue(); mutedRoleID = mutedRole.getId(); handleMuteChannels(mutedRole);
List<Role> roles = guild.getRoles(); for (Role role : roles) { if (role.getPosition() == -1) { continue;