Fix for a ConcurrentModificationException that can occur during the data save process

feat/data-edit-commands
William 3 years ago
parent deb92a767a
commit af95e80765

@ -172,7 +172,7 @@ public class BungeeRedisListener extends RedisListener {
// When all the data has been received, save it
if (MPDBMigrator.migratedDataSent == MPDBMigrator.playersMigrated) {
MPDBMigrator.loadIncomingData();
MPDBMigrator.loadIncomingData(MPDBMigrator.incomingPlayerData);
}
}
}

@ -33,7 +33,7 @@ public class MPDBMigrator {
private static final HuskSyncBungeeCord plugin = HuskSyncBungeeCord.getInstance();
public static HashMap<PlayerData,String> incomingPlayerData;
public static HashMap<PlayerData, String> incomingPlayerData;
public static MigrationSettings migrationSettings = new MigrationSettings();
private static Database sourceDatabase;
@ -198,15 +198,17 @@ public class MPDBMigrator {
}
/**
* Load all incoming decoded MPDB data to cache / SQL
* Loads all incoming decoded MPDB data to the cache and database
*
* @param dataToLoad HashMap of the {@link PlayerData} to player Usernames that will be loaded
*/
public static void loadIncomingData() {
public static void loadIncomingData(HashMap<PlayerData, String> dataToLoad) {
ProxyServer.getInstance().getScheduler().runAsync(plugin, () -> {
int playersSaved = 0;
plugin.getLogger().log(Level.INFO, "Saving data for " + playersMigrated + " players...");
for (PlayerData playerData : incomingPlayerData.keySet()) {
String playerName = incomingPlayerData.get(playerData);
for (PlayerData playerData : dataToLoad.keySet()) {
String playerName = dataToLoad.get(playerData);
// Add the player to the MySQL table
DataManager.ensurePlayerExists(playerData.getPlayerUUID(), playerName);

Loading…
Cancel
Save