Search in sources :

Example 6 with VanillaStack

use of com.almuradev.almura.shared.item.VanillaStack in project Almura by AlmuraDev.

the class StoreListScreen method listOrModify.

private void listOrModify() {
    if (!this.buttonList.isEnabled()) {
        return;
    }
    // Check if there are any valid combinations
    final boolean isBuyValid = !this.buyQtyTextBox.getText().isEmpty() && !this.buyPricePerTextBox.getText().isEmpty();
    final boolean isSellValid = !this.sellQtyTextBox.getText().isEmpty() && !this.sellPricePerTextBox.getText().isEmpty();
    if (isBuyValid) {
        // We're modifying an existing listing
        if (this.toModifyBuy != null) {
            final int newBuyQuantity = Integer.valueOf(this.buyQtyTextBox.getText());
            storeManager.requestModifyBuyingItem(this.store.getId(), this.toModifyBuy.getRecord(), newBuyQuantity, 0, new BigDecimal(this.buyPricePerTextBox.getText()));
        } else {
            // We're adding a new listing
            final VanillaStack toListBuy = new BasicVanillaStack(this.toList);
            toListBuy.setQuantity(Integer.valueOf(this.buyQtyTextBox.getText()));
            storeManager.requestListBuyingItem(this.store.getId(), toListBuy, 0, new BigDecimal(this.buyPricePerTextBox.getText()));
        }
    } else if (this.toModifyBuy != null) {
        // We're unlisting an existing listing
        storeManager.requestDelistBuyingItem(this.store.getId(), this.toModifyBuy.getRecord());
    }
    if (isSellValid) {
        // We're modifying an existing listing
        if (this.toModifySell != null) {
            final int newQuantity = Integer.valueOf(this.sellQtyTextBox.getText());
            storeManager.requestModifySellingItem(this.store.getId(), this.toModifySell.getRecord(), newQuantity, 0, new BigDecimal(this.sellPricePerTextBox.getText()));
        } else {
            // We're adding a new listing
            final VanillaStack toListSell = new BasicVanillaStack(this.toList);
            toListSell.setQuantity(Integer.valueOf(this.sellQtyTextBox.getText()));
            storeManager.requestListSellingItem(this.store.getId(), toListSell, 0, new BigDecimal(this.sellPricePerTextBox.getText()));
        }
    } else if (this.toModifySell != null) {
        // We're unlisting an existing listing
        storeManager.requestDelistSellingItem(this.store.getId(), this.toModifySell.getRecord());
    }
    ((StoreScreen) this.parent).refresh(true);
    this.close();
}
Also used : BasicVanillaStack(com.almuradev.almura.shared.item.BasicVanillaStack) BigDecimal(java.math.BigDecimal) VanillaStack(com.almuradev.almura.shared.item.VanillaStack) BasicVanillaStack(com.almuradev.almura.shared.item.BasicVanillaStack)

Aggregations

VanillaStack (com.almuradev.almura.shared.item.VanillaStack)6 BigDecimal (java.math.BigDecimal)4 BasicVanillaStack (com.almuradev.almura.shared.item.BasicVanillaStack)3 IOException (java.io.IOException)3 SQLException (java.sql.SQLException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ItemStack (net.minecraft.item.ItemStack)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 DSLContext (org.jooq.DSLContext)3 BasicStore (com.almuradev.almura.feature.store.basic.BasicStore)2 ClientboundListItemsResponsePacket (com.almuradev.almura.feature.store.network.ClientboundListItemsResponsePacket)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 Almura (com.almuradev.almura.Almura)1 Exchange (com.almuradev.almura.feature.exchange.Exchange)1 InventoryAction (com.almuradev.almura.feature.exchange.InventoryAction)1 BasicExchange (com.almuradev.almura.feature.exchange.basic.BasicExchange)1