Made this because someone asked about this functionality. When enabled, a person needs a permission node to be able to attack an entity. Players (which are entities) can optionally be excluded.
Made under 1.17, but will likely work under most versions as it doesn't use anything particularly modern.
Default permission format is kill.(entity name). The prefix can be changed via the config.permprefix value, so if you set premprefix: canattack for example, then to punch a pig they need canattack.pig.
Commands
ATKPERM toggle atkperm.toggle Toggles global plugin functionality, just in case you want to temporarily remove the perm requirement w/o having to adjust people/groups directly.
ATKPERM prefix atkperm.prefix Sets the permission prefix used when checking if they can attack an entity ATKPERM reload atkperm.reload Reloads configuration from disk