Chat Message Cooldown

I want to code a chat cooldown, so that you have to wait for x seconds to chat again after sending a message.

But I have no Idea how to do that.


You can use a HashMap<Player, int> to store the last time they send a message. When the user want to send another message, you check the int value in the HashMap. If the value is more than x seconds ago, then you send the message and update the value linked to the player. When the message is within x seconds, you send a message to the user telling them they cannot send a message yet.

1 Like