Solved can i have 2 events in 1 class

Discussion in 'Plugin Development' started by satarskrin, Mar 11, 2016.

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

    satarskrin

    I want to have a hit and fire event fore a fishingrod in 1 file where i can use the player who did shot
    and the player who got hitted




    Code:
    public class player implements Listener {
        @EventHandler
        public void onshot(ProjectileLaunchEvent event){
            Projectile ent = event.getEntity();
            if(event.getEntityType() == EntityType.FISHING_HOOK){
                Player player = (Player) ent.getShooter();
               
                public void onhit(ProjectileHitEvent event2){
                    Projectile ent2 = event2.getEntity();
                    if(event2.getEntityType() == EntityType.FISHING_HOOK){
                        Player player2 = (Player) ent.getShooter();
                    }
                }
            }
        }
    }
     
  2. Offline

    Zombie_Striker

  3. Offline

    HoeMC

    I think he means multiple event listeners in the same class, not a custom event.

    @satarskrin Yes, you can. Just remember to use the @EventHandler annotation when creating the method for the second listener. You can't have the method nested within another like you have in your original post though.
     
  4. Offline

    87pen

    @satarskrin You can have every event Bukkit has to offer in one class as long as you register them all. The code you posted you have an event inside another event move the second event out of the first one and place it under it.
     
Thread Status:
Not open for further replies.

Share This Page