How can I filter items with a certain enchantement? [duplicate]

I am trying to build a custom Adventure Island. At this moment I am trying to limit the allowed items on this island. I'm trying to do this by filtering on a certain enchantment which is not item-specific.

For example.

When you want to filter an wooden sword with a custom name, you use this command:

/testfor @p[r=5] {Inventory:[{tag:{display:{Name:"Custom Sword"}}}]} <

When you want to filter a wooden sword with a custom name and specific enchantement, you can use:

/testfor @p[r=5] {Inventory:[{tag:{display:{Name:"Custom Sword"},ench:[{id:16,lvl:1}]}}]} <

But how can I filter on items with a specific enchantment on ANY item? I tried:

/testfor @p[r=5] {Inventory:[{tag:{ench:[{id:16,lvl:1}]}}]} <

But this ain't work. Does anyone know how to solve this issue?


Solution 1:

Your issue here is that your values are not integers. Because enchantment level and id are both stored as shorts, you must add an 's' after them. Thus, the working command would be:
/testfor @p[r=5] {Inventory:[{tag:{ench:[{id:16s,lvl:1s}]}}]}