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 // When all the data has been received, save it
if (MPDBMigrator.migratedDataSent == MPDBMigrator.playersMigrated) { if (MPDBMigrator.migratedDataSent == MPDBMigrator.playersMigrated) {
MPDBMigrator.loadIncomingData(); MPDBMigrator.loadIncomingData(MPDBMigrator.incomingPlayerData);
} }
} }
} }

@ -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, () -> { ProxyServer.getInstance().getScheduler().runAsync(plugin, () -> {
int playersSaved = 0; int playersSaved = 0;
plugin.getLogger().log(Level.INFO, "Saving data for " + playersMigrated + " players..."); plugin.getLogger().log(Level.INFO, "Saving data for " + playersMigrated + " players...");
for (PlayerData playerData : incomingPlayerData.keySet()) { for (PlayerData playerData : dataToLoad.keySet()) {
String playerName = incomingPlayerData.get(playerData); String playerName = dataToLoad.get(playerData);
// Add the player to the MySQL table // Add the player to the MySQL table
DataManager.ensurePlayerExists(playerData.getPlayerUUID(), playerName); DataManager.ensurePlayerExists(playerData.getPlayerUUID(), playerName);

Loading…
Cancel
Save