Search in sources :

Example 1 with PacketPlayOutCustomPayload

use of net.minecraft.server.v1_15_R1.PacketPlayOutCustomPayload in project solinia3-core by mixxit.

the class ForgeUtils method sendForgeMessage.

public static void sendForgeMessage(Player player, String channelName, byte discriminator, String message) throws Exception {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    DataOutputStream dataOut = new DataOutputStream(stream);
    try {
        // diesieben07 - Forge uses an unsigned byte for the discriminator, for a start
        // dataOut.writeInt(discriminator);
        dataOut.writeByte(discriminator);
        // diesieben07 - But you should really send some kind of length prefix
        // and then only read that much of the string
        // You're already using DataOuput, it has writeUTFString
        // dataOut.write(message.getBytes(StandardCharsets.UTF_8));
        dataOut.writeUTF(message);
        PacketPlayOutCustomPayload packet = new PacketPlayOutCustomPayload(new MinecraftKey(channelName), new PacketDataSerializer(Unpooled.wrappedBuffer(stream.toByteArray())));
        ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
    } finally {
        dataOut.close();
        stream.close();
    }
}
Also used : PacketDataSerializer(net.minecraft.server.v1_15_R1.PacketDataSerializer) DataOutputStream(java.io.DataOutputStream) PacketPlayOutCustomPayload(net.minecraft.server.v1_15_R1.PacketPlayOutCustomPayload) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MinecraftKey(net.minecraft.server.v1_15_R1.MinecraftKey)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 MinecraftKey (net.minecraft.server.v1_15_R1.MinecraftKey)1 PacketDataSerializer (net.minecraft.server.v1_15_R1.PacketDataSerializer)1 PacketPlayOutCustomPayload (net.minecraft.server.v1_15_R1.PacketPlayOutCustomPayload)1 CraftPlayer (org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer)1