mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 14:46:46 +01:00
Save users asynchronously
This commit is contained in:
parent
6d719988bf
commit
4fb4d6fc0c
@ -422,12 +422,12 @@ public final class ExperienceAPI {
|
||||
profile.addLevels(parentSkill, (levels / parentSkills.size()));
|
||||
}
|
||||
|
||||
profile.save();
|
||||
profile.scheduleAsyncSave();
|
||||
return;
|
||||
}
|
||||
|
||||
profile.addLevels(skill, levels);
|
||||
profile.save();
|
||||
profile.scheduleAsyncSave();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -656,7 +656,7 @@ public final class ExperienceAPI {
|
||||
PlayerProfile profile = getOfflineProfile(playerName);
|
||||
|
||||
profile.addXp(skill, XP);
|
||||
profile.save();
|
||||
profile.scheduleAsyncSave();
|
||||
}
|
||||
|
||||
private static PlayerProfile getOfflineProfile(String playerName) {
|
||||
|
@ -27,7 +27,7 @@ public class AddlevelsCommand extends ExperienceCommand {
|
||||
profile.addLevels(skill, value);
|
||||
|
||||
if (player == null) {
|
||||
profile.save();
|
||||
profile.scheduleAsyncSave();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ public class AddxpCommand extends ExperienceCommand {
|
||||
}
|
||||
else {
|
||||
profile.addXp(skill, value);
|
||||
profile.save();
|
||||
profile.scheduleAsyncSave();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ public class MmoeditCommand extends ExperienceCommand {
|
||||
profile.modifySkill(skill, value);
|
||||
|
||||
if (player == null) {
|
||||
profile.save();
|
||||
profile.scheduleAsyncSave();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ public class SkillresetCommand implements TabExecutor {
|
||||
profile.modifySkill(skill, 0);
|
||||
|
||||
if (player == null) {
|
||||
profile.save();
|
||||
profile.scheduleAsyncSave();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ import com.gmail.nossr50.datatypes.MobHealthbarType;
|
||||
import com.gmail.nossr50.datatypes.experience.FormulaType;
|
||||
import com.gmail.nossr50.datatypes.skills.AbilityType;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.runnables.player.PlayerProfileSaveTask;
|
||||
import com.gmail.nossr50.skills.child.FamilyTree;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
|
||||
@ -19,7 +20,7 @@ import com.google.common.collect.ImmutableMap;
|
||||
public class PlayerProfile {
|
||||
private final String playerName;
|
||||
private boolean loaded;
|
||||
private boolean changed;
|
||||
private volatile boolean changed;
|
||||
|
||||
/* HUDs */
|
||||
private MobHealthbarType mobHealthbarType;
|
||||
@ -60,12 +61,18 @@ public class PlayerProfile {
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
public void scheduleAsyncSave() {
|
||||
new PlayerProfileSaveTask(this).runTaskAsynchronously(mcMMO.p);
|
||||
}
|
||||
|
||||
public void save() {
|
||||
if (!changed || !loaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
changed = !mcMMO.getDatabaseManager().saveUser(new PlayerProfile(playerName, ImmutableMap.copyOf(skills), ImmutableMap.copyOf(skillsXp), ImmutableMap.copyOf(abilityDATS), mobHealthbarType));
|
||||
// TODO should this part be synchronized?
|
||||
PlayerProfile profileCopy = new PlayerProfile(playerName, ImmutableMap.copyOf(skills), ImmutableMap.copyOf(skillsXp), ImmutableMap.copyOf(abilityDATS), mobHealthbarType);
|
||||
changed = !mcMMO.getDatabaseManager().saveUser(profileCopy);
|
||||
|
||||
if (changed) {
|
||||
mcMMO.p.getLogger().warning("PlayerProfile for " + playerName + " failed to save");
|
||||
|
@ -363,7 +363,7 @@ public class PlayerListener implements Listener {
|
||||
|
||||
mcMMOPlayer.resetAbilityMode();
|
||||
BleedTimerTask.bleedOut(player);
|
||||
mcMMOPlayer.getProfile().save();
|
||||
mcMMOPlayer.getProfile().scheduleAsyncSave();
|
||||
UserManager.remove(player);
|
||||
ScoreboardManager.teardownPlayer(player);
|
||||
}
|
||||
|
@ -205,6 +205,7 @@ public class mcMMO extends JavaPlugin {
|
||||
try {
|
||||
Alchemy.finishAllBrews(); // Finish all partially complete AlchemyBrewTasks to prevent vanilla brewing continuation on restart
|
||||
UserManager.saveAll(); // Make sure to save player information if the server shuts down
|
||||
UserManager.clearAll();
|
||||
PartyManager.saveParties(); // Save our parties
|
||||
ScoreboardManager.teardownAll();
|
||||
formulaManager.saveFormula();
|
||||
|
@ -41,7 +41,8 @@ public class FormulaConversionTask extends BukkitRunnable {
|
||||
}
|
||||
|
||||
editValues(profile);
|
||||
profile.save(); // Since this is a temporary profile, we save it here.
|
||||
// Since this is a temporary profile, we save it here.
|
||||
profile.scheduleAsyncSave();
|
||||
}
|
||||
else {
|
||||
profile = mcMMOPlayer.getProfile();
|
||||
|
@ -47,7 +47,7 @@ public final class UserManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Save all users.
|
||||
* Save all users ON THIS THREAD.
|
||||
*/
|
||||
public static void saveAll() {
|
||||
Player[] onlinePlayers = mcMMO.p.getServer().getOnlinePlayers();
|
||||
|
Loading…
Reference in New Issue
Block a user