Projectile hit Event

Discussion in 'Plugin Development' started by MineCrusher08, Feb 18, 2020.

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

    MineCrusher08

    Problem: I am working on a One in the chamber plugin (a minigame where you get 1 arrow and you have to shoot someone to gain a point) I currently have the code working but now I am adding more projectiles to the minigame and can't seem to find a way to register the event to allow any projectile in minecraft when use eliminates the player.

    Here is the working code to get projectile arrow to work but now I need snowballs, eggs, etc. added:
    @EventHandler
    public void onHit(EntityDamageByEntityEvent e)
    {
    if (((e.getEntity() instanceof Player)) && ((e.getDamager() instanceof Arrow)))
    {
    Arrow arrow = (Arrow)e.getDamager();
    if ((arrow.getShooter() instanceof Player))
    {
    Player attacker = (Player)arrow.getShooter();
    Player player = (Player)e.getEntity();
    if ((Arenas.isInArena(player)) && (Arenas.isInArena(attacker)))
    {
    Arena arena = Arenas.getArena(player);
    if (arena.isOn()) {
    if (!player.getName().equalsIgnoreCase(attacker.getName())) {
    e.setDamage(100.0D);
    } else {
    e.setCancelled(true);
    }
    }
    }
    }
    }
    }

    @EventHandler
    public void onProjHit(ProjectileHitEvent e){

    if(e.getEntity() instanceof Arrow){

    Arrow arrow = (Arrow) e.getEntity();

    if(arrow.getShooter() instanceof Player){

    Player shooter = (Player) arrow.getShooter();

    if(Arenas.isInArena(shooter)){
    Arena arena = Arenas.getArena(shooter);
    if(arena.isOn()){
    arrow.remove();
    }
    }
    }
    }
    }



    Any suggestions to make it register all projectiles instead of me having to go through and do one each by hand would be helpful, Thanks!
     
  2. Offline

    KarimAKL

    MineCrusher08 and Sw_aG like this.
  3. Offline

    MineCrusher08

    Wow, I didn't realize it was that simple. Thanks for the help!
     
Thread Status:
Not open for further replies.

Share This Page