//设置冷却时间
//调用方法
//if (!global.CoolDownTime(entity, "keyName", cooldownTicks , true)) return;
global.CoolDownTime = function (entity, key, cooldownTicks, receipt) {
  let eData = entity.persistentData
  let CDdata = eData.getCompound("CoolDownTime")
  let time = entity.level.time
  let lastTime = CDdata.getInt(key)
  if (!lastTime || time - lastTime >= cooldownTicks) {
    CDdata.putInt(key, time)
    eData.put("CoolDownTime", CDdata)
    return true
  } else {
    let remaining = cooldownTicks - (time - lastTime)
    if (remaining > 54000) {
      if (entity.isPlayer() && receipt === true) {
        entity.tell(`冷却CD超过45分钟，可能是代码出错，已取消冷却并自动重置`)
      }
      CDdata.putInt(key, time)
      eData.put("CoolDownTime", CDdata)
      return true
    }
    if (entity.isPlayer() && receipt === true) {
      entity.tell(`§c冷却中，还需等待 ${Math.ceil(remaining / 20)} 秒！`)
    }
    return false
  }
}