I was wondering how to implement a timer into my plugin. So basically like after they do /command claim to claim an item they have to wait another x amount hours to claim that item again. I want the timer to save where it stopped, so basically if I /stop the server or if the server restarts, it starts back at where the countdown previously stopped. Also please if you have the time, please do break down the code so I can understand it instead of just throwing code at me, thanks!
Use php's time() function to get the current timestamp. Use your preferred way to save that together with a player's name or uuid. Compare times whenever the command gets run.
This is stupid. Before doing nothing, learn how time() works. You must create a variable for each player to save the previous time where he had ran the command, this can be inside the .yml file of the player or whatever thing you've made (sqlite, mysql) PHP: class CustomPlayer extends Player { private $countdown = null; public function getCountdown() { return $this->countdown; } public function setCountdown(?int $countdown) { $this->countdown = $countdown; }}class Countdown { private const SECONDS_TO_WAIT = 60 * 5; private static function getPlayerCountdown(CustomPlayer $player) { return time() - $player->getCountdown(); } public static function setPlayerCountdown(CustomPlayer $player) { $player->setCountdown(time()); } public static function hasPlayerCountdown(CustomPlayer $player) { $countdown = self::getPlayerCountdown($player); if($countdown > self::SECONDS_TO_WAIT) { $player->setCountdown(null); return false; } elseif($player->getCountdown() != null) { $player->sendMessage("You can't use this command for " . self::SECONDS_TO_WAIT - $countdown . " seconds."); return true; } return false; }}class YourCommand extends Command { // Just an example public function execute(CustomPlayer $player) { if(Countdown::hasPlayerCountdown($player)) { // Dont execute the command } else { // Execute the command Countdown::startPlayerCountdown($player)); } }} Hope you understood this well.