/**
   * @param field
   * @param player
   * @return
   */
  public Location getOutsideFieldLocation(Field field, Player player) {
    World world = player.getWorld();

    int x = player.getLocation().getBlockX();
    int y = player.getLocation().getBlockY() + 1;
    int z = player.getLocation().getBlockZ();

    int edgeX1 = field.getX() + (field.getRadius() + 1);
    int edgeX2 = field.getX() - (field.getRadius() + 1);
    int edgeZ1 = field.getZ() + (field.getRadius() + 1);
    int edgeZ2 = field.getZ() - (field.getRadius() + 1);

    Location loc = world.getSpawnLocation();

    if (isEmptySpace(world, edgeX1, y, z)) {
      loc =
          new Location(
              world,
              ((double) edgeX1) + .5,
              y,
              ((double) z) + .5,
              player.getLocation().getYaw(),
              player.getLocation().getPitch());
    } else if (isEmptySpace(world, edgeX2, y, z)) {
      loc =
          new Location(
              world,
              ((double) edgeX2) + .5,
              y,
              ((double) z) + .5,
              player.getLocation().getYaw(),
              player.getLocation().getPitch());
    } else if (isEmptySpace(world, x, y, edgeZ1)) {
      loc =
          new Location(
              world,
              ((double) x) + .5,
              y,
              ((double) edgeZ1) + .5,
              player.getLocation().getYaw(),
              player.getLocation().getPitch());
    } else if (isEmptySpace(world, x, y, edgeZ2)) {
      loc =
          new Location(
              world,
              ((double) x) + .5,
              y,
              ((double) edgeZ2) + .5,
              player.getLocation().getYaw(),
              player.getLocation().getPitch());
    }

    return loc;
  }
示例#2
0
  public boolean extractData(Block signBlock, String[] lines) {
    // extract the tag line, exit if not recognized

    tag = ChatColor.stripColor(lines[0]);
    fieldSign =
        tag.equalsIgnoreCase(ChatHelper.format("fieldSignRent"))
            || tag.equalsIgnoreCase(ChatHelper.format("fieldSignBuy"))
            || tag.equalsIgnoreCase(ChatHelper.format("fieldSignShare"));

    if (!fieldSign) {
      // reason removed due to it being triggered by using signs for other plugins
      failReason = null;
      return false;
    }

    // extract the price

    price = SignHelper.extractPrice(ChatColor.stripColor(lines[1]));

    if (price == 0) {
      failReason = "fieldSignNoPrice";
      return false;
    }

    // extract the item from the price
    // use the default item currency if nothing found in parenthesis and no economy plugin is being
    // used

    item = SignHelper.extractItemFromParenthesis(ChatColor.stripColor(lines[1]));

    if (item == null) {
      if (!PreciousStones.getInstance().getPermissionsManager().hasEconomy()) {
        item = PreciousStones.getInstance().getSettingsManager().getDefaulItemCurrency();

        if (item == null) {
          item = new BlockTypeEntry(Material.GOLD_INGOT);
        }
      }
    }

    Block attachedBlock = SignHelper.getAttachedBlock(signBlock);
    field = PreciousStones.getInstance().getForceFieldManager().getField(attachedBlock);

    // trying to create a rent sign on a block that is not a field

    if (field == null) {
      // reason removed due to it being triggered by using signs for other plugins
      failReason = null;
      return false;
    }

    // trying to create a rent sign on someone elses field

    if (playerName != null) {
      if (!field.isOwner(playerName)) {
        failReason = "fieldSignNotOwner";
        return false;
      }
    }

    // make sure the time period is valid

    if (!isBuyable()) {
      period = ChatColor.stripColor(lines[2]);

      if (!SignHelper.isValidPeriod(period)) {
        failReason = "fieldSignInvalidPeriod";
        return false;
      }
    }

    // creating a rent sign on a non-rent field

    if (isRentable()) {
      if (!field.hasFlag(FieldFlag.RENTABLE)) {
        failReason = "fieldSignNotRentable";
        return false;
      }
    }

    // creating a rent sign on a non-share field

    if (isShareable()) {
      if (!field.hasFlag(FieldFlag.SHAREABLE)) {
        failReason = "fieldSignNotShareable";
        return false;
      }
    }

    // creating a rent sign on a non-buy field

    if (isBuyable()) {
      if (!field.hasFlag(FieldFlag.BUYABLE)) {
        failReason = "fieldSignNotBuyable";
        return false;
      }
    }

    return true;
  }