So uh.. A while back I made a custom enchants plugin, right? And it included a lifesteal enchantment (very original) which worked along the lines of double newHealth = e.getDamage / 5 double Health = e.getEntity.getHealth + newHealth; e.getEntity().setHealth(health); And I'm not gonna lie it worked, however, if I do this: public void kkk(EntitySpawnEvent e){ if(e.getEntity().getName().equals(MobEngine.getWeakzombie())){ int health = 5; e.getEntity().WHY } } where it says WHY the method setHealth doesn't work (In this case I was going to do setMaxHealth()) so uhh.. How do I make it work? also "LEARN JAVA" incoming
I believe EntitySpawnEvent.getEntity() returns a simple Entity class. You must check if the returned object is an instanceof Damageable and then cast it to see health methods. In newer spigot builds, getMaxHealth() is deprecated for Damageable entities. To appropriately get the max health, you'll need to instead check if the entity is an instanceof LivingEntity, then get the max health attribute value using LivingEntity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue().
Could you use code tags, and show the entire method please? Edit: ^^ Entire method code to make sure that you are performing the right checks on the entity.
I mentioned the instanceof checking, but I forgot to say that you need to cast afterwards: Code (Java): if(event.getEntity() instanceof LivingEntity){ ((LivingEntity)event.getEntity()).getHealth(); }
That is literally the entire class besides public class yadayada extends JavaPlugin implements Listener
Unrelated but you seem to know your stuff. I continued with this: @EventHandler public void kkk(EntitySpawnEvent e){ if(e.getEntity().getName().equals(MobEngine.getWeakzombie())){ if(e.getEntity() instanceof LivingEntity){ ((LivingEntity)e.getEntity()).setHealth(5); if(e.getEntity()instanceof Monster){ ((Monster)e.getEntity()).setDamage(3); } } } } and set damage isn't a method(I already knew) so uh How does one set a mobs damage?
That's another value accessible through attributes. Code (Java): //Get the entity's GENERIC_ATTACK_DAMAGE attribute AttributeInstance dmgAttribute = livingEntity.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE); //Not all living entities have this attribute, so a null check is necessary. Example: Pigs if(dmgAttribute != null){ //To completely override its damage (instead of modifying the current value), change the base value. dmgAttribute.setBaseValue(3.0); }