im not sure if it's possible to prevent an attack, but you can make a trigger that follows this general idea:
Event:
Unit/Building gets attacked
Condition:
Unit/Building is equal to Unit type of Unit/Building
Attacking unit is ally of Attacked unit
Actions:
Order attacking unit to stop
or
A text message to players that a certain player is being attacked
or
instantly move attacking unit away from building
or
make do damage to attacking unit
or
some weird combination that would make it a very good idea to stop attacking the building.
be creative, im sure u can figure something out