mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 07:28:19 +01:00
Synchronize cache access
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
85559abb28
commit
ac4d78acf1
@ -111,8 +111,10 @@ final class TagHandlerImpl implements TagHandler {
|
|||||||
}
|
}
|
||||||
entries[index] = new Entry<>(tag, nbt);
|
entries[index] = new Entry<>(tag, nbt);
|
||||||
}
|
}
|
||||||
this.cache = null;
|
synchronized (this) {
|
||||||
this.entries = entries;
|
this.cache = null;
|
||||||
|
this.entries = entries;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -120,32 +122,29 @@ final class TagHandlerImpl implements TagHandler {
|
|||||||
return updatedCache().compound;
|
return updatedCache().compound;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Cache updatedCache() {
|
private synchronized Cache updatedCache() {
|
||||||
Cache cache = this.cache;
|
Cache cache = this.cache;
|
||||||
if (cache == null) {
|
if (cache == null) {
|
||||||
synchronized (this) {
|
Entry<?>[] entries = this.entries;
|
||||||
if ((cache = this.cache) != null) return cache;
|
if (entries.length > 0) {
|
||||||
Entry<?>[] entries = this.entries;
|
entries = entries.clone();
|
||||||
if (entries.length > 0) {
|
MutableNBTCompound tmp = new MutableNBTCompound();
|
||||||
entries = entries.clone();
|
for (Entry<?> entry : entries) {
|
||||||
MutableNBTCompound tmp = new MutableNBTCompound();
|
if (entry == null) continue;
|
||||||
for (Entry<?> entry : entries) {
|
final Tag<?> tag = entry.tag;
|
||||||
if (entry == null) continue;
|
final Object value = entry.value;
|
||||||
final Tag<?> tag = entry.tag;
|
if (value instanceof TagHandler handler) {
|
||||||
final Object value = entry.value;
|
// Path-able entry
|
||||||
if (value instanceof TagHandler handler) {
|
tmp.put(tag.getKey(), handler.asCompound());
|
||||||
// Path-able entry
|
} else {
|
||||||
tmp.put(tag.getKey(), handler.asCompound());
|
tag.writeUnsafe(tmp, value);
|
||||||
} else {
|
|
||||||
tag.writeUnsafe(tmp, value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
cache = !tmp.isEmpty() ? new Cache(entries, tmp.toCompound()) : Cache.EMPTY;
|
|
||||||
} else {
|
|
||||||
cache = Cache.EMPTY;
|
|
||||||
}
|
}
|
||||||
this.cache = cache;
|
cache = !tmp.isEmpty() ? new Cache(entries, tmp.toCompound()) : Cache.EMPTY;
|
||||||
|
} else {
|
||||||
|
cache = Cache.EMPTY;
|
||||||
}
|
}
|
||||||
|
this.cache = cache;
|
||||||
}
|
}
|
||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user