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

Solved How can I delay the use of items?

Discussion in 'Plugin Help' started by MinekCz, Jul 28, 2020.

  1. MinekCz

    MinekCz Spider Jockey

    Messages:
    29
    Hi, I would like to put in my plugin a timer that restricts the use of tools.

    Example: I dig a wood, but if I want to dig it again, I have to wait 3 seconds.That's all I need. Mainly to make the code as simple as possible and to do it in one file. Thank you for your help :)
     
  2. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    Hello, Use RpTask, you can make some thing like this :
    PHP:
    $GodWeedZao = []
    then you can check if godweedzao is set, unset or if not Run the task like :
    PHP:
    $timer--
    and its DONE ;)
     
  3. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    also, iforget to say, you should use $GodWeedZao or what ever you want in Your Class Lol

    if you didnt underestand, or you need help tag me here ;)
     
  4. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    also please use Items instead Tools :p
     
  5. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    is your probelm solved? or you need code?
     
  6. MinekCz

    MinekCz Spider Jockey

    Messages:
    29
  7. MinekCz

    MinekCz Spider Jockey

    Messages:
    29
    My original idea was to add a player to the array and if there is he won't be able to destroy the blocks, but I have no idea how to remove him after a while. If there is a better way, I will be happy too.
     
  8. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    You can see what did i say in here, its an example for you CLICK
     
  9. MinekCz

    MinekCz Spider Jockey

    Messages:
    29
    @GodWeedZao despite that EnderPearlPlugin it is unusable. I need a better way
     
  10. MinekCz

    MinekCz Spider Jockey

    Messages:
    29
    Probably somehow through ticks or a task. I really don't know so I need some useful example.
     
  11. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    its the first and last way to do it with this!
     
  12. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    Ok, i help you a bit, but you should learn php fist!
    1. Create a RpTask in your Mai.php
    + there is toturial for that, pls see them
    2. use some thing like this in your Main class
    PHP:
    public $GodWeedZao = [];
    it is example Lol :p
    3. create new file in your src (in folder main.php exist) and Call what ever you want
    for example: Cooldown.php
    4. use some thing like this
    PHP:
    class Cooldown {
    private 
    $GodWeedZao// i always use my name in code examples Lol, Sorry
    public function __cunstruct(Main $GodWeedZao) {
    $this->GW $GodWeedZao;
    }
    //so now you can create you task in here.
    //see the toturials in forum :)
    }
    and its DONE
    any more questions?
     
  13. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    also i forget to say you should create task in Main.php in onEnable function ;)
    You can learn php array to underestand how to use unset and check if isset , these are perfect for create Cooldown and easy!
     
  14. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    please see toturial to create RepeatTask and then ask, i'll anwser you dont worry ;) :)
     
  15. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    oh wait!
    you said how to set Cooldown in Items?
    or
    you want to set Cooldown for BlockPlacing Event?
     
  16. MinekCz

    MinekCz Spider Jockey

    Messages:
    29
    I've already found a way
    PHP:
      public function Interact(PlayerInteractEvent $event) {

        
    $player $event->getPlayer();
        
    $name $player->getName();

        if (
    $player instanceof Player) {
          if (isset(
    $this->time[$sender->getName()])) {
            if (
    $this->time[$sender->getName()] <= time()) {
              
    $this->time[$sender->getName()] = time() + 120;
            } else {
              
    $time $this->time[$sender->getName()] - time();
              
    $time gmdate("i:s"$time);
              
    $sender->sendMessage("Před použitím musíš počkat {$time}!");
              
    $event->setCancelled(true);
              return;
            }
          }
          
    //INSERT THE CODE HERE
          
    $this->time[$sender->getName()] = time() + 120;
          return;
        }
      }
     
  17. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    Bruh, there is noway to do that, you should create RepeatTask, mybe its work but repeatTask is best way, do you test this code?
     
  18. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    can you shom me $this->time?
     
  19. MinekCz

    MinekCz Spider Jockey

    Messages:
    29
    My code works fine
     
  20. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    Ok, but if you use tasks better for that.
     
  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.