• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SimplyVanilla / SimplyPerms / #9

07 Mar 2024 12:34PM UTC coverage: 28.729% (-0.2%) from 28.889%
#9

push

github

web-flow
Fixed [Velocity crash](https://gist.github.com/Netherwhal/5e37bd8a1656dbb9ac8cc88530144a65) happening when users in list are null (#6)

0 of 1 new or added line in 1 file covered. (0.0%)

1 existing line in 1 file now uncovered.

52 of 181 relevant lines covered (28.73%)

0.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.71
/src/main/java/net/simplyvanilla/simplyperms/users/User.java
1
package net.simplyvanilla.simplyperms.users;
2

3
import com.velocitypowered.api.permission.Tristate;
4
import it.fulminazzo.fulmicollection.objects.Printable;
5
import net.simplyvanilla.simplyperms.PermissionHolder;
6
import net.simplyvanilla.simplyperms.groups.Group;
7
import lombok.Getter;
8

9
import java.util.*;
10
import java.util.stream.Collectors;
11

12
@Getter
13
public class User extends Printable implements PermissionHolder {
14
    private static final List<User> USERS = new LinkedList<>();
1✔
15
    private final UUID uniqueId;
×
16
    Set<String> groups = new LinkedHashSet<>();
1✔
17

18
    public User(final String rawId) {
1✔
19
        try {
20
            this.uniqueId = UUID.fromString(rawId);
1✔
21
        } catch (Exception e) {
×
22
            throw new IllegalArgumentException(String.format("'%s' is not a valid UUID", rawId));
×
23
        }
1✔
24

25
        USERS.add(this);
1✔
26
    }
1✔
27

28
    @Override
29
    public boolean hasPermission(final String permission) {
30
        return getPermissionState(permission).equals(Tristate.TRUE);
1✔
31
    }
32

33
    @Override
34
    public Tristate getPermissionState(String permission) {
35
        return getGroups().stream()
1✔
36
                .map(g -> g.getPermissionState(permission))
1✔
37
                .findFirst().orElse(Tristate.UNDEFINED);
1✔
38
    }
39

40
    @Override
41
    public Set<String> getPermissions() {
42
        return getGroups().stream().flatMap(g -> g.getPermissions().stream()).collect(Collectors.toSet());
×
43
    }
44

45
    /**
46
     * Returns the corresponding set of groups of the user,
47
     * sorted from higher to lower weight.
48
     *
49
     * @return the groups
50
     */
51
    public Set<Group> getGroups() {
52
        this.groups.add("default");
1✔
53
        return this.groups.stream()
1✔
54
                .map(Group::getGroup)
1✔
55
                .filter(Objects::nonNull)
1✔
56
                .sorted(Comparator.comparing(g -> -Group.getWeight(g)))
1✔
57
                .collect(Collectors.toCollection(LinkedHashSet::new));
1✔
58
    }
59

60
    public static User getUser(final UUID uniqueId) {
61
        return uniqueId == null ? null : getUsers().stream()
×
62
                .filter(g -> g.getUniqueId().equals(uniqueId))
×
63
                .findFirst().orElseGet(() -> new User(uniqueId.toString()));
×
64
    }
65

66
    public static List<User> getUsers() {
NEW
67
        USERS.removeIf(Objects::isNull);
×
UNCOV
68
        return new LinkedList<>(USERS);
×
69
    }
70

71
    public static void clearUsers() {
72
        USERS.clear();
×
73
    }
×
74
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc