Search in sources :

Example 6 with SpongeInventory

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);
}
Also used : SpongePlayer(io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer) Player(org.spongepowered.api.entity.living.player.Player) CarriedInventory(org.spongepowered.api.item.inventory.type.CarriedInventory) GridInventory(org.spongepowered.api.item.inventory.type.GridInventory) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) SpongeInventory(io.github.wysohn.triggerreactor.sponge.bridge.SpongeInventory) InventoryTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger) SlotIndex(org.spongepowered.api.item.inventory.property.SlotIndex) SpongeInventory(io.github.wysohn.triggerreactor.sponge.bridge.SpongeInventory) IInventory(io.github.wysohn.triggerreactor.core.bridge.IInventory) GridInventory(org.spongepowered.api.item.inventory.type.GridInventory) CarriedInventory(org.spongepowered.api.item.inventory.type.CarriedInventory) Listener(org.spongepowered.api.event.Listener)

Example 7 with SpongeInventory

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));
}
Also used : SpongeInventory(io.github.wysohn.triggerreactor.sponge.bridge.SpongeInventory) SpongePlayer(io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer) CarriedInventory(org.spongepowered.api.item.inventory.type.CarriedInventory) SpongeInventory(io.github.wysohn.triggerreactor.sponge.bridge.SpongeInventory) IInventory(io.github.wysohn.triggerreactor.core.bridge.IInventory) GridInventory(org.spongepowered.api.item.inventory.type.GridInventory) CarriedInventory(org.spongepowered.api.item.inventory.type.CarriedInventory) Listener(org.spongepowered.api.event.Listener)

Aggregations

IInventory (io.github.wysohn.triggerreactor.core.bridge.IInventory)7 SpongeInventory (io.github.wysohn.triggerreactor.sponge.bridge.SpongeInventory)7 GridInventory (org.spongepowered.api.item.inventory.type.GridInventory)6 CarriedInventory (org.spongepowered.api.item.inventory.type.CarriedInventory)5 InventoryTrigger (io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger)4 SpongePlayer (io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer)4 Listener (org.spongepowered.api.event.Listener)4 Player (org.spongepowered.api.entity.living.player.Player)3 Inventory (org.spongepowered.api.item.inventory.Inventory)3 IPlayer (io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer)2 UUID (java.util.UUID)2 SlotIndex (org.spongepowered.api.item.inventory.property.SlotIndex)2 IEvent (io.github.wysohn.triggerreactor.core.bridge.event.IEvent)1 Trigger (io.github.wysohn.triggerreactor.core.manager.trigger.Trigger)1 ProcessInterrupter (io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.ProcessInterrupter)1 Node (io.github.wysohn.triggerreactor.core.script.parser.Node)1 TriggerReactorStartEvent (io.github.wysohn.triggerreactor.sponge.manager.event.TriggerReactorStartEvent)1 TriggerReactorStopEvent (io.github.wysohn.triggerreactor.sponge.manager.event.TriggerReactorStopEvent)1 DelegatedPlayer (io.github.wysohn.triggerreactor.sponge.tools.DelegatedPlayer)1 ConfigurationNode (ninja.leaping.configurate.ConfigurationNode)1