use of com.github.dirtpowered.dirtmv.network.server.ServerSession in project DirtMultiversion by DirtPowered.
the class GlobalProtocolHandler method registerTranslators.
@Override
public void registerTranslators() {
// chat (pre-netty)
addTranslator(0x03, ProtocolState.PRE_NETTY, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
int clientVersion = session.getUserData().getClientVersion().getRegistryId();
String message = clientVersion <= 10 ? data.read(Type.UTF8_STRING, 0) : data.read(Type.STRING, 0);
onChat(session, message);
return data;
}
});
// chat (post-netty)
addTranslator(0x01, ProtocolState.PLAY, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
String message = data.read(Type.V1_7_STRING, 0);
onChat(session, message);
return data;
}
});
// login (pre-netty)
addTranslator(0x01, ProtocolState.PRE_NETTY, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
int clientVersion = session.getUserData().getClientVersion().getRegistryId();
String username = clientVersion <= 10 ? data.read(Type.UTF8_STRING, 1) : data.read(Type.STRING, 1);
session.getUserData().setUsername(username);
return data;
}
});
// login (post-netty)
addTranslator(0x00, ProtocolState.LOGIN, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
session.getUserData().setUsername(data.read(Type.V1_7_STRING, 0));
return data;
}
});
}
Aggregations