I'm having an issue with my kit plugin the cooldown resets after restart code: PHP: public function onDisable(): void{ foreach($this->cooldown as $kit => $cooldown){ $handle = fopen($this->getDataFolder() . $kit . "-cooldown.txt", "w"); fwrite($handle, serialize($cooldown)); fclose($handle); $this->cooldown->save(); } } error: 02.09 17:23:01 [Server] Server thread/CRITICAL Error: "Call to a member function save() on array" (EXCEPTION) in "kits/src/kits/main" at line 32
I see that you realise that $cooldown is an array. However tell me what this is suppose to do? PHP: $this->cooldown->save(); Shall this work ? PHP: ["content"]->save(); Solution: Is to remove that freakin' line. You already did all file writing/saving. When you want to load it, just deserialize.
He doesn’t know what you mean so he said that The content means the cfg So PHP: $cooldown = config for cooldown$cooldown->save();
serialize is bad bad enough that you are even using fopen you should just create a new config class, call it cooldowns,yml which then you setall from cooldown and you call save which would be easier
i already selected the files the cooldown will be saved in but even after i restart it doesn't save PHP: public function onEnable(): void{ @mkdir($this->getDataFolder()); if(file_exists($this->getDataFolder() . "citizen-cooldowns.txt")) $this->cooldowns["citizen"] = unserialize(file_get_contents($this->getDataFolder() . "citizen-cooldowns.txt")); if(file_exists($this->getDataFolder() . "weekly-cooldowns.txt")) $this->cooldowns["weekly"] = unserialize(file_get_contents($this->getDataFolder() . "weekly-cooldowns.txt")); if(file_exists($this->getDataFolder() . "monthly-cooldowns.txt")) $this->cooldowns["monthly"] = unserialize(file_get_contents($this->getDataFolder() . "monthly-cooldowns.txt")); $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); if($api === null){ $this->getServer()->getPluginManager()->disablePlugin($this); } }
Use the Config class to manage your cool downs set, delete and get. Also has setNested if you know how to use it.