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