Search in sources :

Example 1 with TranslationMessage

use of com.github.steveice10.mc.protocol.data.message.TranslationMessage in project DragonProxy by DragonetMC.

the class MessageTranslator method translationTranslateParams.

public static String[] translationTranslateParams(Message[] messages) {
    ArrayList<String> strings = new ArrayList<>();
    for (int i = 0; i < messages.length; i++) {
        if (messages[i] instanceof TranslationMessage) {
            TranslationMessage tmsg = (TranslationMessage) messages[i];
            StringBuilder build = new StringBuilder("");
            build.append("%");
            build.append(tmsg.getTranslationKey());
            strings.add(build.toString());
            if (tmsg.getTranslationKey().equals("commands.gamemode.success.other"))
                strings.add("");
            for (int j = 0; j < translationTranslateParams(tmsg.getTranslationParams()).length; j++) strings.add(translationTranslateParams(tmsg.getTranslationParams())[j]);
        } else {
            StringBuilder build = new StringBuilder("");
            build.append(toMinecraftColor(messages[i].getStyle().getColor()));
            build.append(toMinecraftFormat(messages[i].getStyle().getFormats()));
            build.append(translate(messages[i]));
            strings.add(build.toString());
        }
    }
    String[] stringArray = new String[strings.size()];
    return strings.toArray(stringArray);
}
Also used : ArrayList(java.util.ArrayList) TranslationMessage(com.github.steveice10.mc.protocol.data.message.TranslationMessage)

Example 2 with TranslationMessage

use of com.github.steveice10.mc.protocol.data.message.TranslationMessage in project DragonProxy by DragonetMC.

the class PCChatPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerChatPacket packet) {
    TextPacket pe = new TextPacket();
    switch(packet.getType()) {
        case NOTIFICATION:
            pe.message = pe.message = MessageTranslator.translate(packet.getMessage());
            pe.type = TYPE_POPUP;
            break;
        case CHAT:
            if (packet.getMessage() instanceof TranslationMessage) {
                pe.type = TYPE_TRANSLATION;
                pe.needsTranslation = true;
                pe.message = MessageTranslator.translationTranslateText((TranslationMessage) packet.getMessage());
                pe.params = MessageTranslator.translationTranslateParams(((TranslationMessage) packet.getMessage()).getTranslationParams());
            } else {
                pe.message = pe.message = MessageTranslator.translate(packet.getMessage());
                pe.type = TYPE_RAW;
            }
            break;
        case SYSTEM:
            if (packet.getMessage() instanceof TranslationMessage) {
                pe.type = TYPE_TRANSLATION;
                pe.needsTranslation = true;
                pe.message = MessageTranslator.translationTranslateText((TranslationMessage) packet.getMessage());
                pe.params = MessageTranslator.translationTranslateParams(((TranslationMessage) packet.getMessage()).getTranslationParams());
            } else {
                pe.message = pe.message = MessageTranslator.translate(packet.getMessage());
                pe.type = TYPE_RAW;
            }
            break;
    }
    return new PEPacket[] { pe };
}
Also used : TextPacket(org.dragonet.protocol.packets.TextPacket) PEPacket(org.dragonet.protocol.PEPacket) TranslationMessage(com.github.steveice10.mc.protocol.data.message.TranslationMessage)

Aggregations

TranslationMessage (com.github.steveice10.mc.protocol.data.message.TranslationMessage)2 ArrayList (java.util.ArrayList)1 PEPacket (org.dragonet.protocol.PEPacket)1 TextPacket (org.dragonet.protocol.packets.TextPacket)1