Skip to content
Rutger Kok edited this page Jan 6, 2016 · 3 revisions

Checking for an item type

Lets start simple. The following will prevent End Stone from being placed in an Ender Chest.

IllegalItems:
- check: itemType
  for: end_stone

Here we are checking the item type for End Stone. We have used end_stone here, but there are four possible ways to specify a material:

  • Use a Mojang name: end_stone
  • Use a prefixed Mojang name: minecraft:end_stone
  • Use a Spigot name: ENDER_STONE
  • Use a block id: 121. This option is discouraged, as block ids may change in the future.

Checking for a custom name

IllegalItems:
- check: customName
  for: Key

This example checks whether the custom name of an item matches "Key". It is case sensitive.

If you don't want the check to be case sensitive, add the following:

IllegalItems:
- check: customName
  for: Key
  ignoring: case

Now items named "key" or "KEY" are also blocked.

Checking for a lore

Checking for a lore of a single line

IllegalItems:
- check: lore
  for: ["Forbidden lore"]

Items with a lore of exactly one line, reading "Forbidden lore" (case sensitive) cannot be placed in Ender Chests.

Because a lore can be multiple lines, the for-value needs to be a list: it needs to be enclosed in brackets, even when checking for only a single line (like in this example).

Like for custom names, it is possible to make the check case insensitive:

IllegalItems:
- check: lore
  for: ["Forbidden lore"]
  ignoring: case

Checking for a lore of multiple lines

IllegalItems:
- check: lore
  for: ["Forbidden", "lore"]

Items with a lore of exactly two lines, the first line reading "Forbidden", the second one reading "lore" (both case sensitive) cannot be placed in Ender Chests.

Combining rules

IllegalItems is a list. If an item matches any of the rules on this list, it cannot be placed in Ender Chests.

Checking for either a custom name or a lore

IllegalItems:
- check: customName
  for: "Key"
- check: lore
  for: ["Forbidden lore"]

Items with a name of "Key" (case sensitive) or a lore of exactly one line, reading "Forbidden lore" (case sensitive) cannot be placed in Ender Chests.

Checking for items with both a lore and a custom name

Sometimes you want to prevent items that have two properties at the same time. For example, you want 'diamond' as the item type and 'Key' as the lore. You can create such a rule as follows:

IllegalItems:
- check: customName
  for: "Key"
  and:
    check: itemType
    for: diamond

You can even go one step further:

IllegalItems:
- check: customName
  for: "Key"
  and:
    check: itemType
    for: diamond
    and:
      check: lore
      for: ["Forbidden lore"]

Now diamonds named "Key" and with a lore of a single line ("Forbidden lore", case sensitive) cannot be placed in an Ender Chest.

Color codes

Item names and lores can have color codes. The following text will be about custom item names, but it is applicable to item lores as well.

When an item has a custom name of §rKey ('Key' with a reset color code before it), for: Key won't match. You will need to write:

IllegalItems:
- check: customName
  for: '&rKey'

Using this rule, items with a custom name of "Key" (case sensitive), prefixed with the 'reset' color code, cannot be placed in Ender Chests. The single quotes around &rKey are required, as the character & is a control character.

If you want to ignore colors altogether, you can use this:

IllegalItems:
- check: customName
  ignoring: color
  for: 'Key'

This will match items with a custom name of 'Key' (case sensitive), no matter which color the name is in. When using this method, there must be no color codes in for: 'Key'. The ignoring: color option works by removing the color from the item name first (so an item named '&2Key' is read as if it were named 'Key') and then comparing it to the text after for: . So when the text after for: contains color codes, the check would always fail.

If you want to ignore both colors and letter case, use the following:

IllegalItems:
- check: customName
  ignoring: [color, case]
  for: 'Key'

This will match items with a custom name of 'Key' (case insensitive), no matter which color the name is in.

When using regular expressions (see below), you can only use the § (section sign) symbol to check for color codes. In regular expressions, the & character is not translated automatically to a §. Also, the regex must not contain color codes when ignoring: color is present.

Regular expressions

This is for advanced users. Regular expressions, also called regex, are a powerful way to check the syntax of some text.

Checking the custom name using a regular expression

IllegalItems:
- check: customName
  forRegex: ^Key

Items with a name starting with "Key" (case sensitive) cannot be placed in Ender Chests.

Checking the lore using a regular expression

IllegalItems:
- check: lore
  forRegex: ^Forbidden[\n ]lore$

Items with a lore of either one line reading "Forbidden lore", or two lines reading "Forbidden" and "lore" (all case sensitive), cannot be placed in Ender Chests.

Note that although check has been set to lore, forRegex is not a list. Previously, for had to be a list, but when using a regex you must use \n to check for a new line. The following two examples are equivalent:

IllegalItems:
- check: lore
  for: ["Forbidden", "lore"]
IllegalItems:
- check: lore
  forRegex: ^Forbidden\nlore$

To ignore color codes and letter case, you can use the following example:

IllegalItems:
- check: lore
  forRegex: ^Forbidden\nlore$
  ignoring: [color, case]

Items with a lore of either two lines reading "Forbidden" and "lore" (case insensitive, lines can be in any color), cannot be placed in Ender Chests.