diff --git a/Plugins/Mineplex.Core/src/mineplex/core/mission/MissionManager.java b/Plugins/Mineplex.Core/src/mineplex/core/mission/MissionManager.java index f9deba3cb..9abc9d9e7 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/mission/MissionManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/mission/MissionManager.java @@ -444,6 +444,7 @@ public class MissionManager extends MiniDbClientPlugin if (started > 0) { player.sendMessage(F.main(getName(), "You started " + F.count(started) + " new mission" + (started == 1 ? "" : "s") + ". Visit " + NPC_NAME + C.mBody + " to view them.")); + runAsync(_repository::bulkProcess); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/mission/MissionRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/mission/MissionRepository.java index 420475ced..4ddec63b3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/mission/MissionRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/mission/MissionRepository.java @@ -49,12 +49,14 @@ public class MissionRepository extends RepositoryBase } private final List _queries; + private final Object _lock; MissionRepository() { super(DBPool.getAccount()); _queries = new ArrayList<>(); + _lock = new Object(); } public void addQueryToQueue(MissionQuery query) @@ -69,21 +71,24 @@ public class MissionRepository extends RepositoryBase public void bulkProcess() { - if (_queries.isEmpty()) + synchronized (_lock) { - return; + if (_queries.isEmpty()) + { + return; + } + + String sqlQuery = _queries.stream() + .map(query -> query._query) + .collect(Collectors.joining()); + + if (executeUpdate(sqlQuery) > 0) + { + _queries.forEach(query -> query._callback.run()); + } + + _queries.clear(); } - - String sqlQuery = _queries.stream() - .map(query -> query._query) - .collect(Collectors.joining()); - - if (executeUpdate(sqlQuery) > 0) - { - _queries.forEach(query -> query._callback.run()); - } - - _queries.clear(); } public boolean completeMission(int accountId, int missionId)