@@ -13,6 +13,8 @@ import kotlinx.coroutines.CoroutineScope
1313import kotlinx.coroutines.Dispatchers
1414import kotlinx.coroutines.async
1515import kotlinx.coroutines.launch
16+ import kotlinx.coroutines.sync.Mutex
17+ import kotlinx.coroutines.sync.withLock
1618import net.minecraft.entity.player.ServerPlayerEntity
1719import org.apache.logging.log4j.LogManager
1820import 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