ItemStack within a configuration

Next, we will expand the MobEnhancer plugin even further by allowing the option of giving armor and weapons to zombies and skeletons. In order to do this, we must first learn how to add an ItemStack object as an option in a configuration file. An ItemStack method is more complicated than a simple integer or double. It is an object that has many nested values. It may also include a meta value, which will have more nested values. Meta contains additional information for the item, such as a custom display name or lines of text that make up the lore of the item. The following is a sample of an ItemStack method in a YAML file:

SampleItem:
  ==: org.bukkit.inventory.ItemStack
  type: DIAMOND_SWORD
  damage: 1500
  amount: 1
  meta:
    ==: ItemMeta
    meta-type: UNSPECIFIC
    display-name: §6Sample Item
    lore:
    - First line of lore
    - Second line of lore
    - §1Color §2support
    enchants:
      DAMAGE_ALL: 2
      KNOCKBACK: 7
      FIRE_ASPECT: 1

Once loaded, the item in the results is shown in the following screenshot:

ItemStack within a configuration

Only the type field is required. You can omit any other segment. The type refers to the type of material. These materials can be found in the API documentation under org.bukkit.Material, which can be viewed by visiting https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html. The damage is used to indicate how much damage an item has taken. For items such as wool, this will set the color of the wool. The amount will set the stack size. For example, I may have one sword or twenty logs. The meta includes additional information such as the color and pattern of a banner or the author and number of pages of a book. Given the path, getConfig().getItemStack("SampleItem"); will retrieve the item.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.251.155