You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

BungeeCord消息通道接收内容与发送内容不一致问题求助

问题分析与解决

问题根源

你在Paper端使用ByteStreams.newDataOutput().writeUTF()发送命令字符串时,这个方法会自动在字符串前添加2字节的UTF-8长度前缀。而Bungee端直接将整个字节数组转为String,会把这个二进制前缀解析成乱码(也就是你看到的§和空格),导致命令无法识别执行。

修复代码

修改BungeeCord的消息接收逻辑,用ByteArrayDataInput正确读取writeUTF()写入的内容:

@EventHandler
public void onPluginMessageReceived(PluginMessageEvent event) {
    if(!event.getTag().equals("hqueue:inventory")) return;
    
    // 用对应工具类读取带长度前缀的UTF字符串
    ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
    String command = in.readUTF();
    
    System.out.println("Data received: " + command);
    ProxyServer.getInstance().getPluginManager().dispatchCommand(ProxyServer.getInstance().getConsole(), command);
}

关键说明

  • writeUTF()和readUTF()是成对使用的方法:前者负责给字符串添加长度前缀并编码,后者负责先读取前缀确定长度,再读取对应长度的有效字符串内容
  • 禁止直接用new String(event.getData())处理writeUTF()输出的字节数组,因为二进制长度前缀不属于命令字符串的一部分

内容的提问来源于stack exchange,提问作者Mike Chilled

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 02:41:07