mirror of
https://github.com/Minestom/Minestom.git
synced 2024-10-27 22:10:21 +01:00
Made packet caching optional (enabled by default)
This commit is contained in:
parent
0e6bb6cc3d
commit
27414f65ab
@ -128,6 +128,7 @@ public final class MinecraftServer {
|
|||||||
private static int chunkViewDistance = 8;
|
private static int chunkViewDistance = 8;
|
||||||
private static int entityViewDistance = 5;
|
private static int entityViewDistance = 5;
|
||||||
private static int compressionThreshold = 256;
|
private static int compressionThreshold = 256;
|
||||||
|
private static boolean packetCaching = true;
|
||||||
private static ResponseDataConsumer responseDataConsumer;
|
private static ResponseDataConsumer responseDataConsumer;
|
||||||
private static String brandName = "Minestom";
|
private static String brandName = "Minestom";
|
||||||
private static Difficulty difficulty = Difficulty.NORMAL;
|
private static Difficulty difficulty = Difficulty.NORMAL;
|
||||||
@ -520,6 +521,33 @@ public final class MinecraftServer {
|
|||||||
MinecraftServer.compressionThreshold = compressionThreshold;
|
MinecraftServer.compressionThreshold = compressionThreshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets if the packet caching feature is enabled.
|
||||||
|
* <p>
|
||||||
|
* This feature allows some packets (implementing the {@link net.minestom.server.utils.cache.CacheablePacket} to be cached
|
||||||
|
* in order to do not have to be written and compressed over and over gain), this is especially useful for chunk and light packets.
|
||||||
|
* <p>
|
||||||
|
* It is enabled by default and it is our recommendation, you should only disable it if you want to focus on low memory usage
|
||||||
|
* at the cost of many packet writing and compression.
|
||||||
|
*
|
||||||
|
* @return true if the packet caching feature is enabled, false otherwise
|
||||||
|
*/
|
||||||
|
public static boolean hasPacketCaching() {
|
||||||
|
return packetCaching;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables or disable packet caching.
|
||||||
|
*
|
||||||
|
* @param packetCaching true to enable packet caching
|
||||||
|
* @throws IllegalStateException if this is called after the server started
|
||||||
|
* @see #hasPacketCaching()
|
||||||
|
*/
|
||||||
|
public static void setPacketCaching(boolean packetCaching) {
|
||||||
|
Check.stateCondition(started, "You cannot change the packet caching value after the server has been started.");
|
||||||
|
MinecraftServer.packetCaching = packetCaching;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the consumer executed to show server-list data.
|
* Gets the consumer executed to show server-list data.
|
||||||
*
|
*
|
||||||
|
@ -114,7 +114,7 @@ public class NettyPlayerConnection extends PlayerConnection {
|
|||||||
if (shouldSendPacket(serverPacket)) {
|
if (shouldSendPacket(serverPacket)) {
|
||||||
if (getPlayer() != null) {
|
if (getPlayer() != null) {
|
||||||
// Flush happen during #update()
|
// Flush happen during #update()
|
||||||
if (serverPacket instanceof CacheablePacket) {
|
if (serverPacket instanceof CacheablePacket && MinecraftServer.hasPacketCaching()) {
|
||||||
CacheablePacket cacheablePacket = (CacheablePacket) serverPacket;
|
CacheablePacket cacheablePacket = (CacheablePacket) serverPacket;
|
||||||
final UUID identifier = cacheablePacket.getIdentifier();
|
final UUID identifier = cacheablePacket.getIdentifier();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user