use of io.github.wysohn.triggerreactor.sponge.bridge.SpongeInventory in project TriggerReactor by wysohn.
the class InventoryTriggerManager method onClick.
@Listener
public void onClick(ClickInventoryEvent e) {
Inventory inv = e.getTargetInventory();
if (!(inv instanceof CarriedInventory))
return;
CarriedInventory inventory = (CarriedInventory) inv;
Carrier carrier = (Carrier) inventory.getCarrier().orElse(null);
if (carrier == null)
return;
if (!this.hasInventoryOpen(new SpongeInventory(inventory, carrier)))
return;
InventoryTrigger trigger = getTriggerForOpenInventory(new SpongeInventory(inventory, carrier));
// just always cancel if it's GUI
e.setCancelled(true);
Player player = e.getCause().first(Player.class).orElse(null);
if (player == null)
return;
int rawSlot = -1;
SlotTransaction slotTransaction = null;
List<SlotTransaction> transactions = e.getTransactions();
if (!transactions.isEmpty()) {
slotTransaction = e.getTransactions().get(0);
Slot slot = slotTransaction.getSlot();
SlotIndex slotIndex = slot.getInventoryProperty(SlotIndex.class).orElse(null);
rawSlot = slotIndex.getValue();
}
Map<String, Object> varMap = getSharedVarsForInventory(new SpongeInventory(inventory, carrier));
ItemStackSnapshot clickedItemOpt = slotTransaction == null ? ItemStackSnapshot.NONE : slotTransaction.getOriginal();
varMap.put("item", clickedItemOpt.createStack());
varMap.put("slot", rawSlot);
varMap.put("click", e.getClass().getSimpleName());
varMap.put("trigger", "click");
Inventory grids = inv.query(QueryOperationTypes.INVENTORY_TYPE.of(GridInventory.class));
varMap.put("inventory", grids.first());
trigger.activate(e, varMap);
}
use of io.github.wysohn.triggerreactor.sponge.bridge.SpongeInventory in project TriggerReactor by wysohn.
the class InventoryTriggerManager method onClose.
@Listener
public void onClose(InteractInventoryEvent.Close e, @First Player player) {
if (player == null)
return;
Inventory inv = e.getTargetInventory();
if (!(inv instanceof CarriedInventory))
return;
CarriedInventory inventory = (CarriedInventory) inv;
Carrier carrier = (Carrier) inventory.getCarrier().orElse(null);
if (carrier == null)
return;
onInventoryClose(e, new SpongePlayer(player), new SpongeInventory(inv, carrier));
}
Aggregations