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

SimplyVanilla / SimplyPerms / #18

11 Mar 2024 09:36PM UTC coverage: 26.178% (-2.1%) from 28.261%
#18

push

github

web-flow
Fix velocity crash #3 (#10)

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

* Added forced stack trace to individuate error on Velocity restart

* Removed internal static list and reworked constructor

* Created UsersManager to keep track of loaded users

* Added usersManager field

* Added addUser method

* Updated some methods to use users manager

* Updated to use users manager to retrieve users

* Updated SimplePermProvider

1 of 24 new or added lines in 4 files covered. (4.17%)

1 existing line in 1 file now uncovered.

50 of 191 relevant lines covered (26.18%)

0.26 hits per line

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

78.95
/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 lombok.Getter;
6
import net.simplyvanilla.simplyperms.PermissionHolder;
7
import net.simplyvanilla.simplyperms.groups.Group;
8

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

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

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

25
    @Override
26
    public boolean hasPermission(final String permission) {
27
        return getPermissionState(permission).equals(Tristate.TRUE);
1✔
28
    }
29

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

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

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