Package net.glowstone.net.message.play.game

Source Code of net.glowstone.net.message.play.game.PluginMessage

package net.glowstone.net.message.play.game;

import com.flowpowered.networking.Message;
import com.flowpowered.networking.util.ByteBufUtils;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import lombok.Data;
import net.glowstone.GlowServer;

import java.io.IOException;
import java.util.logging.Level;

@Data
public final class PluginMessage implements Message {

    private final String channel;
    private final byte[] data;

    public static PluginMessage fromString(String channel, String text) {
        ByteBuf buf = Unpooled.buffer(5 + text.length());
        try {
            ByteBufUtils.writeUTF8(buf, text);
        } catch (IOException e) {
            GlowServer.logger.log(Level.WARNING, "Error converting to PluginMessage: \"" + channel + "\", \"" + text + "\"", e);
        }
        return new PluginMessage(channel, buf.array());
    }

}
TOP

Related Classes of net.glowstone.net.message.play.game.PluginMessage

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.