Please help.

Discussion in 'Plugin Development' started by Mr_Squidels, Feb 3, 2014.

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

    Mr_Squidels

    Hello, I am in need of help. So basically what's happening in my code is I've got some code running the throw tnt, etc. So I added a cooldown, tried it and what's happing is the first time when I use the throw tnt, it works, then when I click it again it says "please wait another 1 second" which is good but then it doesn't even work after the message is gone. My throw tnt isn't working anymore. Have I forgot to check if they are still in the cooldown or what? Please tell me what I've done wrong, thanks!


    Code:
        ArrayList<String>cooldown = new ArrayList<String>();
     
        @EventHandler
        public void onShoot(PlayerInteractEvent e) {
         
            final Player player = e.getPlayer();
         
            if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                        if (player.getItemInHand().getType() == Material.TNT) {
                            UtilPlayer u = Splode.getSplode().pm.getPlayer(player);
                            if (u.getGame() != null && u.isAlive()) {     
                                if (u.getGame().getStatus() == Status.INGAME) {
                                      Player player1 = e.getPlayer();
                                      if(!cooldown.contains(player.getName())) {
                                        if(player1.getInventory().getItemInHand().getType() == Material.TNT && e.getAction() == Action.RIGHT_CLICK_AIR);
                                        player1.playSound(player1.getLocation(), Sound.NOTE_BASS, 1F, 1F);
                                        TNTPrimed tnt = (TNTPrimed)player1.getWorld().spawnEntity(player1.getEyeLocation(), EntityType.PRIMED_TNT);
                                        tnt.setVelocity(player1.getEyeLocation().getDirection().multiply(2));
                                        tnt.setFuseTicks(40);
                                        tnt.setYield(3F);
                                        Splode.getSplode().chat.sendMessage(player, "&9Please wait another 1 second to use this again!");
                                        cooldown.add(player.getName());
                                        Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                                            public void run(){
                                            cooldown.remove(player.getName());
                                            Splode.getSplode().chat.sendMessage(player, "&9You can use Throw TNT again!");
                                         
                                            }
                                            }, 40L);
                                      }
                                }
                                    }
                            }
                        }
        }
     
  2. Offline

    ThePlayerPaul

    It's easier if you use a HashMap
     
  3. Offline

    Mr_Squidels

    sorry, for the late reply... bump.
     
Thread Status:
Not open for further replies.

Share This Page