Repository navigation
Your first Interactable Item
With this API, you are able to easily create an item, which has a left and right click function, and also a cooldown!
First off, we need to create a class that extends from the RItemStack class, lets call it 'MyItem'
This class represents the Item we wish to create
@ItemStackInfo(name = "", lore = {}, amount = 0, type = null, itemFlags = {}, cooldown = 0) // Here we specify the meta information of our item
public class MyItem extends RItemStack {
@Override
public boolean onLeftClick(@NotNull PlayerInteractEvent e, @NotNull RUser user) {
...
return false;
}
@Override
public boolean onRightClick(@NotNull PlayerInteractEvent e, @NotNull RUser user) {
...
return false;
}
@Override
public void onCooldown(@NotNull PlayerInteractEvent e, @NotNull RUser user) {
...
}
@Override
public void onCooldownExpire(@NotNull RUser user) {
...
}
}As you can see, with this implementation, we are using an annotation called ItemStackInfo, you will see this pattern all over the API
With this annotation, we can specify our item's 'data' (name, lore, type, amount, etc)
This annotation replaces the need to manually set every property using methods
The API handles all of the background work of using every property that is specified within the ItemStackInfo annotation so you dont have to worry about that!
If you dont want to use this annotation, you can also call the super() constructor within the class that extends the RItemStack class like this:
public class MyItem extends RItemStack {
public MyItem() {
super(ITEMSTACK INSTANCE);
}
@Override
public boolean onLeftClick(@NotNull PlayerInteractEvent e, @NotNull RUser user) {
...
return false;
}
@Override
public boolean onRightClick(@NotNull PlayerInteractEvent e, @NotNull RUser user) {
...
return false;
}
@Override
public void onCooldown(@NotNull PlayerInteractEvent e, @NotNull RUser user) {
...
}
@Override
public void onCooldownExpire(@NotNull RUser user) {
...
}
}It is good practice, to create only one instance of this item (Singleton)
I normally create an interface where I store every item of this plugin (MyItems)
After creating our item, we need to register it, the way we registered our listener
So lets head on over back to our main class and register our newly created item!
public class MyPlugin extends RPlugin {
@Override
public void onPluginEnable() {
getItemStackManager().register(new MyItem()); // <- Singular itemstack registration
getItemStackManager().registerAll("PACKAGE NAME OF MULTIPLE LISTENERS"); // <- Multiple itemstack registration
}
@Override
public void onPluginDisable() {
...
}
}DONE!
Thats all we need to create and register a fully functioning item!