Search in sources :

Example 1 with SpongeItemStack

use of io.github.wysohn.triggerreactor.sponge.bridge.SpongeItemStack 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)

Aggregations

IInventory (io.github.wysohn.triggerreactor.core.bridge.IInventory)1 IItemStack (io.github.wysohn.triggerreactor.core.bridge.IItemStack)1 IPlayer (io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer)1 TriggerReactorCore (io.github.wysohn.triggerreactor.core.main.TriggerReactorCore)1 AbstractInventoryEditManager (io.github.wysohn.triggerreactor.core.manager.AbstractInventoryEditManager)1 InventoryTrigger (io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger)1 SpongeInventory (io.github.wysohn.triggerreactor.sponge.bridge.SpongeInventory)1 SpongeItemStack (io.github.wysohn.triggerreactor.sponge.bridge.SpongeItemStack)1 SpongePlayer (io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer)1 TextUtil (io.github.wysohn.triggerreactor.sponge.tools.TextUtil)1 List (java.util.List)1 UUID (java.util.UUID)1 Keys (org.spongepowered.api.data.key.Keys)1 Player (org.spongepowered.api.entity.living.player.Player)1 Listener (org.spongepowered.api.event.Listener)1 InteractInventoryEvent (org.spongepowered.api.event.item.inventory.InteractInventoryEvent)1 ClientConnectionEvent (org.spongepowered.api.event.network.ClientConnectionEvent)1 ItemTypes (org.spongepowered.api.item.ItemTypes)1 Inventory (org.spongepowered.api.item.inventory.Inventory)1 InventoryArchetypes (org.spongepowered.api.item.inventory.InventoryArchetypes)1