Hello, I am working on adding guns to my server i have made the guns but i don't know how to make them have a fire rate. Here is the code for one of the guns: Code: public class FiveSeven implements Listener { @EventHandler public void onPlayerInteract(PlayerInteractEvent e){ Player p = e.getPlayer(); if(!(e.getAction()== Action.RIGHT_CLICK_AIR)) return; if(!(e.getItem().getType()==Material.WOOD_HOE)) return; if(!(p.getInventory().contains(Material.SUGAR))) { p.playSound(p.getLocation(), Sound.CLICK, 1F, 1F); ChatUtils.sm(p,"" + ChatColor.RED + "Sorry but you have run out of ammo you can buy some at the shop /shop"); return; } p.getInventory().removeItem(new ItemStack(Material.SUGAR, 1)); p.updateInventory(); Arrow a = e.getPlayer().launchProjectile(Arrow.class); a.setKnockbackStrength((int) 0.1); a.setBounce(false); a.setVelocity(a.getVelocity().multiply(0.7)); p.playSound(p.getLocation(), Sound.EXPLODE, 1F, 1F);} } Thanks
From what I've heard, the PlayerInteractEvent can only be called 4 or 5 times a tick at most. What you could do is associate an integer with each gun Object and when the "trigger" is pulled, change the int value and when it reaches a certain value, fire the gun.