Event Bus - DevNatan/inventory-framework GitHub Wiki

This feature is not available yet.

Table of Contents

Project Setup

Event Bus is available under the inventory-framework-eventbus artifact.\

implementation 'me.devnatan:inventory-framework-eventbus:<version>'

Installation

To use the EventBus feature you need to install it on your framework. See the Integration with External Features documentation if you don't know yet how to install a feature.

import me.devnatan.inventoryframework.feature.eventbus.EventBusFeature.EventBus;

install(EventBus);

Creating a new EventBus

TBD

Using events to update a item programmatically

In this example we will use an item that when clicked will launch an event and from the launch of this event another item will be updated.

  1. Creates two items: DIAMOND and GOLD_INGOT
  2. Registers an "gold-digger" event to update GOLD_INGOT when it's called.
  3. Calls "gold-digger" event when player clicks on DIAMOND.
  4. When player clicks on DIAMOND it calls "gold-digger" event that updates GOLD_INGOT item.
  5. "Gold item was updated" message is sent to the player because GOLD_INGOT was updated (see onUpdate).
class EventItemUpdateView extends View {

    private static final GOLD_DIGGER_EVENT = "gold-digger";

    @Override
    public void onFirstRender(RenderContext render) {
        // Creates DIAMOND item in the first slot
        render.firstSlot(new ItemStack(Material.DIAMOND))
              .cancelOnClick()
              .onClick(click -> render.emitEvent(GOLD_DIGGER_EVENT));

       // Creates GOLD_INGOT item in the next available slot
       // `asRef()` returns the reference of the item, to be able to use `#update()` later on
       IFItem goldItem = render.availableSlot(new ItemStack(Material.GOLD_INGOT))
             .onUpdate(update -> update.getPlayer().sendMessage("Gold item was updated"));
             .asRef();

       // Listens to the "gold-digger" event and then calls update on the gold item.
       render.listenEvent(GOLD_DIGGER_EVENT, goldItem::update);
    }
}
⚠️ **GitHub.com Fallback** ⚠️