package mineplex.game.clans.items; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import mineplex.core.common.util.UtilInv; import mineplex.game.clans.items.attributes.ItemAttribute; import mineplex.game.clans.items.legendaries.LegendaryItem; /** * Quick little guide on how to use this thing: *

* The method fabricate() returns an ItemStack. *

* * For creating a legendary item, do: *

* RareItemFactory.begin(ItemType.LEGENDARY).setLegendary(AlligatorsTooth.class) * .fabricate(); *

* * For creating a Flaming Jagged Diamond Sword of Conquering, simply do: *

* RareItemFactory.begin(ItemType.WEAPON).setType(Material.DIAMOND_SWORD). * setSuperPrefix(FlamingAttribute.class).setPrefix(JaggedAttribute.class). * setSuffix(ConqueringAttribute.class).fabricate(); */ public class RareItemFactory { private Class _superPrefix; private Class _prefix; private Class _suffix; private ItemType _itemType; private Material _material; private CustomItem _item; public RareItemFactory(ItemType itemType) { _itemType = itemType; } public static RareItemFactory begin(ItemType itemType) { return new RareItemFactory(itemType); } public RareItemFactory setType(Material type) { _item = new CustomItem(type); _material = type; return this; } public RareItemFactory setLegendary(Class legendary) { if (_itemType.equals(ItemType.LEGENDARY)) { try { _item = legendary.newInstance(); _material = _item.getMaterial(); } catch (InstantiationException | IllegalAccessException e) { e.printStackTrace(); } } else { throw new RuntimeException("Unexpected call to setLegendary(LegendaryType)"); } return this; } public RareItemFactory setSuperPrefix(Class superPrefix) { _superPrefix = superPrefix; return this; } public RareItemFactory setPrefix(Class prefix) { _prefix = prefix; return this; } public RareItemFactory setSuffix(Class suffix) { _suffix = suffix; return this; } public ItemStack fabricate() { try { if (_superPrefix != null) { _item.getAttributes().addAttribute(_superPrefix.newInstance()); } if (_prefix != null) { _item.getAttributes().addAttribute(_prefix.newInstance()); } if (_suffix != null) { _item.getAttributes().addAttribute(_suffix.newInstance()); } } catch (InstantiationException | IllegalAccessException e) { e.printStackTrace(); } ItemStack item = _item.toItemStack(); UtilInv.addDullEnchantment(item); return item; } public ItemType getItemType() { return _itemType; } public Material getMaterial() { return _material; } public CustomItem getWrapper() { return _item; } }