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));
}
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);
}
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);
}
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);
}
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());
}
Aggregations