cn.nukkit.event.entity.EntityDamageEvent.DamageCause Java Examples
The following examples show how to use
cn.nukkit.event.entity.EntityDamageEvent.DamageCause.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Effect.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public void applyEffect(Entity entity) { switch (this.id) { case Effect.POISON: //POISON if (entity.getHealth() > 1) { entity.attack(new EntityDamageEvent(entity, DamageCause.MAGIC, 1)); } break; case Effect.WITHER: //WITHER entity.attack(new EntityDamageEvent(entity, DamageCause.MAGIC, 1)); break; case Effect.REGENERATION: //REGENERATION if (entity.getHealth() < entity.getMaxHealth()) { entity.heal(new EntityRegainHealthEvent(entity, 1, EntityRegainHealthEvent.CAUSE_MAGIC)); } break; } }
Example #2
Source File: BlockLava.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public void onEntityCollide(Entity entity) { entity.highestPosition -= (entity.highestPosition - entity.y) * 0.5; if (!entity.hasEffect(Effect.FIRE_RESISTANCE)) { entity.attack(new EntityDamageByBlockEvent(this, entity, DamageCause.LAVA, 4)); } // Always setting the duration to 15 seconds? TODO EntityCombustByBlockEvent ev = new EntityCombustByBlockEvent(this, entity, 15); Server.getInstance().getPluginManager().callEvent(ev); if (!ev.isCancelled() // Making sure the entity is acutally alive and not invulnerable. && entity.isAlive() && entity.noDamageTicks == 0) { entity.setOnFire(ev.getDuration()); } super.onEntityCollide(entity); }
Example #3
Source File: Entity.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public boolean attack(EntityDamageEvent source) { if (hasEffect(Effect.FIRE_RESISTANCE) && (source.getCause() == DamageCause.FIRE || source.getCause() == DamageCause.FIRE_TICK || source.getCause() == DamageCause.LAVA)) { return false; } getServer().getPluginManager().callEvent(source); if (source.isCancelled()) { return false; } if (this.absorption > 0) { //Damage Absorption float absorptionHealth = this.absorption - source.getFinalDamage() > 0 ? source.getFinalDamage() : this.absorption; this.setAbsorption(this.absorption - absorptionHealth); source.setDamage(-absorptionHealth, EntityDamageEvent.DamageModifier.ABSORPTION); } setLastDamageCause(source); setHealth(getHealth() - source.getFinalDamage()); return true; }
Example #4
Source File: Entity.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public boolean attack(EntityDamageEvent source) { if (hasEffect(Effect.FIRE_RESISTANCE) && (source.getCause() == DamageCause.FIRE || source.getCause() == DamageCause.FIRE_TICK || source.getCause() == DamageCause.LAVA)) { return false; } getServer().getPluginManager().callEvent(source); if (source.isCancelled()) { return false; } if (this.absorption > 0) { // Damage Absorption this.setAbsorption(Math.max(0, this.getAbsorption() + source.getDamage(EntityDamageEvent.DamageModifier.ABSORPTION))); } setLastDamageCause(source); setHealth(getHealth() - source.getFinalDamage()); return true; }
Example #5
Source File: EntityProjectile.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public void onCollideWithEntity(Entity entity) { this.server.getPluginManager().callEvent(new ProjectileHitEvent(this, MovingObjectPosition.fromEntity(entity))); float damage = this.getResultDamage(); EntityDamageEvent ev; if (this.shootingEntity == null) { ev = new EntityDamageByEntityEvent(this, entity, DamageCause.PROJECTILE, damage); } else { ev = new EntityDamageByChildEntityEvent(this.shootingEntity, this, entity, DamageCause.PROJECTILE, damage); } if (entity.attack(ev)) { this.hadCollision = true; if (this.fireTicks > 0) { EntityCombustByEntityEvent event = new EntityCombustByEntityEvent(this, entity, 5); this.server.getPluginManager().callEvent(ev); if (!event.isCancelled()) { entity.setOnFire(event.getDuration()); } } } if (closeOnCollide) { this.close(); } }
Example #6
Source File: Entity.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public void fall(float fallDistance) { float damage = (float) Math.floor(fallDistance - 3 - (this.hasEffect(Effect.JUMP) ? this.getEffect(Effect.JUMP).getAmplifier() + 1 : 0)); if (damage > 0) { this.attack(new EntityDamageEvent(this, DamageCause.FALL, damage)); } if (fallDistance > 0.75) { BlockVector3 v = new BlockVector3(getFloorX(), getFloorY() - 1, getFloorZ()); int down = this.level.getBlockIdAt(v.x, v.y, v.z); if (down == Item.FARMLAND) { if (this instanceof Player) { Player p = (Player) this; PlayerInteractEvent ev = new PlayerInteractEvent(p, p.getInventory().getItemInHand(), this.temporalVector.setComponents(v.x, v.y, v.z), null, Action.PHYSICAL); this.server.getPluginManager().callEvent(ev); if (ev.isCancelled()) { return; } } this.level.setBlock(this.temporalVector.setComponents(v.x, v.y, v.z), new BlockDirt(), true, true); } } }
Example #7
Source File: BlockLava.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public void onEntityCollide(Entity entity) { entity.highestPosition -= (entity.highestPosition - entity.y) * 0.5; // Always setting the duration to 15 seconds? TODO EntityCombustByBlockEvent ev = new EntityCombustByBlockEvent(this, entity, 15); Server.getInstance().getPluginManager().callEvent(ev); if (!ev.isCancelled() // Making sure the entity is actually alive and not invulnerable. && entity.isAlive() && entity.noDamageTicks == 0) { entity.setOnFire(ev.getDuration()); } if (!entity.hasEffect(Effect.FIRE_RESISTANCE)) { entity.attack(new EntityDamageByBlockEvent(this, entity, DamageCause.LAVA, 4)); } super.onEntityCollide(entity); }
Example #8
Source File: Entity.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public boolean attack(EntityDamageEvent source) { if (hasEffect(Effect.FIRE_RESISTANCE) && (source.getCause() == DamageCause.FIRE || source.getCause() == DamageCause.FIRE_TICK || source.getCause() == DamageCause.LAVA)) { return false; } getServer().getPluginManager().callEvent(source); if (source.isCancelled()) { return false; } if (this.absorption > 0) { //Damage Absorption float absorptionHealth = this.absorption - source.getFinalDamage() > 0 ? source.getFinalDamage() : this.absorption; this.setAbsorption(this.absorption - absorptionHealth); source.setDamage(-absorptionHealth, EntityDamageEvent.DamageModifier.ABSORPTION); } setLastDamageCause(source); setHealth(getHealth() - source.getFinalDamage()); return true; }
Example #9
Source File: EntityProjectile.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public void onCollideWithEntity(Entity entity) { this.server.getPluginManager().callEvent(new ProjectileHitEvent(this)); float damage = this.getResultDamage(); EntityDamageEvent ev; if (this.shootingEntity == null) { ev = new EntityDamageByEntityEvent(this, entity, DamageCause.PROJECTILE, damage); } else { ev = new EntityDamageByChildEntityEvent(this.shootingEntity, this, entity, DamageCause.PROJECTILE, damage); } entity.attack(ev); this.hadCollision = true; if (this.fireTicks > 0) { EntityCombustByEntityEvent event = new EntityCombustByEntityEvent(this, entity, 5); this.server.getPluginManager().callEvent(ev); if (!event.isCancelled()) { entity.setOnFire(event.getDuration()); } } this.close(); }
Example #10
Source File: EnchantmentProtectionAll.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public float getProtectionFactor(EntityDamageEvent e) { DamageCause cause = e.getCause(); if (level <= 0 || cause == DamageCause.VOID || cause == DamageCause.CUSTOM || cause == DamageCause.MAGIC) { return 0; } return (float) (getLevel() * getTypeModifier()); }
Example #11
Source File: BlockFire.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public void onEntityCollide(Entity entity) { if (!entity.hasEffect(Effect.FIRE_RESISTANCE)) { entity.attack(new EntityDamageByBlockEvent(this, entity, DamageCause.FIRE, 1)); } EntityCombustByBlockEvent ev = new EntityCombustByBlockEvent(this, entity, 8); if (entity instanceof EntityArrow) { ev.setCancelled(); } Server.getInstance().getPluginManager().callEvent(ev); if (!ev.isCancelled() && entity.isAlive() && entity.noDamageTicks == 0) { entity.setOnFire(ev.getDuration()); } }
Example #12
Source File: EnchantmentProtectionFall.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public float getProtectionFactor(EntityDamageEvent e) { DamageCause cause = e.getCause(); if (level <= 0 || (cause != DamageCause.FALL)) { return 0; } return (float) (getLevel() * getTypeModifier()); }
Example #13
Source File: EnchantmentProtectionFire.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public float getProtectionFactor(EntityDamageEvent e) { DamageCause cause = e.getCause(); if (level <= 0 || (cause != DamageCause.LAVA && cause != DamageCause.FIRE && cause != DamageCause.FIRE_TICK)) { return 0; } return (float) (getLevel() * getTypeModifier()); }
Example #14
Source File: EnchantmentProtectionExplosion.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public float getProtectionFactor(EntityDamageEvent e) { DamageCause cause = e.getCause(); if (level <= 0 || (cause != DamageCause.ENTITY_EXPLOSION && cause != DamageCause.BLOCK_EXPLOSION)) { return 0; } return (float) (getLevel() * getTypeModifier()); }
Example #15
Source File: EntityXPOrb.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean attack(EntityDamageEvent source) { return (source.getCause() == DamageCause.VOID || source.getCause() == DamageCause.FIRE_TICK || source.getCause() == DamageCause.ENTITY_EXPLOSION || source.getCause() == DamageCause.BLOCK_EXPLOSION) && super.attack(source); }
Example #16
Source File: EnchantmentProtectionProjectile.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public float getProtectionFactor(EntityDamageEvent e) { DamageCause cause = e.getCause(); if (level <= 0 || (cause != DamageCause.PROJECTILE)) { return 0; } return (float) (getLevel() * getTypeModifier()); }
Example #17
Source File: Entity.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public void onStruckByLightning(Entity entity) { if (this.attack(new EntityDamageByEntityEvent(entity, this, DamageCause.LIGHTNING, 5))) { if (this.fireTicks < 8 * 20) { this.setOnFire(8); } } }
Example #18
Source File: EnchantmentProtectionFall.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public float getDamageProtection(EntityDamageEvent e) { DamageCause cause = e.getCause(); if (level <= 0 || (cause != DamageCause.FALL)) { return 0; } return (float) (getLevel() * getTypeModifier()); }
Example #19
Source File: Player.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean attack(EntityDamageEvent source) { if (!this.isAlive()) { return false; } if (this.isSpectator() || (this.isCreative() && source.getCause() != DamageCause.SUICIDE)) { //source.setCancelled(); return false; } else if (this.getAdventureSettings().get(Type.ALLOW_FLIGHT) && source.getCause() == DamageCause.FALL) { //source.setCancelled(); return false; } else if (source.getCause() == DamageCause.FALL) { if (this.getLevel().getBlock(this.getPosition().floor().add(0.5, -1, 0.5)).getId() == Block.SLIME_BLOCK) { if (!this.isSneaking()) { //source.setCancelled(); this.resetFallDistance(); return false; } } } if (super.attack(source)) { //!source.isCancelled() if (this.getLastDamageCause() == source && this.spawned) { if (source instanceof EntityDamageByEntityEvent) { Entity damager = ((EntityDamageByEntityEvent) source).getDamager(); if (damager instanceof Player) { ((Player) damager).getFoodData().updateFoodExpLevel(0.3); } } EntityEventPacket pk = new EntityEventPacket(); pk.eid = this.id; pk.event = EntityEventPacket.HURT_ANIMATION; this.dataPacket(pk); } return true; } else { return false; } }
Example #20
Source File: EntityItem.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean attack(EntityDamageEvent source) { return (source.getCause() == DamageCause.VOID || source.getCause() == DamageCause.FIRE_TICK || source.getCause() == DamageCause.ENTITY_EXPLOSION || source.getCause() == DamageCause.BLOCK_EXPLOSION) && super.attack(source); }
Example #21
Source File: EntityXPOrb.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean attack(EntityDamageEvent source) { return (source.getCause() == DamageCause.VOID || source.getCause() == DamageCause.FIRE_TICK || source.getCause() == DamageCause.ENTITY_EXPLOSION || source.getCause() == DamageCause.BLOCK_EXPLOSION) && super.attack(source); }
Example #22
Source File: Entity.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public void onStruckByLightning(Entity entity) { this.attack(new EntityDamageByEntityEvent(entity, this, DamageCause.LIGHTNING, 5)); if (this.fireTicks < 8 * 20) { this.setOnFire(8); } }
Example #23
Source File: EnchantmentThorns.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public void doPostAttack(Entity attacker, Entity entity) { if (!(entity instanceof EntityHumanType)) { return; } EntityHumanType human = (EntityHumanType) entity; int thornsDamage = 0; Random rnd = new Random(); for (Item armor : human.getInventory().getArmorContents()) { Enchantment thorns = armor.getEnchantment(Enchantment.ID_THORNS); if (thorns != null && thorns.getLevel() > 0) { int chance = thorns.getLevel() * 15; if (chance > 90) { chance = 90; } if (rnd.nextInt(100) + 1 <= chance) { thornsDamage += rnd.nextInt(4) + 1; } } } if (thornsDamage > 0) { attacker.attack(new EntityDamageEvent(attacker, DamageCause.MAGIC, rnd.nextInt(4) + 1)); } }
Example #24
Source File: EnchantmentProtectionProjectile.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public float getDamageProtection(EntityDamageEvent e) { DamageCause cause = e.getCause(); if (level <= 0 || (cause != DamageCause.PROJECTILE)) { return 0; } return (float) (getLevel() * getTypeModifier()); }
Example #25
Source File: EnchantmentProtectionAll.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public float getDamageProtection(EntityDamageEvent e) { DamageCause cause = e.getCause(); if (level <= 0 || cause == DamageCause.VOID || cause == DamageCause.CUSTOM || cause == DamageCause.MAGIC) { return 0; } return (float) (getLevel() * getTypeModifier()); }
Example #26
Source File: EnchantmentProtectionExplosion.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public float getDamageProtection(EntityDamageEvent e) { DamageCause cause = e.getCause(); if (level <= 0 || (cause != DamageCause.ENTITY_EXPLOSION && cause != DamageCause.BLOCK_EXPLOSION)) { return 0; } return (float) (getLevel() * getTypeModifier()); }
Example #27
Source File: EnchantmentProtectionFire.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public float getDamageProtection(EntityDamageEvent e) { DamageCause cause = e.getCause(); if (level <= 0 || (cause != DamageCause.LAVA && cause != DamageCause.FIRE && cause != DamageCause.FIRE_TICK)) { return 0; } return (float) (getLevel() * getTypeModifier()); }
Example #28
Source File: EnchantmentProtectionFall.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public float getDamageProtection(EntityDamageEvent e) { DamageCause cause = e.getCause(); if (level <= 0 || (cause != DamageCause.FALL)) { return 0; } return (float) (getLevel() * getTypeModifier()); }
Example #29
Source File: BlockFire.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public void onEntityCollide(Entity entity) { if (!entity.hasEffect(Effect.FIRE_RESISTANCE)) { entity.attack(new EntityDamageByBlockEvent(this, entity, DamageCause.FIRE, 1)); } EntityCombustByBlockEvent ev = new EntityCombustByBlockEvent(this, entity, 8); if (entity instanceof EntityArrow) { ev.setCancelled(); } Server.getInstance().getPluginManager().callEvent(ev); if (!ev.isCancelled() && entity instanceof Player && !((Player) entity).isCreative()) { entity.setOnFire(ev.getDuration()); } }
Example #30
Source File: Effect.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public void applyEffect(Entity entity) { switch (this.id) { case Effect.POISON: //POISON if (entity.getHealth() > 1) { entity.attack(new EntityDamageEvent(entity, DamageCause.MAGIC, 1)); } break; case Effect.WITHER: //WITHER entity.attack(new EntityDamageEvent(entity, DamageCause.MAGIC, 1)); break; case Effect.REGENERATION: //REGENERATION if (entity.getHealth() < entity.getMaxHealth()) { entity.heal(new EntityRegainHealthEvent(entity, 1, EntityRegainHealthEvent.CAUSE_MAGIC)); } break; case Effect.SPEED: if (entity instanceof Player) { ((Player) entity).setMovementSpeed((float) (((this.amplifier + 1) * 0.2 + 1) * 0.1)); } break; case Effect.SLOWNESS: if (entity instanceof Player) { ((Player) entity).setMovementSpeed((float) (((this.amplifier + 1) * -0.15 + 1) * 0.1)); } break; } }