mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-23 16:41:35 +01:00
Small code cleanup for packet caching
This commit is contained in:
parent
25c2dc661f
commit
bde027432a
@ -129,26 +129,27 @@ public class NettyPlayerConnection extends PlayerConnection {
|
||||
// This packet explicitly asks to do not retrieve the cache
|
||||
write(serverPacket);
|
||||
} else {
|
||||
final long time = cacheablePacket.getTimestamp();
|
||||
final long timestamp = cacheablePacket.getTimestamp();
|
||||
// Try to retrieve the cached buffer
|
||||
TemporaryCache<TimedBuffer> temporaryCache = cacheablePacket.getCache();
|
||||
TimedBuffer timedBuffer = temporaryCache.retrieve(identifier);
|
||||
boolean shouldUpdate = false;
|
||||
|
||||
// Update the buffer if non-existent or outdated
|
||||
final boolean shouldUpdate = timedBuffer == null ||
|
||||
timestamp > timedBuffer.getTimestamp();
|
||||
|
||||
|
||||
if (timedBuffer == null) {
|
||||
// Buffer not found, create and cache it
|
||||
// Buffer not found, create it
|
||||
final ByteBuf buffer = PacketUtils.createFramedPacket(serverPacket, false);
|
||||
timedBuffer = new TimedBuffer(buffer, time);
|
||||
shouldUpdate = true;
|
||||
} else if (time > timedBuffer.getTimestamp()) { // Verify if `serverPacket` is more up-to-date
|
||||
shouldUpdate = true;
|
||||
timedBuffer = new TimedBuffer(buffer, timestamp);
|
||||
}
|
||||
|
||||
if (shouldUpdate) {
|
||||
temporaryCache.cache(identifier, timedBuffer);
|
||||
}
|
||||
|
||||
FramedPacket framedPacket = new FramedPacket(timedBuffer.getBuffer());
|
||||
write(framedPacket);
|
||||
write(new FramedPacket(timedBuffer.getBuffer()));
|
||||
}
|
||||
|
||||
} else
|
||||
|
Loading…
Reference in New Issue
Block a user