How can I clear all items from a player's inventory without an NBT tag in 1.15.2?


This is my current command:
execute as @a[distance=..100] run execute at @s if block ~ ~-1 ~ minecraft:quartz_block run /clear @s <...>
I would like to clear the executing entity's inventory of all items without the NBT tag {PitAllow:1b}.
I am in version 1.15.2 and if any plugins are required (Bukkit or Spigot) I'd be fine with installing those.


Solution 1:

You'll need one command per slot:

/execute unless entity @s[nbt={Inventory:[{Slot:0b,tag:{PitAllow:1b}}]}] run replaceitem entity @s hotbar.0 air
…
/execute unless entity @s[nbt={Inventory:[{Slot:8b,tag:{PitAllow:1b}}]}] run replaceitem entity @s hotbar.8 air
/execute unless entity @s[nbt={Inventory:[{Slot:9b,tag:{PitAllow:1b}}]}] run replaceitem entity @s inventory.0 air
…
/execute unless entity @s[nbt={Inventory:[{Slot:35b,tag:{PitAllow:1b}}]}] run replaceitem entity @s inventory.26 air
/execute unless entity @s[nbt={Inventory:[{Slot:-106b,tag:{PitAllow:1b}}]}] run replaceitem entity @s weapon.offhand air