This commit is contained in:
Eoghanmc22 2020-11-20 12:16:55 -05:00
commit c1c84217c2
3 changed files with 21 additions and 15 deletions

View File

@ -127,17 +127,18 @@ public class ChunkBatch implements InstanceBatch {
chunkPopulator.populateChunk(this, chunk);
}
}
// Refresh chunk for viewers
this.chunk.sendChunkUpdate();
this.instance.refreshLastBlockChangeTime();
// Safe callback
instance.scheduleNextTick(inst -> {
OptionalCallback.execute(callback, chunk);
});
}
// Refresh chunk for viewers
this.chunk.sendChunkUpdate();
this.instance.refreshLastBlockChangeTime();
// Safe callback
instance.scheduleNextTick(inst -> {
OptionalCallback.execute(callback, chunk);
});
});
}
@ -199,9 +200,9 @@ public class ChunkBatch implements InstanceBatch {
// Refresh chunk for viewers
chunk.sendChunkUpdate();
if (callback != null) {
this.instance.refreshLastBlockChangeTime();
this.instance.refreshLastBlockChangeTime();
if (callback != null) {
if (safeCallback) {
this.instance.scheduleNextTick(inst -> callback.accept(chunk));
} else {

View File

@ -124,7 +124,7 @@ public class NettyPlayerConnection extends PlayerConnection {
} else {
// Try to retrieve the cached buffer
TemporaryCache<ByteBuf> temporaryCache = cacheablePacket.getCache();
ByteBuf buffer = temporaryCache.retrieve(identifier);
ByteBuf buffer = temporaryCache.retrieve(identifier, cacheablePacket.getLastUpdateTime());
if (buffer == null) {
// Buffer not found, create and cache it
final long time = System.currentTimeMillis();

View File

@ -60,8 +60,13 @@ public class TemporaryCache<T> {
* @return the retrieved object or null if not found
*/
@Nullable
public T retrieve(@NotNull UUID identifier) {
return cache.get(identifier);
public synchronized T retrieve(@NotNull UUID identifier, long lastUpdate) {
if (!cacheTime.containsKey(identifier)) {
return null;
}
final long cachedTime = cacheTime.get(identifier);
return lastUpdate <= cachedTime ? cache.get(identifier) : null;
}
/**