Sponge <-> Bungee communication

The case:
We have a chat plugin running on bungee so that we can have a global chat between all of our servers (a mix of spigot and sponge), and for that we want to get the display name of the player on every server. For that we’re using bridges to send the data to the bungee plugin, and a bridge for spigot has already been made. Now we want to make a bridge for sponge, but since we’re new to sponge we don’t really know anything about coding a plugin for sponge and can’t find anything about it in the docs.

My question:
Is there a way for me to send the plugin on bungee a message containing the displayname of a player? If not, what do you think we should do, and is this a problem with bungee or sponge?

Context:
The plugin is Multichat. The dev for it is on hold if more details are required

Yes. You can use the Bungee API’s Forward protocol to send a plugin message packet to another server. This isn’t in the docs because it’s Bungee functionality, not Sponge functionality. I’m assuming you already know how to run plugin messages in Bukkit; Sponge’s is handled through the ChannelRegistrar.

1 Like

Thanks for the help so far, we’ve been trying to get it to work but I guess that we’re doing something completely wrong.
We have been trying to use the channelregistrar but so far aren’t having much luck. The bungee code is as follows:

public static void sendMessage(String message, ServerInfo server)
{
ByteArrayOutputStream stream = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(stream);
try
{
out.writeUTF(message);
}
catch (IOException e)
{
e.printStackTrace();
}
server.sendData(“MultiChat”, stream.toByteArray());

}

Sponge is as follows:

@Plugin(id = “multichat”, name = “MultiChat - Sponge Bridge”, version = “1.0”)
public final class SpongeComm {

ChannelRegistrar channelRegistrar;
RawDataChannel channel;

public void onServerStart(GameStartedServerEvent event) {
channelRegistrar = Sponge.getGame().getChannelRegistrar();
ChannelBinding.RawDataChannel channel = Sponge.getGame().getChannelRegistrar().createRawChannel(this, “MultiChat”);
channel.addListener(Platform.Type.SERVER, new MultiChatRawDataListener(channel));
this.channel = channel;
}

public void onServerStop(GameStoppingServerEvent event) {
Sponge.getChannelRegistrar().unbindChannel(channel);
}
}
public class MultiChatRawDataListener implements RawDataListener {

private RawDataChannel channel;

public MultiChatRawDataListener(RawDataChannel channel) {
super();
this.channel = channel;
System.out.println(“Created!”);
}

 @Override
 public void handlePayload(ChannelBuf data, RemoteConnection connection, Platform.Type side) {
  
     Optional<Player> player = Sponge.getServer().getPlayer(data.getUTF(0));
     Player p = player.get();
     channel.sendTo(p,buffer -> buffer.writeUTF(p.getDisplayNameData().displayName().toString()).writeUTF(p.getName()));
 
     System.out.println("DISPLAY NAME:" + p.getDisplayNameData().displayName().toString());
     
 }

}

It seems like sponge doesn’t even recieve the message from bungee, as we have the “System.out.println()” which never gets executed. The bungee code works perfectly with spigot. Do we need to modify the bungee code, sponge code or what is the error in this code?

You’re missing the @Listener annotation on your onServerStart and onServerStop methods, without that, Sponge doesn’t know that you’re listening for those events.

See https://docs.spongepowered.org/master/en-GB/plugin/event/listeners.html

Thank you dual! We’re still having some problems but I think we can work with this. Again, thanks a lot!