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
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
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
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.
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 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, Sorrypublic 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?
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!
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; } }
Bruh, there is noway to do that, you should create RepeatTask, mybe its work but repeatTask is best way, do you test this code?