Search in sources :

Example 11 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 = PlayerUtils.getUuidOrName(player);
    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(PlayerUtils.getUuidOrName(player), limbo);
    saveEntries(entries, file);
}
Also used : LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) File(java.io.File)

Example 12 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 = PlayerUtils.getUuidOrName(player);
    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 13 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);
    ConsoleLogger.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)

Example 14 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);
    String group = getString(jsonObject, GROUP);
    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, group, canFly, walkSpeed, flySpeed);
}
Also used : JsonObject(com.google.gson.JsonObject) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) Location(org.bukkit.Location)

Example 15 with LimboPlayer

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

the class DistributedFilesPersistenceHandler method removeLimboPlayer.

@Override
public void removeLimboPlayer(Player player) {
    String uuid = PlayerUtils.getUuidOrName(player);
    File file = getPlayerSegmentFile(uuid);
    if (file.exists()) {
        Map<String, LimboPlayer> entries = readLimboPlayers(file);
        if (entries != null && entries.remove(PlayerUtils.getUuidOrName(player)) != null) {
            saveEntries(entries, file);
        }
    }
}
Also used : LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) File(java.io.File)

Aggregations

LimboPlayer (fr.xephi.authme.data.limbo.LimboPlayer)25 Test (org.junit.Test)17 Player (org.bukkit.entity.Player)16 Location (org.bukkit.Location)10 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)9 File (java.io.File)7 World (org.bukkit.World)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 LimboService (fr.xephi.authme.data.limbo.LimboService)2 Logger (java.util.logging.Logger)2 JsonObject (com.google.gson.JsonObject)1 DebugSectionUtils.applyToLimboPlayersMap (fr.xephi.authme.command.executable.authme.debug.DebugSectionUtils.applyToLimboPlayersMap)1 DebugSectionUtils.formatLocation (fr.xephi.authme.command.executable.authme.debug.DebugSectionUtils.formatLocation)1 LimboPlayerMatchers.hasLocation (fr.xephi.authme.data.limbo.LimboPlayerMatchers.hasLocation)1 LimboPersistence (fr.xephi.authme.data.limbo.persistence.LimboPersistence)1 LoginEvent (fr.xephi.authme.events.LoginEvent)1 DebugSectionPermissions (fr.xephi.authme.permission.DebugSectionPermissions)1 PermissionNode (fr.xephi.authme.permission.PermissionNode)1 PermissionsManager (fr.xephi.authme.permission.PermissionsManager)1