@Override
    public int compare(PermissionHolder o1, PermissionHolder o2) {
        // if both users, return 0
        // if one or the other is a user, give a higher priority to the user
        boolean o1IsUser = o1.getType() == HolderType.USER;
        boolean o2IsUser = o2.getType() == HolderType.USER;
        if (o1IsUser && o2IsUser) {
            return 0;
        } else if (o1IsUser) {
            return 1;
        } else if (o2IsUser) {
            return -1;
        }

        Group o1Group = (Group) o1;
        Group o2Group = (Group) o2;

        int result = Integer.compare(o1.getWeight().orElse(0), o2.getWeight().orElse(0));
        if (result != 0) {
            return result;
        }

        // failing differing group weights, check if one of the groups is a primary group
        if (this.origin != null) {
            return Boolean.compare(
                    o1Group.getName().equalsIgnoreCase(this.origin.getPrimaryGroup().getStoredValue().orElse(GroupManager.DEFAULT_GROUP_NAME)),
                    o2Group.getName().equalsIgnoreCase(this.origin.getPrimaryGroup().getStoredValue().orElse(GroupManager.DEFAULT_GROUP_NAME))
            );
        }

        // failing weight/primary group checks, fallback to the node ordering
        // this comparator is only ever used by Collections.sort - which is stable. the existing
        // ordering of the nodes will therefore apply.
        return 0;
    }
Determines the order of group inheritance in {@link PermissionHolder}.
common/src/main/java/me/lucko/luckperms/common/inheritance/InheritanceComparator.java