Note the hierarchy when working with ItemStack
in YAML. This is similar to how commands and permissions have nested values in the plugin.yml
files. We can utilize a hierarchy within the config
file to make it easier to use and understand.
We want to give items to two types of mobs, namely Zombie
and Skeleton
. Each type will have a unique armor and weapon. This means that we will need 10 different ItemStack
classes. We can name them ZombieHolding
, SkeletonHolding
, ZombieHelmet
, SkeletonHelmet
, and so on. However, a hierarchy will be much more efficient. We will have a Zombie
key and a Skeleton
key. Within each zombie and skeleton, we will have a key for each item. The following is a sample of the hierarchy of the mob armor segment of the config
file:
Zombie: holding: ==: org.bukkit.inventory.ItemStack type: STONE_SWORD helmet: ==: org.bukkit.inventory.ItemStack type: CHAINMAIL_HELMET Skeleton: holding: ==: org.bukkit.inventory.ItemStack type: BOW helmet: ==: org.bukkit.inventory.ItemStack type: LEATHER_HELMET
If we want to retrieve the ItemStack
method for the boots of a skeleton, we will use getConfig().getItemStack("Skeleton.boots");
. Remember that the hierarchy is conveyed using a period. Here is a section that will be appended to config.yml
, which includes mob armor, as discussed. We also have a GiveArmorToMobs
Boolean value, which will be included to easily disable the mob armor feature:
### MOB ARMOR ### GiveArmorToMobs: true Zombie: holding: ==: org.bukkit.inventory.ItemStack type: STONE_SWORD helmet: ==: org.bukkit.inventory.ItemStack type: CHAINMAIL_HELMET Skeleton: holding: ==: org.bukkit.inventory.ItemStack type: BOW meta: ==: ItemMeta meta-type: UNSPECIFIC enchants: ARROW_FIRE: 1 helmet: ==: org.bukkit.inventory.ItemStack type: LEATHER_HELMET color: ==: Color RED: 102 BLUE: 51 GREEN: 127
18.218.168.16