Jump to content

Recommended Posts

Posted

Hello,

 

in Spigot I can send a message to the client like this: 

PluginInstance.getServer().getMessenger().registerOutgoingPluginChannel(pluginInstance, "namespace:path");

player.sendPluginMessage(PluginInstance, "namespace:path", "Message".getBytes(java.nio.charset.Charset.forName("UTF-8")));

 

I wasn't able to find the place where i can listen to those messages on the client side.

I tried 

SimpleChannel HANDLER = NetworkRegistry.ChannelBuilder.(...).simpleChannel();
HANDLER.registerMessage(...);

but i looks like this only works if client and server are sending custom packets (such with their own class and encode and decode methods), not custom payload packets.

I also tried

NetworkRegistry.newEventChannel(...).addListener(this::onNetworkEvent);

but this didn't work either.

 

As a last desperate attempt i "hacked" into the NetworkManager using a coremod to monitor all incomming packets, but even there the plugin message was no where to be found.

Am I missing something obvious, did I manage to always maneuver around the place there is documented or is there just no way how I can accomplish this?

Thanks in advance for any awnsers, have a nice day

Posted

Thank you for the response!

 

Can you give an example of how this would look like as code or which method I should use? How do I know which packet id bukkit used to send the packet to forge, or is there a general id which is used in this case? I'm a bit confused, since I can only register a custom packet class, so I don't know where I should put the packet id. Or maybe I am misunderstanding your explanation?

There are some more parameters confusing me, for example, I have to set client and server accepted version, but I cant set a version on the Spigot/Bukkit side.

Thanks in advance for any awnsers

Posted (edited)

Good evening!

 

Sorry, I am not able to make it work :(

 

Currently, I am using this piece of code to register the packet:

private static final SimpleChannel HANDLER = NetworkRegistry.ChannelBuilder
        .named(new ResourceLocation("namespace", "path"))
        .clientAcceptedVersions(NetworkRegistry.ABSENT::equals) //not sure about this, since I cant send a version on bukkit side
        .serverAcceptedVersions(NetworkRegistry.ABSENT::equals) //not sure about this, since I cant define a version on bukkit side
        .networkProtocolVersion(() -> "1")
        .simpleChannel();

....

HANDLER.registerMessage(0, CustomPacket.class, CustomPacket::encode, CustomPacket::decode, CustomPacket.Handler::handle); //is the 0 the id? the parameter name is "index", so I am not sure

 

On Bukkit/Spigot side I am sending this:

player.sendPluginMessage(pluginInstance, "namespace:path", "0|CustomPacket|Something".getBytes(java.nio.charset.Charset.forName("UTF-8")));

 

What am I doing wrong?

 

Thanks in advance for any awnsers

Edited by Quandtrium
Posted

Good evening!

 

Sadly, I still could not make it work :(

 

byte[] textMessageBytes = "SomeMessage".getBytes(java.nio.charset.Charset.forName("UTF-8")); //string message to bytes

byte[] message = new byte[messageBytes.length + 1]; //create an array big enough for the message and packet id

message[0] = (byte) 0; //set the first byte in the array as 0 (the packet id)

for(int index = 0; index < textMessageBytes.length; index++) //add the message
{
    message[index + 1] = textMessageBytes[index];
}
player.sendPluginMessage(pluginInstance, "namespace:path", message); //send

 

I'm sorry, but could you please tell me what I'am doing wrong here and give an example on how to do it correctly. Otherwise, is there any place where it is documented how to do this? I have searched a lot but could not find anything

Thanks in advance for any awnsers

Posted

I put debug messages into the handling method of the custom packet and used a core mod to display every incomming packet (NetworkManager#channelRead0), but the CustomPacket did not appear once. Maybe something is wrong with how I register it?

 

private static final SimpleChannel HANDLER = NetworkRegistry.ChannelBuilder
        .named(new ResourceLocation("path"ACCEPTVANILLAACCEPTVANILLA"1"
HANDLER.registerMessage(0, CustomPacket.class, CustomPacket::encode, CustomPacket::decode, CustomPacket.Handler::handle);
Posted

Sorry, that thing got messed up while copy pasting it, it looks like this:
 

private static final SimpleChannel HANDLER = NetworkRegistry.ChannelBuilder
        .named(new ResourceLocation("namespace", "path"))
        .clientAcceptedVersions(NetworkRegistry.ACCEPTVANILLA::equals)
        .serverAcceptedVersions(NetworkRegistry.ACCEPTVANILLA::equals)
        .networkProtocolVersion(() -> "1")
        .simpleChannel();

 

Thank you for looking into the source code, I would not have found this.
I will open a bug report on this.

Thank you for your help!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.