com.nukkitx.protocol.bedrock.packet.TextPacket Java Examples

The following examples show how to use com.nukkitx.protocol.bedrock.packet.TextPacket. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TextSerializer_v354.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, TextPacket packet) {
    TextPacket.Type type = TextPacket.Type.values()[buffer.readUnsignedByte()];
    packet.setType(type);
    packet.setNeedsTranslation(buffer.readBoolean());
    switch (type) {
        case CHAT:
        case WHISPER:
        case ANNOUNCEMENT:
            packet.setSourceName(BedrockUtils.readString(buffer));
        case RAW:
        case TIP:
        case SYSTEM:
            packet.setMessage(BedrockUtils.readString(buffer));
            break;
        case TRANSLATION:
        case POPUP:
        case JUKEBOX_POPUP:
            packet.setMessage(BedrockUtils.readString(buffer));
            BedrockUtils.readArray(buffer, packet.getParameters(), BedrockUtils::readString);
            break;
    }
    packet.setXuid(BedrockUtils.readString(buffer));
    packet.setPlatformChatId(BedrockUtils.readString(buffer));
}
 
Example #2
Source File: TextSerializer_v388.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, TextPacket packet) {
    TextPacket.Type type = TextPacket.Type.values()[buffer.readUnsignedByte()];
    packet.setType(type);
    packet.setNeedsTranslation(buffer.readBoolean());
    switch (type) {
        case CHAT:
        case WHISPER:
        case ANNOUNCEMENT:
            packet.setSourceName(BedrockUtils.readString(buffer));
        case RAW:
        case TIP:
        case SYSTEM:
            packet.setMessage(BedrockUtils.readString(buffer));
            break;
        case TRANSLATION:
        case POPUP:
        case JUKEBOX_POPUP:
            packet.setMessage(BedrockUtils.readString(buffer));
            BedrockUtils.readArray(buffer, packet.getParameters(), BedrockUtils::readString);
            break;
    }
    packet.setXuid(BedrockUtils.readString(buffer));
    packet.setPlatformChatId(BedrockUtils.readString(buffer));
}
 
Example #3
Source File: TextSerializer_v340.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, TextPacket packet) {
    TextPacket.Type type = TextPacket.Type.values()[buffer.readUnsignedByte()];
    packet.setType(type);
    packet.setNeedsTranslation(buffer.readBoolean());
    switch (type) {
        case CHAT:
        case WHISPER:
        case ANNOUNCEMENT:
            packet.setSourceName(BedrockUtils.readString(buffer));
        case RAW:
        case TIP:
        case SYSTEM:
            packet.setMessage(BedrockUtils.readString(buffer));
            break;
        case TRANSLATION:
        case POPUP:
        case JUKEBOX_POPUP:
            packet.setMessage(BedrockUtils.readString(buffer));
            BedrockUtils.readArray(buffer, packet.getParameters(), BedrockUtils::readString);
            break;
    }
    packet.setXuid(BedrockUtils.readString(buffer));
    packet.setPlatformChatId(BedrockUtils.readString(buffer));
}
 
Example #4
Source File: TextSerializer_v313.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, TextPacket packet) {
    TextPacket.Type type = TextPacket.Type.values()[buffer.readUnsignedByte()];
    packet.setType(type);
    packet.setNeedsTranslation(buffer.readBoolean());
    switch (type) {
        case CHAT:
        case WHISPER:
        case ANNOUNCEMENT:
            packet.setSourceName(BedrockUtils.readString(buffer));
        case RAW:
        case TIP:
        case SYSTEM:
            packet.setMessage(BedrockUtils.readString(buffer));
            break;
        case TRANSLATION:
        case POPUP:
        case JUKEBOX_POPUP:
            packet.setMessage(BedrockUtils.readString(buffer));
            BedrockUtils.readArray(buffer, packet.getParameters(), BedrockUtils::readString);
            break;
    }
    packet.setXuid(BedrockUtils.readString(buffer));
    packet.setPlatformChatId(BedrockUtils.readString(buffer));
}
 
Example #5
Source File: TextSerializer_v361.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, TextPacket packet) {
    TextPacket.Type type = TextPacket.Type.values()[buffer.readUnsignedByte()];
    packet.setType(type);
    packet.setNeedsTranslation(buffer.readBoolean());
    switch (type) {
        case CHAT:
        case WHISPER:
        case ANNOUNCEMENT:
            packet.setSourceName(BedrockUtils.readString(buffer));
        case RAW:
        case TIP:
        case SYSTEM:
            packet.setMessage(BedrockUtils.readString(buffer));
            break;
        case TRANSLATION:
        case POPUP:
        case JUKEBOX_POPUP:
            packet.setMessage(BedrockUtils.readString(buffer));
            BedrockUtils.readArray(buffer, packet.getParameters(), BedrockUtils::readString);
            break;
    }
    packet.setXuid(BedrockUtils.readString(buffer));
    packet.setPlatformChatId(BedrockUtils.readString(buffer));
}
 
Example #6
Source File: TextSerializer_v332.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, TextPacket packet) {
    TextPacket.Type type = TextPacket.Type.values()[buffer.readUnsignedByte()];
    packet.setType(type);
    packet.setNeedsTranslation(buffer.readBoolean());
    switch (type) {
        case CHAT:
        case WHISPER:
        case ANNOUNCEMENT:
            packet.setSourceName(BedrockUtils.readString(buffer));
        case RAW:
        case TIP:
        case SYSTEM:
            packet.setMessage(BedrockUtils.readString(buffer));
            break;
        case TRANSLATION:
        case POPUP:
        case JUKEBOX_POPUP:
            packet.setMessage(BedrockUtils.readString(buffer));
            BedrockUtils.readArray(buffer, packet.getParameters(), BedrockUtils::readString);
            break;
    }
    packet.setXuid(BedrockUtils.readString(buffer));
    packet.setPlatformChatId(BedrockUtils.readString(buffer));
}
 
Example #7
Source File: TextSerializer_v291.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, TextPacket packet) {
    TextPacket.Type type = TextPacket.Type.values()[buffer.readUnsignedByte()];
    packet.setType(type);
    packet.setNeedsTranslation(buffer.readBoolean());
    switch (type) {
        case CHAT:
        case WHISPER:
        case ANNOUNCEMENT:
            packet.setSourceName(BedrockUtils.readString(buffer));
        case RAW:
        case TIP:
        case SYSTEM:
            packet.setMessage(BedrockUtils.readString(buffer));
            break;
        case TRANSLATION:
        case POPUP:
        case JUKEBOX_POPUP:
            packet.setMessage(BedrockUtils.readString(buffer));
            BedrockUtils.readArray(buffer, packet.getParameters(), BedrockUtils::readString);
            break;
    }
    packet.setXuid(BedrockUtils.readString(buffer));
    packet.setPlatformChatId(BedrockUtils.readString(buffer));
}
 
Example #8
Source File: JavaChatTranslator.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public void translate(ServerChatPacket packet, GeyserSession session) {
    TextPacket textPacket = new TextPacket();
    textPacket.setPlatformChatId("");
    textPacket.setSourceName("");
    textPacket.setXuid(session.getAuthData().getXboxUUID());
    switch (packet.getType()) {
        case CHAT:
            textPacket.setType(TextPacket.Type.CHAT);
            break;
        case SYSTEM:
            textPacket.setType(TextPacket.Type.SYSTEM);
            break;
        case NOTIFICATION:
            textPacket.setType(TextPacket.Type.TIP);
            break;
        default:
            textPacket.setType(TextPacket.Type.RAW);
            break;
    }

    String locale = session.getClientData().getLanguageCode();

    if (packet.getMessage() instanceof TranslationMessage) {
        textPacket.setType(TextPacket.Type.TRANSLATION);
        textPacket.setNeedsTranslation(true);

        List<String> paramsTranslated = MessageUtils.getTranslationParams(((TranslationMessage) packet.getMessage()).getTranslationParams(), locale);
        textPacket.setParameters(paramsTranslated);

        textPacket.setMessage(MessageUtils.insertParams(MessageUtils.getTranslatedBedrockMessage(packet.getMessage(), locale, true), paramsTranslated));
    } else {
        textPacket.setNeedsTranslation(false);

        textPacket.setMessage(MessageUtils.getTranslatedBedrockMessage(packet.getMessage(), locale, false));
    }

    session.sendUpstreamPacket(textPacket);
}
 
Example #9
Source File: BedrockTextTranslator.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public void translate(TextPacket packet, GeyserSession session) {
    String message = packet.getMessage().replaceAll("^\\.", "/").trim();

    if (MessageUtils.isTooLong(message, session)) {
        return;
    }

    ClientChatPacket chatPacket = new ClientChatPacket(message);
    session.sendDownstreamPacket(chatPacket);
}
 
Example #10
Source File: TextSerializer_v354.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, TextPacket packet) {
    TextPacket.Type type = packet.getType();
    buffer.writeByte(type.ordinal());
    buffer.writeBoolean(packet.isNeedsTranslation());

    switch (type) {
        case CHAT:
        case WHISPER:
        case ANNOUNCEMENT:
            BedrockUtils.writeString(buffer, packet.getSourceName());
        case RAW:
        case TIP:
        case SYSTEM:
            BedrockUtils.writeString(buffer, packet.getMessage());
            break;
        case TRANSLATION:
        case POPUP:
        case JUKEBOX_POPUP:
            BedrockUtils.writeString(buffer, packet.getMessage());
            BedrockUtils.writeArray(buffer, packet.getParameters(), BedrockUtils::writeString);
            break;
    }

    BedrockUtils.writeString(buffer, packet.getXuid());
    BedrockUtils.writeString(buffer, packet.getPlatformChatId());
}
 
Example #11
Source File: TextSerializer_v388.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, TextPacket packet) {
    TextPacket.Type type = packet.getType();
    buffer.writeByte(type.ordinal());
    buffer.writeBoolean(packet.isNeedsTranslation());

    switch (type) {
        case CHAT:
        case WHISPER:
        case ANNOUNCEMENT:
            BedrockUtils.writeString(buffer, packet.getSourceName());
        case RAW:
        case TIP:
        case SYSTEM:
            BedrockUtils.writeString(buffer, packet.getMessage());
            break;
        case TRANSLATION:
        case POPUP:
        case JUKEBOX_POPUP:
            BedrockUtils.writeString(buffer, packet.getMessage());
            BedrockUtils.writeArray(buffer, packet.getParameters(), BedrockUtils::writeString);
            break;
    }

    BedrockUtils.writeString(buffer, packet.getXuid());
    BedrockUtils.writeString(buffer, packet.getPlatformChatId());
}
 
Example #12
Source File: TextSerializer_v340.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, TextPacket packet) {
    TextPacket.Type type = packet.getType();
    buffer.writeByte(type.ordinal());
    buffer.writeBoolean(packet.isNeedsTranslation());

    switch (type) {
        case CHAT:
        case WHISPER:
        case ANNOUNCEMENT:
            BedrockUtils.writeString(buffer, packet.getSourceName());
        case RAW:
        case TIP:
        case SYSTEM:
            BedrockUtils.writeString(buffer, packet.getMessage());
            break;
        case TRANSLATION:
        case POPUP:
        case JUKEBOX_POPUP:
            BedrockUtils.writeString(buffer, packet.getMessage());
            BedrockUtils.writeArray(buffer, packet.getParameters(), BedrockUtils::writeString);
            break;
    }

    BedrockUtils.writeString(buffer, packet.getXuid());
    BedrockUtils.writeString(buffer, packet.getPlatformChatId());
}
 
Example #13
Source File: TextSerializer_v313.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, TextPacket packet) {
    TextPacket.Type type = packet.getType();
    buffer.writeByte(type.ordinal());
    buffer.writeBoolean(packet.isNeedsTranslation());

    switch (type) {
        case CHAT:
        case WHISPER:
        case ANNOUNCEMENT:
            BedrockUtils.writeString(buffer, packet.getSourceName());
        case RAW:
        case TIP:
        case SYSTEM:
            BedrockUtils.writeString(buffer, packet.getMessage());
            break;
        case TRANSLATION:
        case POPUP:
        case JUKEBOX_POPUP:
            BedrockUtils.writeString(buffer, packet.getMessage());
            BedrockUtils.writeArray(buffer, packet.getParameters(), BedrockUtils::writeString);
            break;
    }

    BedrockUtils.writeString(buffer, packet.getXuid());
    BedrockUtils.writeString(buffer, packet.getPlatformChatId());
}
 
Example #14
Source File: TextSerializer_v361.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, TextPacket packet) {
    TextPacket.Type type = packet.getType();
    buffer.writeByte(type.ordinal());
    buffer.writeBoolean(packet.isNeedsTranslation());

    switch (type) {
        case CHAT:
        case WHISPER:
        case ANNOUNCEMENT:
            BedrockUtils.writeString(buffer, packet.getSourceName());
        case RAW:
        case TIP:
        case SYSTEM:
            BedrockUtils.writeString(buffer, packet.getMessage());
            break;
        case TRANSLATION:
        case POPUP:
        case JUKEBOX_POPUP:
            BedrockUtils.writeString(buffer, packet.getMessage());
            BedrockUtils.writeArray(buffer, packet.getParameters(), BedrockUtils::writeString);
            break;
    }

    BedrockUtils.writeString(buffer, packet.getXuid());
    BedrockUtils.writeString(buffer, packet.getPlatformChatId());
}
 
Example #15
Source File: TextSerializer_v332.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, TextPacket packet) {
    TextPacket.Type type = packet.getType();
    buffer.writeByte(type.ordinal());
    buffer.writeBoolean(packet.isNeedsTranslation());

    switch (type) {
        case CHAT:
        case WHISPER:
        case ANNOUNCEMENT:
            BedrockUtils.writeString(buffer, packet.getSourceName());
        case RAW:
        case TIP:
        case SYSTEM:
            BedrockUtils.writeString(buffer, packet.getMessage());
            break;
        case TRANSLATION:
        case POPUP:
        case JUKEBOX_POPUP:
            BedrockUtils.writeString(buffer, packet.getMessage());
            BedrockUtils.writeArray(buffer, packet.getParameters(), BedrockUtils::writeString);
            break;
    }

    BedrockUtils.writeString(buffer, packet.getXuid());
    BedrockUtils.writeString(buffer, packet.getPlatformChatId());
}
 
Example #16
Source File: TextSerializer_v291.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, TextPacket packet) {
    TextPacket.Type type = packet.getType();
    buffer.writeByte(type.ordinal());
    buffer.writeBoolean(packet.isNeedsTranslation());

    switch (type) {
        case CHAT:
        case WHISPER:
        case ANNOUNCEMENT:
            BedrockUtils.writeString(buffer, packet.getSourceName());
        case RAW:
        case TIP:
        case SYSTEM:
            BedrockUtils.writeString(buffer, packet.getMessage());
            break;
        case TRANSLATION:
        case POPUP:
        case JUKEBOX_POPUP:
            BedrockUtils.writeString(buffer, packet.getMessage());
            BedrockUtils.writeArray(buffer, packet.getParameters(), BedrockUtils::writeString);
            break;
    }

    BedrockUtils.writeString(buffer, packet.getXuid());
    BedrockUtils.writeString(buffer, packet.getPlatformChatId());
}