3 minutes estimated read time

Items

Every interactable item will be its own class that extends VitalItem and is annotated with @VitalItem.Info.

MyItem.java
@VitalItem.Info(name = "My item", type = Material.COBBLESTONE)
public class MyItem extends VitalItem {
  
}

Now you can give this item to a player, e.g., when he joins the server.

MyListener.java
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
  e.getPlayer().getInventory().setItem(0, myItem.getItemStack(e.getPlayer()));
}

Note that we have to call the getItemStack method of our MyItem instance to get a copy of the item that our class defines.

Now if we want to react to an interaction, like a right-click, we can use the onRightClick lifecycle.

MyItem.java
@VitalItem.Info(name = "My item", type = Material.COBBLESTONE)
public class MyItem extends VitalItem {
  @Override
  public void onRightClick(PlayerInteractEvent e) {
    // ...
  }
}

Cooldowns

Items also support cooldowns.
Every cooldown is tied to the player that interacted with the item and will automatically work right out of the box without you having to configure anything.

Just define the cooldown in your info annotation (millis).

MyItem.java
@VitalItem.Info(cooldown = 1_000)

Localization

Plugins that also use vital-localization can benefit from localized items that are displayed and automatically updated when a player changes his locale!
Simply set the item name in your info annotation to your resource key, and Vital will automatically display the correct translated version of your item name, just how you provided it in your messages_*.properties files.

MyItem.java
@VitalItem.Info(name = "servername.pluginname.item.myitem")

When you change the locale of a player via VitalLocalizationModule.Spigot.setVitalLocale(Player, Locale), Vital will automatically translate all items of the player's inventory.

Lifecycles

LifecycleUsage
onLeftClick(PlayerInteractEvent)Perform an action when this item is left-clicked while not on cooldown.
onRightClick(PlayerInteractEvent)Perform an action when this item is right-clicked while not on cooldown.
onCooldown(PlayerInteractEvent)Perform an action when this item is left- or right-clicked while on cooldown.
onCooldownTick(Player)Perform an action when the cooldown of this item is ticked (every 50ms / 1 game tick).
onCooldownExpire(Player)Perform an action when the cooldown of this item reaches 0.

Found an issue?

Help us improve the documentation by reporting typos, missing information, or anything confusing.

Don't worry, we will auto-fill most of the annoying fields.

Create GitHub issue

This site and the Vital framework were built with ❤️ by Mike Neumann