Use the time() function in PHP. If you have not struggled to make it yet, then please give it a try before asking.
since you post this in plugin development i will suspect that you want to make a kit plugin WITH time feature in state of setting cooldown into someone's kit plugin so there two routes: use a callback timer aka heartbeat task or use time() and compare them most prefer the easy route look here: (heartbeat task) https://github.com/ThunderDoesPlugins/DeathBanV1/blob/master/src/Thunder33345/DeathBan/Main.php#L120 PHP: private function update() { foreach ($this->bans as $index => $ban) { if ($ban['time'] < 0) { unset($this->bans[$index]); } else { $this->bans[$index]['time'] = $ban['time'] - 1; } } } (yeah i know it is not the best pratice) if you wonder what i mean by that it does work but it create unnessary strains on server for having a heartbeat task running every so often and sorting a bunch of arrays (in most cases you dont need heartbeat task i could have just use time() and check it with current time on login event) the second one would be to use time ex on kit use PHP: $this->cabinet[$name]->setTime(time()+$kitCooldownTime)and to check would be toif(time() > $this->cabinet[$name]->getTime()){//means the cooldown have been over} else {$time = $this->cabinet[$name]->getTime() -time();echo "cooldown over in :".$time;//not over} about the $this->cabinet[$name] it was just my way of doing things without confusing arrays littered everywhere you can just use $this->data[$name]['time'] it is just the matter of personal preferences it was consist of a class with array object implemented if you wish to take a look go here https://github.com/ThunderDoesPlugins/WorldEdit/tree/master/src/Thunder33345/WorldEdit/Utilities EDIT: changed the code tag to PHP
It is very questionable to use time() in Minecraft at all. MCPC MCPE and MCPC Official server software nearly never use it. I'd almost always recommend using the ticks. Of course ticks can be inaccurate if the server is under high load, but as everything is slower than that is normally what you want. There are some scenarios where you would of course use time(): - TimeBanning (server could be stopped too) - Server Uptime (for whatever reason) - Player Online time
Main reason to not to use ticks are because they are not reliable and rely on server runtime. To be more accurate I always use microtime function
well using time or heartbeat task is alwayls a case by case basis if you are just making a kit plugin it may just be best to use time if you are making something that is more dynamic [Insert example] it would actually be better to use heartbeat task
Sorry forgot to put in the code PHP: <?phpnamespace RoyalMCPE;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\event\player\PlayerInteractEvent;use pocketmine\utils\TextFormat as c;use pocketmine\command\{CommandSender, Command};use pocketmine\Player;use pocketmine\Server;use pocketmine\item\Item;use pocketmine\item\enchantment\Enchantment;use pocketmine\entity\Effect;class Main extends PluginBase implements Listener{ public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this, $this); } public function onCommand(CommandSender $sender, Command $cmd, $label, array $args){ $prefix = c::BOLD.c::DARK_GRAY."[".c::DARK_PURPLE."MCA".c::DARK_GRAY."] ".c::DARK_AQUA; $inv = $sender->getInventory(); if(strtolower($cmd->getName()) == "kit"){ $sender->sendMessage($prefix."Select a kit"); $inv->addItem(Item::get(Item::WOODEN_SWORD,0,1)->setCustomName(c::GRAY."Starter")); } } public function onSelect(PlayerInteractEvent $e){ $p = $e->getPlayer(); $i = $e->getItem(); $inv = $p->getInventory(); $prefix = c::BOLD.c::DARK_GRAY."[".c::DARK_PURPLE."MCA".c::DARK_GRAY."] ".c::DARK_AQUA; if($inv->getItemInHand()->getId() === 268 && $i->hasCustomName(c::GRAY."Starter")){ $inv->removeItem($i); $prot = Enchantment::getEnchantment(0)->setLevel(1); $sharp = Enchantment::getEnchantment(9); $p->addEffect(Effect::getEffect(5)->setDuration(1200)->setAmplifier(2)); $inv->addItem(Item::get(Item::LEATHER_CAP,0,1)->setCustomName(c::GRAY."Starter Helemt")->addEnchantment($prot)); $inv->addItem(Item::get(Item::LEATHER_TUNIC,0,1)->setCustomName(c::GRAY."Starter Chestplate")->addEnchantment($prot)); $inv->addItem(Item::get(Item::LEATHER_PANTS,0,1)->setCustomName(c::GRAY."Starter Leggings")->addEnchantment($prot)); $inv->addItem(Item::get(Item::LEATHER_BOOTS,0,1)->setCustomName (c::GRAY."Starter Boots")->addEnchantment($prot)); $inv->addItem(Item::get(Item::STONE_SWORD,0,1)->setCustomName(c::GRAY."Starter Sword")->addEnchantment($sharp)); $inv->addItem(Item::get(Item::STONE_PICKAXE,0,1)->setCustomName(c::GRAY."Starter Pickaxe")); $inv->addItem(Item::get(Item::STONE_SHOVEL,0,1)->setCustomName(c::GRAY."Starter Shovel")); $inv->addItem(Item::get(Item::STONE_AXE,0,1)->setCustomName(c::GRAY."Starter Axe")->addEnchantment($sharp)); $inv->addItem(Item::get(Item::STEAK,0,64)); $inv->addItem(Item::get(Item::GOLDEN_APPLE,0,3)->setCustomName(c::RED."Med Kit")); $p->sendPopup("You have recived the starter kit"); } }}
i will give you idea on how to implement it but i doubt it that i will write you the code to do so for you to just copy and paste it but i am happy to teach you on how to implement it