Exemplo n.º 1
0
  public boolean getPermission(
      Player player,
      TownBlockStatus status,
      WorldCoord pos,
      TownyPermission.ActionType actionType) {
    if (status == TownBlockStatus.OFF_WORLD
        || status == TownBlockStatus.WARZONE
        || status == TownBlockStatus.PLOT_OWNER
        || status
            == TownBlockStatus
                .TOWN_OWNER) // || plugin.isTownyAdmin(player)) // status == TownBlockStatus.ADMIN
                             // ||
    return true;

    if (status == TownBlockStatus.NOT_REGISTERED) {
      cacheBlockErrMsg(player, TownySettings.getLangString("msg_cache_block_error"));
      return false;
    }

    if (status == TownBlockStatus.LOCKED) {
      cacheBlockErrMsg(player, TownySettings.getLangString("msg_cache_block_error_locked"));
      return false;
    }

    TownBlock townBlock;
    // Town town;
    try {
      townBlock = pos.getTownBlock();
      // town = townBlock.getTown();
    } catch (NotRegisteredException e) {

      // Wilderness Permissions
      if (status == TownBlockStatus.UNCLAIMED_ZONE)
        if (TownyUniverse.getPermissionSource()
            .hasPermission(player, PermissionNodes.TOWNY_WILD_ALL.getNode(actionType.toString()))) {
          return true;

        } else if (!TownyPermission.getUnclaimedZonePerm(actionType, pos.getWorld())) {
          // Don't have permission to build/destroy/switch/item_use here
          cacheBlockErrMsg(
              player,
              String.format(
                  TownySettings.getLangString("msg_cache_block_error_wild"),
                  actionType.toString()));
          return false;
        } else return true;
      else {
        TownyMessaging.sendErrorMsg(player, "Error updating destroy permission.");
        return false;
      }
    }

    // Allow admins to have ALL permissions over towns.
    if (TownyUniverse.getPermissionSource().isTownyAdmin(player)) return true;

    // Plot Permissions
    // try {
    //        Resident owner = townBlock.getResident();
    if (townBlock.hasResident()) {
      if (status == TownBlockStatus.PLOT_FRIEND) {
        if (townBlock.getPermissions().getResidentPerm(actionType)) return true;
        else {
          cacheBlockErrMsg(
              player,
              String.format(
                  TownySettings.getLangString("msg_cache_block_error_plot"),
                  "friends",
                  actionType.toString()));
          return false;
        }
      } else if (status == TownBlockStatus.PLOT_ALLY)
        if (townBlock.getPermissions().getAllyPerm(actionType)) return true;
        else {
          cacheBlockErrMsg(
              player,
              String.format(
                  TownySettings.getLangString("msg_cache_block_error_plot"),
                  "allies",
                  actionType.toString()));
          return false;
        }
      else { // TODO: (Remove) if (status == TownBlockStatus.OUTSIDER)

        if (townBlock.getPermissions().getOutsiderPerm(actionType)) {
          // System.out.print("Outsider true");
          return true;
        } else {
          cacheBlockErrMsg(
              player,
              String.format(
                  TownySettings.getLangString("msg_cache_block_error_plot"),
                  "outsiders",
                  actionType.toString()));
          return false;
        }
      }
    }
    // } catch (NotRegisteredException x) {
    // }

    // Town Permissions
    if (status == TownBlockStatus.TOWN_RESIDENT) {
      if (townBlock.getPermissions().getResidentPerm(actionType)) return true;
      else {
        cacheBlockErrMsg(
            player,
            String.format(
                TownySettings.getLangString("msg_cache_block_error_town_resident"),
                actionType.toString()));
        return false;
      }
    } else if (status == TownBlockStatus.TOWN_ALLY)
      if (townBlock.getPermissions().getAllyPerm(actionType)) return true;
      else {
        cacheBlockErrMsg(
            player,
            String.format(
                TownySettings.getLangString("msg_cache_block_error_town_allies"),
                actionType.toString()));
        return false;
      }
    else if (status == TownBlockStatus.OUTSIDER || status == TownBlockStatus.ENEMY)
      if (townBlock.getPermissions().getOutsiderPerm(actionType)) return true;
      else {
        cacheBlockErrMsg(
            player,
            String.format(
                TownySettings.getLangString("msg_cache_block_error_town_outsider"),
                actionType.toString()));
        return false;
      }

    TownyMessaging.sendErrorMsg(player, "Error updating " + actionType.toString() + " permission.");
    return false;
  }