WirePackets cause a client-side error
SenseiKiwi opened this issue ยท 2 comments
Describe the bug
Sending WirePackets causes a client-side error. I tested by creating a WirePacket from a chat packet and sending the WirePacket five seconds later. I also tested with block change packets with similar results.
To Reproduce
I wrote the following small plugin as a test:
public class WirePacketDemoPlugin extends JavaPlugin {
@Override
public void onEnable() {
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
PacketAdapter.AdapterParameteters parameters = new PacketAdapter.AdapterParameteters()
.plugin(this)
.types(PacketType.Play.Server.CHAT)
.listenerPriority(ListenerPriority.MONITOR);
protocolManager.addPacketListener(new PacketAdapter(parameters) {
@Override
public void onPacketSending(PacketEvent event) {
// Send the same chat packet as a WirePacket, 5 seconds later.
plugin.getLogger().info("Sending chat packet...");
WirePacket wirePacket = WirePacket.fromPacket( event.getPacket() );
Player player = event.getPlayer();
Runnable delayedResend = new Runnable() {
@Override
public void run() {
if (player.isOnline()) {
try {
plugin.getLogger().info("Resending chat packet...");
protocolManager.sendWirePacket(player, wirePacket);
}
catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
};
Bukkit.getScheduler().runTaskLater(this.plugin, delayedResend, 5 * 20);
}
});
}
@Override
public void onDisable() { }
}
Logging onto a server running this plugin is enough to trigger the error (after a delay) since the server sends a chat message indicating that you connected.
Expected behavior
I expected the player to receive duplicate chat messages, five seconds apart.
Screenshots
The message seen on the client:
Version Info
https://pastebin.com/xdFxYrj3
Additional context
Apologies if I'm misunderstanding something about the library. I want WirePackets so that I can store and resend them in the future.
Can I at least get some clarification about whether I'm misusing the library? Or whether this feature is abandoned? It would save me from waiting weeks on something that might never work.
Apparently, WirePacket.fromPacket
only gets the ProtocolLib type from the packet, not its ID.
Internally, WirePacket
s use the ID of the current MC version to serialize the packets, meaning you will have to manually create a WirePacket
with the correct integer ID for the 1.16.5 chat packet.