} catch(Exception e) {
Out.exception(e);
}
Account rsAccount = Account.get(user);
Rank rsRank = (rsAccount == null) ? Rank.get(0) : rsAccount.getRank();
if(rsRank != null) {
// Autopromotions
Integer apDays = rsRank.getApDays();
// Check that they meet the days requirement
apBlock: if((apDays != null) && (apDays != 0)) {
double timeElapsed = 0;
if(rsAccount == null) {
timeElapsed = rsUser.getCreated().getTime();
} else if(rsAccount.getLastRankChange() != null) {
timeElapsed = rsAccount.getLastRankChange().getTime();
}
timeElapsed = System.currentTimeMillis() - timeElapsed;
timeElapsed /= 1000 * 60 * 60 * 24;
if(timeElapsed < apDays)
break apBlock;
if((rsRank.getApWins() == null)
|| (rsRank.getApD2Level() == null)
|| (rsRank.getApW3Level() == null))
break apBlock;
int apWins = rsRank.getApWins().intValue();
int apD2Level = rsRank.getApD2Level().intValue();
int apW3Level = rsRank.getApW3Level().intValue();
long wins[];
if(rsAccount == null)
wins = new long[] {0, 0, 0};
else
wins = rsAccount.getWinsLevels(GlobalSettings.recruitTagPrefix, GlobalSettings.recruitTagSuffix);
boolean hasEnoughWins = false;
hasEnoughWins |= ((apWins > 0) && (wins[0] >= apWins));
hasEnoughWins |= ((apD2Level > 0) && (wins[1] >= apD2Level));
hasEnoughWins |= ((apW3Level > 0) && (wins[2] >= apW3Level));
hasEnoughWins |= ((apWins == 0) && (apD2Level == 0) && (apW3Level == 0));
if(hasEnoughWins) {
// Check RS
long rs = 0;
if(rsAccount != null)
rs = rsAccount.getRecruitScore(GlobalSettings.recruitAccess);
Integer apRS = rsRank.getApRecruitScore();
if((apRS == null) || (apRS == 0) || (rs >= apRS)) {
int rank = 0;
if(rsAccount != null)
rank = rsAccount.getAccess();
else {
String name = user.getFullAccountName();
name = name.substring(0, name.indexOf('@'));
try {
Account recoverAccount = Account.get(name);
if((recoverAccount != null)
&& (recoverAccount.getAccess() <= 1)
&& (recoverAccount.getBnLogins().size() == 0)) {
rsAccount = recoverAccount;
// Reset the account to rank zero, just in case
rsAccount.setRank(Rank.get(0));
rsUser.setAccount(rsAccount);
rsUser.updateRow();
} else {
rsAccount = createAccount(name, 0, null, rsUser);
}
} catch(Exception e) {
Out.exception(e);
user.sendChat("I couldn't make an account for you: " + e.getMessage(), true);
break apBlock;
}
}
// Store the old AP mail message
String apMail = rsRank.getApMail();
// Give them a promotion
rsRank = Rank.get(++rank);
rsAccount.setRank(rsRank);
rsAccount.setLastRankChange(new Date(System.currentTimeMillis()));
try {
rsAccount.updateRow();
} catch(Exception e) {
Out.exception(e);
break apBlock;
}
user.resetPrettyName(); //Reset the presentable name
source.sendChat("Congratulations " + user.toString(GlobalSettings.bnUserToStringCommandResponse) + ", you've recieved a promotion! Your rank is now " + rsRank.getPrefix() + " (" + rank + ").");
if((apMail != null) && (apMail.length() > 0))
Mail.send(null, rsAccount, apMail);
} else {
user.sendChat("You need " + Long.toString(apRS - rs) + " more recruitment points to recieve a promotion!", true);
}
} else {
String msg = "You need ";
switch(user.getStatString().getProduct()) {
case STAR:
case SEXP:
case W2BN:
msg += Long.toString(apWins - wins[0]) + " more win";
if(apWins - wins[0] > 1)
msg += "s";
break;
case D2DV:
case D2XP:
msg += "to reach Diablo 2 level " + apD2Level;
break;
case WAR3:
case W3XP:
msg += "to reach Warcraft 3 level " + apW3Level;
break;
default:
break apBlock;
}
msg += " to recieve a promotion!";
user.sendChat(msg, true);
}
}
// Greetings
String greeting = rsRank.getGreeting();
if(greeting != null) {
try {
greeting = String.format(greeting, user.toString(), user.getPing(), user.getFullLogonName());
source.sendChat(greeting);
} catch(NoSuchMethodError e) {