So what you describe is constructing a path by chaining paths between obstacles, this can easily be achieved with the LocalPathWalker. There are many implementations available for findPath, some of them are like this
LocalPathFinder lpf = new LocalPathFinder(getBot());
lpf.findPath(entity); // path from player's position to an entity
lpf.findPath(startPosition, endPosition); // path between 2 positions
lpf.findPath(endPosition); // path from player's position to a position
lpf.findPath(startPosition, entity); // path from a position to an entity
You you will probably need the last one. Start with player position and build a path to the destination position, if none is found, iterate through all entities that can be reached and determine whether the position past that entity (use rotation/orientation do determine the position after the entity) can get you closer to the destination. If it still doesn't reach the destination, iterate through all entites that can be reached from the position after the first entity and do the steps above for n iterations. Then simply add up all the paths to create the main path (include the entities that have to be interacted with on the way).
There is no need for flags for the above as there are many high level methods already provided in the API that wrap everything needed, but the main problem you will encounter here is that the game only loads in 104x104 blocks, meaning that you can't dynamically access information about entities or flags outside the loaded region without having all this preprocessed and cached. You can do this around fred's house to open gates/doors, but varrock is not loaded and you can't find doors around the castle for example.
I strongly suggest you take a look at webwalking, it may save you a lot of time by just calling
getWalking().webWalk(destination);
Which will automatically walk anywhere on the map, handle all obstacles (not just doors and gates). This can also walk between planes, use teleports, enchanted jewelry, spirit trees, gnome gliders, ships and pretty much everything available in runescape. OSBot's webwalker has been continuously developed for the last 4 years and provided support for advanced scripts like questing, slayer, automated farms and many more. It already has information about obstacle requirements everywhere on the map, including things like passing through the Al Kharid gate depending on whether the user has coins in inventory or the quest completed to pass for free, and would take the longer path otherwise.
PS: See WebWalkEvent in the API docs for advanced usage and configuring options like teleports