Program: 187622
Project: 187622
Buggy source:
@EventHandler public void onEntityDamage(final EntityDamageEvent event){
  if (event.isCancelled()) {
    return;
  }
  if (event instanceof EntityDamageByEntityEvent) {
    EntityDamageByEntityEvent e=(EntityDamageByEntityEvent)event;
    if (event.getEntity() instanceof CraftMyPet) {
      if (e.getDamager() instanceof Player || (e.getDamager() instanceof Arrow && ((Arrow)e.getDamager()).getShooter() instanceof Player)) {
        Player damager;
        if (e.getDamager() instanceof Arrow) {
          damager=(Player)((Arrow)e.getDamager()).getShooter();
        }
 else {
          damager=(Player)e.getDamager();
        }
        MyPet myPet=MyPetList.getMyPet(event.getEntity().getEntityId());
        if (myPet.getCraftPet().getHandle().isRidden()) {
          event.setCancelled(true);
          if (myPet.getSkillSystem().hasSkill("String_Node_Str")) {
            if (myPet.getCraftPet().getHandle().petPathfinderSelector.hasGoal("String_Node_Str")) {
              ((EntityAIRide)myPet.getCraftPet().getHandle().petPathfinderSelector.getGoal("String_Node_Str")).toggleRiding();
            }
          }
        }
 else         if (damager.getItemInHand().getType() == MyPetConfig.leashItem) {
          String msg;
          if (myPet.getHealth() > myPet.getMaxHealth() / 3 * 2) {
            msg="String_Node_Str" + ChatColor.GREEN + myPet.getHealth()+ ChatColor.WHITE+ "String_Node_Str"+ myPet.getMaxHealth();
          }
 else           if (myPet.getHealth() > myPet.getMaxHealth() / 3) {
            msg="String_Node_Str" + ChatColor.YELLOW + myPet.getHealth()+ ChatColor.WHITE+ "String_Node_Str"+ myPet.getMaxHealth();
          }
 else {
            msg="String_Node_Str" + ChatColor.RED + myPet.getHealth()+ ChatColor.WHITE+ "String_Node_Str"+ myPet.getMaxHealth();
          }
          damager.sendMessage(MyPetUtil.setColors("String_Node_Str").replace("String_Node_Str",myPet.petName));
          damager.sendMessage(MyPetUtil.setColors("String_Node_Str").replace("String_Node_Str",myPet.petName).replace("String_Node_Str",msg));
          if (!myPet.getOwner().equals(damager)) {
            damager.sendMessage(MyPetUtil.setColors("String_Node_Str").replace("String_Node_Str",myPet.getOwner().getName()));
          }
 else {
            if (!myPet.isPassiv()) {
              int damage=MyPet.getStartDamage(myPet.getClass()) + (myPet.getSkillSystem().hasSkill("String_Node_Str") ? myPet.getSkillSystem().getSkillLevel("String_Node_Str") : 0);
              damager.sendMessage(MyPetUtil.setColors("String_Node_Str").replace("String_Node_Str",myPet.petName).replace("String_Node_Str","String_Node_Str" + damage));
            }
            if (MyPetConfig.hungerSystem) {
              damager.sendMessage(MyPetUtil.setColors("String_Node_Str").replace("String_Node_Str","String_Node_Str" + myPet.getHungerValue()));
            }
            if (MyPetConfig.levelSystem) {
              int lvl=myPet.getExperience().getLevel();
              double exp=myPet.getExperience().getCurrentExp();
              double reqEXP=myPet.getExperience().getRequiredExp();
              damager.sendMessage(MyPetUtil.setColors("String_Node_Str").replace("String_Node_Str","String_Node_Str" + lvl));
              damager.sendMessage(MyPetUtil.setColors("String_Node_Str").replace("String_Node_Str",String.format("String_Node_Str",exp)).replace("String_Node_Str",String.format("String_Node_Str",reqEXP)));
            }
          }
          damager.sendMessage("String_Node_Str");
          event.setCancelled(true);
        }
 else         if (myPet.getOwner().equals(damager) && (!MyPetConfig.ownerCanAttackPet || !MyPetUtil.canHurtAt(myPet.getOwner().getPlayer(),myPet.getLocation()))) {
          event.setCancelled(true);
        }
 else         if (!myPet.getOwner().equals(damager) && !MyPetUtil.canHurt(damager,myPet.getOwner().getPlayer())) {
          event.setCancelled(true);
        }
      }
    }
 else     if (MyPetType.isLeashableEntityType(event.getEntity().getType())) {
      if (e.getDamager() instanceof Player) {
        Player damager=(Player)e.getDamager();
        if (!MyPetList.hasMyPet(damager)) {
          LivingEntity leashTarget=(LivingEntity)event.getEntity();
          if (!MyPetPermissions.has(damager,"String_Node_Str" + MyPetType.getMyPetTypeByEntityType(leashTarget.getType()).getTypeName()) || damager.getItemInHand().getType() != MyPetConfig.leashItem) {
            return;
          }
          boolean willBeLeashed=true;
          List<LeashFlag> leashFlags=MyPet.getLeashFlags(MyPetType.getMyPetTypeByEntityType(leashTarget.getType()).getMyPetClass());
          for (          LeashFlag flag : leashFlags) {
            if (flag == LeashFlag.Adult) {
              if (leashTarget instanceof Ageable) {
                willBeLeashed=((Ageable)leashTarget).isAdult();
              }
 else               if (leashTarget instanceof Zombie) {
                willBeLeashed=!((Zombie)leashTarget).isBaby();
              }
            }
 else             if (flag == LeashFlag.Baby) {
              if (leashTarget instanceof Ageable) {
                willBeLeashed=!((Ageable)leashTarget).isAdult();
              }
 else               if (leashTarget instanceof Zombie) {
                willBeLeashed=((Zombie)leashTarget).isBaby();
              }
            }
 else             if (flag == LeashFlag.LowHp) {
              willBeLeashed=leashTarget.getHealth() <= 2;
            }
 else             if (flag == LeashFlag.UserCreated) {
              if (leashTarget instanceof IronGolem) {
                willBeLeashed=((IronGolem)leashTarget).isPlayerCreated();
              }
            }
 else             if (flag == LeashFlag.Wild) {
              if (leashTarget instanceof IronGolem) {
                willBeLeashed=!((IronGolem)leashTarget).isPlayerCreated();
              }
 else               if (leashTarget instanceof Tameable) {
                willBeLeashed=!((Tameable)leashTarget).isTamed();
              }
            }
 else             if (flag == LeashFlag.Tamed) {
              if (leashTarget instanceof Tameable) {
                willBeLeashed=((Tameable)leashTarget).isTamed();
              }
            }
            if (!willBeLeashed || flag == LeashFlag.None) {
              willBeLeashed=false;
              break;
            }
          }
          if (willBeLeashed) {
            event.setCancelled(true);
            InactiveMyPet inactiveMyPet=new InactiveMyPet(MyPetPlayer.getMyPetPlayer(damager.getName()));
            inactiveMyPet.setPetType(MyPetType.getMyPetTypeByEntityType(leashTarget.getType()));
            inactiveMyPet.setPetName(MyPetType.getMyPetTypeByEntityType(leashTarget.getType()).getTypeName());
            inactiveMyPet.setLocation(leashTarget.getLocation());
            NBTTagCompound extendedInfo=new NBTTagCompound("String_Node_Str");
            if (leashTarget instanceof Ocelot) {
              extendedInfo.setInt("String_Node_Str",((Ocelot)leashTarget).getCatType().getId());
              extendedInfo.setBoolean("String_Node_Str",((Ocelot)leashTarget).isSitting());
            }
 else             if (leashTarget instanceof Wolf) {
              extendedInfo.setBoolean("String_Node_Str",((Wolf)leashTarget).isSitting());
              extendedInfo.setBoolean("String_Node_Str",((Wolf)leashTarget).isTamed());
              extendedInfo.setByte("String_Node_Str",(byte)((CraftWolf)leashTarget).getHandle().getCollarColor());
            }
 else             if (leashTarget instanceof Sheep) {
              extendedInfo.setInt("String_Node_Str",((Sheep)leashTarget).getColor().getData());
              extendedInfo.setBoolean("String_Node_Str",((Sheep)leashTarget).isSheared());
            }
 else             if (leashTarget instanceof Villager) {
              extendedInfo.setInt("String_Node_Str",((Villager)leashTarget).getProfession().getId());
            }
 else             if (leashTarget instanceof Pig) {
              extendedInfo.setBoolean("String_Node_Str",((Pig)leashTarget).hasSaddle());
            }
 else             if (leashTarget instanceof Slime) {
              extendedInfo.setInt("String_Node_Str",((Slime)leashTarget).getSize());
            }
 else             if (leashTarget instanceof Creeper) {
              extendedInfo.setBoolean("String_Node_Str",((Creeper)leashTarget).isPowered());
            }
 else             if (leashTarget instanceof Zombie) {
              extendedInfo.setBoolean("String_Node_Str",((Zombie)leashTarget).isBaby());
              extendedInfo.setBoolean("String_Node_Str",((Zombie)leashTarget).isVillager());
            }
 else             if (leashTarget instanceof Ageable) {
              extendedInfo.setBoolean("String_Node_Str",!((Ageable)leashTarget).isAdult());
            }
 else             if (leashTarget instanceof Enderman) {
              extendedInfo.setShort("String_Node_Str",(short)((CraftEnderman)leashTarget).getHandle().getCarriedId());
              extendedInfo.setShort("String_Node_Str",(short)((CraftEnderman)leashTarget).getHandle().getCarriedData());
            }
            inactiveMyPet.setInfo(extendedInfo);
            event.getEntity().remove();
            MyPet myPet=MyPetList.setMyPetActive(inactiveMyPet);
            myPet.createPet();
            MyPetUtil.getServer().getPluginManager().callEvent(new MyPetLeashEvent(myPet));
            MyPetUtil.getDebugLogger().info("String_Node_Str");
            MyPetUtil.getDebugLogger().info("String_Node_Str" + myPet.toString());
            MyPetUtil.getDebugLogger().info(MyPetPlugin.getPlugin().savePets(false) + "String_Node_Str");
            damager.sendMessage(MyPetUtil.setColors(MyPetLanguage.getString("String_Node_Str")));
          }
        }
      }
    }
  }
 else   if (event.getEntity() instanceof CraftMyChicken || event.getEntity() instanceof CraftMyBat) {
    if (event.getCause() == DamageCause.FALL) {
      event.setCancelled(true);
    }
  }
 else   if (event.getEntity() instanceof CraftMyIronGolem) {
    if (event.getCause() == DamageCause.FALL || event.getCause() == DamageCause.DROWNING) {
      event.setCancelled(true);
    }
  }
}

Fixed version (ground truth):
@EventHandler public void onEntityDamage(final EntityDamageEvent event){
  if (event.isCancelled()) {
    return;
  }
  if (event instanceof EntityDamageByEntityEvent) {
    EntityDamageByEntityEvent e=(EntityDamageByEntityEvent)event;
    if (event.getEntity() instanceof CraftMyPet) {
      if (e.getDamager() instanceof Player || (e.getDamager() instanceof Arrow && ((Arrow)e.getDamager()).getShooter() instanceof Player)) {
        Player damager;
        if (e.getDamager() instanceof Arrow) {
          damager=(Player)((Arrow)e.getDamager()).getShooter();
        }
 else {
          damager=(Player)e.getDamager();
        }
        MyPet myPet=MyPetList.getMyPet(event.getEntity().getEntityId());
        if (myPet.getCraftPet().getHandle().isRidden()) {
          event.setCancelled(true);
          if (myPet.getSkillSystem().hasSkill("String_Node_Str")) {
            if (myPet.getCraftPet().getHandle().petPathfinderSelector.hasGoal("String_Node_Str")) {
              ((EntityAIRide)myPet.getCraftPet().getHandle().petPathfinderSelector.getGoal("String_Node_Str")).toggleRiding();
            }
          }
        }
 else         if (damager.getItemInHand().getType() == MyPetConfig.leashItem) {
          String msg;
          if (myPet.getHealth() > myPet.getMaxHealth() / 3 * 2) {
            msg="String_Node_Str" + ChatColor.GREEN + myPet.getHealth()+ ChatColor.WHITE+ "String_Node_Str"+ myPet.getMaxHealth();
          }
 else           if (myPet.getHealth() > myPet.getMaxHealth() / 3) {
            msg="String_Node_Str" + ChatColor.YELLOW + myPet.getHealth()+ ChatColor.WHITE+ "String_Node_Str"+ myPet.getMaxHealth();
          }
 else {
            msg="String_Node_Str" + ChatColor.RED + myPet.getHealth()+ ChatColor.WHITE+ "String_Node_Str"+ myPet.getMaxHealth();
          }
          damager.sendMessage(MyPetUtil.setColors("String_Node_Str").replace("String_Node_Str",myPet.petName));
          damager.sendMessage(MyPetUtil.setColors("String_Node_Str").replace("String_Node_Str",myPet.petName).replace("String_Node_Str",msg));
          if (!myPet.getOwner().equals(damager)) {
            damager.sendMessage(MyPetUtil.setColors("String_Node_Str").replace("String_Node_Str",myPet.getOwner().getName()));
          }
 else {
            if (!myPet.isPassiv()) {
              int damage=MyPet.getStartDamage(myPet.getClass()) + (myPet.getSkillSystem().hasSkill("String_Node_Str") ? myPet.getSkillSystem().getSkillLevel("String_Node_Str") : 0);
              damager.sendMessage(MyPetUtil.setColors("String_Node_Str").replace("String_Node_Str",myPet.petName).replace("String_Node_Str","String_Node_Str" + damage));
            }
            if (MyPetConfig.hungerSystem) {
              damager.sendMessage(MyPetUtil.setColors("String_Node_Str").replace("String_Node_Str","String_Node_Str" + myPet.getHungerValue()));
            }
            if (MyPetConfig.levelSystem) {
              int lvl=myPet.getExperience().getLevel();
              double exp=myPet.getExperience().getCurrentExp();
              double reqEXP=myPet.getExperience().getRequiredExp();
              damager.sendMessage(MyPetUtil.setColors("String_Node_Str").replace("String_Node_Str","String_Node_Str" + lvl));
              damager.sendMessage(MyPetUtil.setColors("String_Node_Str").replace("String_Node_Str",String.format("String_Node_Str",exp)).replace("String_Node_Str",String.format("String_Node_Str",reqEXP)));
            }
          }
          damager.sendMessage("String_Node_Str");
          event.setCancelled(true);
        }
 else         if (myPet.getOwner().equals(damager) && (!MyPetConfig.ownerCanAttackPet || !MyPetUtil.canHurtAt(myPet.getOwner().getPlayer(),myPet.getLocation()))) {
          event.setCancelled(true);
        }
 else         if (!myPet.getOwner().equals(damager) && !MyPetUtil.canHurt(damager,myPet.getOwner().getPlayer())) {
          event.setCancelled(true);
        }
      }
    }
 else     if (MyPetType.isLeashableEntityType(event.getEntity().getType())) {
      if (e.getDamager() instanceof Player) {
        Player damager=(Player)e.getDamager();
        if (!MyPetList.hasMyPet(damager)) {
          LivingEntity leashTarget=(LivingEntity)event.getEntity();
          if (!MyPetPermissions.has(damager,"String_Node_Str" + MyPetType.getMyPetTypeByEntityType(leashTarget.getType()).getTypeName()) || damager.getItemInHand().getType() != MyPetConfig.leashItem) {
            return;
          }
          boolean willBeLeashed=true;
          List<LeashFlag> leashFlags=MyPet.getLeashFlags(MyPetType.getMyPetTypeByEntityType(leashTarget.getType()).getMyPetClass());
          for (          LeashFlag flag : leashFlags) {
            if (flag == LeashFlag.Adult) {
              if (leashTarget instanceof Ageable) {
                willBeLeashed=((Ageable)leashTarget).isAdult();
              }
 else               if (leashTarget instanceof Zombie) {
                willBeLeashed=!((Zombie)leashTarget).isBaby();
              }
            }
 else             if (flag == LeashFlag.Baby) {
              if (leashTarget instanceof Ageable) {
                willBeLeashed=!((Ageable)leashTarget).isAdult();
              }
 else               if (leashTarget instanceof Zombie) {
                willBeLeashed=((Zombie)leashTarget).isBaby();
              }
            }
 else             if (flag == LeashFlag.LowHp) {
              willBeLeashed=leashTarget.getHealth() <= 2;
            }
 else             if (flag == LeashFlag.UserCreated) {
              if (leashTarget instanceof IronGolem) {
                willBeLeashed=((IronGolem)leashTarget).isPlayerCreated();
              }
            }
 else             if (flag == LeashFlag.Wild) {
              if (leashTarget instanceof IronGolem) {
                willBeLeashed=!((IronGolem)leashTarget).isPlayerCreated();
              }
 else               if (leashTarget instanceof Tameable) {
                willBeLeashed=!((Tameable)leashTarget).isTamed();
              }
            }
 else             if (flag == LeashFlag.Tamed) {
              if (leashTarget instanceof Tameable) {
                willBeLeashed=((Tameable)leashTarget).isTamed();
              }
            }
            if (!willBeLeashed || flag == LeashFlag.None) {
              willBeLeashed=false;
              break;
            }
          }
          if (willBeLeashed) {
            event.setCancelled(true);
            InactiveMyPet inactiveMyPet=new InactiveMyPet(MyPetPlayer.getMyPetPlayer(damager.getName()));
            inactiveMyPet.setPetType(MyPetType.getMyPetTypeByEntityType(leashTarget.getType()));
            inactiveMyPet.setPetName(MyPetType.getMyPetTypeByEntityType(leashTarget.getType()).getTypeName());
            inactiveMyPet.setLocation(leashTarget.getLocation());
            NBTTagCompound extendedInfo=new NBTTagCompound("String_Node_Str");
            if (leashTarget instanceof Ocelot) {
              extendedInfo.setInt("String_Node_Str",((Ocelot)leashTarget).getCatType().getId());
              extendedInfo.setBoolean("String_Node_Str",((Ocelot)leashTarget).isSitting());
            }
 else             if (leashTarget instanceof Wolf) {
              extendedInfo.setBoolean("String_Node_Str",((Wolf)leashTarget).isSitting());
              extendedInfo.setBoolean("String_Node_Str",((Wolf)leashTarget).isTamed());
              extendedInfo.setByte("String_Node_Str",(byte)((CraftWolf)leashTarget).getHandle().getCollarColor());
            }
 else             if (leashTarget instanceof Sheep) {
              extendedInfo.setInt("String_Node_Str",((Sheep)leashTarget).getColor().getData());
              extendedInfo.setBoolean("String_Node_Str",((Sheep)leashTarget).isSheared());
            }
 else             if (leashTarget instanceof Villager) {
              extendedInfo.setInt("String_Node_Str",((Villager)leashTarget).getProfession().getId());
            }
 else             if (leashTarget instanceof Pig) {
              extendedInfo.setBoolean("String_Node_Str",((Pig)leashTarget).hasSaddle());
            }
 else             if (leashTarget instanceof Slime) {
              extendedInfo.setInt("String_Node_Str",((Slime)leashTarget).getSize());
            }
 else             if (leashTarget instanceof Creeper) {
              extendedInfo.setBoolean("String_Node_Str",((Creeper)leashTarget).isPowered());
            }
 else             if (leashTarget instanceof Zombie) {
              extendedInfo.setBoolean("String_Node_Str",((Zombie)leashTarget).isBaby());
              extendedInfo.setBoolean("String_Node_Str",((Zombie)leashTarget).isVillager());
            }
 else             if (leashTarget instanceof Enderman) {
              extendedInfo.setShort("String_Node_Str",(short)((CraftEnderman)leashTarget).getHandle().getCarriedId());
              extendedInfo.setShort("String_Node_Str",(short)((CraftEnderman)leashTarget).getHandle().getCarriedData());
            }
            if (leashTarget instanceof Ageable) {
              extendedInfo.setBoolean("String_Node_Str",!((Ageable)leashTarget).isAdult());
            }
            inactiveMyPet.setInfo(extendedInfo);
            event.getEntity().remove();
            MyPet myPet=MyPetList.setMyPetActive(inactiveMyPet);
            myPet.createPet();
            MyPetUtil.getServer().getPluginManager().callEvent(new MyPetLeashEvent(myPet));
            MyPetUtil.getDebugLogger().info("String_Node_Str");
            MyPetUtil.getDebugLogger().info("String_Node_Str" + myPet.toString());
            MyPetUtil.getDebugLogger().info(MyPetPlugin.getPlugin().savePets(false) + "String_Node_Str");
            damager.sendMessage(MyPetUtil.setColors(MyPetLanguage.getString("String_Node_Str")));
          }
        }
      }
    }
  }
 else   if (event.getEntity() instanceof CraftMyChicken || event.getEntity() instanceof CraftMyBat) {
    if (event.getCause() == DamageCause.FALL) {
      event.setCancelled(true);
    }
  }
 else   if (event.getEntity() instanceof CraftMyIronGolem) {
    if (event.getCause() == DamageCause.FALL || event.getCause() == DamageCause.DROWNING) {
      event.setCancelled(true);
    }
  }
}