How do I execute a command only if a player does not have a certain item

So, I'm making a map where you can basically open doors depending on your xp level, now, I've made this team that always has xp level 1, but I want to make it so that when you have glass pane in your inventory, for example, the limit stops and the xp level can be set to whatever I want it to be.

The team is called Class-D and now it's just

execute as @a[team=Class-D] run xp set @s 1 levels

This is a repeating commandblock, always active.

I'm not quite sure how to make it so that the levels only change to 1 when you don't have a glass pane in your inventory.

I've tried tags, but I'm not quite sure how that'd work

Does anyone have a solution to this problem?


Solution 1:

/execute as @a[team=Class-D] unless entity @s[nbt=!{Inventory:[{id:"minecraft:glass_pane"}]}] run xp set @s 1 levels

... although /execute isn't exactly necessary in this case, and you could simplify the command to:

/xp set @a[team=Class-D,nbt=!{Inventory:[{id:"minecraft:glass_pane"}]}] 1 levels