Solved Machine Gun Rapid Fire

Discussion in 'Plugin Development' started by Agentleader1, Apr 27, 2015.

Thread Status:
Not open for further replies.
  1. Offline


    I'm making a gun plugin for a minigame, and I stumbled over a question ahead of time.
    How do I make a machine gun rapid fire? PlayerInteractEvent has like a delay of 10 seconds.

    //Edit: I think I may know a way, but is there something that triggers when someone stops "interacting" and if it can be more specific "right clicking"?

    Solution (open)

    Last edited: May 11, 2015
  2. Offline


    This is a very interesting question!
    The way I make my bows rapid fire is by using a repeating task and cancelling it after it has ran X times, however it can be laggy...
  3. Offline


    @meguy26 Thanks for the feedback, but is there a way to make it rapid fire for the playerinteractevent?

    Found my solution:

    public class ShootMachineGun implements Listener{
        private static HashMap<String, Integer> shooting = new HashMap<String, Integer>();
        public void onShoot(PlayerInteractEvent pie){
            final Player player = pie.getPlayer();
                    || pie.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
                    (new MachineGun()).getShot(player.getEyeLocation(), player);
                        int x = shooting.get(player.getName());
                        shooting.put(player.getName(), x + 1);
                        shooting.put(player.getName(), 0);
        public static void startTest(){
            Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.instance, new Runnable(){
                public void run(){
                    for(Player p: Bukkit.getOnlinePlayers()){
                            if(shooting.get(p.getName()) > 0){
                                new MachineGun().getShot(p.getEyeLocation(), p);
                                int x = shooting.get(p.getName());
                                shooting.put(p.getName(), x - 1);
            }, 1, 1);
    EDIT by Timtower: merged posts
    Last edited by a moderator: Apr 27, 2015
Thread Status:
Not open for further replies.

Share This Page