use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class AsynchronousUnregister method unregister.
/**
* Processes a player's request to unregister himself. Unregisters the player after
* successful password check.
*
* @param player the player
* @param password the input password to check before unregister
*/
public void unregister(Player player, String password) {
final String name = player.getName();
final PlayerAuth cachedAuth = playerCache.getAuth(name);
if (passwordSecurity.comparePassword(password, cachedAuth.getPassword(), name)) {
if (dataSource.removeAuth(name)) {
performUnregister(name, player);
ConsoleLogger.info(name + " unregistered himself");
bukkitService.createAndCallEvent(isAsync -> new UnregisterByPlayerEvent(player, isAsync));
} else {
service.send(player, MessageKey.ERROR);
}
} else {
service.send(player, MessageKey.WRONG_PASSWORD);
}
}
use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class AbstractDataSourceConverter method execute.
// Implementation note: Because of ForceFlatToSqlite it is possible that the CommandSender is null,
// which is never the case when a converter is launched from the /authme converter command.
@Override
public void execute(CommandSender sender) {
if (destinationType != destination.getType()) {
if (sender != null) {
sender.sendMessage("Please configure your connection to " + destinationType + " and re-run this command");
}
return;
}
S source;
try {
source = getSource();
} catch (Exception e) {
logAndSendMessage(sender, "The data source to convert from could not be initialized");
ConsoleLogger.logException("Could not initialize source:", e);
return;
}
List<String> skippedPlayers = new ArrayList<>();
for (PlayerAuth auth : source.getAllAuths()) {
if (destination.isAuthAvailable(auth.getNickname())) {
skippedPlayers.add(auth.getNickname());
} else {
adaptPlayerAuth(auth);
destination.saveAuth(auth);
destination.updateQuitLoc(auth);
}
}
if (!skippedPlayers.isEmpty()) {
logAndSendMessage(sender, "Skipped conversion for players which were already in " + destinationType + ": " + String.join(", ", skippedPlayers));
}
logAndSendMessage(sender, "Database successfully converted from " + source.getType() + " to " + destinationType);
}
use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class LoginSecurityConverter method migrateData.
/**
* Migrates the accounts.
*
* @param sender the command sender
* @param resultSet result set with the account data to migrate
*/
private void migrateData(CommandSender sender, ResultSet resultSet) throws SQLException {
List<String> skippedPlayers = new ArrayList<>();
long successfulSaves = 0;
while (resultSet.next()) {
String name = resultSet.getString("last_name");
if (dataSource.isAuthAvailable(name)) {
skippedPlayers.add(name);
} else {
PlayerAuth auth = buildAuthFromLoginSecurity(name, resultSet);
dataSource.saveAuth(auth);
++successfulSaves;
}
}
logAndSendMessage(sender, "Migrated " + successfulSaves + " accounts successfully from LoginSecurity");
if (!skippedPlayers.isEmpty()) {
logAndSendMessage(sender, "Skipped conversion for players which were already in AuthMe: " + String.join(", ", skippedPlayers));
}
}
use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class PlayerListener method onPlayerRespawn.
// TODO: check this, why do we need to update the quit loc? -sgdc3
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPlayerRespawn(PlayerRespawnEvent event) {
if (settings.getProperty(RestrictionSettings.NO_TELEPORT)) {
return;
}
if (!listenerService.shouldCancelEvent(event)) {
return;
}
Player player = event.getPlayer();
String name = player.getName().toLowerCase();
Location spawn = spawnLoader.getSpawnLocation(player);
if (settings.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION) && dataSource.isAuthAvailable(name)) {
PlayerAuth auth = PlayerAuth.builder().name(name).realName(player.getName()).location(spawn).build();
dataSource.updateQuitLoc(auth);
}
if (spawn != null && spawn.getWorld() != null) {
event.setRespawnLocation(spawn);
}
}
use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class AsynchronousUnregisterTest method shouldHandleDatabaseError.
@Test
public void shouldHandleDatabaseError() {
// given
Player player = mock(Player.class);
String name = "Frank21";
given(player.getName()).willReturn(name);
PlayerAuth auth = mock(PlayerAuth.class);
given(playerCache.getAuth(name)).willReturn(auth);
HashedPassword password = new HashedPassword("password", "in_auth_obj");
given(auth.getPassword()).willReturn(password);
String userPassword = "pass";
given(passwordSecurity.comparePassword(userPassword, password, name)).willReturn(true);
given(dataSource.removeAuth(name)).willReturn(false);
// when
asynchronousUnregister.unregister(player, userPassword);
// then
verify(passwordSecurity).comparePassword(userPassword, password, name);
verify(dataSource).removeAuth(name);
verify(service).send(player, MessageKey.ERROR);
verifyZeroInteractions(teleportationService, bukkitService);
}
Aggregations