1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-25 12:05:16 +01:00

In case of user record duplication, newest one should be used

This commit is contained in:
Zrips 2024-09-28 11:12:10 +03:00
parent f592a0f8b8
commit ec603b9842
2 changed files with 44 additions and 23 deletions

View File

@ -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) {

View File

@ -928,30 +928,32 @@ public class JobsPlayer {
*/
public void save(boolean async) {
// synchronized (saveLock) {
if (!isSaved) {
JobsDAO dao = Jobs.getJobsDAO();
if (!async) {
dao.save(this);
dao.saveLog(this);
dao.savePoints(this);
dao.recordPlayersLimits(this);
dao.updateSeen(this);
} else {
dao.saveAsync(this);
dao.saveLogAsync(this);
dao.savePointsAsync(this);
dao.recordPlayersLimitsAsync(this);
dao.updateSeenAsync(this);
}
if (isSaved)
return;
setSaved(true);
Player player = getPlayer();
if (player == null || !player.isOnline()) {
Jobs.getPlayerManager().addPlayerToCache(this);
Jobs.getPlayerManager().removePlayer(player);
}
JobsDAO dao = Jobs.getJobsDAO();
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);
Player player = getPlayer();
if (player == null || !player.isOnline()) {
Jobs.getPlayerManager().addPlayerToCache(this);
Jobs.getPlayerManager().removePlayer(player);
}
// }
}