mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-24 00:51:34 +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
|
// This packet explicitly asks to do not retrieve the cache
|
||||||
write(serverPacket);
|
write(serverPacket);
|
||||||
} else {
|
} else {
|
||||||
final long time = cacheablePacket.getTimestamp();
|
final long timestamp = cacheablePacket.getTimestamp();
|
||||||
// Try to retrieve the cached buffer
|
// Try to retrieve the cached buffer
|
||||||
TemporaryCache<TimedBuffer> temporaryCache = cacheablePacket.getCache();
|
TemporaryCache<TimedBuffer> temporaryCache = cacheablePacket.getCache();
|
||||||
TimedBuffer timedBuffer = temporaryCache.retrieve(identifier);
|
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) {
|
if (timedBuffer == null) {
|
||||||
// Buffer not found, create and cache it
|
// Buffer not found, create it
|
||||||
final ByteBuf buffer = PacketUtils.createFramedPacket(serverPacket, false);
|
final ByteBuf buffer = PacketUtils.createFramedPacket(serverPacket, false);
|
||||||
timedBuffer = new TimedBuffer(buffer, time);
|
timedBuffer = new TimedBuffer(buffer, timestamp);
|
||||||
shouldUpdate = true;
|
|
||||||
} else if (time > timedBuffer.getTimestamp()) { // Verify if `serverPacket` is more up-to-date
|
|
||||||
shouldUpdate = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldUpdate) {
|
if (shouldUpdate) {
|
||||||
temporaryCache.cache(identifier, timedBuffer);
|
temporaryCache.cache(identifier, timedBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
FramedPacket framedPacket = new FramedPacket(timedBuffer.getBuffer());
|
write(new FramedPacket(timedBuffer.getBuffer()));
|
||||||
write(framedPacket);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else
|
} else
|
||||||
|
Loading…
Reference in New Issue
Block a user