NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
>[danger] 这个工具可以自定义一些冷却时间 ``` import com.google.common.collect.HashBasedTable; import com.google.common.collect.Table; class CooldownUtil { static Table cooldown; static{ cooldown = HashBasedTable.create(); } /** * 判定玩家某个类型是否在冷却中 * * @param player 玩家 * @param type 自定义类型,如: "攻击冷却" * @return 在冷却中返回true */ static boolean isCooldown(Player player,String type){ int id = player.getEntityId(); if(!cooldown.contains(id,type)) return false; long cooldown = cooldown.get(id,type); return cooldown > System.currentTimeMillis(); } /** * 设置某个玩家的冷却 * * @param player 玩家 * @param type 自定义类型,如: "攻击冷却" * @param time 冷却时间,毫秒 */ static void setCooldown(Player player,String type,long time){ cooldown.put(player.getEntityId(),type,System.currentTimeMillis()+time); } } ```