How can I make Villager invincible

Discussion in 'Plugin Development' started by HerrPrefix, Oct 27, 2014.

Thread Status:
Not open for further replies.
  1. How can I make Villager with Custom Names invincible, because Potion Effects wont last forever.
     
  2. Offline

    MasterDoctor

    You can make a potion effect last forever!​
    Give it a duration of 9999 and Minecraft automatically makes it last forever :)
     
    war_man333 likes this.

  3. The potion effect stops after a day
     
  4. Offline

    Funergy

    HerrPrefix Entity damage event if the entity is a Villager and if the villager has a custom name visible then cancel the event.
    and the same for entity damage by entity if de entity that has been damaged a Villager with a custom name visible then cancel the event
     
    ChipDev likes this.
  5. Offline

    MasterDoctor

    Then Every day, assign the effect to the villager
     
  6. Solved it.

    Code:
        @EventHandler
        public void onDeath(EntityDeathEvent e) {
            Villager v = (Villager) e.getEntity();
            if(v.isDead()) {
                Location loc = v.getLocation();
                Villager v2 = (Villager) v.getWorld().spawnCreature(loc, CreatureType.VILLAGER);
                v2.setCustomName(v.getCustomName());
                v2.setCustomNameVisible(true);
                v2.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 200000, 255));
               
            }
        }
     
  7. Offline

    jpjunho

    HerrPrefix
    If you solved it, please mark the thread as solved
     
Thread Status:
Not open for further replies.

Share This Page