Array List restricting block damage and destruction.

Discussion in 'Plugin Development' started by racoonsru1e, Dec 29, 2014.

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

    racoonsru1e

    Hi. I am creating a plugin with custom armour abilities with cooldowns. I have made an ability called "Leap" to be used by players with leather armour equipped. When the player is added to the array list, they may not break or destroy blocks until they are removed from the list. How can I change this so that they can damage blocks?

    Code:
    Code:
    private ArrayList<String> leap = new ArrayList<String>();
            @EventHandler
            public void onPlayerInteract(final PlayerInteractEvent event){
               if(leap.contains(event.getPlayer().getName())) { event.setCancelled(true); return;}
               final Player player = event.getPlayer();
               if(player.getInventory().getBoots().getType() == Material.LEATHER_BOOTS){
                     if(player.getInventory().getLeggings().getType() == Material.LEATHER_LEGGINGS){
                         if(player.getInventory().getChestplate().getType() == Material.LEATHER_CHESTPLATE){
                             if(player.getInventory().getHelmet().getType() == Material.LEATHER_HELMET){
                                 if(player.getItemInHand().getType() == Material.IRON_AXE){
                   if (event.getAction() == Action. RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK ){
                  player.sendMessage(ChatColor.BLUE + "You used" + ChatColor.GREEN + " Leap!" );
                  player.setVelocity(player.getLocation().getDirection().multiply(1.5));
                  player.getWorld().playSound(player.getLocation(), Sound.FIZZ, 1.0F, 17.0F);
                  leap.add(player.getName());
                  player.sendMessage(ChatColor.RED + "You must wait 6 seconds until you may use " + ChatColor.GREEN + "Leap " + ChatColor.RED + "again.");
                 getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                      public void run(){
                      player.sendMessage(ChatColor.GREEN + "You may now use Leap!");
                      leap.remove(event.getPlayer().getName());
                                          }
                                      }, 120);
                                  }
                             }
                         }      
                     }
                   }
            }
            }
    Thanks!

    EDIT: I just realised that this line of code:
    Code:
               if(leap.contains(event.getPlayer().getName())) { event.setCancelled(true); return;}
    cancels block interaction, but without it I cannot cancel the event so that the player does not use the ability more than once consecutively. Any way I can get around this?
     
    Last edited: Dec 29, 2014
  2. Offline

    racoonsru1e

  3. Offline

    racoonsru1e

  4. Offline

    racoonsru1e

    118 Views and still nothing.. [ BUMP ]
     
Thread Status:
Not open for further replies.

Share This Page