Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
ItemFactory.java
1 package org.bukkit.inventory;
2 
3 import org.bukkit.Color;
4 import org.bukkit.Material;
5 import org.bukkit.Server;
9 
10 /**
11  * An instance of the ItemFactory can be obtained with {@link
12  * Server#getItemFactory()}.
13  * <p>
14  * The ItemFactory is solely responsible for creating item meta containers to
15  * apply on item stacks.
16  */
17 public interface ItemFactory {
18 
19  /**
20  * This creates a new item meta for the material.
21  *
22  * @param material The material to consider as base for the meta
23  * @return a new ItemMeta that could be applied to an item stack of the
24  * specified material
25  */
26  ItemMeta getItemMeta(final Material material);
27 
28  /**
29  * This method checks the item meta to confirm that it is applicable (no
30  * data lost if applied) to the specified ItemStack.
31  * <p>
32  * A {@link SkullMeta} would not be valid for a sword, but a normal {@link
33  * ItemMeta} from an enchanted dirt block would.
34  *
35  * @param meta Meta to check
36  * @param stack Item that meta will be applied to
37  * @return true if the meta can be applied without losing data, false
38  * otherwise
39  * @throws IllegalArgumentException if the meta was not created by this
40  * factory
41  */
42  boolean isApplicable(final ItemMeta meta, final ItemStack stack) throws IllegalArgumentException;
43 
44  /**
45  * This method checks the item meta to confirm that it is applicable (no
46  * data lost if applied) to the specified Material.
47  * <p>
48  * A {@link SkullMeta} would not be valid for a sword, but a normal {@link
49  * ItemMeta} from an enchanted dirt block would.
50  *
51  * @param meta Meta to check
52  * @param material Material that meta will be applied to
53  * @return true if the meta can be applied without losing data, false
54  * otherwise
55  * @throws IllegalArgumentException if the meta was not created by this
56  * factory
57  */
58  boolean isApplicable(final ItemMeta meta, final Material material) throws IllegalArgumentException;
59 
60  /**
61  * This method is used to compare two item meta data objects.
62  *
63  * @param meta1 First meta to compare, and may be null to indicate no data
64  * @param meta2 Second meta to compare, and may be null to indicate no
65  * data
66  * @return false if one of the meta has data the other does not, otherwise
67  * true
68  * @throws IllegalArgumentException if either meta was not created by this
69  * factory
70  */
71  boolean equals(final ItemMeta meta1, final ItemMeta meta2) throws IllegalArgumentException;
72 
73  /**
74  * Returns an appropriate item meta for the specified stack.
75  * <p>
76  * The item meta returned will always be a valid meta for a given
77  * ItemStack of the specified material. It may be a more or less specific
78  * meta, and could also be the same meta or meta type as the parameter.
79  * The item meta returned will also always be the most appropriate meta.
80  * <p>
81  * Example, if a {@link SkullMeta} is being applied to a book, this method
82  * would return a {@link BookMeta} containing all information in the
83  * specified meta that is applicable to an {@link ItemMeta}, the highest
84  * common interface.
85  *
86  * @param meta the meta to convert
87  * @param stack the stack to convert the meta for
88  * @return An appropriate item meta for the specified item stack. No
89  * guarantees are made as to if a copy is returned. This will be null
90  * for a stack of air.
91  * @throws IllegalArgumentException if the specified meta was not created
92  * by this factory
93  */
94  ItemMeta asMetaFor(final ItemMeta meta, final ItemStack stack) throws IllegalArgumentException;
95 
96  /**
97  * Returns an appropriate item meta for the specified material.
98  * <p>
99  * The item meta returned will always be a valid meta for a given
100  * ItemStack of the specified material. It may be a more or less specific
101  * meta, and could also be the same meta or meta type as the parameter.
102  * The item meta returned will also always be the most appropriate meta.
103  * <p>
104  * Example, if a {@link SkullMeta} is being applied to a book, this method
105  * would return a {@link BookMeta} containing all information in the
106  * specified meta that is applicable to an {@link ItemMeta}, the highest
107  * common interface.
108  *
109  * @param meta the meta to convert
110  * @param material the material to convert the meta for
111  * @return An appropriate item meta for the specified item material. No
112  * guarantees are made as to if a copy is returned. This will be null for air.
113  * @throws IllegalArgumentException if the specified meta was not created
114  * by this factory
115  */
116  ItemMeta asMetaFor(final ItemMeta meta, final Material material) throws IllegalArgumentException;
117 
118  /**
119  * Returns the default color for all leather armor.
120  *
121  * @return the default color for leather armor
122  */
124 }
boolean isApplicable(final ItemMeta meta, final ItemStack stack)
ItemMeta asMetaFor(final ItemMeta meta, final ItemStack stack)
boolean equals(final ItemMeta meta1, final ItemMeta meta2)
ItemMeta getItemMeta(final Material material)