* @return CharacterResult
*/
public CharacterResult create() {
final Result result = validators.runValidators();
if (result != null) {
return new CharacterResult(result, character, template);
}
final TransactionPool transactionPool = SingletonRepository.getTransactionPool();
final DBTransaction trans = transactionPool.beginWork();
final CharacterDAO characterDAO = DAORegister.get().get(CharacterDAO.class);
try {
if (characterDAO.hasCharacter(trans, character)) {
logger.warn("Character already exist: " + character);
transactionPool.commit(trans);
return new CharacterResult(Result.FAILED_PLAYER_EXISTS,
character, template);
}
final Player object = Player.createZeroLevelPlayer(character, template);
// monitor new account names
final String text = "Support: A new character has just been created called " + character + ".";
SingletonRepository.getRuleProcessor().sendMessageToSupporters(text);
/*
* Finally we add it to database.
*/
characterDAO.addCharacter(trans, username, character, object);
transactionPool.commit(trans);
return new CharacterResult(Result.OK_CREATED, character, object);
} catch (final Exception e) {
transactionPool.rollback(trans);
logger.error("Can't create character", e);
return new CharacterResult(Result.FAILED_EXCEPTION, character, template);
}
}