how do i get the time left of cooldown command cooldown PHP: if ((!isset($this->cd[$player->getName()])) || (($this->cd[$player->getName()] + 15 - time() <= 0))) { $this->cd[$player->getName()] = time(); } else { $event->setCancelled(true); $player->sendMessage("wait cooldowntime seconds"); }
Check here how I did cooldown: https://github.com/InfinityGamers/G...nfinityGamers/Gears/Utils/KitUtils.php#L7-L24
that only checks if player is in cooldown but me is trying to get the time left of cooldown in seconds
Are you trying to: 1) send a live countdown or 2) just when the player does a specific thing that requires cool down?
SO my plugin is a command cooldown for 5 second. So if player spam /test they will just get the message of how many seconds are left
Use this function, if player is on cool down it will return the time left, if player can use the command again it will return -1. PHP: /** * @var int[] */ public $coolDown = []; /** * @param $name * @param int $seconds * * @return int */ public function checkCoolDown($name, $seconds = 5): int{ if(!isset($this->coolDown[$name])){ $this->coolDown[$name] = time(); return -1; } if(((time() - $this->coolDown[$name]) <= $seconds)){ $this->coolDown[$name] = time(); return -1; } $timeLeft = ($seconds - (time() - $this->coolDown[$name])) return $timeLeft; }