GeyserMC/MCProtocolLib

I cannot chat after joining a server created with MCProtocolLib

Drownek opened this issue · 0 comments

I created serverAdapter to add sessionAdapter packetReceived listener. But when I send something in chat it does not appears in chat and it doesn't send any packet

server.addListener(new ServerAdapter() {
            @Override
            public void sessionAdded(final SessionAddedEvent event) {

                event.getSession().addListener(new SessionAdapter() {
                    @Override
                    public void packetReceived(final PacketReceivedEvent event) {

                        System.out.println("packet name: " + event.getPacket());
                        if (event.getPacket() instanceof ClientChatPacket) {
                            final ClientChatPacket packet = event.getPacket();
                            final GameProfile profile = event.getSession().getFlag("profile");

                            final Session session = event.getSession();
                            final String[] args = packet.getMessage().split(" ");

                            sendMessage("Your message is: " + packet.getMessage(), session);
                        }
                    }
                });
            }
        });

I also had a problem with libraries because they didn't have a few classes when I tried example code. So I used org.spacehq mcprotocollib (i don't know it is an older version or another library), and the server worked, but the chat didn't work.

My code:

        Server server = new Server("0.0.0.0", 25565, MinecraftProtocol.class, new TcpSessionFactory());

        server.setGlobalFlag("compression-threshold", 100);
        server.setGlobalFlag("verify-users", false);

        server.setGlobalFlag("login-handler", (ServerLoginHandler) session -> {

            session.send(new ServerJoinGamePacket(1, false,
                    GameMode.SURVIVAL, 0, Difficulty.PEACEFUL, 1000,
                    WorldType.FLAT, false));
            session.send(new ServerSpawnPositionPacket(new Position(
                    0, 100, 0)));
            session.send(new ServerPlayerAbilitiesPacket(false, false, false, false, 0.1f, 0.1f));
            session.send(new ServerChangeHeldItemPacket(0));
            session.send(new ServerUpdateTimePacket(1, 0L));
            session.send(new ServerPlayerPositionRotationPacket(0, 1337, 0, 0.0F, 0.0F));
        });
        server.addListener(new ServerAdapter() {
            @Override
            public void sessionAdded(final SessionAddedEvent event) {

                event.getSession().addListener(new SessionAdapter() {
                    @Override
                    public void packetReceived(final PacketReceivedEvent event) {

                        System.out.println("packet name: " + event.getPacket());
                        if (event.getPacket() instanceof ClientChatPacket) {
                            final ClientChatPacket packet = event.getPacket();
                            final GameProfile profile = event.getSession().getFlag("profile");

                            final Session session = event.getSession();
                            final String[] args = packet.getMessage().split(" ");

                            //message sent
                        }
                    }
                });
            }
        });
        server.bind();

Thank you for your help