Can I prevent being attacked?
TL:DR you cannot stop people from attacking you, as that is part of the game mechanics as designed by supercell.
No, you cannot prevent people from attacking you indefinitely. you can try to stay online, but after 3 hours it will force you to take a break. you can buy shields with gems, but they will eventually run out, and there are cooldowns on how often you can buy a shield, so you cannot keep buying shields to prevent people from attacking you. and as of the recent update, while attacking with a shield does not destroy it like it used to, it will take time off of it.