Created
July 19, 2016 03:08
-
-
Save fynntimes/545ee7a9fe5f8253785c3613bcd91050 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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