use of org.bukkit.entity.Damageable in project QualityArmory by ZombieStriker.
the class GunUtil method shoot.
public static void shoot(Player p, double sway, double damage, int shots, int range) {
for (int i = 0; i < shots; i++) {
Location start = p.getEyeLocation().clone();
Vector go = p.getLocation().getDirection().normalize();
go.add(new Vector((Math.random() * 2 * sway) - sway, (Math.random() * 2 * sway) - sway, (Math.random() * 2 * sway) - sway));
Vector step = go.clone().multiply(Main.bulletStep);
// Simple values to make it easier on the search
boolean posX = go.getX() > 0;
boolean posZ = go.getZ() > 0;
Entity hitTarget = null;
double dis2 = range;
boolean overrideocculde = false;
boolean headShot = false;
Location bulletHitLoc = null;
int maxDistance = range;
Block b = p.getTargetBlock(null, range);
if (isSolid(b, b.getLocation())) {
maxDistance = (int) Math.min(range, b.getLocation().distance(start));
}
for (Entity e : p.getNearbyEntities(maxDistance, maxDistance, maxDistance)) {
if (e != p && e != p.getVehicle())
if (e.getLocation().getX() - start.getX() > 0 == posX)
if (e.getLocation().getZ() - start.getZ() > 0 == posZ) {
double dis = e.getLocation().distance(start);
if (dis > dis2)
continue;
Location test = start.clone();
if (HeadShotUtil.closeEnough(e, test.clone().add(go.clone().multiply(dis)))) {
// If the entity is close to the line of fire.
if (e instanceof Damageable) {
if (Main.hasParties && (!Main.friendlyFire)) {
try {
if (Parties.getApi().getPartyPlayer(e.getUniqueId()).getPartyName().equalsIgnoreCase(Parties.getApi().getPartyPlayer(p.getUniqueId()).getPartyName()))
continue;
} catch (Error | Exception e43) {
}
}
boolean occulde = false;
double lastingDist = dis;
for (int dist = 0; dist < dis / Main.bulletStep; dist++) {
test.add(step);
if (isSolid(test.getBlock(), test)) {
if (!HeadShotUtil.closeEnough(e, test)) {
occulde = true;
lastingDist = dist;
break;
}
}
}
if (!occulde) {
bulletHitLoc = test;
dis2 = lastingDist;
overrideocculde = true;
hitTarget = e;
headShot = HeadShotUtil.isHeadShot(e, test);
if (headShot) {
try {
p.playSound(p.getLocation(), Sound.BLOCK_NOTE_PLING, 2, 1);
} catch (Error | Exception h4) {
p.playSound(p.getLocation(), Sound.valueOf("POP"), 1, 1);
}
}
}
}
}
}
}
if (hitTarget != null) {
if (!(hitTarget instanceof Player) || Main.allowGunsInRegion(hitTarget.getLocation())) {
((Damageable) hitTarget).damage(damage * (BulletProtectionUtil.stoppedBullet(p, bulletHitLoc, go) ? 0.1 : 1) * (headShot ? 2 : 1), p);
((LivingEntity) hitTarget).setNoDamageTicks(0);
}
}
double smokeDistance = 0;
for (int dist = 0; dist < (dis2 / Main.bulletStep); dist++) {
start.add(step);
if (dist % 25 == 0) {
try {
start.getWorld().playSound(start, Sound.BLOCK_DISPENSER_LAUNCH, 2, 2);
start.getWorld().playSound(start, Sound.BLOCK_FIRE_EXTINGUISH, 2, 2);
} catch (Error e) {
start.getWorld().playSound(start, Sound.valueOf("SHOOT_ARROW"), 2, 2);
start.getWorld().playSound(start, Sound.valueOf("FIRE_IGNITE"), 2, 2);
}
}
if (overrideocculde || !isSolid(start.getBlock(), start)) {
if (Main.enableBulletTrails)
if (smokeDistance >= Main.smokeSpacing) {
try {
start.getWorld().spawnParticle((Particle) Main.bulletTrail, start, 0);
} catch (Error e2) {
}
smokeDistance = 0;
} else {
smokeDistance += Main.bulletStep;
}
} else {
// start.getWorld().spawnParticle(Particle.BLOCK_DUST,start,start.getBlock().getTypeId());
start.getWorld().playEffect(start, Effect.STEP_SOUND, start.getBlock().getType());
break;
}
}
}
}
use of org.bukkit.entity.Damageable in project QualityArmory by ZombieStriker.
the class GunUtil method shoot.
public static void shoot(Player p, double sway, double damage, int shots, int range) {
for (int i = 0; i < shots; i++) {
Location start = p.getEyeLocation().clone();
Vector go = p.getLocation().getDirection().normalize();
go.add(new Vector((Math.random() * 2 * sway) - sway, (Math.random() * 2 * sway) - sway, (Math.random() * 2 * sway) - sway));
Vector step = go.clone().multiply(Main.bulletStep);
// Simple values to make it easier on the search
boolean posX = go.getX() > 0;
boolean posZ = go.getZ() > 0;
Entity hitTarget = null;
double dis2 = range;
boolean overrideocculde = false;
boolean headShot = false;
int maxDistance = range;
Block b = p.getTargetBlock(null, range + 2);
if (isSolid(b, b.getLocation())) {
maxDistance = (int) Math.min(range, p.getTargetBlock(null, range).getLocation().distance(start));
}
for (Entity e : p.getNearbyEntities(maxDistance, maxDistance, maxDistance)) {
if (e != p && e != p.getVehicle())
if (e.getLocation().getX() - start.getX() > 0 == posX)
if (e.getLocation().getZ() - start.getZ() > 0 == posZ) {
double dis = e.getLocation().distance(start);
if (dis > dis2)
continue;
Location test = start.clone();
if (HeadShotUtil.nearestDistance(e, test.clone().add(go.clone().multiply(dis)))) {
// If the entity is close to the line of fire.
if (e instanceof Damageable) {
boolean occulde = false;
for (int dist = 0; dist < dis / Main.bulletStep; dist++) {
test.add(step);
if (isSolid(test.getBlock(), test)) {
if (HeadShotUtil.nearestDistance(e, test)) {
occulde = true;
break;
}
}
}
if (!occulde) {
dis2 = dis;
overrideocculde = true;
hitTarget = e;
headShot = HeadShotUtil.isHeadShot(e, test);
}
}
}
}
}
if (hitTarget != null) {
if (!(hitTarget instanceof Player) || Main.allowGunsInRegion(hitTarget.getLocation())) {
((Damageable) hitTarget).damage(damage * (headShot ? 2 : 1), p);
((LivingEntity) hitTarget).setNoDamageTicks(0);
}
}
double smokeDistance = 0;
for (int dist = 0; dist < (dis2 / Main.bulletStep); dist++) {
start.add(step);
if (dist % 25 == 0) {
try {
start.getWorld().playSound(start, Sound.BLOCK_DISPENSER_LAUNCH, 2, 2);
start.getWorld().playSound(start, Sound.BLOCK_FIRE_EXTINGUISH, 2, 2);
} catch (Error e) {
start.getWorld().playSound(start, Sound.valueOf("SHOOT_ARROW"), 2, 2);
start.getWorld().playSound(start, Sound.valueOf("FIRE_IGNITE"), 2, 2);
}
}
if (overrideocculde || !isSolid(start.getBlock(), start)) {
if (Main.enableBulletTrails)
if (smokeDistance >= Main.smokeSpacing) {
try {
start.getWorld().spawnParticle((Particle) Main.bulletTrail, start, 0);
} catch (Error e2) {
}
smokeDistance = 0;
} else {
smokeDistance += Main.bulletStep;
}
} else {
break;
}
}
}
}
use of org.bukkit.entity.Damageable in project QualityArmory by ZombieStriker.
the class CopyOfGunUtil method shoot.
public static void shoot(Player p, double sway, double damage, int shots, int range) {
for (int i = 0; i < shots; i++) {
Location start = p.getEyeLocation().clone();
Vector go = p.getLocation().getDirection().normalize();
go.add(new Vector((Math.random() * 2 * sway) - sway, (Math.random() * 2 * sway) - sway, (Math.random() * 2 * sway) - sway));
Vector step = go.clone().multiply(Main.bulletStep);
// Simple values to make it easier on the search
boolean posX = go.getX() > 0;
boolean posZ = go.getZ() > 0;
Entity hitTarget = null;
double dis2 = range;
boolean overrideocculde = false;
boolean headShot = false;
int maxDistance = range;
Block b = p.getTargetBlock(null, range + 2);
if (isSolid(b, b.getLocation())) {
maxDistance = (int) Math.min(range, p.getTargetBlock(null, range).getLocation().distance(start));
}
for (Entity e : p.getNearbyEntities(maxDistance, maxDistance, maxDistance)) {
if (e != p && e != p.getVehicle())
if (e.getLocation().getX() - start.getX() > 0 == posX)
if (e.getLocation().getZ() - start.getZ() > 0 == posZ) {
double dis = e.getLocation().distance(start);
if (dis > dis2)
continue;
Location test = start.clone();
if (HeadShotUtil.nearestDistance(e, test.clone().add(go.clone().multiply(dis)))) {
// If the entity is close to the line of fire.
if (e instanceof Damageable) {
boolean occulde = false;
for (int dist = 0; dist < dis / Main.bulletStep; dist++) {
test.add(step);
if (isSolid(test.getBlock(), test)) {
if (HeadShotUtil.nearestDistance(e, test)) {
occulde = true;
break;
}
}
}
if (!occulde) {
dis2 = dis;
overrideocculde = true;
hitTarget = e;
headShot = HeadShotUtil.isHeadShot(e, test);
}
}
}
}
}
if (hitTarget != null) {
if (!(hitTarget instanceof Player) || Main.allowGunsInRegion(hitTarget.getLocation())) {
((Damageable) hitTarget).damage(damage * (headShot ? 2 : 1), p);
((LivingEntity) hitTarget).setNoDamageTicks(0);
}
}
for (int dist = 0; dist < (dis2 / Main.bulletStep); dist++) {
start.add(step);
if (dist % 25 == 0) {
try {
start.getWorld().playSound(start, Sound.BLOCK_DISPENSER_LAUNCH, 2, 2);
start.getWorld().playSound(start, Sound.BLOCK_FIRE_EXTINGUISH, 2, 2);
} catch (Error e) {
start.getWorld().playSound(start, Sound.valueOf("SHOOT_ARROW"), 2, 2);
start.getWorld().playSound(start, Sound.valueOf("FIRE_IGNITE"), 2, 2);
}
}
if (overrideocculde || !isSolid(start.getBlock(), start)) {
if (Main.enableBulletTrails)
try {
start.getWorld().spawnParticle(org.bukkit.Particle.CLOUD, start, 0);
} catch (Error e2) {
}
} else {
break;
}
}
}
}
use of org.bukkit.entity.Damageable in project MagicPlugin by elBukkit.
the class DamageAction method perform.
@Override
public SpellResult perform(CastContext context) {
Entity entity = context.getTargetEntity();
if (entity == null || !(entity instanceof Damageable) || entity.isDead()) {
return SpellResult.NO_TARGET;
}
double damage = 1;
Damageable targetEntity = (Damageable) entity;
LivingEntity livingTarget = (entity instanceof LivingEntity) ? (LivingEntity) entity : null;
context.registerDamaged(targetEntity);
Mage mage = context.getMage();
MageController controller = context.getController();
double previousKnockbackResistance = 0D;
try {
if (knockbackResistance != null && livingTarget != null) {
AttributeInstance knockBackAttribute = livingTarget.getAttribute(Attribute.GENERIC_KNOCKBACK_RESISTANCE);
previousKnockbackResistance = knockBackAttribute.getBaseValue();
knockBackAttribute.setBaseValue(knockbackResistance);
}
if (controller.isElemental(entity)) {
damage = elementalDamage;
controller.damageElemental(entity, damage * mage.getDamageMultiplier(), 0, mage.getCommandSender());
} else {
if (percentage != null) {
damage = percentage * targetEntity.getMaxHealth();
} else if (targetEntity instanceof Player) {
damage = playerDamage;
} else {
damage = entityDamage;
}
String multiplierType = damageType;
if (multiplierType == null) {
multiplierType = magicDamage ? "magic" : "physical";
}
double mageMultiplier = mage.getDamageMultiplier(multiplierType);
damage *= mageMultiplier;
if (maxDistanceSquared > 0) {
double distanceSquared = context.getLocation().distanceSquared(entity.getLocation());
if (distanceSquared > maxDistanceSquared) {
return SpellResult.NO_TARGET;
}
if (distanceSquared > 0) {
damage = damage * (1 - distanceSquared / maxDistanceSquared);
}
}
if (damageMultiplier != null) {
damage *= damageMultiplier;
mageMultiplier *= damageMultiplier;
}
if (damageType != null) {
Mage targetMage = controller.getRegisteredMage(targetEntity);
String targetAnnotation = "";
if (targetMage != null) {
targetMage.setLastDamageType(damageType);
} else {
targetAnnotation = "*";
}
mage.sendDebugMessage(ChatColor.RED + "Damaging (" + ChatColor.DARK_RED + damageType + ChatColor.RED + ") x " + ChatColor.DARK_RED + mageMultiplier + ChatColor.RED + " to " + ChatColor.BLUE + targetEntity.getType() + targetAnnotation + ": " + ChatColor.RED + damage, 5);
// mages since other plugins may be tracking kills.
if (mage.isPlayer() && controller.getDamageTypes().contains(damageType)) {
CompatibilityUtils.magicDamage(targetEntity, damage, mage.getEntity());
} else {
CompatibilityUtils.damage(targetEntity, damage, mage.getEntity(), damageType);
}
} else if (magicDamage && (magicEntityDamage || targetEntity instanceof Player)) {
mage.sendDebugMessage(ChatColor.RED + "Damaging (Magic) x " + ChatColor.DARK_RED + mageMultiplier + ChatColor.RED + " to " + ChatColor.BLUE + targetEntity.getType() + ": " + damage, 5);
CompatibilityUtils.magicDamage(targetEntity, damage, mage.getEntity());
} else {
mage.sendDebugMessage(ChatColor.RED + "Damaging x " + ChatColor.DARK_RED + mageMultiplier + ChatColor.RED + " to " + ChatColor.BLUE + targetEntity.getType() + ": " + damage, 5);
CompatibilityUtils.damage(targetEntity, damage, mage.getEntity());
}
if (damage == (int) damage) {
context.addMessageParameter("damage", Integer.toString((int) damage));
} else {
context.addMessageParameter("damage", Double.toString(damage));
}
if (damageType != null && !damageType.isEmpty()) {
String typeDescription = context.getController().getMessages().get("damage_types." + damageType, damageType);
context.addMessageParameter("damage_type", typeDescription);
}
}
} finally {
if (knockbackResistance != null && livingTarget != null) {
AttributeInstance knockBackAttribute = livingTarget.getAttribute(Attribute.GENERIC_KNOCKBACK_RESISTANCE);
knockBackAttribute.setBaseValue(previousKnockbackResistance);
}
}
return SpellResult.CAST;
}
use of org.bukkit.entity.Damageable in project QualityArmory by ZombieStriker.
the class FireProjectile method spawn.
@SuppressWarnings("deprecation")
@Override
public void spawn(final Gun g, final Location s, final Player player, final Vector dir) {
Location test = player.getEyeLocation();
double maxDist = GunUtil.getTargetedSolidMaxDistance(dir, test, g.getMaxDistance());
Vector dir2 = dir.clone().multiply(QAMain.bulletStep);
Collection<Entity> nearby = test.getWorld().getNearbyEntities(test.clone().add(dir.clone().multiply(maxDist / 2)), maxDist / 2, maxDist / 2, maxDist / 2);
// test.add(dir);
for (double distance = 0; distance < maxDist; distance += QAMain.bulletStep) {
test.add(dir2);
if (test.getBlock().getType().name().equals("WATER") || test.getBlock().getType().name().equals("STATIONARY_WATER"))
break;
for (Entity e : new ArrayList<>(nearby)) {
if (e != player && e != player.getVehicle() && e != player.getPassenger()) {
AbstractBoundingBox box = BoundingBoxManager.getBoundingBox(e);
if (box.intersects(player, test, e)) {
if (e instanceof Damageable) {
((Damageable) e).damage(g.getDamage(), player);
if (e instanceof LivingEntity) {
((LivingEntity) e).setNoDamageTicks(0);
try {
if (ProtectionHandler.canPvp(e.getLocation())) {
e.setFireTicks(20 * 3);
}
} catch (Error error) {
QAMain.DEBUG("Cannot use protection hook: " + error.getMessage());
e.setFireTicks(20 * 3);
}
}
}
nearby.remove(e);
}
// else if (distance * distance > e.getLocation().distance(start)) {
// nearby.remove(e);
// }
}
}
try {
test.getWorld().spawnParticle(Particle.FLAME, test, 0);
} catch (Error | Exception e) {
}
}
}
Aggregations