mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-06 00:17:58 +01:00
Only direct buffer should be used for IO
This commit is contained in:
parent
abe4d0f6ad
commit
165b7bced2
@ -3,7 +3,6 @@ package net.minestom.server.utils;
|
|||||||
import com.velocitypowered.natives.compression.VelocityCompressor;
|
import com.velocitypowered.natives.compression.VelocityCompressor;
|
||||||
import com.velocitypowered.natives.util.Natives;
|
import com.velocitypowered.natives.util.Natives;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.adventure.audience.ForwardingAudience;
|
import net.kyori.adventure.audience.ForwardingAudience;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
@ -34,7 +33,6 @@ public final class PacketUtils {
|
|||||||
private static final ThreadLocal<VelocityCompressor> COMPRESSOR = ThreadLocal.withInitial(() -> Natives.compress.get().create(4));
|
private static final ThreadLocal<VelocityCompressor> COMPRESSOR = ThreadLocal.withInitial(() -> Natives.compress.get().create(4));
|
||||||
|
|
||||||
private PacketUtils() {
|
private PacketUtils() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,7 +93,7 @@ public final class PacketUtils {
|
|||||||
// Send grouped packet...
|
// 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, true);
|
final ByteBuf finalBuffer = createFramedPacket(packet);
|
||||||
final FramedPacket framedPacket = new FramedPacket(finalBuffer);
|
final FramedPacket framedPacket = new FramedPacket(finalBuffer);
|
||||||
|
|
||||||
// Send packet to all players
|
// Send packet to all players
|
||||||
@ -281,14 +279,10 @@ public final class PacketUtils {
|
|||||||
* <p>
|
* <p>
|
||||||
* Can be used if you want to store a raw buffer and send it later without the additional writing cost.
|
* Can be used if you want to store a raw buffer and send it later without the additional writing cost.
|
||||||
* Compression is applied if {@link MinecraftServer#getCompressionThreshold()} is greater than 0.
|
* Compression is applied if {@link MinecraftServer#getCompressionThreshold()} is greater than 0.
|
||||||
*
|
|
||||||
* @param serverPacket the server packet to write
|
|
||||||
*/
|
*/
|
||||||
@NotNull
|
public static @NotNull ByteBuf createFramedPacket(@NotNull ServerPacket serverPacket) {
|
||||||
public static ByteBuf createFramedPacket(@NotNull ServerPacket serverPacket, boolean directBuffer) {
|
ByteBuf packetBuf = BufUtils.direct();
|
||||||
ByteBuf packetBuf = directBuffer ? BufUtils.direct() : Unpooled.buffer();
|
|
||||||
writeFramedPacket(packetBuf, serverPacket);
|
writeFramedPacket(packetBuf, serverPacket);
|
||||||
return packetBuf;
|
return packetBuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ public interface CacheablePacket {
|
|||||||
|
|
||||||
if (shouldUpdate) {
|
if (shouldUpdate) {
|
||||||
// Buffer freed by guava cache #removalListener
|
// Buffer freed by guava cache #removalListener
|
||||||
final ByteBuf buffer = PacketUtils.createFramedPacket(serverPacket, true);
|
final ByteBuf buffer = PacketUtils.createFramedPacket(serverPacket);
|
||||||
timedBuffer = new TimedBuffer(buffer, timestamp);
|
timedBuffer = new TimedBuffer(buffer, timestamp);
|
||||||
temporaryCache.cache(identifier, timedBuffer);
|
temporaryCache.cache(identifier, timedBuffer);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user