use of fr.xephi.authme.data.limbo.LimboPlayer in project AuthMeReloaded by AuthMe.
the class DistributedFilesPersistenceHandler method convertOldDataToCurrentSegmentScheme.
/**
* Loads segment files in the cache folder that don't correspond to the current segmenting scheme
* and migrates the data into files of the current segments. This allows a player to change the
* segment size without any loss of data.
*/
private void convertOldDataToCurrentSegmentScheme() {
String currentPrefix = segmentNameBuilder.getPrefix();
File[] files = listFiles(cacheFolder);
Map<String, LimboPlayer> allLimboPlayers = new HashMap<>();
List<File> migratedFiles = new ArrayList<>();
for (File file : files) {
if (isLimboJsonFile(file) && !file.getName().startsWith(currentPrefix)) {
Map<String, LimboPlayer> data = readLimboPlayers(file);
if (data != null) {
allLimboPlayers.putAll(data);
migratedFiles.add(file);
}
}
}
if (!allLimboPlayers.isEmpty()) {
saveToNewSegments(allLimboPlayers);
migratedFiles.forEach(FileUtils::delete);
}
}
use of fr.xephi.authme.data.limbo.LimboPlayer in project AuthMeReloaded by AuthMe.
the class LimboPlayerViewer method execute.
@Override
public void execute(CommandSender sender, List<String> arguments) {
if (arguments.isEmpty()) {
sender.sendMessage("/authme debug limbo <player>: show a player's limbo info");
sender.sendMessage("Available limbo records: " + applyToLimboPlayersMap(limboService, Map::keySet));
return;
}
LimboPlayer memoryLimbo = limboService.getLimboPlayer(arguments.get(0));
Player player = bukkitService.getPlayerExact(arguments.get(0));
LimboPlayer diskLimbo = player != null ? limboPersistence.getLimboPlayer(player) : null;
if (memoryLimbo == null && player == null) {
sender.sendMessage("No limbo info and no player online with name '" + arguments.get(0) + "'");
return;
}
sender.sendMessage(ChatColor.GOLD + "Showing disk limbo / limbo / player info for '" + arguments.get(0) + "'");
new InfoDisplayer(sender, diskLimbo, memoryLimbo, player).sendEntry("Is op", LimboPlayer::isOperator, Player::isOp).sendEntry("Walk speed", LimboPlayer::getWalkSpeed, Player::getWalkSpeed).sendEntry("Can fly", LimboPlayer::isCanFly, Player::getAllowFlight).sendEntry("Fly speed", LimboPlayer::getFlySpeed, Player::getFlySpeed).sendEntry("Location", l -> formatLocation(l.getLocation()), p -> formatLocation(p.getLocation())).sendEntry("Group", LimboPlayer::getGroup, permissionsManager::getPrimaryGroup);
}
use of fr.xephi.authme.data.limbo.LimboPlayer in project AuthMeReloaded by AuthMe.
the class DebugSectionUtilsTest method shouldFetchMapInLimboService.
@Test
public void shouldFetchMapInLimboService() {
// given
LimboService limboService = mock(LimboService.class);
Map<String, LimboPlayer> limboMap = new HashMap<>();
ReflectionTestUtils.setField(LimboService.class, limboService, "entries", limboMap);
// when
Map map = DebugSectionUtils.applyToLimboPlayersMap(limboService, Function.identity());
// then
assertThat(map, sameInstance(limboMap));
}
use of fr.xephi.authme.data.limbo.LimboPlayer in project AuthMeReloaded by AuthMe.
the class ProcessSyncPlayerLogin method processPlayerLogin.
public void processPlayerLogin(Player player) {
final String name = player.getName().toLowerCase();
final LimboPlayer limbo = limboService.getLimboPlayer(name);
// Limbo contains the State of the Player before /login
if (limbo != null) {
limboService.restoreData(player);
}
if (commonService.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) {
restoreInventory(player);
}
final PlayerAuth auth = dataSource.getAuth(name);
teleportationService.teleportOnLogin(player, auth, limbo);
// We can now display the join message (if delayed)
joinMessageService.sendMessage(name);
if (commonService.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
player.removePotionEffect(PotionEffectType.BLINDNESS);
}
// The Login event now fires (as intended) after everything is processed
bukkitService.callEvent(new LoginEvent(player));
player.saveData();
// Login is done, display welcome message
List<String> welcomeMessage = welcomeMessageConfiguration.getWelcomeMessage(player);
if (commonService.getProperty(RegistrationSettings.USE_WELCOME_MESSAGE)) {
if (commonService.getProperty(RegistrationSettings.BROADCAST_WELCOME_MESSAGE)) {
welcomeMessage.forEach(bukkitService::broadcastMessage);
} else {
welcomeMessage.forEach(player::sendMessage);
}
}
// Login is now finished; we can force all commands
commandManager.runCommandsOnLogin(player);
// Send Bungee stuff. The service will check if it is enabled or not.
bungeeService.connectPlayer(player);
}
use of fr.xephi.authme.data.limbo.LimboPlayer in project AuthMeReloaded by AuthMe.
the class IndividualFilesPersistenceHandlerTest method shouldReturnNullForUnavailablePlayer.
@Test
public void shouldReturnNullForUnavailablePlayer() {
// given
Player player = mock(Player.class);
given(player.getUniqueId()).willReturn(UUID.nameUUIDFromBytes("other-player".getBytes()));
// when
LimboPlayer data = handler.getLimboPlayer(player);
// then
assertThat(data, nullValue());
}
Aggregations