Exemplo n.º 1
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;
  }
Exemplo n.º 2
0
 /**
  * Returns the block the fieldSign is attacked to
  *
  * @return
  */
 public Block getAttachedBlock() {
   return SignHelper.getAttachedBlock(sign.getBlock());
 }