EntityDamageByEntityEvent

Discussion in 'Plugin Development' started by bjsnow, Feb 7, 2013.

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

    bjsnow

    ZeusAllMighty11 Try and help me with this one.
    Code:
    @EventHandler
        public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
            Entity e = event.getEntity();
       
         
            if (e instanceof Player && event.getDamager() instanceof Player) {
                Player player = (Player) e;
              Player damagerp = (Player) event.getDamager();
      if (redTeam.containsKey(player.getName()) && redTeam.containsKey(damagerp.getName())) {
          event.setCancelled(true);
      }else if (blueTeam.containsKey(player.getName()) && blueTeam.containsKey(damagerp.getName())) {
          event.setCancelled(true);
      }else {
         
      }
            }else if(e instanceof Player && event.getDamager() instanceof Arrow) {
                Arrow arrow = (Arrow)event.getEntity();
                if (arrow.getShooter() instanceof Player) {
                Player shooter = (Player) arrow.getShooter();
                Player damaged = (Player) event.getEntity();
                  if (redTeam.containsKey(damaged.getName()) && redTeam.containsKey(shooter.getName())) {
          event.setCancelled(true);
      }else if (blueTeam.containsKey(damaged.getName()) && blueTeam.containsKey(shooter.getName())) {
          event.setCancelled(true);
      }else {
         
      }
            }
            }
            }
    
    I Have got when a player hits a player on the same team to cancel the event but I can't get when a player shoots another player ;/
     
  2. Offline

    skore87

    You're casting an arrow to the wrong entity.

    Arrow arrow = (Arrow)event.getEntity();
    should be using event.getDamager().


    As for the rest of the code, I haven't looked at it.
     
  3. Offline

    CubixCoders

    Debug messages?
    Nvm, listen to skore87
     
  4. Offline

    bjsnow

    Overlooked it :p Ill see if it works now :)
     
  5. Offline

    skore87

    Debug messages are still a good idea though. Unless you're certain that it is right it is often the only way to find what is going on in your program.
     
    ZeusAllMighty11 likes this.
  6. Offline

    ZeusAllMighty11 Retired Staff

    Sorry I couldn't help sooner, working on YouTube stuff ^_^
     
Thread Status:
Not open for further replies.

Share This Page