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

time to use command

Comments in 'Plugin Development' started by MikkiMCPE, Apr 3, 2016.

  1. MikkiMCPE
    Offline

    MikkiMCPE Active Member

    Joined:
    May 16, 2015
    Posts:
    125
    Minecraft User:
    MikkiMC
    Hello!

    how to set cooldown time for some command? thank you
    Last edited: Apr 3, 2016
  2. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    make scheduleDelayedTask
  3. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    And then what?
    He wants a command that is only executable (for example 1 time per secound)
    How to do this?
    Here:
    Save time() in a array (with playername->time) and then check if 1 or 5 secounds are between them
    applqpak likes this.
  4. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    PHP:
    $this->array = array();
    public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args)
    {

      if(
    strtolower($cmd->getName()) === "command")
      {

        
    $name $sender->getName();

        if(isset(
    $this->array[$name]))
        {

          
    $last_usage_time $this->array[$name];

          if((
    time() - $last_usage_time) <= 5// if the last time the user executed the command is less-than or equal to 5 seconds
          
    {

            
    $sender->sendMessage("Please wait " . (time() - $last_usage_time) . " more second(s) to use this command."); // Send the user how many more seconds he / she has to wait to use the command again.

            
    return true;

          }

        }
        else
        {

          
    $this->array[$name] = time();

          
    // Do more stuff

        
    }

      }

    }
    Although there probably is a better way, I'm pretty sure this will work(haven't tested).
    Last edited: Apr 3, 2016
    MikkiMCPE and ImagicalGamer like this.
  5. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    so i don't undderstand what he want to do
    ImagicalGamer likes this.
  6. ImagicalGamer
    Offline

    ImagicalGamer Active Member

    Joined:
    Feb 25, 2016
    Posts:
    141
    Minecraft User:
    ImagicalGamer
    I think he want's a cooldown ex) You can only use this command every X seconds/min/hour/day/week/year/decade/etc.
    MikkiMCPE and applqpak like this.
  7. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Decade srsly
    applqpak and ImagicalGamer like this.
  8. ImagicalGamer
    Offline

    ImagicalGamer Active Member

    Joined:
    Feb 25, 2016
    Posts:
    141
    Minecraft User:
    ImagicalGamer
    Yah, that's what my post says.
    applqpak likes this.
  9. MikkiMCPE
    Offline

    MikkiMCPE Active Member

    Joined:
    May 16, 2015
    Posts:
    125
    Minecraft User:
    MikkiMC
    you are right, sorry with my English xD
    ImagicalGamer likes this.
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Every X teraseconds.
  11. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    PHP:
    $sender instanceof Player
    I think that my console don't want show to all of us her name. :-(
    applqpak likes this.

Share This Page

Advertisement