Is there a way to match multiple tags in a target selector?
While working on my answer to this question, I came across the situation where I'd like to match multiple scoreboard tags at once, i.e. do something like
/tell @a[tag=Great,tag=Awesome] You are a great and awesome person!
The above command does not work as intended (tested on snapshot 15w45a), since the second tag target selector argument overwrites the first (the same behavior as on every other argument). This means that simply awesome (but not great) persons are called awesome and great, rather than those that are both awesome and great!
Is there a way to include multiple tag matches into the same target selector?
Best Answer
A workaround to the problem can be achieved via data tag matching. All entities have a Tags tag that contains all scoreboard tags of that entity. On commands that support data tag matching (such as testfor and scoreboard players), you can directly check if multiple tags are present, e.g.
/testfor @a {Tags:["Great","Awesome"]}
Due to Minecraft's partial tag matching, this will also work if the target entity has other tags beside Great and Awesome.
For commands that do not support data tag matching themselves, a meta-tag can be added, e.g.
/scoreboard players tag @a[tag=GreatAndAwesome] remove GreatAndAwesome
/scoreboard players tag @a[tag=!GreatAndAwesome] add GreatAndAwesome {Tags:["Great","Awesome"]}
Afterwards, a simple tag check can be performed for GreatAndAwesome. However, this adds 2 commands for every meta-tag, and does not easily support negation (i.e. check if an entity is Great but not Awesome). As such, using the pre-1.9 method of dummy objectives set to 0 or 1 is often preferable to a tag (since scoreboard objectives each come with their own target selector arguments), though much less elegant.
Pictures about "Is there a way to match multiple tags in a target selector?"



How do you test for multiple tags in Minecraft?
Alternatively, you could use an execute command to first select players with one of the tags, then execute your command for players with the second tag in a radius of 0. For your example: /execute @a[tag=Great] ~ ~ ~ tell @a[r=0,tag=Awesome] You are a great and awesome person!What does @R do in Minecraft?
Targets a random player. Bedrock Edition can use @r to target non-player entities via the type selector argument; in Java Edition, to select a random entity, use @e[sort=random] instead. In Bedrock Edition, @r can only target entities who are alive. Targets every player, alive or not.What does RY mean in Minecraft?
Bedrock Edition: Target Selector ArgumentsTarget Selector ArgumentDescriptionryMaximum horizontal rotationrymMinimum horizontal rotationtagScoreboard tagtypeEntity type (target must be the specified entity type - see list of entity values)15 more rowsWhat is DX DY DZ Minecraft?
dx dy dz target selector defines coordinates relative to a block.Combining and Chaining CSS Selectors
More answers regarding is there a way to match multiple tags in a target selector?
Answer 2
Alternatively, you could use an execute command to first select players with one of the tags, then execute your command for players with the second tag in a radius of 0.
For your example:
/execute @a[tag=Great] ~ ~ ~ tell @a[r=0,tag=Awesome] You are a great and awesome person!
This solution is not 100% perfect; if two players are standing in the same place, only one of them has to have the Great tag for them all to match the second command. However, if you know that there is a small chance that two players will be in the same place, or you can somehow narrow down the selectors even more, this provides a solution in only one command block.
Answer 3
Nowadays, the solution above will work perfectly. You could try something like this:
execute @e[tag=Great] ~ ~ ~ execute @s[tag=Awesome] ~ ~ ~ [put your command here]
@s represents the player you are executing the command at.
Answer 4
You could do a Repeating Command Block
testfor @a[tag=Great]
Leading into a Chain Command Block with
testfor @a[tag=Awesome]
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Meruyert Gonullu, Meruyert Gonullu, shutter_speed, Erik Mclean
