I made something like that from code in other plugins like from antispam. It's working in 50% because when i throw this snowball at first time it's send's me "You can throw pearls every 5 seconds" but 2rd time it's doing nothing. Any ideas how to repair this? PHP: $player = $shooter; $player_name = $shooter->getName(); $cooldown = 5; if(isset($this->cooldown[$player_name])) { $last_chat_time = $this->cooldown[$player_name]; if((time() - $last_chat_time) <= $cooldown) { $timeDifference = (time() - $last_chat_time); $player->sendMessage("ยง7You can throw pearl every 5 seconds!"); $event->setCancelled(); } } else { $this->cooldown[$player_name] = time(); $shooter->teleport($posTo); if(!$shooter->isCreative()){ $ev = new EntityDamageEvent( $shooter, EntityDamageEvent::CAUSE_MAGIC, $this->config->get("damage") ); $shooter->attack($ev->getFinalDamage(), $ev); } }
//$time = last throw $player = Player $cooldown = cooldown if (!isset($time) OR time() - $time > $cooldown){ tell($player,"thrown"); $time = time(); //throw it } else { tell($player,"cooldown wait ".$cooldown- time() - $time); } something like this SHOULD do if you dont copy directly from it