mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-23 00:21:26 +01:00
Remove write branching
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
6db55ce91f
commit
65df72fa82
@ -188,7 +188,11 @@ 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()
|
||||||
write(serverPacket, skipTranslating);
|
if ((MinestomAdventure.AUTOMATIC_COMPONENT_TRANSLATION && !skipTranslating) && serverPacket instanceof ComponentHoldingServerPacket) {
|
||||||
|
serverPacket = ((ComponentHoldingServerPacket) serverPacket).copyWithOperator(component ->
|
||||||
|
GlobalTranslator.render(component, Objects.requireNonNullElseGet(getPlayer().getLocale(), MinestomAdventure::getDefaultLocale)));
|
||||||
|
}
|
||||||
|
attemptWrite(PacketUtils.createFramedPacket(serverPacket));
|
||||||
} else {
|
} else {
|
||||||
// Player is probably not logged yet
|
// Player is probably not logged yet
|
||||||
writeAndFlush(serverPacket);
|
writeAndFlush(serverPacket);
|
||||||
@ -196,28 +200,12 @@ public class NettyPlayerConnection extends PlayerConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(@NotNull Object message) {
|
public void write(@NotNull FramedPacket framedPacket) {
|
||||||
this.write(message, false);
|
attemptWrite(framedPacket.getBody());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(@NotNull Object message, boolean skipTranslating) {
|
public void write(@NotNull ByteBuffer buffer) {
|
||||||
if (message instanceof FramedPacket) {
|
attemptWrite(buffer);
|
||||||
final FramedPacket framedPacket = (FramedPacket) message;
|
|
||||||
attemptWrite(framedPacket.getBody());
|
|
||||||
return;
|
|
||||||
} else if (message instanceof ServerPacket) {
|
|
||||||
ServerPacket serverPacket = (ServerPacket) message;
|
|
||||||
if ((MinestomAdventure.AUTOMATIC_COMPONENT_TRANSLATION && !skipTranslating) && getPlayer() != null && serverPacket instanceof ComponentHoldingServerPacket) {
|
|
||||||
serverPacket = ((ComponentHoldingServerPacket) serverPacket).copyWithOperator(component ->
|
|
||||||
GlobalTranslator.render(component, Objects.requireNonNullElseGet(getPlayer().getLocale(), MinestomAdventure::getDefaultLocale)));
|
|
||||||
}
|
|
||||||
attemptWrite(PacketUtils.createFramedPacket(serverPacket));
|
|
||||||
return;
|
|
||||||
} else if (message instanceof ByteBuffer) {
|
|
||||||
attemptWrite((ByteBuffer) message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
throw new UnsupportedOperationException("type " + message.getClass() + " is not supported");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeAndFlush(@NotNull ServerPacket packet) {
|
public void writeAndFlush(@NotNull ServerPacket packet) {
|
||||||
@ -235,6 +223,7 @@ public class NettyPlayerConnection extends PlayerConnection {
|
|||||||
this.channel.write(tickBuffer.flip());
|
this.channel.write(tickBuffer.flip());
|
||||||
this.channel.write(buffer);
|
this.channel.write(buffer);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
|
disconnect();
|
||||||
MinecraftServer.getExceptionManager().handleException(ex);
|
MinecraftServer.getExceptionManager().handleException(ex);
|
||||||
} finally {
|
} finally {
|
||||||
this.tickBuffer.clear();
|
this.tickBuffer.clear();
|
||||||
|
@ -102,7 +102,7 @@ public final class PacketUtils {
|
|||||||
final PlayerConnection playerConnection = player.getPlayerConnection();
|
final PlayerConnection playerConnection = player.getPlayerConnection();
|
||||||
if (playerConnection instanceof NettyPlayerConnection) {
|
if (playerConnection instanceof NettyPlayerConnection) {
|
||||||
final NettyPlayerConnection nettyPlayerConnection = (NettyPlayerConnection) playerConnection;
|
final NettyPlayerConnection nettyPlayerConnection = (NettyPlayerConnection) playerConnection;
|
||||||
nettyPlayerConnection.write(framedPacket, true);
|
nettyPlayerConnection.write(framedPacket);
|
||||||
} else {
|
} else {
|
||||||
playerConnection.sendPacket(packet);
|
playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user