How do I use ! on teams and items

I am working on a Minecraft bed-wars map and I want to make 2 things; an alarm and something that destroys items on the ground except iron ingots, gold ingots, emeralds, and diamonds. I can already destroy individual items, but id rather not make a command block for around 20 different items. My current code for each is this:
/kill @e[type=item,nbt={Item:{id:"minecraft:the item I want"}}]
Is there a way to put ! into it so it destroys everything but the iron ingots, gold ingots, emeralds, and diamonds? For the alarm I need to either get a way to add the 3 other teams (I only can put one in at the moment). Or could I use !blue somehow to detect teams other than blue within a radius of 50. Some kind of code like this, this one doesn't work
/execute at @a[team=!blue,distance=..50] run say blue alarm triggered
Best Answer
To target all except some items, you can tag the items you don't want to kill.
Put the following in a repeating command blocks for each item you want to keep.
tag @e[type=item,nbt={Item:{id:"minecraft:some_item"}}] add dontDestroy
Then you can target items without the dontDestroy
tag:
/kill @e[type=item,tag=!dontDestroy]
For the teams command, create a dummy scoreboard objective to track if the alarms have been triggered:
/scoreboard objectives add alarmTriggered dummy
Fake players will be used to keep track if each team's alarm is triggered.
Put the following in a repeating command block:
execute if entity @a[team!=blue,distance=..50] if score blueTeam alarmTriggered matches 0 run say blue alarm triggered
Then put the following in a conditional chain command block next to it to update the scoreboard:
scoreboard players set blueTeam alarmTriggered 1
Do this for every team. To reset the game, run /scoreboard players set @a alarmTriggered 0
.
Without the scoreboard, the message "blue alarm triggered" would be shown constantly because of the repeating command block.
Pictures about "How do I use ! on teams and items"



How do you make action items in Microsoft Teams?
From the Tasks tab (personal tasks)How do you use the at symbol in Microsoft Teams?
To get someone's attention in a channel conversation or a chat, @mention them. Just type @ before their name and then select them from the menu that appears. Note: You can also mention someone simply by typing their name.How do you add items to team chat?
Tip: Teams works particularly well with Microsoft Office documents.How do you add items to a team?
Open the list where you want to add an item. Tap New. Under New Item, enter or select the data you want to add. Tap Save.🏫 Microsoft Teams Tutorial in 10 min
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: RODNAE Productions, RODNAE Productions, Tima Miroshnichenko, Faizan