Java Code Examples for cn.nukkit.entity.Entity#attack()
The following examples show how to use
cn.nukkit.entity.Entity#attack() .
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: 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 2
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 3
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 4
Source File: EnchantmentThorns.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public void doPostAttack(Entity attacker, Entity entity) { if (!(entity instanceof EntityHumanType)) { return; } EntityHumanType human = (EntityHumanType) entity; int thornsLevel = 0; for (Item armor : human.getInventory().getArmorContents()) { Enchantment thorns = armor.getEnchantment(Enchantment.ID_THORNS); if (thorns != null) { thornsLevel = Math.max(thorns.getLevel(), thornsLevel); } } ThreadLocalRandom random = ThreadLocalRandom.current(); if (shouldHit(random, thornsLevel)) { attacker.attack(new EntityDamageByEntityEvent(entity, attacker, EntityDamageEvent.DamageCause.ENTITY_ATTACK, getDamage(random, level), 0f)); } }
Example 5
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 6
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 7
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 8
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; } }
Example 9
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 10
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 11
Source File: EnchantmentThorns.java From Jupiter 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 12
Source File: Potion.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public void applyPotion(Entity entity, double health) { if (!(entity instanceof EntityLiving)) { return; } Effect applyEffect = getEffect(this.getId(), this.isSplash()); if (applyEffect == null) { return; } if (entity instanceof Player) { if (!((Player) entity).isSurvival() && applyEffect.isBad()) { return; } } PotionApplyEvent event = new PotionApplyEvent(this, entity); entity.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return; } switch (this.getId()) { case INSTANT_HEALTH: case INSTANT_HEALTH_II: entity.heal(new EntityRegainHealthEvent(entity, (float) (health * (double) (4 << (applyEffect.getAmplifier() + 1))), EntityRegainHealthEvent.CAUSE_EATING)); break; case HARMING: case HARMING_II: entity.attack(new EntityDamageEvent(entity, DamageCause.MAGIC, (float) (health * (double) (6 << (applyEffect.getAmplifier() + 1))))); break; default: int duration = (int) ((isSplash() ? health : 1) * (double) applyEffect.getDuration() + 0.5); applyEffect.setDuration(duration); entity.addEffect(applyEffect); } }
Example 13
Source File: Effect.java From Jupiter 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; } }
Example 14
Source File: BlockFire.java From Jupiter 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 15
Source File: BlockLava.java From Jupiter with GNU General Public License v3.0 | 5 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)); } EntityCombustByBlockEvent ev = new EntityCombustByBlockEvent(this, entity, 15); Server.getInstance().getPluginManager().callEvent(ev); if (!ev.isCancelled()) { entity.setOnFire(ev.getDuration()); } super.onEntityCollide(entity); }
Example 16
Source File: BlockCactus.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public void onEntityCollide(Entity entity) { entity.attack(new EntityDamageByBlockEvent(this, entity, DamageCause.CONTACT, 1)); }
Example 17
Source File: Potion.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public void applyPotion(Entity entity, double health) { if (!(entity instanceof EntityLiving)) { return; } Effect applyEffect = getEffect(this.getId(), this.isSplash()); if (applyEffect == null) { return; } if (entity instanceof Player) { if (!((Player) entity).isSurvival() && applyEffect.isBad()) { return; } } PotionApplyEvent event = new PotionApplyEvent(this, applyEffect, entity); entity.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return; } applyEffect = event.getApplyEffect(); switch (this.getId()) { case INSTANT_HEALTH: case INSTANT_HEALTH_II: entity.heal(new EntityRegainHealthEvent(entity, (float) (health * (double) (4 << (applyEffect.getAmplifier() + 1))), EntityRegainHealthEvent.CAUSE_EATING)); break; case HARMING: case HARMING_II: entity.attack(new EntityDamageEvent(entity, DamageCause.MAGIC, (float) (health * (double) (6 << (applyEffect.getAmplifier() + 1))))); break; default: int duration = (int) ((isSplash() ? health : 1) * (double) applyEffect.getDuration() + 0.5); applyEffect.setDuration(duration); entity.addEffect(applyEffect); } }
Example 18
Source File: Potion.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public void applyPotion(Entity entity, double health) { if (!(entity instanceof EntityLiving)) { return; } Effect applyEffect = getEffect(this.getId(), this.isSplash()); if (applyEffect == null) { return; } if (entity instanceof Player) { if (!((Player) entity).isSurvival() && !((Player) entity).isAdventure() && applyEffect.isBad()) { return; } } PotionApplyEvent event = new PotionApplyEvent(this, applyEffect, entity); entity.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return; } applyEffect = event.getApplyEffect(); switch (this.getId()) { case INSTANT_HEALTH: case INSTANT_HEALTH_II: entity.heal(new EntityRegainHealthEvent(entity, (float) (health * (double) (4 << (applyEffect.getAmplifier() + 1))), EntityRegainHealthEvent.CAUSE_MAGIC)); break; case HARMING: case HARMING_II: entity.attack(new EntityDamageEvent(entity, DamageCause.MAGIC, (float) (health * (double) (6 << (applyEffect.getAmplifier() + 1))))); break; default: int duration = (int) ((isSplash() ? health : 1) * (double) applyEffect.getDuration() + 0.5); applyEffect.setDuration(duration); entity.addEffect(applyEffect); } }
Example 19
Source File: BlockCactus.java From Jupiter with GNU General Public License v3.0 | 4 votes |
@Override public void onEntityCollide(Entity entity) { entity.attack(new EntityDamageByBlockEvent(this, entity, DamageCause.CONTACT, 1)); }
Example 20
Source File: BlockCactus.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public void onEntityCollide(Entity entity) { entity.attack(new EntityDamageByBlockEvent(this, entity, DamageCause.CONTACT, 1)); }