How to get server join/quit messages?
gamerpiss opened this issue ยท 7 comments
Not sure if this is the right place to ask, but I am trying to create a command that lets a player toggle the visibility of join and quit messages. This is the code I have inside of Main.onEnable().
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(this, PacketType.Play.Client.CHAT) {
public void onPacketReceiving(PacketEvent e) {
PacketType packetType = e.getPacketType();
if (connectionsOnFor(e.getPlayer())) {
return;
}
if (packetType.equals(PacketType.Play.Client.CHAT)) {
PacketContainer packetContainer = e.getPacket();
String msg = packetContainer.getSpecificModifier(String.class).read(0);
if (msg.equals("join message") || msg.equals("quit message")) {
e.setCancelled(true);
}
}
}
});
I do not know how to check the join or quit messages as the player name changes all the time.
why the hell would you disable join and quit messages via a packet listener?
just use the bukkit event api and listen to the join and quit events and set the message to null
why the hell would you disable join and quit messages via a packet listener?
just use the bukkit event api and listen to the join and quit events and set the message to null
Because I am trying to disable it just for the player that runs the command. When I set the message to null it sets it for the whole server, which is not what I want.
My recommendation would be to use the Bukkit event to cancel the global join/quit message and re-send it manually to every other player. That would probably be easier than trying to list for every chat message. Something along the lines of:
event.setCancelled(true)
for player in online:
if player is not ourPlayer
player.sendMessage(joinMessage)
My recommendation would be to use the Bukkit event to cancel the global join/quit message and re-send it manually to every other player. That would probably be easier than trying to list for every chat message. Something along the lines of:
event.setCancelled(true) for player in online: if player is not ourPlayer player.sendMessage(joinMessage)
Which event should I use? I have tried onPlayerJoin/onPlayerQuit but it does not have a cancel function. The other issue is getting the join and quit messages as it has a player name will change everytime.
Ah right. You would use the join/quit events but set the message to null.
As I said previously that only sets it for the whole server. There also isn't a function to get recipients for me to remove them, which is why I went to ProtocolLib to try looking for the packets. I have also tried to set the .getJoinMessage() and .getQuitMessage() in variables for the packet listener as well but it didn't work.