cn.nukkit.event.entity.EntityDamageByEntityEvent Java Examples
The following examples show how to use
cn.nukkit.event.entity.EntityDamageByEntityEvent.
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: DeathEventListener.java From Plan with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onMobDeath(EntityDeathEvent event) { long time = System.currentTimeMillis(); Entity dead = event.getEntity(); try { EntityDamageEvent entityDamageEvent = dead.getLastDamageCause(); if (!(entityDamageEvent instanceof EntityDamageByEntityEvent)) { return; } EntityDamageByEntityEvent entityDamageByEntityEvent = (EntityDamageByEntityEvent) entityDamageEvent; Entity killerEntity = entityDamageByEntityEvent.getDamager(); handleKill(time, /* Not a player */ null, killerEntity); } catch (Exception e) { errorLogger.log(L.ERROR, e, ErrorContext.builder().related(event, dead).build()); } }
Example #2
Source File: DeathEventListener.java From Plan with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onPlayerDeath(PlayerDeathEvent event) { long time = System.currentTimeMillis(); Player dead = event.getEntity(); SessionCache.getCachedSession(dead.getUniqueId()).ifPresent(Session::died); try { EntityDamageEvent entityDamageEvent = dead.getLastDamageCause(); if (!(entityDamageEvent instanceof EntityDamageByEntityEvent)) { return; } EntityDamageByEntityEvent entityDamageByEntityEvent = (EntityDamageByEntityEvent) entityDamageEvent; Entity killerEntity = entityDamageByEntityEvent.getDamager(); UUID uuid = dead.getUniqueId(); handleKill(time, uuid, killerEntity); } catch (Exception e) { errorLogger.log(L.ERROR, e, ErrorContext.builder().related(event, dead).build()); } }
Example #3
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 #4
Source File: EntityCreeper.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public Item[] getDrops(){ if(this.getLastDamageCause() instanceof EntityDamageByEntityEvent){ if(((EntityDamageByEntityEvent) this.getLastDamageCause()).getDamager() instanceof EntitySkeleton){ return new Item[]{Item.get(500 + new NukkitRandom().nextRange(0, 12), 0, 1)}; //レコード }else{ return new Item[]{new ItemGunpowder(0, new NukkitRandom().nextRange(0, 2))}; } } return new Item[]{}; }
Example #5
Source File: EntitySheep.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public Item[] getDrops() { if (this.lastDamageCause instanceof EntityDamageByEntityEvent) { return new Item[]{Item.get(Item.WOOL, getColor(), 1)}; } return new Item[0]; }
Example #6
Source File: EntityPainting.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean attack(EntityDamageEvent source) { if (super.attack(source)) { if (source instanceof EntityDamageByEntityEvent) { Entity damager = ((EntityDamageByEntityEvent) source).getDamager(); if (damager instanceof Player && ((Player) damager).isSurvival() && this.level.getGameRules().getBoolean(GameRule.DO_ENTITY_DROPS)) { this.level.dropItem(this, new ItemPainting()); } } this.close(); return true; } else { return false; } }
Example #7
Source File: EntityMinecartAbstract.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean attack(EntityDamageEvent source) { if (invulnerable) { return false; } else { Entity damager = ((EntityDamageByEntityEvent) source).getDamager(); boolean instantKill = damager instanceof Player && ((Player) damager).isCreative(); if (!instantKill) performHurtAnimation((int) source.getFinalDamage()); if (instantKill || getDamage() > 40) { if (linkedEntity != null) { mountEntity(linkedEntity); } if (instantKill && (!hasCustomName())) { kill(); } else { if (level.getGameRules().getBoolean(GameRule.DO_ENTITY_DROPS)) { dropItem(); } close(); } } } return true; }
Example #8
Source File: EntityCreeper.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public Item[] getDrops() { if (this.lastDamageCause instanceof EntityDamageByEntityEvent) { return new Item[]{Item.get(Item.GUNPOWDER, ThreadLocalRandom.current().nextInt(2) + 1)}; } return new Item[0]; }
Example #9
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 #10
Source File: EntitySheep.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public Item[] getDrops() { if (this.lastDamageCause instanceof EntityDamageByEntityEvent) { return new Item[]{Item.get(((this.isOnFire()) ? Item.COOKED_MUTTON : Item.RAW_MUTTON)), Item.get(Item.WOOL, getColor(), 1)}; } return new Item[0]; }
Example #11
Source File: EntityEnderPearl.java From Nukkit with GNU General Public License v3.0 | 5 votes |
private void teleport() { if (!this.level.equals(this.shootingEntity.getLevel())) { return; } this.shootingEntity.teleport(new Vector3(NukkitMath.floorDouble(this.x) + 0.5, this.y, NukkitMath.floorDouble(this.z) + 0.5), TeleportCause.ENDER_PEARL); if ((((Player) this.shootingEntity).getGamemode() & 0x01) == 0) { this.shootingEntity.attack(new EntityDamageByEntityEvent(this, shootingEntity, EntityDamageEvent.DamageCause.PROJECTILE, 5f, 0f)); } this.level.addSound(this, Sound.MOB_ENDERMEN_PORTAL); }
Example #12
Source File: EntityVehicle.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean attack(EntityDamageEvent source) { VehicleDamageEvent event = new VehicleDamageEvent(this, source.getEntity(), source.getFinalDamage()); getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return false; } boolean instantKill = false; if (source instanceof EntityDamageByEntityEvent) { Entity damager = ((EntityDamageByEntityEvent) source).getDamager(); instantKill = damager instanceof Player && ((Player) damager).isCreative(); } if (instantKill || getHealth() - source.getFinalDamage() < 1) { VehicleDestroyEvent event2 = new VehicleDestroyEvent(this, source.getEntity()); getServer().getPluginManager().callEvent(event2); if (event2.isCancelled()) { return false; } } if (instantKill) { source.setDamage(1000); } return super.attack(source); }
Example #13
Source File: EntityPainting.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean attack(EntityDamageEvent source) { if (super.attack(source)) { if (source instanceof EntityDamageByEntityEvent) { Entity damager = ((EntityDamageByEntityEvent) source).getDamager(); if (damager instanceof Player && ((Player) damager).isSurvival() && this.level.getGameRules().getBoolean(GameRule.DO_ENTITY_DROPS)) { this.level.dropItem(this, new ItemPainting()); } } this.close(); return true; } else { return false; } }
Example #14
Source File: EntityCreeper.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public Item[] getDrops() { if (this.lastDamageCause instanceof EntityDamageByEntityEvent) { return new Item[]{Item.get(Item.GUNPOWDER, ThreadLocalRandom.current().nextInt(2) + 1)}; } return new Item[0]; }
Example #15
Source File: EntityRabbit.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public Item[] getDrops() { Item drops[] = new Item[3]; drops[0] = this.isOnFire() ? new ItemRabbitCooked(0, random.nextRange(0, 1)) : new ItemRabbitRaw(0, random.nextRange(0, 1)); drops[1] = new ItemRabbitHide(0, random.nextRange(0, 1)); if (this.getLastDamageCause() instanceof EntityDamageByEntityEvent && random.nextRange(1, 10) == 1) { drops[2] = new ItemRabbitFoot(random.nextRange(0, 1)); } return drops; }
Example #16
Source File: Entity.java From Jupiter 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 #17
Source File: EntityLiving.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean attack(EntityDamageEvent source) { if (this.attackTime > 0 || this.noDamageTicks > 0) { EntityDamageEvent lastCause = this.getLastDamageCause(); if (lastCause != null && lastCause.getDamage() >= source.getDamage()) { return false; } } if (super.attack(source)) { if (source instanceof EntityDamageByEntityEvent) { Entity e = ((EntityDamageByEntityEvent) source).getDamager(); if (source instanceof EntityDamageByChildEntityEvent) { e = ((EntityDamageByChildEntityEvent) source).getChild(); } if (e.isOnFire() && !(e instanceof Player)) { this.setOnFire(2 * this.server.getDifficulty()); } double deltaX = this.x - e.x; double deltaZ = this.z - e.z; this.knockBack(e, source.getDamage(), deltaX, deltaZ, ((EntityDamageByEntityEvent) source).getKnockBack()); } EntityEventPacket pk = new EntityEventPacket(); pk.entityRuntimeId = this.getId(); pk.event = this.getHealth() <= 0 ? EntityEventPacket.DEATH_ANIMATION : EntityEventPacket.HURT_ANIMATION; Server.broadcastPacket(this.level.getPlayers().values(), pk); this.attackTime = 10; return true; } else { return false; } }
Example #18
Source File: EntityPainting.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean attack(EntityDamageEvent source) { if (super.attack(source)){ if (source instanceof EntityDamageByEntityEvent) { Entity damager = ((EntityDamageByEntityEvent) source).getDamager(); if (damager instanceof Player && ((Player) damager).isSurvival()) { this.level.dropItem(this, new ItemPainting()); } } this.close(); return true; } else { return false; } }
Example #19
Source File: EntityBoat.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean attack(EntityDamageEvent source) { if (invulnerable) { return false; } else { performHurtAnimation((int) source.getFinalDamage()); Entity damager = ((EntityDamageByEntityEvent) source).getDamager(); boolean instantKill = damager instanceof Player && ((Player) damager).isCreative(); if (instantKill || getDamage() > 40) { if (linkedEntity != null) { mountEntity(linkedEntity); } if (instantKill && (!hasCustomName())) { kill(); } else { if (level.getGameRules().getBoolean("doentitydrops")) { this.level.dropItem(this, new ItemBoat()); } close(); } } } return true; }
Example #20
Source File: EntityMinecartAbstract.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean attack(EntityDamageEvent source) { if (invulnerable) { return false; } else { Entity damager = ((EntityDamageByEntityEvent) source).getDamager(); boolean instantKill = damager instanceof Player && ((Player) damager).isCreative(); if (!instantKill) performHurtAnimation((int) source.getFinalDamage()); if (instantKill || getDamage() > 40) { if (linkedEntity != null) { mountEntity(linkedEntity); } if (instantKill && (!hasCustomName())) { kill(); } else { if (level.getGameRules().getBoolean("doentitydrops")) { dropItem(); } close(); } } } return true; }
Example #21
Source File: EntityElderGuardian.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public Item[] getDrops() { Item drops[] = new Item[4]; drops[0] = new ItemPrismarineCrystals(0, random.nextRange(0, 1)); drops[1] = new ItemPrismarineShard(0, random.nextRange(0, 2)); //TODO: 60%の確率で生魚、25%の確率で生鮭、2%の確率でクマノミ、13%の確率でフグ。また焼死時には焼き魚、焼き鮭をドロップ if (this.getLastDamageCause() instanceof EntityDamageByEntityEvent) { drops[2] = new ItemBlock(new BlockSponge()); } return drops; }
Example #22
Source File: EntityLiving.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public boolean attack(EntityDamageEvent source) { if (this.noDamageTicks > 0) { return false; } else if (this.attackTime > 0) { EntityDamageEvent lastCause = this.getLastDamageCause(); if (lastCause != null && lastCause.getDamage() >= source.getDamage()) { return false; } } if (super.attack(source)) { if (source instanceof EntityDamageByEntityEvent) { Entity damager = ((EntityDamageByEntityEvent) source).getDamager(); if (source instanceof EntityDamageByChildEntityEvent) { damager = ((EntityDamageByChildEntityEvent) source).getChild(); } //Critical hit if (damager instanceof Player && !damager.onGround) { AnimatePacket animate = new AnimatePacket(); animate.action = AnimatePacket.Action.CRITICAL_HIT; animate.eid = getId(); this.getLevel().addChunkPacket(damager.getChunkX(), damager.getChunkZ(), animate); this.getLevel().addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_ATTACK_STRONG); source.setDamage(source.getDamage() * 1.5f); } if (damager.isOnFire() && !(damager instanceof Player)) { this.setOnFire(2 * this.server.getDifficulty()); } double deltaX = this.x - damager.x; double deltaZ = this.z - damager.z; this.knockBack(damager, source.getDamage(), deltaX, deltaZ, ((EntityDamageByEntityEvent) source).getKnockBack()); } EntityEventPacket pk = new EntityEventPacket(); pk.eid = this.getId(); pk.event = this.getHealth() <= 0 ? EntityEventPacket.DEATH_ANIMATION : EntityEventPacket.HURT_ANIMATION; Server.broadcastPacket(this.hasSpawned.values(), pk); this.attackTime = source.getAttackCooldown(); return true; } else { return false; } }
Example #23
Source File: EntityBoat.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public boolean attack(EntityDamageEvent source) { if (invulnerable) { return false; } else { // Event start VehicleDamageEvent event = new VehicleDamageEvent(this, source.getEntity(), source.getFinalDamage()); getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return false; } // Event stop performHurtAnimation((int) event.getDamage()); boolean instantKill = false; if (source instanceof EntityDamageByEntityEvent) { Entity damager = ((EntityDamageByEntityEvent) source).getDamager(); instantKill = damager instanceof Player && ((Player) damager).isCreative(); } if (instantKill || getDamage() > 40) { // Event start VehicleDestroyEvent event2 = new VehicleDestroyEvent(this, source.getEntity()); getServer().getPluginManager().callEvent(event2); if (event2.isCancelled()) { return false; } // Event stop if (linkedEntity != null) { mountEntity(linkedEntity); } if (instantKill && (!hasCustomName())) { kill(); } else { if (level.getGameRules().getBoolean(GameRule.DO_ENTITY_DROPS)) { this.level.dropItem(this, new ItemBoat()); } close(); } } } return true; }