Skip to content

Commit 538864e

Browse files
committed
Mutex lock added for apply in LocalizationAPI.kt.
Signed-off-by: Pavel Erokhin (MairwunNx) <MairwunNx@gmail.com>
1 parent efddef4 commit 538864e

File tree

1 file changed

+10
-5
lines changed
  • src/main/kotlin/com/mairwunnx/projectessentials/core/api/v1/localization

1 file changed

+10
-5
lines changed

src/main/kotlin/com/mairwunnx/projectessentials/core/api/v1/localization/LocalizationAPI.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import kotlinx.coroutines.CoroutineScope
1313
import kotlinx.coroutines.Dispatchers
1414
import kotlinx.coroutines.async
1515
import kotlinx.coroutines.launch
16+
import kotlinx.coroutines.sync.Mutex
17+
import kotlinx.coroutines.sync.withLock
1618
import net.minecraft.entity.player.ServerPlayerEntity
1719
import org.apache.logging.log4j.LogManager
1820
import org.json.JSONObject
@@ -31,6 +33,7 @@ object LocalizationAPI {
3133
getConfigurationByName<GeneralConfiguration>("general")
3234
}
3335

36+
val mutex = Mutex()
3437
val localizations: HashMap<String, MutableList<HashMap<String, String>>> = hashMapOf()
3538

3639
inline fun apply(clazz: Class<*>, crossinline entries: () -> List<String>) {
@@ -47,11 +50,13 @@ object LocalizationAPI {
4750
predicate != "_comment"
4851
}.forEach { key ->
4952
val value = jsonObject.get(key) as String
50-
val result = localizations[name]
51-
if (result == null) {
52-
localizations[name] = mutableListOf(hashMapOf(key to value))
53-
} else {
54-
result.add(hashMapOf(Pair(key, value)))
53+
mutex.withLock {
54+
val result = localizations[name]
55+
if (result == null) {
56+
localizations[name] = mutableListOf(hashMapOf(key to value))
57+
} else {
58+
result.add(hashMapOf(Pair(key, value)))
59+
}
5560
}
5661
}
5762
}

0 commit comments

Comments
 (0)