Example #1
0
  protected static boolean damagePlayers(World world, int x, int y, int z, int damage, String id) {
    y = getSafeY(world, x, y, z);

    boolean damaged = false;
    for (Player player : etc.getServer().getPlayerList()) {
      Location pLoc = player.getLocation();
      Vector pVec = new Vector(pLoc.x, pLoc.y, pLoc.z);

      if (player.getWorld() == world
          && (pVec.getBlockX() == x || pVec.getBlockX() == x + 1 || pVec.getBlockX() == x - 1)
          && pVec.getBlockY() == y
          && (pVec.getBlockZ() == z || pVec.getBlockZ() == z + 1 || pVec.getBlockZ() == z - 1)) {
        if (!id.isEmpty()) {
          if ((id.charAt(0) == 'g' && player.isInGroup(id.substring(2)))
              || (id.charAt(0) == 'p' && player.getName().equalsIgnoreCase(id.substring(2)))) {
            player.getEntity().a(ODamageSource.j, damage);
            damaged = true;
          }
        } else {
          player.getEntity().a(ODamageSource.j, damage);
          damaged = true;
        }
      }
    }

    return damaged;
  }
Example #2
0
  @SuppressWarnings("rawtypes")
  protected static boolean damageEntities(
      List list, World world, int x, int y, int z, int damage, String id) {
    y = getSafeY(world, x, y, z);

    boolean damaged = false;
    boolean isNamed =
        !id.isEmpty()
            && !id.equalsIgnoreCase("animal")
            && !id.equalsIgnoreCase("animals")
            && !id.equalsIgnoreCase("mob")
            && !id.equalsIgnoreCase("mobs");

    for (Object obj : list) {
      BaseEntity entity = (BaseEntity) obj;
      if (entity != null
          && entity
              .getWorld()
              .isChunkLoaded((int) entity.getX(), (int) entity.getY(), (int) entity.getZ())
          && (entity.isMob() || entity.isAnimal())) {
        Vector pVec = new Vector(entity.getX(), entity.getY(), entity.getZ());

        if (entity.getWorld() == world
            && (pVec.getBlockX() == x || pVec.getBlockX() == x + 1 || pVec.getBlockX() == x - 1)
            && pVec.getBlockY() == y
            && (pVec.getBlockZ() == z || pVec.getBlockZ() == z + 1 || pVec.getBlockZ() == z - 1)) {
          if (isNamed) {
            // Mob mob = (Mob)entity;
            if (entity.getName().equalsIgnoreCase(id)) {
              entity.getEntity().a(ODamageSource.j, damage);
              damaged = true;
            }
          } else {
            entity.getEntity().a(ODamageSource.j, damage);
            damaged = true;
          }
        }
      }
    }

    return damaged;
  }