Interface ItemFactory


  • public interface ItemFactory
    An instance of the ItemFactory can be obtained with Server.getItemFactory().

    The ItemFactory is solely responsible for creating item meta containers to apply on item stacks.

    • Method Detail

      • getItemMeta

        @Nullable
        @Nullable ItemMeta getItemMeta​(@NotNull
                                       @NotNull Material material)
        This creates a new item meta for the material.
        Parameters:
        material - The material to consider as base for the meta
        Returns:
        a new ItemMeta that could be applied to an item stack of the specified material
      • isApplicable

        boolean isApplicable​(@Nullable
                             @Nullable ItemMeta meta,
                             @Nullable
                             @Nullable ItemStack stack)
                      throws IllegalArgumentException
        This method checks the item meta to confirm that it is applicable (no data lost if applied) to the specified ItemStack.

        A SkullMeta would not be valid for a sword, but a normal ItemMeta from an enchanted dirt block would.

        Parameters:
        meta - Meta to check
        stack - Item that meta will be applied to
        Returns:
        true if the meta can be applied without losing data, false otherwise
        Throws:
        IllegalArgumentException - if the meta was not created by this factory
      • isApplicable

        boolean isApplicable​(@Nullable
                             @Nullable ItemMeta meta,
                             @Nullable
                             @Nullable Material material)
                      throws IllegalArgumentException
        This method checks the item meta to confirm that it is applicable (no data lost if applied) to the specified Material.

        A SkullMeta would not be valid for a sword, but a normal ItemMeta from an enchanted dirt block would.

        Parameters:
        meta - Meta to check
        material - Material that meta will be applied to
        Returns:
        true if the meta can be applied without losing data, false otherwise
        Throws:
        IllegalArgumentException - if the meta was not created by this factory
      • asMetaFor

        @Nullable
        @Nullable ItemMeta asMetaFor​(@NotNull
                                     @NotNull ItemMeta meta,
                                     @NotNull
                                     @NotNull ItemStack stack)
                              throws IllegalArgumentException
        Returns an appropriate item meta for the specified stack.

        The item meta returned will always be a valid meta for a given ItemStack of the specified material. It may be a more or less specific meta, and could also be the same meta or meta type as the parameter. The item meta returned will also always be the most appropriate meta.

        Example, if a SkullMeta is being applied to a book, this method would return a BookMeta containing all information in the specified meta that is applicable to an ItemMeta, the highest common interface.

        Parameters:
        meta - the meta to convert
        stack - the stack to convert the meta for
        Returns:
        An appropriate item meta for the specified item stack. No guarantees are made as to if a copy is returned. This will be null for a stack of air.
        Throws:
        IllegalArgumentException - if the specified meta was not created by this factory
      • asMetaFor

        @Nullable
        @Nullable ItemMeta asMetaFor​(@NotNull
                                     @NotNull ItemMeta meta,
                                     @NotNull
                                     @NotNull Material material)
                              throws IllegalArgumentException
        Returns an appropriate item meta for the specified material.

        The item meta returned will always be a valid meta for a given ItemStack of the specified material. It may be a more or less specific meta, and could also be the same meta or meta type as the parameter. The item meta returned will also always be the most appropriate meta.

        Example, if a SkullMeta is being applied to a book, this method would return a BookMeta containing all information in the specified meta that is applicable to an ItemMeta, the highest common interface.

        Parameters:
        meta - the meta to convert
        material - the material to convert the meta for
        Returns:
        An appropriate item meta for the specified item material. No guarantees are made as to if a copy is returned. This will be null for air.
        Throws:
        IllegalArgumentException - if the specified meta was not created by this factory
      • getDefaultLeatherColor

        @NotNull
        @NotNull Color getDefaultLeatherColor()
        Returns the default color for all leather armor.
        Returns:
        the default color for leather armor