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

Timer

Discussion in 'Development' started by Karanpatel567, Dec 3, 2017.

  1. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    How would I make it so when I use a command it adds a timer and that timer would end I'm 30 days! And if someone tries to use that command during that time it would send a message saying timer is going on.
     
  2. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    you can use time()+30days in second and set it on config
    if the time() is lesser then config, it meant the cooldown is still ongoing
     
    jasonwynn10 likes this.
  3. friscowz

    friscowz Baby Zombie Ban Evader Banned

    Messages:
    128
    GitHub:
    friscowzmcpe
    if you want the code:
    PHP:
    public $config//Make you sure to add this and create a new Config() when server is enabled

    /**
    * @param string $command
    * @param int $delay
    */
    public function addTimer(string $commandint $delay)
    {
        if(
    $this->config instanceof Config) {
            
    $this->config->set($command$delay time());
        } else {
            
    $this->config = new Config($this->getDataFolder() . "timers.json"Config::JSON);
            
    $this->config->set($command$delay time());
        }
    }

    /**
    * @param string $command
    * @return int
    */
    public function getTimer(string $command) : int
    {
        if(
    $this->config instanceof Config) {
            if(
    $this->config->exists($command)){
                return 
    $this->config->get($command);
            }
            return 
    0;
        } else {
            
    $this->config = new Config($this->getDataFolder() . "timers.json"Config::JSON);
            if(
    $this->config->exists($command)){
                return 
    $this->config->get($command);
            }
            return 
    0;
        }
    }
     
  4. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Assuming the code you provided is for the main class, it can be made better with this:
    PHP:
    /**
     * @param string $command
     * @param int $delay
     */
    public function addTimer(string $commandint $delay) : void {
        
    $this->getConfig()->set($command$delay time());
        
    $this->getConfig()->save();
    }

    /**
     * @param string $command
     *
     * @return int|null
     */
    public function getTimer(string $command) : ?int {
        return 
    $this->config->get($commandnull);
    }
     
    Last edited: Dec 5, 2017
  5. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    what about saving the config?
     
    jasonwynn10 likes this.
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Note the potential garbage data you want to clear after time's up.
     
  7. friscowz

    friscowz Baby Zombie Ban Evader Banned

    Messages:
    128
    GitHub:
    friscowzmcpe
    ok.
     
  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.