Okay so i am making a lil minigames plugin that involves "guns" and i want to make it where if the player hold the screen the "gun" shpuld shoot rapidly. Here is my code PHP: /** * @param PlayerInteractEvent $event */ public function onInteract(PlayerInteractEvent $event){ $player = $event->getPlayer(); $inventory = $player->getInventory(); $class = $this->getUtils()->getClassManager($player); if($class instanceof ClassManager){ if($event->getAction() !== PlayerInteractEvent::RIGHT_CLICK_AIR){ return; } if($class->getPrimary() !== null && $inventory->getItemInHand()->getId() === $class->getPrimary()->getGunItem()->getId()){ $class->getPrimary()->shoot(); }else if($class->getSecondary() !== null && $inventory->getItemInHand()->getId() === $class->getSecondary()->getGunItem()->getId()){ $class->getSecondary()->shoot(); } } } but it does not shoot rapidly it only shoots once per press/touch; or repress so what is the problem?
There's no way to check if a player is holding tap in the air. I'd call a task in the event that would have the initial item stored in it, to then shoot a bullet on each tick if the the player's hand item is the one that you stored.
The problem with items like snowballs is that you'll be limiting the fire rate of the gun. Snowballs can be shot like once per 8 ticks.
At least its an legitimate way to detect that the player is holding down the screen, i cant think of any other way