Bar resilience to flybys in a cosmological framework