Search in sources :

Example 1 with UserGroup

use of fr.xephi.authme.data.limbo.UserGroup in project AuthMeReloaded by AuthMe.

the class IndividualFilesPersistenceHandlerTest method shouldReadDataFromFile.

@Test
public void shouldReadDataFromFile() {
    // given
    Player player = mock(Player.class);
    given(player.getUniqueId()).willReturn(SAMPLE_UUID);
    World world = mock(World.class);
    given(bukkitService.getWorld("nether")).willReturn(world);
    // when
    LimboPlayer data = handler.getLimboPlayer(player);
    // then
    assertThat(data, not(nullValue()));
    assertThat(data.isOperator(), equalTo(true));
    assertThat(data.isCanFly(), equalTo(true));
    assertThat(data.getWalkSpeed(), equalTo(0.2f));
    assertThat(data.getFlySpeed(), equalTo(0.1f));
    assertThat(data.getGroups(), contains(new UserGroup("players")));
    Location location = data.getLocation();
    assertThat(location.getX(), equalTo(-113.219));
    assertThat(location.getY(), equalTo(72.0));
    assertThat(location.getZ(), equalTo(130.637));
    assertThat(location.getWorld(), equalTo(world));
    assertThat(location.getPitch(), equalTo(24.15f));
    assertThat(location.getYaw(), equalTo(-292.484f));
}
Also used : Player(org.bukkit.entity.Player) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) World(org.bukkit.World) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) UserGroup(fr.xephi.authme.data.limbo.UserGroup) Location(org.bukkit.Location) Test(org.junit.Test)

Example 2 with UserGroup

use of fr.xephi.authme.data.limbo.UserGroup in project AuthMeReloaded by AuthMe.

the class VaultHandlerTest method shouldHandleNullAsGroups.

/**
 * Bug #1702: VaultHandler may return null for groups list.
 */
@Test
public void shouldHandleNullAsGroups() {
    // given
    Permission permissionMock = vaultHandlerTest.permissionMock;
    Player player = mock(Player.class);
    given(permissionMock.getPlayerGroups(null, player)).willReturn(null);
    // when
    List<UserGroup> result = vaultHandlerTest.getGroups(player);
    // then
    assertThat(result, empty());
    verify(permissionMock).getPlayerGroups(null, player);
}
Also used : Player(org.bukkit.entity.Player) Permission(net.milkbowl.vault.permission.Permission) UserGroup(fr.xephi.authme.data.limbo.UserGroup) Test(org.junit.Test)

Example 3 with UserGroup

use of fr.xephi.authme.data.limbo.UserGroup in project AuthMeReloaded by AuthMe.

the class VaultHandlerTest method shouldReturnGroups.

@Test
public void shouldReturnGroups() {
    // given
    Permission permissionMock = vaultHandlerTest.permissionMock;
    Player player = mock(Player.class);
    given(permissionMock.getPlayerGroups(null, player)).willReturn(new String[] { "abc", "test" });
    // when
    List<UserGroup> result = vaultHandlerTest.getGroups(player);
    // then
    List<String> groupNames = result.stream().map(UserGroup::getGroupName).collect(toList());
    assertThat(groupNames, contains("abc", "test"));
    verify(permissionMock).getPlayerGroups(null, player);
}
Also used : Player(org.bukkit.entity.Player) Permission(net.milkbowl.vault.permission.Permission) UserGroup(fr.xephi.authme.data.limbo.UserGroup) Test(org.junit.Test)

Example 4 with UserGroup

use of fr.xephi.authme.data.limbo.UserGroup in project AuthMeReloaded by AuthMe.

the class LimboPlayerDeserializer method deserialize.

@Override
public LimboPlayer deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) {
    JsonObject jsonObject = jsonElement.getAsJsonObject();
    if (jsonObject == null) {
        return null;
    }
    Location loc = deserializeLocation(jsonObject);
    boolean operator = getBoolean(jsonObject, IS_OP);
    Collection<UserGroup> groups = getLimboGroups(jsonObject);
    boolean canFly = getBoolean(jsonObject, CAN_FLY);
    float walkSpeed = getFloat(jsonObject, WALK_SPEED, LimboPlayer.DEFAULT_WALK_SPEED);
    float flySpeed = getFloat(jsonObject, FLY_SPEED, LimboPlayer.DEFAULT_FLY_SPEED);
    return new LimboPlayer(loc, operator, groups, canFly, walkSpeed, flySpeed);
}
Also used : JsonObject(com.google.gson.JsonObject) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) Location(org.bukkit.Location) UserGroup(fr.xephi.authme.data.limbo.UserGroup)

Example 5 with UserGroup

use of fr.xephi.authme.data.limbo.UserGroup in project AuthMeReloaded by AuthMe.

the class LuckPermsHandler method getGroups.

@Override
public List<UserGroup> getGroups(OfflinePlayer player) {
    String playerName = player.getName();
    if (playerName == null) {
        return Collections.emptyList();
    }
    User user = luckPerms.getUserManager().getUser(playerName);
    if (user == null) {
        logger.warning("LuckPermsHandler: tried to get groups for offline user " + player.getName() + " but it isn't loaded!");
        return Collections.emptyList();
    }
    return user.getDistinctNodes().stream().filter(node -> node instanceof InheritanceNode).map(node -> (InheritanceNode) node).map(node -> {
        Group group = luckPerms.getGroupManager().getGroup(node.getGroupName());
        if (group == null) {
            return null;
        }
        return new LuckPermGroup(group, node.getContexts());
    }).filter(Objects::nonNull).sorted((o1, o2) -> sortGroups(user, o1, o2)).map(g -> new UserGroup(g.getGroup().getName(), g.getContexts().toFlattenedMap())).collect(Collectors.toList());
}
Also used : ConsoleLoggerFactory(fr.xephi.authme.output.ConsoleLoggerFactory) PermissionNode(fr.xephi.authme.permission.PermissionNode) QueryOptions(net.luckperms.api.query.QueryOptions) TimeoutException(java.util.concurrent.TimeoutException) User(net.luckperms.api.model.user.User) UserGroup(fr.xephi.authme.data.limbo.UserGroup) ContextSetFactory(net.luckperms.api.context.ContextSetFactory) CachedPermissionData(net.luckperms.api.cacheddata.CachedPermissionData) ConsoleLogger(fr.xephi.authme.ConsoleLogger) DataMutateResult(net.luckperms.api.model.data.DataMutateResult) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) PermissionsSystemType(fr.xephi.authme.permission.PermissionsSystemType) UUID(java.util.UUID) Group(net.luckperms.api.model.group.Group) QueryMode(net.luckperms.api.query.QueryMode) Collectors(java.util.stream.Collectors) LuckPermsProvider(net.luckperms.api.LuckPermsProvider) OfflinePlayer(org.bukkit.OfflinePlayer) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) LuckPerms(net.luckperms.api.LuckPerms) NodeEqualityPredicate(net.luckperms.api.node.NodeEqualityPredicate) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) UserGroup(fr.xephi.authme.data.limbo.UserGroup) Group(net.luckperms.api.model.group.Group) User(net.luckperms.api.model.user.User) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) UserGroup(fr.xephi.authme.data.limbo.UserGroup)

Aggregations

UserGroup (fr.xephi.authme.data.limbo.UserGroup)9 Player (org.bukkit.entity.Player)5 Test (org.junit.Test)5 LimboPlayer (fr.xephi.authme.data.limbo.LimboPlayer)4 Location (org.bukkit.Location)4 JsonObject (com.google.gson.JsonObject)2 UUID (java.util.UUID)2 DataMutateResult (net.luckperms.api.model.data.DataMutateResult)2 Group (net.luckperms.api.model.group.Group)2 User (net.luckperms.api.model.user.User)2 InheritanceNode (net.luckperms.api.node.types.InheritanceNode)2 Permission (net.milkbowl.vault.permission.Permission)2 World (org.bukkit.World)2 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 ConsoleLogger (fr.xephi.authme.ConsoleLogger)1 LimboPlayerMatchers.hasLocation (fr.xephi.authme.data.limbo.LimboPlayerMatchers.hasLocation)1 ConsoleLoggerFactory (fr.xephi.authme.output.ConsoleLoggerFactory)1 PermissionNode (fr.xephi.authme.permission.PermissionNode)1