Skip to content

Instantly share code, notes, and snippets.

@fynntimes
Created July 19, 2016 03:08
Show Gist options
  • Save fynntimes/545ee7a9fe5f8253785c3613bcd91050 to your computer and use it in GitHub Desktop.
Save fynntimes/545ee7a9fe5f8253785c3613bcd91050 to your computer and use it in GitHub Desktop.
// 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!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment