Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Command Interval?

Comments in 'Plugin Development' started by Radix, Jul 15, 2015.

  1. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    I was wondering in php is there a way to have a timed command! Where you lets say you run /kit starter you can set a cool down so it can't be ran for 24 Hours!
    PHP:
    for ($i = *start time*; $i = *end time*; $i += *time interval*) {
        echo 
    $i;
    }
    Maybe something like this? I meam I have no idea , so any help would help lol!
  2. Guillaume351
    Offline

    Guillaume351 Active Member Plugin Developer

    Joined:
    Oct 11, 2013
    Posts:
    150
    Plugins:
    1
    Minecraft User:
    Guillaume351
    You have to use something like this (it's not a beautiful but works) (does not work if you reboot)
    PHP:
    <?php

    namespace Server;



    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\TextFormat;

    class 
    Main extends PluginBase implements Listener{

        public  
    $kitTick = [];

        public function 
    onLoad(){
            
    $this->getLogger()->info(TextFormat::WHITE "Server plugin loaded");
        }



        public function 
    onEnable()
        {
       
        }

        public function 
    onCommand(CommandSender $senderCommand $command$label, array $args){
            switch (
    $command){
                case 
    "blabla":
                    if(!isset(
    $this->kitTick[$sender->getName()]) or ($this->kitTick[$sender->getName()] - $this->getServer()->getTick()) >= 20*60*60*24){
                         
    $this->kitTick[$sender->getName()] = $this->getServer()->getTick();
                        
    //WhatCOmmandHasToDO
                    
    }else{
                        
    $sender->sendMessage("You can't use this command. You have to wait ".($this->kitTick[$sender->getName()] - $this->getServer()->getTick())/(20*60)." minutes.");
                   
                   
                   break;

                    }
               
            }
       
       
        }


    }
  3. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Just save the time of when the command was last ran somewhere and check if the current time has a difference of lets say more than a day (86400 seconds).
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Use time() >.< and save it in a database, or what you guys like, config files.
  5. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Lol. What you guys like. We like MySQL. But no need for it.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    A database can also refer to a well planned custom implemented database, like the YAML files in SimpleAuth; it's still a database. But I won't call one simple YAML file a database. (SQLite3 is an exception)
    Legoboy0215 likes this.
  7. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    I though databases had to be like MySQL before. I found out SQLite was a database too!
    PEMapModder likes this.

Share This Page

Advertisement