How can I target a player after detecting an item in their inventory

If I detect a player having a nether star in his inventory, and it detected let’s say “XPhotoCrafterX”, how can I make it so it automatically effects him with strength 3?

I’ve tried to search on google but it didn’t work.

  • What makes a villager spawn?
  • Can mobs use levers?
  • What rare items exist in Minecraft, and where can I find them?
  • How do the customized world settings work?
  • How often can animals breed?
  • How can I clear the water out of this area?
  • Minecraft ArmorStand Teleportation
  • How much space is required for a ghast to spawn?
  • If I'm already above the clouds — how much higher can I go?
  • Why is =! not working in testfor command?
  • What enchantments can books have?
  • How do you host a multi-player survival game in Minecraft?
  • One Solution collect form web for “How can I target a player after detecting an item in their inventory”

    You will need to assign a label to the player based on their NBT data first and then target based on their label. /testfor will not be useful as it does not label the players that were found.

    1.9

    No objectives needed.

    /scoreboard players tag @a[tag=HasItem] remove HasItem
    /scoreboard players tag @a[tag=!HasItem] add HasItem {Inventory:[{id:"minecraft:nether_star"}]}
    

    And then you’d target them with the tag parameter.

    /effect @a[tag=HasItem] minecraft:strength 1 3
    

    1.8

    Objective required.

    /scoreboard objectives add HasItem dummy
    

    Run on a clock in presented order.

    /scoreboard players set @a HasItem 0
    /scoreboard players set @a HasItem 1 {Inventory:[{id:"minecraft:nether_star"}]}
    

    Players will have their “HasItem” score set to 1 if they have a nether star in their inventory. You can then target them based on their score.

    /effect @a[score_HasItem_min=1] minecraft:strength 1 3
    
    We love Playing Games, especially Video Games.