Make one event run before a different event.

Discussion in 'Plugin Development' started by GeorgeeeHD, Mar 31, 2016.

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

    GeorgeeeHD

    I have two events, EntityDamageByEntityEvent and ProjectileHitEvent, I need EntityDamageByEntityEvent to run first. I have tried to use priorities setting EntityDamageByEntityEvent to LOWEST and ProjectileHitEvent to highest yet ProjectileHitEvent still runs first. I would rather not use a task to delay the ProjectileHitEvent by a tick so if there are any other options please let me know. Thanks
     
  2. Offline

    WolfMage1

    AFAIK Bukkit handles the events, and the order they get fired is the order they get fired.

    Why do you want to delay it anyway?

    And the priorities just set which plugin has the final say on the event.
     
  3. Offline

    GeorgeeeHD

    @WolfMage1
    Code:
    @EventHandler
        public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent e)
        {
            if (e.getDamager() instanceof Arrow && e.getEntity() instanceof Player)
            {
                Player p = (Player) e.getEntity();
                Arrow arrow = (Arrow) e.getDamager();
    
                if (isElementalArrow(arrow))
                {
                    switch (getElementalArrowType(arrow))
                    {
                        case POISON:
                            p.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 20 * 5, 1, true));
                            break;
    
                        case FREEZING:
                            p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 20 * 5, 4, true));
                            break;
                    }
                }
            }
        }
    
        @EventHandler
        public void onProjectileHitEvent(ProjectileHitEvent e)
        {
            if (e.getEntity() instanceof Arrow)
            {
                Arrow arrow = (Arrow) e.getEntity();
    
                if (isElementalArrow(arrow))
                {
                    if (getElementalArrowType(arrow) == ElementalArrowType.LIGHTNING)
                    {
                        arrow.getWorld().strikeLightning(arrow.getLocation());
                    }
    
                    removeElementalArrow(arrow);
                }
    
                arrow.remove();
            }
        }
    The problem is that the arrow gets removed as an elemental arrow in ProjectileHitEvent so in
    EntityDamageByEntityEvent it doesnt register as an elemental arrow
     
  4. Offline

    WolfMage1

    Then.............. remove it in the damage event??
     
  5. Offline

    GeorgeeeHD

    @WolfMage1
    Can't. One of the effects of the arrow is causing lighting where it lands, whether or not it hits a player.
     
  6. Offline

    mcdorli

    Then just use the damage one, check if the damage is caused by an arrow, if it is, then spawn a lightning.
     
  7. Offline

    GeorgeeeHD

    @mcdorli
    But i want it to be able to cause lightning if you miss a player and it hits the ground, hence why i used ProjectileHitEvent
     
  8. Offline

    mcdorli

    Then follow the arrow with a scheduler, store the arrows you spawn a lightning with in an arraylist, and once the projectile hits an entity, remove it from the arraylist, else, if it does before you remove it, then spawn a lightning in the last place it was.
     
    WolfMage1 likes this.
Thread Status:
Not open for further replies.

Share This Page