Custom data
The editor's Custom Data section (Equipment tab, advanced settings) lets a designer put your own tags on an item. This is how you read them.
Read a tag
NamespacedKey key = NxEquipementsKeys.customData("custom_id");
ItemMeta meta = item.getItemMeta();
String value = meta.getPersistentDataContainer()
.get(key, PersistentDataType.STRING);
if (value != null) {
getLogger().info("custom_id = " + value);
}
Read a number
NamespacedKey key = NxEquipementsKeys.customData("power_level");
Integer power = item.getItemMeta()
.getPersistentDataContainer()
.get(key, PersistentDataType.INTEGER);
if (power != null && power > 5) {
// ...
}
Match the type to what was picked in the editor — String, Boolean, Integer, Long, Float or Double.
Read the set and piece directly
api.readId(item) is the easy way, but the raw keys are stable if you'd rather use them:
PersistentDataContainer pdc = item.getItemMeta().getPersistentDataContainer();
String setId = pdc.get(NxEquipementsKeys.SET, PersistentDataType.STRING);
String pieceKey = pdc.get(NxEquipementsKeys.PIECE, PersistentDataType.STRING);
The keys
| Key | Holds |
|---|---|
NxEquipementsKeys.SET | The set id, as a String |
NxEquipementsKeys.PIECE | The piece key, as a String |
NxEquipementsKeys.customData(name) | The key for one of your custom tags |
NxEquipementsKeys.NAMESPACE | "nxeq" |
Keys are always lowercase. Ask your designer to use lowercase names with underscores in the editor —
power_level, not Power Level.