Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error gearth.protocol.HPacket cannot be converted to java.lang.String #35

Closed
sep1 opened this issue Mar 10, 2019 · 6 comments
Closed

Error gearth.protocol.HPacket cannot be converted to java.lang.String #35

sep1 opened this issue Mar 10, 2019 · 6 comments

Comments

@sep1
Copy link

sep1 commented Mar 10, 2019

Hello,

i'm trying to send a packet to the server using this method as suggested here

hashSupport.sendToServer(new HPacket("{l}{u:280}{s:This is a test!}{i:0}{i:0}"));

but i'm getting this error:

gearth.protocol.HPacket cannot be converted to java.lang.String

@XePeleato
Copy link
Collaborator

That's because you're using a HashSupport to send the packet. It takes as the first argument the name or the hash of the packet.

If you want to use the header id, then don't use the HashSupport, or remove the header from the packet and add the hash/name as the first argument of the function.

@sep1
Copy link
Author

sep1 commented Mar 10, 2019

Thanks! There is another problem. This is the code:

protected void initExtension() {
        hashSupport = new HashSupport(this);
        hashSupport.intercept(HMessage.Side.TOCLIENT, "RoomUserTalk", this::goSendMessage);
    }
private void goSendMessage(HMessage message) {
    	HPacket packet = message.getPacket();
        String speechtext = packet.readString();
        sendToServer(new HPacket("{l}{u:280}{s:"+speechtext+"}{i:0}{i:0}"));
    }

the speechtext variable return empty. What is the reason?

@XePeleato
Copy link
Collaborator

Check RoomUserTalk's structure, it doesn't start with a string, so it can't read it or it reads a corrupted one

@sep1
Copy link
Author

sep1 commented Mar 10, 2019

mmm, i'm still trying but i dont get it...

@XePeleato
Copy link
Collaborator

RoomUserTalk: {l}{u:830}{i:6313}{s:whatever}{i:0}{i:0}{i:0}{i:-1}

Don't you see that the string is in the second position?
do:

HPacket packet = message.getPacket();
        packet.readInteger(); // ADD THIS
        String speechtext = packet.readString();

@sep1
Copy link
Author

sep1 commented Mar 10, 2019

Now it's clear! Thank you very much. I appreciate it. ;)

@sep1 sep1 closed this as completed Mar 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants