// Imports, I just wrote this up quick in Gist
public class Cooldowns extends JavaPlugin {
private Map<UUID, Long> cooldowns = new HashMap<>();
private long cooldownDurationMillis = 3000; // 3 seconds (1000 millis = 1 second)
@Override public void onEnable() {
}
@Override public void onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) {
sender.sendMessage("You must be a player to do this.");
return;
}
UUID senderUid = ((Player) sender).getUniqueId();
if(command.getName().equalsIgnoreCase("cooldown")) {
long cooldownStartTime = cooldowns.get(senderUid);
if(!cooldowns.containsKey(senderUid) || System.currentTimeMillis() >= cooldownStartTime) {
// The cooldown has expired
sender.sendMessage("You won't be able to use this command for another 3 seconds.");
cooldowns.put(senderUid, System.currentTimeMillis());
return;
}
sender.sendMessage("Still cooling down!");
}
}
}