Click to call function

Discussion in 'Plugin Development' started by rumfiske, Jul 5, 2015.

Thread Status:
Not open for further replies.
  1. i want to do so when a player right click and is holding the "Scorpion Sword" the function "if(p.getItemInHand().getItemMeta().getDisplayName().contains(ChatColor.GREEN + "Scorpion Sword"))el.addPotionEffect(new PotionEffect(PotionEffectType.POISON,5*20, 1, false));" Is called for 2-3 secs, then there is a cooldown on 15 secs.




    @EventHandler
    public void Scorpion (EntityDamageByEntityEvent e) {
    if((e.getDamager()instanceof Player));
    if(!(e.getEntity()instanceof LivingEntity));
    Player p = (Player)e.getDamager();
    LivingEntity el = (LivingEntity)e.getEntity(); {
    if(p.getItemInHand().getItemMeta().getDisplayName().contains(ChatColor.GREEN + "Scorpion Sword"))el.addPotionEffect(new PotionEffect(PotionEffectType.POISON,5*20, 1, false));
    }

    }






    @EventHandler
    public void onPlayerInteract(PlayerInteractEvent event) {
    Player p = (Player) event.getPlayer();
    if (event.getAction() == Action.RIGHT_CLICK_AIR && (p.getItemInHand().getItemMeta().getDisplayName().contains(ChatColor.GREEN + "Scorpion Sword"))) {
    event.getPlayer().sendMessage(ChatColor.AQUA + "" + ChatColor.BOLD + "Poison ability now activated!");



    }
    }
     
  2. Set a boolean to true on the event.
    Schedule a task with 1 tick repeat time which checks for the variable and changes it to false, if it changes increment az integer, if it doesn't change reset the integer.
    If the integer reaches seconds*20 (20 ticks per second) then do something.
     
  3. Offline

    Zombie_Striker

    @rumfiske
    Use the code feature for your code. If you are posting your entire class use spoilers.
     
Thread Status:
Not open for further replies.

Share This Page