code: PHP: public function giveKit(Player $player, $kitName) { $config = MainClass::getInstance()->kit; $kit = $config->get($kitName); $items = $kit["items"]; if (isset($items)) { foreach ($items as $i) { $data = explode(":", $i); $item = Item::get($data[0], $data[1], $data[2]); if (isset($data[3]) and isset($data[4])) { $enchant = Enchantment::getEnchantment($data[3]); $item->addEnchantment(new EnchantmentInstance($enchant, $data[4])); } if(isset($data[5])){ $item->setCustomName(implode(" ", $data[5])); } $player->getInventory()->addItem($item); } $sqlite = MainClass::getInstance()->sqlite; $time = time(); $cd = MainClass::getInstance()->kit->getNested($kitName.".cooldown"); $cooldown = $sqlite->prepare("INSERT INTO kitCooldowns (player, kit, cooldown) VALUES (:player, :kit, :cooldown);"); $cooldown->bindValue(":player", $player->getName()); $cooldown->bindValue(":cooldown", $time + $cd); $cooldown->bindValue(":kit", $kitName); $cooldown->execute(); } } public function checkCooldown(Player $player) { $sqlite = MainClass::getInstance()->sqlite; $info = $sqlite->query("SELECT * FROM kitCooldowns;"); $array = $info->fetchArray(SQLITE3_ASSOC); if (!empty($array)) { $banInfo = $sqlite->query("SELECT * FROM kitCooldowns;"); $i = -1; $j = $i + 1; $kitPlayer = $array['player']; if ($player->getName() == $kitPlayer) { $banInfo = $sqlite->query("SELECT * FROM kitCooldowns WHERE player = '$kitPlayer';"); $array = $banInfo->fetchArray(SQLITE3_ASSOC); if (!empty($array)) { $cooldown = $array['cooldown']; $kit = $array['kit']; $now = time(); if ($cooldown > $now) { $remainingTime = $cooldown - $now; $day = floor($remainingTime / 86400); $hourSeconds = $remainingTime % 86400; $hour = floor($hourSeconds / 3600); $minuteSec = $hourSeconds % 3600; $minute = floor($minuteSec / 60); $remainingSec = $minuteSec % 60; $second = ceil($remainingSec); $player->sendMessage(TextFormat::RED . "Kit {$kit} is in cooldown for {$day} day(s) {$hour} hour(s) {$minute} minute(s) and {$second} seconds"); } else { $banInfo = $sqlite->query("SELECT * FROM kitCooldowns WHERE player = '$kitPlayer';"); $array = $banInfo->fetchArray(SQLITE3_ASSOC); if (!empty($array)) { $sqlite->query("DELETE FROM kitCooldowns WHERE player = '$kitPlayer';"); } } } $i = $i + 1; } } } creating sqlite PHP: $this->sqlite = new \SQLite3($this->getDataFolder() . "kits.db"); $this->sqlite->exec("CREATE TABLE IF NOT EXISTS kitCooldowns(player TEXT, kit TEXT PRIMARY KEY, cooldown INTEGER);"); onCommand //giving items PHP: $api = new API(); $api->checkCooldown($sender); $api->giveKit($sender, $kit); config Code: --- test: cooldown: 3600 customName: Cool pickaxe items: - "278:0:1:15:10" - "307:0:1" - "364:0:15" ... error is when i do /kit test after the coooldown is set i get super fps lag and the server freeze
PHP: $t = microtime(true);//code here$t = microtime(true) - $t;var_dump(number_format($t, 10));//returns how many secs it took for code to execute