hey, I'm making a kit plugin but the cooldown resets when the server restarts. and i dont want that to happen my code: oh and its the same thing as when they leave, the cooldown resets but i fixed it onJoin PHP: public $config;public $cooldown = [];public function onEnable(){ @mkdir($this->getServer()->getDataPath() . "/plugins/Kit"); $this->config = new Config($this->getServer()->getDataPath() . "/plugins/Kit/cooldowns.yml", Config::YAML, [ "starter" => 86400, "god" => 86400 ]);}public function onJoin(PlayerJoinEvent $e) { $player = $e->getPlayer(); if (isset($this->cooldown[$player->getName()])) { $this->cooldown[$player->getName()] = time(); } } public function onQuit(PlayerQuitEvent $e){ } public function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool { switch ($command->getName()) { case "kit": if (!isset($args[0])) { $sender->sendMessage("/kit <name>"); return true; } $kit = $args[0]; if ($kit == "starter") { if ((!isset($this->cooldown[$sender->getName()])) || (($this->cooldown[$sender->getName()] + $this->config->get("starter")) - time() <= 0) ) { $helmet = Item::get(306); $chestplate = Item::get(311); foreach([$helmet, $chestplate] as $items){ $sender->getInventory()->addItem($items); } $sender->sendMessage("You got your kit"); $this->cooldown[$sender->getName()] = time(); } else { $sender->sendMessage("kit on cooldown!"); }
Because once the server shuts down all the data in $this->cooldown, to fix this just do PHP: public function onDisable(){ foreach($this->cooldown as $player => $time){ $this->config->set($player, $time); $this->config->save(); }} Then on in you onEnable add PHP: foreach($this->config->getAll() as $player => $time){ $this->cooldown[$player] = $time;}
then whats this PHP: $this->config = new Config($this->getServer()->getDataPath() . "/plugins/Kit/cooldowns.yml",
PHP: public function onDisable(){ foreach($this->cooldown as $player => $time){ $this->config->set($player, $time); $this->config->save(); }} Then on in you onEnable add PHP: foreach($this->config->getAll() as $player => $time){ $this->cooldown[$player] = $time;} [/QUOTE] thank you!! it worked