java Cool downs.java

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java Cool downs.java相关的知识,希望对你有一定的参考价值。

// 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!");
    }
  }
  
}

以上是关于java Cool downs.java的主要内容,如果未能解决你的问题,请参考以下文章

太秀了!程序媛小姐姐写出代码版《本草纲目》,刘畊宏回复:很cool!

程序员小姐姐写出代码版《本草纲目》毽子操,刘畊宏回复:很cool!

Cool edit pro 、Cubase SX 、 Nuendo 和Pro Tools对比

关于cool edit pro播放中的设置问题

如何更新 graphql 端点(不使用 Graph.cool)

Delphi 与 Graph.cool API?