CustomItems for Developers
The goal of this project, give developer easy tools for creation CustomItems and control them.
Why?
CustomItems API-plugin suppose to write less code and more control on custom item stack. The API provides writing business logic right in the Item.
Features:
- Full ItemStack compatibility - CustomItemStack is ItemStack, but with your logic
- Custom Factories for your Item - need some component of your plugin? No problem use Custom Factories (Example with Guice)
- Auto scan your items for the registry - no manually register
For example:
* Plugin to strike Lightning with specific item *
Create SwordOfGod:
Code (Java):
/**
* The type Sword of god.
*/
@CustomItem
(type
= Material.
DIAMOND_SWORD, customModelData
=
41
)
public
class SwordOfGod
extends AbstractCustomItemStack
{
/**
* Instantiates a new Sword of god.
*
* @param stack the stack
* @throws IllegalArgumentException the illegal argument exception
*/
public SwordOfGod
(ItemStack stack
)
throws
IllegalArgumentException
{
super
(stack
)
;
ItemMeta meta
=
this.
getItemMeta
(
)
;
meta.
setDisplayName
(
"§6Sword of the gods"
)
;
this.
setItemMeta
(meta
)
;
}
/**
* Randomly get power of lighting.
* Btw you can store with data with NBT Provider
*
* @return power level
*/
public
int getPowerLevel
(
)
{
return
new
Random
(
).
nextInt
(
5
)
;
}
/**
* Launch strike at location
*
* @param location target location
*/
public
void strike
(Location location
)
{
int power
=
this.
getPowerLevel
(
)
;
while
(power
>
0
)
{
location.
getWorld
(
).
strikeLightning
(location
)
;
power
--;
}
}
}
Then just listen custom event.
Code (Java):
@EventHandler
public
void onPlayerDamage
(EntityDamageByPlayerWithCustomItemStackEvent event
)
{
if
(event.
getAbstractCustomItemStack
(
)
instanceof SwordOfGod
)
{
(
(SwordOfGod
) event.
getAbstractCustomItemStack
(
)
).
strike
(
event.
getSourceEvent
(
).
getEntity
(
).
getLocation
(
)
)
;
}
}
Result: