Using packets to mute and deafen players kicks them from the server
klaytonme opened this issue ยท 1 comments
Hi there!
I couldn't find duplicates of this problem anywhere, but I'm also very new to ProtocolLib and may be making a very silly mistake.
Expected Behavior
We are trying to block certain players from receiving or sending any chat messages (deafened and muted) when they join the server for the first time so it doesn't interrupt the welcome message and a couple other things we have planned.
Methods Used
To do this, I am generating a listener for any chat events being sent to or received by players on a list that is changed from elsewhere in the plugin.
Problem
The deafening and muting actually seems to be working great, but upon the transfer of a single message after being removed from the list (after the welcome message is done), they are booted from the server.
- If someone else sends the first chat, the error is: "Connection Lost, Server sent an invalid packet" (Error1.png)
- If the new player sends the first chat, the error is: "Connection Lost, Recieved chat packet with missing or invalid signature" (Error2.png)
Attempted Debugging
We have tried changing the server property "enforce-secure-profile" to false and installing the plugin "System Chat" which funnels all chat messages through system messages. These all to no avail. I pasted the code and included pictures of errors. Like I said, I've looked for duplicates of this issue, but I'm also very new to packet handling, so I'm not exactly sure what I'm looking for. Please let me know if I'm doing something very silly!
Thanks!
Clayton
Code (called from plugin's onEnable()
)
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(JavaPlugin.getProvidingPlugin(WPFSkyblock.class), ListenerPriority.NORMAL, PacketType.Play.Server.CHAT) {
@Override
public void onPacketSending(PacketEvent event) {
if (chatEvents.deafened.contains(event.getPlayer().getUniqueId().toString()) || chatEvents.deafenedTemp.contains(event.getPlayer().getUniqueId().toString())) {
// Prevent it from ever being sent
event.setCancelled(true);
}
}
@Override
public void onPacketReceiving(PacketEvent event) {
if (chatEvents.deafened.contains(event.getPlayer().getUniqueId().toString()) || chatEvents.deafenedTemp.contains(event.getPlayer().getUniqueId().toString())) {
// Prevent it from ever being sent
event.setCancelled(true);
}
}
});
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(JavaPlugin.getProvidingPlugin(WPFSkyblock.class), ListenerPriority.NORMAL, PacketType.Play.Client.CHAT) {
@Override
public void onPacketSending(PacketEvent event) {
if (chatEvents.muted.contains(event.getPlayer().getUniqueId().toString()) || chatEvents.mutedTemp.contains(event.getPlayer().getUniqueId().toString())) {
// Prevent it from ever being sent
event.setCancelled(true);
}
}
@Override
public void onPacketReceiving(PacketEvent event) {
if (chatEvents.muted.contains(event.getPlayer().getUniqueId().toString()) || chatEvents.mutedTemp.contains(event.getPlayer().getUniqueId().toString())) {
// Prevent it from ever being sent
event.setCancelled(true);
}
}
});
This is caused by the new message signature systems. Once you canceln one incoming chat packet, the chat chain will be broken and subsequent packets will cause a disconnect. This is no issue of ProtocolLib itself but rather a general problem. The same problem occurs when you try to cancel a chat packet on BungeeCord.
I would suggest migrating your code to the AsyncPlayerChatEvent
from Bukkit as it is called after the signature processing is completed. You can either cancel that event or recomve specific players from the recipient list.