mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-28 22:47:41 +02:00
Added option to disable the grouped packet feature
This commit is contained in:
parent
1c916b92fa
commit
0faaea2c1b
@ -133,6 +133,7 @@ public final class MinecraftServer {
|
|||||||
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 boolean packetCaching = true;
|
||||||
|
private static boolean groupedPacket = 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;
|
||||||
@ -571,6 +572,34 @@ public final class MinecraftServer {
|
|||||||
MinecraftServer.packetCaching = packetCaching;
|
MinecraftServer.packetCaching = packetCaching;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets if the packet caching feature is enabled.
|
||||||
|
* <p>
|
||||||
|
* This features allow sending the exact same packet/buffer to multiple connections.
|
||||||
|
* It does provide a great performance benefit by allocating and writing/compressing only once.
|
||||||
|
* <p>
|
||||||
|
* It is enabled by default and it is our recommendation,
|
||||||
|
* you should only disable it if you want to modify packet per-players instead of sharing it.
|
||||||
|
* Disabling the feature would result in performance decrease.
|
||||||
|
*
|
||||||
|
* @return true if the grouped packet feature is enabled, false otherwise
|
||||||
|
*/
|
||||||
|
public static boolean hasGroupedPacket() {
|
||||||
|
return groupedPacket;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables or disable grouped packet.
|
||||||
|
*
|
||||||
|
* @param groupedPacket true to enable grouped packet
|
||||||
|
* @throws IllegalStateException if this is called after the server started
|
||||||
|
* @see #hasGroupedPacket()
|
||||||
|
*/
|
||||||
|
public static void setGroupedPacket(boolean groupedPacket) {
|
||||||
|
Check.stateCondition(started, "You cannot change the grouped packet value after the server has been started.");
|
||||||
|
MinecraftServer.groupedPacket = groupedPacket;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the consumer executed to show server-list data.
|
* Gets the consumer executed to show server-list data.
|
||||||
*
|
*
|
||||||
|
@ -47,6 +47,8 @@ public final class PacketUtils {
|
|||||||
if (players.isEmpty())
|
if (players.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (MinecraftServer.hasGroupedPacket()) {
|
||||||
|
// Send grouped packet...
|
||||||
final boolean success = PACKET_LISTENER_MANAGER.processServerPacket(packet, players);
|
final boolean success = PACKET_LISTENER_MANAGER.processServerPacket(packet, players);
|
||||||
if (success) {
|
if (success) {
|
||||||
final ByteBuf finalBuffer = createFramedPacket(packet, false);
|
final ByteBuf finalBuffer = createFramedPacket(packet, false);
|
||||||
@ -68,6 +70,18 @@ public final class PacketUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Write the same packet for each individual players
|
||||||
|
for (Player player : players) {
|
||||||
|
|
||||||
|
// Verify if the player should receive the packet
|
||||||
|
if (playerValidator != null && !playerValidator.isValid(player))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
final PlayerConnection playerConnection = player.getPlayerConnection();
|
||||||
|
playerConnection.sendPacket(packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user