Minecraft – How to kill name tag villagers with command blocks

minecraft-commandsminecraft-java-edition

So I was planning to do my minecraft server and I want the command block to kill name tag villagers. I don't want my players to name "LeafyisHere", "drugs" and others.

Best Answer

Strictly speaking, this is fairly easy to do, however it does require one additional steps in a scoreboard tag command.

For each name you don't want, you'll want a repeating command block like so:

/scoreboard players tag @e[type=Villager] add tokill {CustomName:"Name"}

From there, you'll have one repeating command block for the kill command:

/kill @e[type=Villager,tag=tokill]

That said, since it sounds like you're trying to eliminate bad behavior with this sort of system, the better solution would be to attempt to find the culprits and ban them, rather than attempting to implement a sort of exhaustive filter. The name matches are literal matches, so you'd need one command block for every single possibility, which will not be practical in the long term.