trying to buff my enemies when attacks

Discussion in 'Plugin Development' started by kasszz, Apr 24, 2013.

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

    kasszz

    Hey bukkiters,

    I'm currenly working on a buff attack, when an enderman attacks, I want to do something to a nearby mob.

    But now I get my self instead of the mob, I know why but how to fix it xD because how can I call for the mob?

    code:
    Code:
        @EventHandler(ignoreCancelled = true)
        public void onEntityDamageByEntity(EntityDamageByEntityEvent event){
            if(event.getDamager() instanceof Enderman){
                if(event.getEntity() instanceof Player){
                    getLogger().info("1");
                    Entity enderman = event.getDamager();
                    double endermanRadiusX = 10.0;
                    double endermanRadiusY = 10.0;
                    double endermanRadiusZ = 10.0;
                    List <Entity> nearbyEntities = enderman.getNearbyEntities(endermanRadiusX, endermanRadiusY, endermanRadiusZ);
                    for (Entity entity : nearbyEntities) {
                        if(entity instanceof Zombie){
                            getLogger().info("2");
                            LivingEntity zombie = (LivingEntity)event.getEntity();
                            int zombieDefenceDuration = 1000;
                            int zombieDefenceStrength = 10;
                            zombie.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE,zombieDefenceDuration, zombieDefenceStrength));
                        }
                        if(entity instanceof Skeleton){
                            getLogger().info("3");
                        }
                        if(entity instanceof Creeper){
                            getLogger().info("4");
                        }
                        if(entity instanceof Spider){
                            getLogger().info("5");
                        }
                    }
                }
            }
     
  2. Offline

    chasechocolate

    Add "Player player = (Player) event.getEntity();" after you check if the event.getEntity() is a player.
     
  3. Offline

    repsor

  4. Offline

    kasszz

  5. if(entity instanceof Zombie){
    getLogger().info("2");
    LivingEntity zombie = (LivingEntity)event.getEntity();

    shouldn't it:
    LivingEntity zombie = (LivingEntity)entity;
     
  6. Offline

    Rprrr

    ferrybig
    No, because he's scanning for nearby entities and looping through them..
     
  7. why would he call it zombie if its checked at the top of the code that its a player?
    if(event.getEntity() instanceof Player){
    that doesn't have any logic
     
  8. Offline

    Rprrr

    ferrybig
    Because he's checking for nearby entities , so not just the entity that is returned when you use event.getEntity(), but also every entity near it in a certain radius. He is doing a 'for'-loop when he's using the 'entity' variable, so the 'entity' variable is not what is returned when you use event.getEntity().
     
  9. He self is event.getEntity() because the enderman attacks him.
    then zombie wil be hisself cast to livingentity, and it add resistence potion to himself
    but he is saying he dont want that effect to him, but to a mob, that why he need to place entity there
     
  10. Offline

    Rprrr

    ferrybig
    Oops, I thought you were suggesting that he should've replaced 'entity' with event.getEntity(), I now see what you mean. My bad, sorry, and yes, that's correct and it will solve the problem.
     
  11. Offline

    kasszz

    ferrybig

    Thanks :D it works, can you explain it to me why? if you don't want to, I do understand :)

    goddamnit :( I'm trying to change my creeper, but it has an error.

    Code:
                            if(entity instanceof Creeper){
                                LivingEntity creeper = (LivingEntity)entity;
                                creeper.setPowered(true);
                            }
    error:
    The method setPowered(boolean) is undefined for the type LivingEntity

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  12. only creepers have setpowered, livingentities dont have it
     
  13. Offline

    kasszz

    ferrybig but is there a way to do it ? xD or is it impossible!? otherwise I have a really nasty other thing to do with the creepers :p
     
  14. kasszz
    Cast to Creeper instead of LivingEntity.
     
  15. Offline

    kasszz

    hahahahah, thanks xD How do you mean tunnle vision xD
     
Thread Status:
Not open for further replies.

Share This Page