Abilities

Discussion in 'Plugin Development' started by ChucknorisSR, Jul 4, 2015.

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

    ChucknorisSR

    I am coding a kitPVP server with special abilities. I have a kit named tank. When tank right clicks I want it to take the item of the player that just hit him. But for some reason this doesn't work. Probably some stupid error. :p
    Code:
    package skits.events;
    
    import java.util.ArrayList;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    
    import skits.main.sKitmain;
    
    
    
    public class TankListener implements Listener { 
       
        ArrayList<Player> cooldown = new ArrayList<Player>();
       
       
        @EventHandler
        public void onAction(PlayerInteractEvent e) {
            final Player player = (Player)e.getPlayer();
            Material mat = player.getItemInHand().getType();
           
           
        if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
            if(mat == Material.STONE_SWORD) {  
            if(cooldown.contains(player)) { 
                player.sendMessage(ChatColor.BLUE + "KitPVP> " + ChatColor.GRAY + "You must wait-out your-cooldown!");
                return;
                }
            
            if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {  
                if(mat == Material.STONE_SWORD) {   
                    player.sendMessage("It works!");
                    final Player lastdamager = (Player)player.getLastDamageCause().getEntity();
                    final ItemStack item = lastdamager.getItemInHand();
                    lastdamager.getInventory().remove(item);
                    cooldown.add(player);
                    
                Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(sKitmain.inst, new Runnable() { 
                    @Override
                    public void run() {
                        lastdamager.getInventory().addItem(item);
                    }
                }, 20*10);
            }
           
               
               
                Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(sKitmain.inst, new Runnable() { 
                    @Override
                    public void run() {
                        cooldown.remove(player); 
                        player.sendMessage(ChatColor.BLUE + "KitPVP> " + ChatColor.GRAY + "You can use " + ChatColor.GREEN + "LEAP" + ChatColor.GRAY + " again!");
                        }
                   
                }, 20*100);
               
                    }
                }
            }
        }
    }
       
    
    I need a reply bump!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  2. Offline

    feff890

    Error log?
     
  3. Offline

    ChucknorisSR

    No error just does nothing
     
  4. Offline

    feff890

    Sorry I am on IOS at the moment. I will look into this as soon as I can get on my computer.
     
  5. Offline

    mythbusterma

  6. Offline

    ChucknorisSR

    Yep.
     
  7. Offline

    Zombie_Striker

    @ChucknorisSR
    Look over your code and remove duplicated if statements (seems you have a lot in there)
     
Thread Status:
Not open for further replies.

Share This Page