Search in sources :

Example 1 with LimboPlayer

use of fr.xephi.authme.data.limbo.LimboPlayer 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 LimboPlayer

use of fr.xephi.authme.data.limbo.LimboPlayer 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 3 with LimboPlayer

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

the class DistributedFilesPersistenceHandler method getLimboPlayer.

@Override
public LimboPlayer getLimboPlayer(Player player) {
    String uuid = player.getUniqueId().toString();
    File file = getPlayerSegmentFile(uuid);
    Map<String, LimboPlayer> entries = readLimboPlayers(file);
    return entries == null ? null : entries.get(uuid);
}
Also used : LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) File(java.io.File)

Example 4 with LimboPlayer

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

the class DistributedFilesPersistenceHandler method saveLimboPlayer.

@Override
public void saveLimboPlayer(Player player, LimboPlayer limbo) {
    String uuid = player.getUniqueId().toString();
    File file = getPlayerSegmentFile(uuid);
    Map<String, LimboPlayer> entries = null;
    if (file.exists()) {
        entries = readLimboPlayers(file);
    } else {
        FileUtils.create(file);
    }
    /* intentionally separate if */
    if (entries == null) {
        entries = new HashMap<>();
    }
    entries.put(uuid, limbo);
    saveEntries(entries, file);
}
Also used : LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) File(java.io.File)

Example 5 with LimboPlayer

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

the class DistributedFilesPersistenceHandler method saveToNewSegments.

/**
 * Saves the LimboPlayer data read from old segmenting schemes into the current segmenting scheme.
 *
 * @param limbosFromOldSegments the limbo players to store into the current segment files
 */
private void saveToNewSegments(Map<String, LimboPlayer> limbosFromOldSegments) {
    Map<String, Map<String, LimboPlayer>> limboBySegment = groupBySegment(limbosFromOldSegments);
    logger.info("Saving " + limbosFromOldSegments.size() + " LimboPlayers from old segments into " + limboBySegment.size() + " current segments");
    for (Map.Entry<String, Map<String, LimboPlayer>> entry : limboBySegment.entrySet()) {
        File file = getSegmentFile(entry.getKey());
        Map<String, LimboPlayer> limbosToSave = Optional.ofNullable(readLimboPlayers(file)).orElseGet(HashMap::new);
        limbosToSave.putAll(entry.getValue());
        saveEntries(limbosToSave, file);
    }
}
Also used : HashMap(java.util.HashMap) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File)

Aggregations

LimboPlayer (fr.xephi.authme.data.limbo.LimboPlayer)29 Test (org.junit.Test)18 Player (org.bukkit.entity.Player)16 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)11 Location (org.bukkit.Location)11 File (java.io.File)7 UserGroup (fr.xephi.authme.data.limbo.UserGroup)4 HashMap (java.util.HashMap)4 World (org.bukkit.World)4 LimboService (fr.xephi.authme.data.limbo.LimboService)3 Map (java.util.Map)3 JsonObject (com.google.gson.JsonObject)2 LoginEvent (fr.xephi.authme.events.LoginEvent)2 List (java.util.List)2 Logger (java.util.logging.Logger)2 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonSerializationContext (com.google.gson.JsonSerializationContext)1 JsonSerializer (com.google.gson.JsonSerializer)1