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) {
|
public void addPlayerToCache(JobsPlayer jPlayer) {
|
||||||
playersUUIDCache.putIfAbsent(jPlayer.playerUUID, 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);
|
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) {
|
public void addPlayer(JobsPlayer jPlayer) {
|
||||||
@ -426,6 +444,7 @@ public class PlayerManager {
|
|||||||
jPlayer.setUserId(info.getID());
|
jPlayer.setUserId(info.getID());
|
||||||
jPlayer.setDoneQuests(info.getQuestsDone());
|
jPlayer.setDoneQuests(info.getQuestsDone());
|
||||||
jPlayer.setQuestProgressionFromString(info.getQuestProgression());
|
jPlayer.setQuestProgressionFromString(info.getQuestProgression());
|
||||||
|
jPlayer.setSeen(info.getSeen());
|
||||||
|
|
||||||
if (jobs != null) {
|
if (jobs != null) {
|
||||||
for (JobsDAOData jobdata : jobs) {
|
for (JobsDAOData jobdata : jobs) {
|
||||||
|
@ -928,30 +928,32 @@ public class JobsPlayer {
|
|||||||
*/
|
*/
|
||||||
public void save(boolean async) {
|
public void save(boolean async) {
|
||||||
// synchronized (saveLock) {
|
// synchronized (saveLock) {
|
||||||
if (!isSaved) {
|
if (isSaved)
|
||||||
JobsDAO dao = Jobs.getJobsDAO();
|
return;
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
setSaved(true);
|
JobsDAO dao = Jobs.getJobsDAO();
|
||||||
|
if (async) {
|
||||||
Player player = getPlayer();
|
dao.saveAsync(this);
|
||||||
if (player == null || !player.isOnline()) {
|
dao.saveLogAsync(this);
|
||||||
Jobs.getPlayerManager().addPlayerToCache(this);
|
dao.savePointsAsync(this);
|
||||||
Jobs.getPlayerManager().removePlayer(player);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user