Added a check to prevent playerdata from saving when it hasn't been fully loaded yet

This commit is contained in:
ASangarin 2020-12-21 21:57:48 +01:00
parent 59dd7ba4e1
commit 6c82011a77
4 changed files with 15 additions and 2 deletions

View File

@ -352,7 +352,7 @@ public class MMOCore extends JavaPlugin {
new BukkitRunnable() {
public void run() {
for (PlayerData loaded : PlayerData.getAll())
dataProvider.getDataManager().saveData(loaded);
if(loaded.isFullyLoaded()) dataProvider.getDataManager().saveData(loaded);
for (Guild guild : dataProvider.getGuildManager().getAll())
dataProvider.getGuildManager().save(guild);
@ -363,6 +363,7 @@ public class MMOCore extends JavaPlugin {
public void onDisable() {
for (PlayerData data : PlayerData.getAll()) {
if(!data.isFullyLoaded()) return;
data.getQuestData().resetBossBar();
dataProvider.getDataManager().saveData(data);
}

View File

@ -97,6 +97,8 @@ public class PlayerData extends OfflinePlayerData {
public boolean nocd;
public CombatRunnable combat;
private boolean fullyLoaded = false;
public PlayerData(MMOPlayerData mmoData) {
super(mmoData.getUniqueId());
@ -577,6 +579,14 @@ public class PlayerData extends OfflinePlayerData {
stellium = Math.max(0, Math.min(amount, getStats().getStat(StatType.MAX_STELLIUM)));
}
public boolean isFullyLoaded() {
return fullyLoaded;
}
public void setFullyLoaded() {
this.fullyLoaded = true;
}
public boolean isCasting() {
return skillCasting != null;
}

View File

@ -105,6 +105,7 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
}
}
}
data.setFullyLoaded();
} catch (SQLException e) {
e.printStackTrace();
}
@ -249,7 +250,7 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
@Override
public void remove(PlayerData data) {
saveData(data);
if(data.isFullyLoaded()) saveData(data);
remove(data.getUniqueId());
}
}

View File

@ -67,6 +67,7 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
} catch (IllegalArgumentException exception) {
MMOCore.log(Level.WARNING, "Could not load class info '" + key + "': " + exception.getMessage());
}
data.setFullyLoaded();
}
@Override