2015-10-26 16:37:44 +01:00
|
|
|
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:
|
|
|
|
* <p>
|
|
|
|
* The method fabricate() returns an ItemStack.
|
|
|
|
* <p>
|
|
|
|
*
|
|
|
|
* For creating a legendary item, do:
|
|
|
|
* <p>
|
|
|
|
* RareItemFactory.begin(ItemType.LEGENDARY).setLegendary(AlligatorsTooth.class)
|
|
|
|
* .fabricate();
|
|
|
|
* <p>
|
|
|
|
*
|
|
|
|
* For creating a Flaming Jagged Diamond Sword of Conquering, simply do:
|
|
|
|
* <p>
|
|
|
|
* RareItemFactory.begin(ItemType.WEAPON).setType(Material.DIAMOND_SWORD).
|
|
|
|
* setSuperPrefix(FlamingAttribute.class).setPrefix(JaggedAttribute.class).
|
|
|
|
* setSuffix(ConqueringAttribute.class).fabricate();
|
|
|
|
*/
|
|
|
|
public class RareItemFactory
|
|
|
|
{
|
|
|
|
private Class<? extends ItemAttribute> _superPrefix;
|
|
|
|
private Class<? extends ItemAttribute> _prefix;
|
|
|
|
private Class<? extends ItemAttribute> _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);
|
2015-11-19 20:03:51 +01:00
|
|
|
_item.addDullEnchantment();
|
2015-10-26 16:37:44 +01:00
|
|
|
_material = type;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public RareItemFactory setLegendary(Class<? extends LegendaryItem> 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<? extends ItemAttribute> superPrefix)
|
|
|
|
{
|
|
|
|
_superPrefix = superPrefix;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public RareItemFactory setPrefix(Class<? extends ItemAttribute> prefix)
|
|
|
|
{
|
|
|
|
_prefix = prefix;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public RareItemFactory setSuffix(Class<? extends ItemAttribute> suffix)
|
|
|
|
{
|
|
|
|
_suffix = suffix;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ItemStack fabricate()
|
2015-11-25 22:45:04 +01:00
|
|
|
{
|
|
|
|
applyAttributes();
|
|
|
|
|
|
|
|
ItemStack item = _item.toItemStack();
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void applyAttributes()
|
2015-10-26 16:37:44 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (_superPrefix != null)
|
|
|
|
{
|
|
|
|
_item.getAttributes().addAttribute(_superPrefix.newInstance());
|
|
|
|
}
|
2015-11-25 22:45:04 +01:00
|
|
|
|
2015-10-26 16:37:44 +01:00
|
|
|
if (_prefix != null)
|
|
|
|
{
|
|
|
|
_item.getAttributes().addAttribute(_prefix.newInstance());
|
|
|
|
}
|
2015-11-25 22:45:04 +01:00
|
|
|
|
2015-10-26 16:37:44 +01:00
|
|
|
if (_suffix != null)
|
|
|
|
{
|
|
|
|
_item.getAttributes().addAttribute(_suffix.newInstance());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (InstantiationException | IllegalAccessException e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public ItemType getItemType()
|
|
|
|
{
|
|
|
|
return _itemType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Material getMaterial()
|
|
|
|
{
|
|
|
|
return _material;
|
|
|
|
}
|
|
|
|
|
|
|
|
public CustomItem getWrapper()
|
|
|
|
{
|
2015-11-25 22:45:04 +01:00
|
|
|
applyAttributes();
|
2015-10-26 16:37:44 +01:00
|
|
|
return _item;
|
|
|
|
}
|
|
|
|
}
|