public class DamageUtil { public static void createExplosion(Projectile pro, WeaponType weapontype, LivingEntity shooter) { int radius = weapontype.getDamage(); Location loc = pro.getLocation(); List en = pro.getNearbyEntities(radius, radius, radius); pro.getLocation().getWorld().createExplosion(loc, 0.0F, false); for (Entity ent : en) { if (ent instanceof LivingEntity) { HumanEntity le = (HumanEntity) ent; Location eyeloc = le.getEyeLocation(); int distance = (int) loc.distanceSquared(ent.getLocation()); if (canDamage(loc, eyeloc)) { int damage = getExplosionDamage(radius, distance); le.damage(damage, shooter); } } } } private static boolean canDamage(Location loc1, Location loc2) { loc1.setY(loc1.getY() + 1.5F); World w = loc1.getWorld(); int minx = Math.min(loc1.getBlockX(), loc2.getBlockX()), miny = Math.min(loc1.getBlockY(), loc2.getBlockY()), minz = Math.min(loc1.getBlockZ(), loc2.getBlockZ()), maxx = Math.max(loc1.getBlockX(), loc2.getBlockX()), maxy = Math.max(loc1.getBlockY(), loc2.getBlockY()), maxz = Math.max(loc1.getBlockZ(), loc2.getBlockZ()); for (int x = minx; x<=maxx;x++) { for (int y = miny; y<=maxy;y++) { for (int z = minz; z<=maxz;z++) { Block b = w.getBlockAt(x, y, z); if (!b.getType().equals(Material.AIR)) { return false; } } } } return true; } private static int getExplosionDamage(int r, int d) { float akk = (float)r*(float)r; float abb = (float) d; return Math.round((((10F/akk)*abb)+(-10F))*(-1F)); } }