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");
}
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);
}
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);
}
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");
}
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);
}
Aggregations