How can you do it in Minecraft so that you can only hit with swords in adventure mode?
Should go like this
/ execute as @a [nbt = {SelectedItem: {id: "minecraft: stone_sword}}] run effect clear @s weakness
/ execute as @a [nbt =! {SelectedItem: {id: "minecraft: stone_sword"}}] run effect clear @s weakness 1000000 255 true
For each sword you have to do the two commands again
What is weakness for an effect?
Weakness, the opposite of strength
So you can't hit with weakness or only weakly?
And it should go like this, right?
/ effect give @a [nbt =…] weakness 1000000 255 true
Yes, as far as I know, it is more performant if you run execute in front of it, but no idea whether that is true.
You need a sharpness enchantment on the weapon to do damage, otherwise it doesn't