1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Cooldown reset issue

Discussion in 'Development' started by Astro, Sep 2, 2018.

  1. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    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($handleserialize($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
     
  2. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    You can’t save a array
     
  3. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Get the config and save that
     
  4. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    i never used configs before
     
  5. Primus

    Primus Zombie Pigman

    Messages:
    749
    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.
     
    xXNiceAssassinlo YT likes this.
  6. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    alright
     
    Last edited: Sep 3, 2018
  7. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    He doesn’t know what you mean so he said that
    The content means the cfg
    So
    PHP:
    $cooldown config for cooldown
    $cooldown
    ->save();
     
    Astro likes this.
  8. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    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
     
    xXNiceAssassinlo YT likes this.
  9. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    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);
            }
        }
     
  10. Angel

    Angel Spider Jockey

    Messages:
    44
    GitHub:
    aimjel
    Use the Config class to manage your cool downs set, delete and get. Also has setNested if you know how to use it.
     
    Astro likes this.
  11. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    alright i'll check it
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.