Search in sources :

Example 6 with InventoryTrigger

use of io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger in project TriggerReactor by wysohn.

the class InventoryEditManager method saveEdit.

@Override
public void saveEdit(IPlayer player) {
    UUID u = player.getUniqueId();
    if (!suspended.containsKey(u)) {
        return;
    }
    Inventory inv = suspended.get(u).get();
    InventoryTrigger trigger = sessions.get(u);
    int size = inv.capacity();
    IItemStack[] iitems = new IItemStack[size];
    for (Inventory slot : inv.slots()) {
        slot.getInventoryProperty(SlotIndex.class).ifPresent(slotIndex -> slot.peek().ifPresent(itemStack -> iitems[slotIndex.getValue()] = new SpongeItemStack(itemStack)));
    }
    // TODO this causes an error waaay down the call chain.  replaceItems also saves the inventory trigger manager
    // but while trying to write the new data, NPE is thrown.  Starting a new edit shows that the new data at least
    // gets written to the trigger, but reloading will throw away the edits.
    // None of the items I want to save are null, so that isn't the source of the NPE.
    // I know this because item.createSnapshot() in the sponge InventoryTriggerManager.writeItemsList() succeeds.
    // please investigate this wysohn, because I have no idea at all why it can't save.
    replaceItems(trigger, iitems);
    stopEdit(player);
    player.sendMessage("Saved edits");
}
Also used : Inventory(org.spongepowered.api.item.inventory.Inventory) TextStyle(org.spongepowered.api.text.format.TextStyle) Keys(org.spongepowered.api.data.key.Keys) ItemTypes(org.spongepowered.api.item.ItemTypes) TriggerReactorCore(io.github.wysohn.triggerreactor.core.main.TriggerReactorCore) SpongeInventory(io.github.wysohn.triggerreactor.sponge.bridge.SpongeInventory) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Text(org.spongepowered.api.text.Text) IItemStack(io.github.wysohn.triggerreactor.core.bridge.IItemStack) InventoryArchetypes(org.spongepowered.api.item.inventory.InventoryArchetypes) TextColors(org.spongepowered.api.text.format.TextColors) TextActions(org.spongepowered.api.text.action.TextActions) IInventory(io.github.wysohn.triggerreactor.core.bridge.IInventory) TextStyles(org.spongepowered.api.text.format.TextStyles) GridInventory(org.spongepowered.api.item.inventory.type.GridInventory) InventoryTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger) InteractInventoryEvent(org.spongepowered.api.event.item.inventory.InteractInventoryEvent) Slot(org.spongepowered.api.item.inventory.Slot) UUID(java.util.UUID) InventoryTitle(org.spongepowered.api.item.inventory.property.InventoryTitle) SpongeItemStack(io.github.wysohn.triggerreactor.sponge.bridge.SpongeItemStack) IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) ClientConnectionEvent(org.spongepowered.api.event.network.ClientConnectionEvent) List(java.util.List) TextUtil(io.github.wysohn.triggerreactor.sponge.tools.TextUtil) QueryOperationTypes(org.spongepowered.api.item.inventory.query.QueryOperationTypes) SpongePlayer(io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer) AbstractInventoryEditManager(io.github.wysohn.triggerreactor.core.manager.AbstractInventoryEditManager) InventoryDimension(org.spongepowered.api.item.inventory.property.InventoryDimension) Player(org.spongepowered.api.entity.living.player.Player) SlotIndex(org.spongepowered.api.item.inventory.property.SlotIndex) Listener(org.spongepowered.api.event.Listener) InventoryTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger) IItemStack(io.github.wysohn.triggerreactor.core.bridge.IItemStack) SlotIndex(org.spongepowered.api.item.inventory.property.SlotIndex) UUID(java.util.UUID) SpongeItemStack(io.github.wysohn.triggerreactor.sponge.bridge.SpongeItemStack) Inventory(org.spongepowered.api.item.inventory.Inventory) SpongeInventory(io.github.wysohn.triggerreactor.sponge.bridge.SpongeInventory) IInventory(io.github.wysohn.triggerreactor.core.bridge.IInventory) GridInventory(org.spongepowered.api.item.inventory.type.GridInventory)

Example 7 with InventoryTrigger

use of io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger in project TriggerReactor by wysohn.

the class InventoryTriggerManager method onOpen.

@Listener
public void onOpen(InteractInventoryEvent.Open 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));
    Map<String, Object> varMap = getSharedVarsForInventory(new SpongeInventory(inventory, carrier));
    varMap.put("player", e.getCause().first(Player.class).orElse(null));
    varMap.put("trigger", "open");
    Inventory grids = inv.query(QueryOperationTypes.INVENTORY_TYPE.of(GridInventory.class));
    varMap.put("inventory", grids.first());
    trigger.activate(e, varMap);
}
Also used : SpongeInventory(io.github.wysohn.triggerreactor.sponge.bridge.SpongeInventory) InventoryTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger) CarriedInventory(org.spongepowered.api.item.inventory.type.CarriedInventory) GridInventory(org.spongepowered.api.item.inventory.type.GridInventory) 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 8 with InventoryTrigger

use of io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger 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 9 with InventoryTrigger

use of io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger in project TriggerReactor by wysohn.

the class InventoryEditManager method saveEdit.

@Override
public void saveEdit(IPlayer player) {
    UUID u = player.getUniqueId();
    if (!sessions.containsKey(u)) {
        return;
    }
    Inventory inv = suspended.get(u).get();
    InventoryTrigger trigger = sessions.get(u);
    ItemStack[] items = inv.getStorageContents();
    IItemStack[] iitems = new IItemStack[items.length];
    for (int i = 0; i < items.length; i++) {
        iitems[i] = new BukkitItemStack(items[i] == null ? new ItemStack(Material.AIR) : items[i]);
    }
    replaceItems(trigger, iitems);
    stopEdit(player);
    player.sendMessage("Saved edits");
}
Also used : InventoryTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger) IItemStack(io.github.wysohn.triggerreactor.core.bridge.IItemStack) BukkitItemStack(io.github.wysohn.triggerreactor.bukkit.bridge.BukkitItemStack) UUID(java.util.UUID) BukkitItemStack(io.github.wysohn.triggerreactor.bukkit.bridge.BukkitItemStack) ItemStack(org.bukkit.inventory.ItemStack) IItemStack(io.github.wysohn.triggerreactor.core.bridge.IItemStack) IInventory(io.github.wysohn.triggerreactor.core.bridge.IInventory) Inventory(org.bukkit.inventory.Inventory)

Example 10 with InventoryTrigger

use of io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger in project TriggerReactor by wysohn.

the class InventoryTriggerManager method onOpen.

@EventHandler
public void onOpen(InventoryOpenEvent e) {
    Inventory inventory = e.getInventory();
    if (!this.hasInventoryOpen(BukkitTriggerReactorCore.getWrapper().wrap(inventory)))
        return;
    InventoryTrigger trigger = getTriggerForOpenInventory(BukkitTriggerReactorCore.getWrapper().wrap(inventory));
    Map<String, Object> varMap = getSharedVarsForInventory(BukkitTriggerReactorCore.getWrapper().wrap(inventory));
    varMap.put("player", e.getPlayer());
    varMap.put("trigger", "open");
    trigger.activate(e, varMap);
}
Also used : InventoryTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger) IInventory(io.github.wysohn.triggerreactor.core.bridge.IInventory) Inventory(org.bukkit.inventory.Inventory) EventHandler(org.bukkit.event.EventHandler)

Aggregations

IInventory (io.github.wysohn.triggerreactor.core.bridge.IInventory)10 InventoryTrigger (io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger)10 IPlayer (io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer)6 SpongeInventory (io.github.wysohn.triggerreactor.sponge.bridge.SpongeInventory)5 IItemStack (io.github.wysohn.triggerreactor.core.bridge.IItemStack)4 SpongePlayer (io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer)4 Inventory (org.bukkit.inventory.Inventory)4 Trigger (io.github.wysohn.triggerreactor.core.manager.trigger.Trigger)3 Player (org.spongepowered.api.entity.living.player.Player)3 Listener (org.spongepowered.api.event.Listener)3 CarriedInventory (org.spongepowered.api.item.inventory.type.CarriedInventory)3 GridInventory (org.spongepowered.api.item.inventory.type.GridInventory)3 IEvent (io.github.wysohn.triggerreactor.core.bridge.event.IEvent)2 ProcessInterrupter (io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.ProcessInterrupter)2 Node (io.github.wysohn.triggerreactor.core.script.parser.Node)2 UUID (java.util.UUID)2 Player (org.bukkit.entity.Player)2 InteractInventoryEvent (org.spongepowered.api.event.item.inventory.InteractInventoryEvent)2 Inventory (org.spongepowered.api.item.inventory.Inventory)2 SlotIndex (org.spongepowered.api.item.inventory.property.SlotIndex)2