Solved Projectile Friendly fire disable

Discussion in 'Plugin Development' started by Telmovieira, Mar 27, 2015.

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

    Telmovieira

    Hello everyone!
    Today i ask you another simple question. I have a code that is suposed to disable frendly fire. It works for normal melee hits, but i does not work for arrows and potions. This was what i have tried, but it doesn't work

    Code:
    @EventHandler(priority = EventPriority.HIGHEST)
        public void onEntityDamage(EntityDamageByEntityEvent event) {
            Player hit = (Player) event.getEntity();
            Player damager = (Player) event.getDamager();
    if(damager instanceof Projectile){
                Projectile proj = (Projectile) event.getEntity();
                  if(proj instanceof Arrow){
                      Arrow arrow = (Arrow) proj;
                      if(arrow.getShooter() instanceof Player){
                          Player shooter = (Player) arrow.getShooter();
                          if(Team.getTeamType(shooter) == Team.getTeamType(hit)){
                              event.setCancelled(true);
                              shooter.sendMessage("plz no team killll!!!!!!!");
                          }
                          if(hit.canSee(shooter) == false){
                              event.setCancelled(true);
                          }
                      }
                  }
            }
    }
    Thank's to anyone who responds. Sample code would be much apriciated as well
     
  2. Offline

    Funergy

    @Telmovieira Is there any error? Have you registered the listener?
     
  3. Offline

    Konato_K

    @Telmovieira So, you're casting the damager to a Player and then checking if it's a Projectile? I'm pretty sure that's not the way it works.

    Anyway, why don't you use the Teams in scoreboards? They are clean and already protect from Projectiles.
     
  4. Offline

    Telmovieira

    @Konato_K, I would use scoreboard teams, but my whole game mode is built around my costume made methods, so i wont altere it now. But if it's possible to use scoreboard teams just to disable frendly fire i would use it, but i don't know how.

    @Funergy
    If there where any errors or the listener was not implemented nothing would work, which is not the case....
     
  5. Offline

    Konato_K

  6. Offline

    Telmovieira

    @Konato_K
    The scoreboards do not work as well.... I made a custom event that was called when sombody joined a team, than i use that event to add people to the scoreboard teams.... probabily i am doing something wrong...
     
  7. Offline

    Funergy

    @Telmovieira Did you fix this
     
  8. Offline

    Telmovieira

    @Funergy I did
    Code:
    @EventHandler
        public void onPlayerHitProjectile(EntityDamageByEntityEvent event){
            Entity damager = event.getDamager();
            Entity hit = event.getEntity();
            if(damager instanceof Projectile){
                Projectile proj = (Projectile) event.getEntity();
                  if(proj instanceof Arrow){
                      Arrow arrow = (Arrow) proj;
                      if(arrow.getShooter() instanceof Player){
                          Player shooter = (Player) arrow.getShooter();
                          if(Team.getTeamType(shooter) == Team.getTeamType((Player) hit)){
                              event.setCancelled(true);
                              shooter.sendMessage("plz no team killll!!!!!!!");
                          }
                          if(((Player) hit).canSee(shooter) == false){
                              event.setCancelled(true);
                          }
                      }
                  }
            }
        }
    still does not work....
     
  9. Offline

    Funergy

    @Telmovieira Did you try debugging if it actually gets to the if(proj instanceof Arrow)
     
  10. Offline

    Telmovieira

    @Funergy It doesn't even go past damager instanceof projectile

    I got it! I rewrote the code completely....

    <Edit by mrCookieSlime: Merged posts. Please don't double post. There is an Edit Button right next to the Date.>
     
    Last edited by a moderator: Mar 27, 2015
Thread Status:
Not open for further replies.

Share This Page