mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-29 05:55:27 +01:00
In case of user record duplication, newest one should be used
This commit is contained in:
parent
f592a0f8b8
commit
ec603b9842
@ -133,8 +133,26 @@ public class PlayerManager {
|
||||
|
||||
public void addPlayerToCache(JobsPlayer jPlayer) {
|
||||
playersUUIDCache.putIfAbsent(jPlayer.playerUUID, jPlayer);
|
||||
if (jPlayer.getName() != null)
|
||||
if (jPlayer.getName() == null)
|
||||
return;
|
||||
|
||||
// On data load check for name duplication
|
||||
if (!Jobs.fullyLoaded) {
|
||||
// Checking for existing record by same name
|
||||
JobsPlayer oldRecord = playersNameCache.get(jPlayer.getName().toLowerCase());
|
||||
if (oldRecord != null) {
|
||||
CMIMessages.consoleMessage("&cDuplicate in database for (&f" + jPlayer.getName() + "&c) -> (&f" + jPlayer.getUniqueId() + "&c) <-> (&f" + oldRecord.getUniqueId() + "&c)");
|
||||
// Using newest record
|
||||
if (jPlayer.getSeen() > oldRecord.getSeen())
|
||||
playersNameCache.put(jPlayer.getName().toLowerCase(), jPlayer);
|
||||
return;
|
||||
}
|
||||
playersNameCache.putIfAbsent(jPlayer.getName().toLowerCase(), jPlayer);
|
||||
} else {
|
||||
// Add player to cache independent if there was other record by this name, we should use latest record
|
||||
playersNameCache.put(jPlayer.getName().toLowerCase(), jPlayer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void addPlayer(JobsPlayer jPlayer) {
|
||||
@ -426,6 +444,7 @@ public class PlayerManager {
|
||||
jPlayer.setUserId(info.getID());
|
||||
jPlayer.setDoneQuests(info.getQuestsDone());
|
||||
jPlayer.setQuestProgressionFromString(info.getQuestProgression());
|
||||
jPlayer.setSeen(info.getSeen());
|
||||
|
||||
if (jobs != null) {
|
||||
for (JobsDAOData jobdata : jobs) {
|
||||
|
@ -928,20 +928,22 @@ public class JobsPlayer {
|
||||
*/
|
||||
public void save(boolean async) {
|
||||
// synchronized (saveLock) {
|
||||
if (!isSaved) {
|
||||
if (isSaved)
|
||||
return;
|
||||
|
||||
JobsDAO dao = Jobs.getJobsDAO();
|
||||
if (!async) {
|
||||
dao.save(this);
|
||||
dao.saveLog(this);
|
||||
dao.savePoints(this);
|
||||
dao.recordPlayersLimits(this);
|
||||
dao.updateSeen(this);
|
||||
} else {
|
||||
if (async) {
|
||||
dao.saveAsync(this);
|
||||
dao.saveLogAsync(this);
|
||||
dao.savePointsAsync(this);
|
||||
dao.recordPlayersLimitsAsync(this);
|
||||
dao.updateSeenAsync(this);
|
||||
} else {
|
||||
dao.save(this);
|
||||
dao.saveLog(this);
|
||||
dao.savePoints(this);
|
||||
dao.recordPlayersLimits(this);
|
||||
dao.updateSeen(this);
|
||||
}
|
||||
|
||||
setSaved(true);
|
||||
@ -951,7 +953,7 @@ public class JobsPlayer {
|
||||
Jobs.getPlayerManager().addPlayerToCache(this);
|
||||
Jobs.getPlayerManager().removePlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user