fix: Fix ConcurrentModificationException on PlayerData-Storage (#39)

This commit is contained in:
Christian Koop 2024-04-06 21:11:13 +02:00
parent 018e26c1b0
commit 4dffd7e2a8
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3
4 changed files with 34 additions and 15 deletions

View File

@ -5,6 +5,7 @@ import com.craftaro.core.hooks.economies.Economy;
import com.craftaro.skyblock.SkyBlock;
import com.craftaro.skyblock.config.FileManager;
import com.craftaro.skyblock.island.Island;
import com.craftaro.skyblock.playerdata.PlayerData;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
@ -12,6 +13,7 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class BankManager {
@ -71,8 +73,11 @@ public class BankManager {
}
private void loadTransactions() {
for (UUID uid : SkyBlock.getInstance().getPlayerDataManager().getPlayerData().keySet()) {
this.log.put(uid, SkyBlock.getInstance().getPlayerDataManager().getPlayerData().get(uid).getTransactions());
Map<UUID, PlayerData> playerDataStorage = SkyBlock.getInstance().getPlayerDataManager().getPlayerData();
synchronized (playerDataStorage) {
for (UUID uid : playerDataStorage.keySet()) {
this.log.put(uid, playerDataStorage.get(uid).getTransactions());
}
}
}

View File

@ -4,6 +4,9 @@ import com.craftaro.skyblock.playerdata.PlayerData;
import com.craftaro.skyblock.playerdata.PlayerDataManager;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Map;
import java.util.UUID;
public class ConfirmationTask extends BukkitRunnable {
private final PlayerDataManager playerDataManager;
@ -13,10 +16,13 @@ public class ConfirmationTask extends BukkitRunnable {
@Override
public void run() {
for (PlayerData playerData : this.playerDataManager.getPlayerData().values()) {
Map<UUID, PlayerData> playerDataStorage = this.playerDataManager.getPlayerData();
synchronized (playerDataStorage) {
for (PlayerData playerData : playerDataStorage.values()) {
if (playerData.getConfirmationTime() > 0) {
playerData.setConfirmationTime(playerData.getConfirmationTime() - 1);
}
}
}
}
}

View File

@ -1189,6 +1189,7 @@ public class IslandManager {
Map<UUID, PlayerData> playerDataStorage = this.plugin.getPlayerDataManager().getPlayerData();
Set<UUID> islandVisitors = new HashSet<>();
synchronized (playerDataStorage) {
for (UUID playerDataStorageList : playerDataStorage.keySet()) {
PlayerData playerData = playerDataStorage.get(playerDataStorageList);
UUID islandOwnerUUID = playerData.getIsland();
@ -1201,6 +1202,7 @@ public class IslandManager {
}
}
}
}
return islandVisitors;
}

View File

@ -4,6 +4,9 @@ import com.craftaro.skyblock.playerdata.PlayerData;
import com.craftaro.skyblock.playerdata.PlayerDataManager;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Map;
import java.util.UUID;
public class VisitTask extends BukkitRunnable {
private final PlayerDataManager playerDataManager;
@ -13,10 +16,13 @@ public class VisitTask extends BukkitRunnable {
@Override
public void run() {
for (PlayerData playerData : this.playerDataManager.getPlayerData().values()) {
Map<UUID, PlayerData> playerDataStorage = this.playerDataManager.getPlayerData();
synchronized (playerDataStorage) {
for (PlayerData playerData : playerDataStorage.values()) {
if (playerData.getIsland() != null) {
playerData.setVisitTime(playerData.getVisitTime() + 1);
}
}
}
}
}