// Damage Hook public void onEntityDamage(EntityDamageEvent event) { // No point in running if this has been stopped if (event.isCancelled()) { return; } // Check if Firetouch user hit another entity ElixirMod plugin = getPlugin(); if (event instanceof EntityDamageByEntityEvent) { Entity damager = ((EntityDamageByEntityEvent) event).getDamager(); Entity damagee = event.getEntity(); // Check if damager is a player if (damager instanceof Player) { Player player = (Player) damager; PotionEntry entry = plugin.BuffList.get(player); // See if that player has Firetouch if (entry != null) { if (entry.HasBuff.get(Name) != null && entry.HasBuff.get(Name)) { // Check if we can ignite with any damage, else unarmed only boolean canIgnite = false; if (unarmedOnly) { if (((Player) damager).getItemInHand().getTypeId() == 0) { canIgnite = true; } } else { canIgnite = true; } if (canIgnite) { // If target is on fire, ignore, else ignite if (damagee.getFireTicks() <= 0) { // Chance ignite int chance = 1 + (int) (Math.random() * (100 - 1)); if (chance <= igniteChance) { damagee.setFireTicks(igniteLength * 20); } } } } } } } }
@Override public void onEntityDamage(EntityDamageEvent event) { if (event instanceof EntityDamageByProjectileEvent) { EntityDamageByProjectileEvent edpe = (EntityDamageByProjectileEvent) event; if (edpe.getProjectile() instanceof Snowball) { Entity tgt = event.getEntity(); if (tgt instanceof LivingEntity) { Player pl = edpe.getDamager() instanceof Player ? (Player) edpe.getDamager() : null; if (SnowballzUtil.hasPermission(_plugin, pl, SnowballzConstants.PERMISSION_SNOWDAMAGE)) { event.setDamage(_plugin.getConfiguration().getInt(Snowballz.SNOW_DAMAGE, 1)); } if (tgt.getFireTicks() > 0 && _plugin.getConfiguration().getBoolean(Snowballz.SNOW_FIRE, true) && SnowballzUtil.hasPermission( _plugin, pl, SnowballzConstants.PERMISSION_PUTOUTFIRE)) { tgt.setFireTicks(0); } } } } }
@EventHandler(priority = EventPriority.NORMAL) public void onEntityDamage(EntityDamageEvent event) { if (event.isCancelled()) return; Entity ent = event.getEntity(); boolean tamedWolf = ent instanceof Wolf ? ((Wolf) ent).isTamed() : false; ClaimedResidence area = Residence.getResidenceManager().getByLoc(ent.getLocation()); /* Living Entities */ if (event instanceof EntityDamageByEntityEvent) { EntityDamageByEntityEvent attackevent = (EntityDamageByEntityEvent) event; Entity damager = attackevent.getDamager(); ClaimedResidence srcarea = null; if (damager != null) srcarea = Residence.getResidenceManager().getByLoc(damager.getLocation()); boolean srcpvp = true; if (srcarea != null) srcpvp = srcarea.getPermissions().has("pvp", true); ent = attackevent.getEntity(); if ((ent instanceof Player || tamedWolf) && (damager instanceof Player || (damager instanceof Arrow && (((Arrow) damager).getShooter() instanceof Player)))) { Player attacker = null; if (damager instanceof Player) attacker = (Player) damager; else if (damager instanceof Arrow) attacker = (Player) ((Arrow) damager).getShooter(); if (!srcpvp) { attacker.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPVPZone")); event.setCancelled(true); return; } /* Check for Player vs Player */ if (area == null) { /* World PvP */ if (!Residence.getWorldFlags().getPerms(damager.getWorld().getName()).has("pvp", true)) { attacker.sendMessage( ChatColor.RED + Residence.getLanguage().getPhrase("WorldPVPDisabled")); event.setCancelled(true); } } else { /* Normal PvP */ if (!area.getPermissions().has("pvp", true)) { attacker.sendMessage(ChatColor.RED + Residence.getLanguage().getPhrase("NoPVPZone")); event.setCancelled(true); } } return; } else if ((ent instanceof Player || tamedWolf) && (damager instanceof Creeper)) { if (area == null) { if (!Residence.getWorldFlags() .getPerms(damager.getWorld().getName()) .has("creeper", true)) { event.setCancelled(true); } } else { if (!area.getPermissions().has("creeper", true)) { event.setCancelled(true); } } } } if (area == null) { if (!Residence.getWorldFlags().getPerms(ent.getWorld().getName()).has("damage", true) && (ent instanceof Player || tamedWolf)) { event.setCancelled(true); } } else { if (!area.getPermissions().has("damage", true) && (ent instanceof Player || tamedWolf)) { event.setCancelled(true); } } if (event.isCancelled()) { /* Put out a fire on a player */ if ((ent instanceof Player || tamedWolf) && (event.getCause() == EntityDamageEvent.DamageCause.FIRE || event.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK)) { ent.setFireTicks(0); } } }
@Override public void run() { entity.setFireTicks(0); }
@SuppressWarnings("deprecation") public void assignMobProps(Entity baseEntity, ISpawnableEntity data) { // This needs to be before everything else! if (data.getRider() != null) { addRider(baseEntity, data.getRider()); } Vector v1 = data.getVelocity(baseEntity); Vector v2 = data.getVelocity2(baseEntity); if (v2.getX() == 0 && v2.getY() == 0 && v2.getZ() == 0) { baseEntity.setVelocity(data.getVelocity(baseEntity).clone()); } else { Vector v3 = randomVector(v1, v2); baseEntity.setVelocity(v3.clone()); } baseEntity.setFireTicks(data.getFireTicks(baseEntity)); if (baseEntity instanceof LivingEntity) { LivingEntity entity = (LivingEntity) baseEntity; setBasicProps(entity, data); if (data.showCustomName()) { setCustomName(entity, data); } if (entity instanceof Ageable) { Ageable a = (Ageable) entity; setAgeProps(a, data); } if (entity instanceof Animals) { Animals animal = (Animals) entity; // Setting animal specific properties if (animal instanceof Pig) { Pig p = (Pig) animal; p.setSaddle(data.isSaddled()); } else if (animal instanceof Sheep) { Sheep s = (Sheep) animal; DyeColor color = DyeColor.valueOf(data.getColor()); s.setColor(color); } else if (animal instanceof Wolf) { Wolf w = (Wolf) animal; w.setAngry(data.isAngry()); w.setTamed(data.isTamed()); if (data.isTamed()) { ArrayList<Player> nearPlayers = getNearbyPlayers(w.getLocation(), 16); int index = (int) Math.round(Math.rint(nearPlayers.size() - 1)); if (nearPlayers != null) { w.setOwner(nearPlayers.get(index)); } w.setSitting(data.isSitting()); } } else if (animal instanceof Ocelot) { Ocelot o = (Ocelot) animal; o.setTamed(data.isTamed()); if (data.isTamed()) { Ocelot.Type catType = Ocelot.Type.valueOf(data.getCatType()); o.setCatType(catType); ArrayList<Player> nearPlayers = getNearbyPlayers(o.getLocation(), 16); int index = (int) Math.round(Math.rint(nearPlayers.size() - 1)); if (nearPlayers != null) { o.setOwner(nearPlayers.get(index)); } o.setSitting(data.isSitting()); } } } else if (entity instanceof Villager) { Villager v = (Villager) entity; v.setAge(data.getAge(baseEntity)); v.setProfession(data.getProfession()); } else if (entity instanceof Monster) { Monster monster = (Monster) entity; // Setting monster specific properties. if (monster instanceof Enderman) { Enderman e = (Enderman) monster; e.setCarriedMaterial(data.getEndermanBlock()); } else if (monster instanceof Creeper) { Creeper c = (Creeper) monster; c.setPowered(data.isCharged()); } else if (monster instanceof PigZombie) { PigZombie p = (PigZombie) monster; if (data.isAngry()) { p.setAngry(true); } p.setBaby((data.getAge(baseEntity) < -1) ? true : false); } else if (monster instanceof Spider) { Spider s = (Spider) monster; if (data.isJockey()) { makeJockey(s, data); } } else if (monster instanceof Zombie) { Zombie z = (Zombie) monster; boolean isVillager = false; if (data.hasProp("zombie")) { isVillager = (Boolean) (data.getProp("zombie")); } z.setBaby((data.getAge(baseEntity) < -1) ? true : false); z.setVillager(isVillager); } else if (monster instanceof Skeleton) { Skeleton sk = (Skeleton) monster; SkeletonType skType = SkeletonType.NORMAL; if (data.hasProp("wither")) { skType = ((Boolean) (data.getProp("wither")) == true) ? SkeletonType.WITHER : SkeletonType.NORMAL; } sk.setSkeletonType(skType); } } else if (entity instanceof Golem) { Golem golem = (Golem) entity; if (golem instanceof IronGolem) { IronGolem i = (IronGolem) golem; if (data.isAngry()) { ArrayList<Player> nearPlayers = getNearbyPlayers(i.getLocation(), 16); int index = (int) Math.round(Math.rint(nearPlayers.size() - 1)); if (nearPlayers != null) { i.setPlayerCreated(false); i.damage(0, nearPlayers.get(index)); i.setTarget(nearPlayers.get(index)); } } } // Some are not classified as animals or monsters } else if (entity instanceof Slime) { Slime s = (Slime) entity; s.setSize(data.getSlimeSize()); } else if (entity instanceof MagmaCube) { MagmaCube m = (MagmaCube) entity; m.setSize(data.getSlimeSize()); } } else if (baseEntity instanceof Projectile) { Projectile pro = (Projectile) baseEntity; // Eventually add explosive arrows and such :D if (pro instanceof Fireball) { Fireball f = (Fireball) pro; setExplosiveProps(f, data); f.setVelocity(new Vector(0, 0, 0)); f.setDirection(data.getVelocity(baseEntity)); } else if (pro instanceof SmallFireball) { SmallFireball f = (SmallFireball) pro; setExplosiveProps(f, data); f.setVelocity(new Vector(0, 0, 0)); f.setDirection(data.getVelocity(baseEntity)); } } else if (baseEntity instanceof Explosive) { Explosive ex = (Explosive) baseEntity; if (ex instanceof TNTPrimed) { TNTPrimed tnt = (TNTPrimed) ex; setExplosiveProps(tnt, data); tnt.setFuseTicks(data.getFuseTicks(baseEntity)); } } else if (baseEntity instanceof Firework) { Firework f = (Firework) baseEntity; ItemMeta meta = data.getItemType().getItemMeta(); if (meta != null) { if (meta instanceof FireworkMeta) { FireworkMeta fMeta = (FireworkMeta) meta; if (fMeta != null) { f.setFireworkMeta(fMeta); } } } } else if (baseEntity instanceof Minecart) { Minecart m = (Minecart) baseEntity; if (data.hasProp("minecartSpeed")) { m.setMaxSpeed((Double) data.getProp("minecartSpeed")); } } else if (baseEntity instanceof ExperienceOrb) { ExperienceOrb o = (ExperienceOrb) baseEntity; o.setExperience(data.getDroppedExp(baseEntity)); } setNBT(baseEntity, data); }
public void setFireTicks(int ticks) { e.setFireTicks(ticks); }