RawPlayDataChannel is not supported during ServerSideConnectionEvent.Join
Affected Product(s)
SpongeVanilla
Version
spongevanilla-1.16.5-8.1.0-RC1175
Operating System
Linux
Java Version
17.0.8.1
Plugins/Mods
LibertyBans 1.1.0-SNAPSHOT, LuckPerms-Sponge 5.4.55.
Describe the bug
I'm using the bungeecord:main channel and attempting to send data during ServerSideConnectionEvent.Join. The channel returns that it is unsupported during this event.
However, RawPlayDataChannel is documented to support sending to clients during the play phase. Surely, is ServerSideConnectionEvent.Join not in the play phase?
Steps to reproduce:
- Configure SpongeVanilla in proxy mode
- Obtain bungeecord:main in ServerSideConnectionEvent.Join
- Check if the client supports this channel
@Listener(order = Order.EARLY)
public void onJoin(ServerSideConnectionEvent.Join event) {
ServerPlayer player = event.player();
Game game = Sponge.game();
RawPlayDataChannel channel = game.channelManager()
.ofType(ResourceKey.of("bungeecord", "main"), RawDataChannel.class)
.play();
boolean supported = channel.isSupportedBy(player.connection());
System.out.println("Supported: " + supported);
}
Link to logs
N/A
Hello,
ServerSideConnectionEvent.Join is called during the server tick and the channel bungeecord:main is registered right after because it is in a task. So a fix is to execute your code in a task
@Listener(order = Order.EARLY)
public void onJoin(ServerSideConnectionEvent.Join event) {
Task task = Task.builder().execute(() -> {
ServerPlayer player = event.player();
Game game = Sponge.game();
RawPlayDataChannel channel = game.channelManager()
.ofType(ResourceKey.of("bungeecord", "main"), RawDataChannel.class)
.play();
boolean supported = channel.isSupportedBy(player.connection());
System.out.println("Supported: " + supported);
}).plugin(this.plugin).build();
Sponge.server().scheduler().submit(task);
}
It works on my side
That might work. However, that behavior isn't documented anywhere to my knowledge -- if anything, the documentation even suggests otherwise. It's quite surprising that the join event works slightly differently: the player is in the play phase at this point, after all.
Why doesn't Sponge register this channel before the join event? That would make API use more approachable and avoid creating this edge case relating to the join event.