Sending data from Spigot server to Fabric client

75 Views Asked by At

I wanna send data from server to client using pluginMessage. using this code on the server

public static void sendPmcAdd(Player player, RegionContainer container) {
        if(!player.hasPermission(ClientModPermission))
            return;

        ByteArrayDataOutput out = ByteStreams.newDataOutput();
        out.write(0);
        out.writeUTF("add");

        container.serialize(out,true);

        player.sendPluginMessage(MineBreak.getInstance(), "mb:region", out.toByteArray());
    }

line: container.serialize(out,true); adds position data of the region.

on the client i read the recived message like this

private void handlePacket(@NotNull MinecraftClient client, @NotNull ClientPlayNetworkHandler handler,
                              @NotNull PacketByteBuf buffer, @NotNull PacketSender sender) {
        String message = buffer.readString();
        System.out.println(message);
    }

but the message is empty. how should i read the data on the client, or am i doing something wrong on the server?

Client is 1.20.1 fabric Server is 1.17.1 with ViaVersion plugin so other then 1.17.1 versions of the game can connect

I tried sending just simple string like "test message" to test if there is something wrong with region adding data. but its still empty on the client.

0

There are 0 best solutions below