mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-24 09:01:54 +01:00
Off-by-default component translation
This commit is contained in:
parent
96826e03d1
commit
8dc7328c76
@ -27,6 +27,11 @@ import java.util.function.Function;
|
|||||||
* {@link TranslationRegistry} or your own implementation of {@link Translator}.
|
* {@link TranslationRegistry} or your own implementation of {@link Translator}.
|
||||||
*/
|
*/
|
||||||
public class SerializationManager {
|
public class SerializationManager {
|
||||||
|
/**
|
||||||
|
* If components should be automatically translated in outgoing packets.
|
||||||
|
*/
|
||||||
|
public static final boolean AUTOMATIC_COMPONENT_TRANSLATION = false;
|
||||||
|
|
||||||
protected static final Localizable NULL_LOCALIZABLE = () -> null;
|
protected static final Localizable NULL_LOCALIZABLE = () -> null;
|
||||||
|
|
||||||
private Function<Component, String> serializer = component -> GsonComponentSerializer.gson().serialize(component);
|
private Function<Component, String> serializer = component -> GsonComponentSerializer.gson().serialize(component);
|
||||||
|
@ -5,6 +5,7 @@ import io.netty.channel.Channel;
|
|||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.socket.SocketChannel;
|
import io.netty.channel.socket.SocketChannel;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
|
import net.minestom.server.adventure.SerializationManager;
|
||||||
import net.minestom.server.entity.PlayerSkin;
|
import net.minestom.server.entity.PlayerSkin;
|
||||||
import net.minestom.server.extras.mojangAuth.Decrypter;
|
import net.minestom.server.extras.mojangAuth.Decrypter;
|
||||||
import net.minestom.server.extras.mojangAuth.Encrypter;
|
import net.minestom.server.extras.mojangAuth.Encrypter;
|
||||||
@ -187,7 +188,7 @@ public class NettyPlayerConnection extends PlayerConnection {
|
|||||||
} else if (message instanceof ServerPacket) {
|
} else if (message instanceof ServerPacket) {
|
||||||
final ServerPacket serverPacket = (ServerPacket) message;
|
final ServerPacket serverPacket = (ServerPacket) message;
|
||||||
|
|
||||||
if (!skipTranslating && getPlayer() != null && serverPacket instanceof ComponentHoldingServerPacket) {
|
if ((SerializationManager.AUTOMATIC_COMPONENT_TRANSLATION && !skipTranslating) && getPlayer() != null && serverPacket instanceof ComponentHoldingServerPacket) {
|
||||||
serverPacket = ((ComponentHoldingServerPacket) serverPacket).copyWithOperator(component -> MinecraftServer.getSerializationManager().translate(component, getPlayer()));
|
serverPacket = ((ComponentHoldingServerPacket) serverPacket).copyWithOperator(component -> MinecraftServer.getSerializationManager().translate(component, getPlayer()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package net.minestom.server.utils;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
|
import net.minestom.server.adventure.SerializationManager;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
import net.minestom.server.listener.manager.PacketListenerManager;
|
import net.minestom.server.listener.manager.PacketListenerManager;
|
||||||
import net.minestom.server.network.netty.packet.FramedPacket;
|
import net.minestom.server.network.netty.packet.FramedPacket;
|
||||||
@ -49,7 +50,7 @@ public final class PacketUtils {
|
|||||||
// work out if the packet needs to be sent individually due to server-side translating
|
// work out if the packet needs to be sent individually due to server-side translating
|
||||||
boolean needsTranslating = false;
|
boolean needsTranslating = false;
|
||||||
|
|
||||||
if (packet instanceof ComponentHoldingServerPacket) {
|
if (SerializationManager.AUTOMATIC_COMPONENT_TRANSLATION && packet instanceof ComponentHoldingServerPacket) {
|
||||||
needsTranslating = MinecraftServer.getSerializationManager().areAnyTranslatable(((ComponentHoldingServerPacket) packet).components());
|
needsTranslating = MinecraftServer.getSerializationManager().areAnyTranslatable(((ComponentHoldingServerPacket) packet).components());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +76,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);
|
nettyPlayerConnection.write(framedPacket, true);
|
||||||
} else {
|
} else {
|
||||||
playerConnection.sendPacket(packet);
|
playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
@ -93,7 +94,7 @@ public final class PacketUtils {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
final PlayerConnection playerConnection = player.getPlayerConnection();
|
final PlayerConnection playerConnection = player.getPlayerConnection();
|
||||||
playerConnection.sendPacket(packet);
|
playerConnection.sendPacket(packet, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user