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,7 +127,6 @@ public class ChunkBatch implements InstanceBatch {
chunkPopulator.populateChunk(this, chunk); chunkPopulator.populateChunk(this, chunk);
} }
} }
}
// Refresh chunk for viewers // Refresh chunk for viewers
this.chunk.sendChunkUpdate(); this.chunk.sendChunkUpdate();
@ -138,6 +137,8 @@ public class ChunkBatch implements InstanceBatch {
instance.scheduleNextTick(inst -> { instance.scheduleNextTick(inst -> {
OptionalCallback.execute(callback, chunk); OptionalCallback.execute(callback, chunk);
}); });
}
}); });
} }
@ -199,9 +200,9 @@ public class ChunkBatch implements InstanceBatch {
// Refresh chunk for viewers // Refresh chunk for viewers
chunk.sendChunkUpdate(); chunk.sendChunkUpdate();
if (callback != null) {
this.instance.refreshLastBlockChangeTime(); this.instance.refreshLastBlockChangeTime();
if (callback != null) {
if (safeCallback) { if (safeCallback) {
this.instance.scheduleNextTick(inst -> callback.accept(chunk)); this.instance.scheduleNextTick(inst -> callback.accept(chunk));
} else { } else {

View File

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

View File

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