fabric: Fix channel identifier not being set correctly, Close #366

This commit is contained in:
William committed 2023-04-24 20:41:10 +01:00
1 parent 5bfe381677
commit c5183b073d
2 files changed
+14 -5

No files matched your search

@@ -138,7 +138,7 @@ public class FabricUser extends OnlineUser {
public void sendPluginMessage(@NotNull String channel, byte[] message) {
final PacketByteBuf buf = PacketByteBufs.create();
buf.writeBytes(message);
final CustomPayloadS2CPacket packet = new CustomPayloadS2CPacket(Identifier.tryParse(channel), buf);
final CustomPayloadS2CPacket packet = new CustomPayloadS2CPacket(parseIdentifier(channel), buf);
player.networkHandler.sendPacket(packet);
}
@@ -152,4 +152,13 @@ public class FabricUser extends OnlineUser {
return false;
}
@NotNull
private static Identifier parseIdentifier(@NotNull String channel) {
if (channel.equals("BungeeCord")) {
return new Identifier("bungeecord", "main");
}
return Optional.ofNullable(Identifier.tryParse(channel))
.orElseThrow(() -> new IllegalArgumentException("Invalid channel name: " + channel));
}
}