Search in sources :

Example 6 with UserGroup

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

the class DistributedFilesPersistenceHandlerTest method shouldAddPlayer.

@Test
public void shouldAddPlayer() {
    // given
    Player uuidToAdd1 = mockPlayerWithUuid(UNKNOWN_UUID);
    Location location1 = mockLocation("1world");
    LimboPlayer limbo1 = new LimboPlayer(location1, false, Collections.singletonList(new UserGroup("group-1")), true, 0.1f, 0.2f);
    Player uuidToAdd2 = mockPlayerWithUuid(UNKNOWN_UUID2);
    Location location2 = mockLocation("2world");
    LimboPlayer limbo2 = new LimboPlayer(location2, true, Collections.emptyList(), false, 0.0f, 0.25f);
    // when
    persistenceHandler.saveLimboPlayer(uuidToAdd1, limbo1);
    persistenceHandler.saveLimboPlayer(uuidToAdd2, limbo2);
    // then
    LimboPlayer addedPlayer1 = persistenceHandler.getLimboPlayer(uuidToAdd1);
    assertThat(addedPlayer1, isLimbo(limbo1));
    assertThat(addedPlayer1, hasLocation(location1));
    LimboPlayer addedPlayer2 = persistenceHandler.getLimboPlayer(uuidToAdd2);
    assertThat(addedPlayer2, isLimbo(limbo2));
    assertThat(addedPlayer2, hasLocation(location2));
    assertThat(persistenceHandler.getLimboPlayer(mockPlayerWithUuid(MIGRATED_UUID)), MIGRATED_LIMBO_MATCHER);
    assertThat(persistenceHandler.getLimboPlayer(mockPlayerWithUuid(UUID_FAB69)), FAB69_MATCHER);
    assertThat(persistenceHandler.getLimboPlayer(mockPlayerWithUuid(UUID_STAFF)), STAFF_MATCHER);
    assertThat(persistenceHandler.getLimboPlayer(mockPlayerWithUuid(UUID_8C679)), SC679_MATCHER);
}
Also used : Player(org.bukkit.entity.Player) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) Location(org.bukkit.Location) LimboPlayerMatchers.hasLocation(fr.xephi.authme.data.limbo.LimboPlayerMatchers.hasLocation) UserGroup(fr.xephi.authme.data.limbo.UserGroup) Test(org.junit.Test)

Example 7 with UserGroup

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

the class LuckPermsHandler method addToGroup.

@Override
public boolean addToGroup(OfflinePlayer player, UserGroup group) {
    Group newGroup = luckPerms.getGroupManager().getGroup(group.getGroupName());
    if (newGroup == null) {
        return false;
    }
    String playerName = player.getName();
    if (playerName == null) {
        return false;
    }
    User user = luckPerms.getUserManager().getUser(playerName);
    if (user == null) {
        return false;
    }
    InheritanceNode node = buildGroupNode(group);
    DataMutateResult result = user.data().add(node);
    if (result == DataMutateResult.FAIL) {
        return false;
    }
    luckPerms.getUserManager().saveUser(user);
    return true;
}
Also used : 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) DataMutateResult(net.luckperms.api.model.data.DataMutateResult)

Example 8 with UserGroup

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

the class LimboPlayerDeserializer method getLimboGroups.

/**
 * @param jsonObject LimboPlayer represented as JSON
 * @return The list of UserGroups create from JSON
 */
private static List<UserGroup> getLimboGroups(JsonObject jsonObject) {
    JsonElement element = jsonObject.get(GROUPS);
    if (element == null) {
        String legacyGroup = ofNullable(jsonObject.get(GROUP_LEGACY)).map(JsonElement::getAsString).orElse(null);
        return legacyGroup == null ? Collections.emptyList() : Collections.singletonList(new UserGroup(legacyGroup, null));
    }
    List<UserGroup> result = new ArrayList<>();
    JsonArray jsonArray = element.getAsJsonArray();
    for (JsonElement arrayElement : jsonArray) {
        if (!arrayElement.isJsonObject()) {
            result.add(new UserGroup(arrayElement.getAsString(), null));
        } else {
            JsonObject jsonGroup = arrayElement.getAsJsonObject();
            Map<String, String> contextMap = null;
            if (jsonGroup.has(CONTEXT_MAP)) {
                JsonElement contextMapJson = jsonGroup.get("contextMap");
                Type type = new TypeToken<Map<String, String>>() {
                }.getType();
                contextMap = new Gson().fromJson(contextMapJson.getAsString(), type);
            }
            String groupName = jsonGroup.get(GROUP_NAME).getAsString();
            result.add(new UserGroup(groupName, contextMap));
        }
    }
    return result;
}
Also used : JsonArray(com.google.gson.JsonArray) Type(java.lang.reflect.Type) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) Map(java.util.Map) UserGroup(fr.xephi.authme.data.limbo.UserGroup)

Example 9 with UserGroup

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

the class IndividualFilesPersistenceHandlerTest method shouldSavePlayerData.

@Test
public void shouldSavePlayerData() {
    // given
    Player player = mock(Player.class);
    UUID uuid = UUID.nameUUIDFromBytes("New player".getBytes());
    given(player.getUniqueId()).willReturn(uuid);
    World world = mock(World.class);
    given(world.getName()).willReturn("player-world");
    Location location = new Location(world, 0.2, 102.25, -89.28, 3.02f, 90.13f);
    LimboPlayer limbo = new LimboPlayer(location, true, Collections.singletonList(new UserGroup("primary-grp")), true, 1.2f, 0.8f);
    // when
    handler.saveLimboPlayer(player, limbo);
    // then
    File playerFile = new File(dataFolder, FileUtils.makePath("playerdata", uuid.toString(), "data.json"));
    assertThat(playerFile.exists(), equalTo(true));
// TODO ljacqu 20160711: Check contents of file
}
Also used : Player(org.bukkit.entity.Player) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) UUID(java.util.UUID) World(org.bukkit.World) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) File(java.io.File) Location(org.bukkit.Location) UserGroup(fr.xephi.authme.data.limbo.UserGroup) Test(org.junit.Test)

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