Search in sources :

Example 16 with ForSaleItem

use of com.almuradev.almura.feature.exchange.listing.ForSaleItem in project Almura by AlmuraDev.

the class ClientboundListItemsSaleStatusPacket method writeTo.

@Override
public void writeTo(final ChannelBuf buf) {
    checkNotNull(this.id);
    buf.writeString(this.id);
    buf.writeInteger(this.listedItems == null ? 0 : this.listedItems.size());
    if (this.listedItems != null) {
        for (final ForSaleItem listedItem : this.listedItems) {
            buf.writeInteger(listedItem.getListItem().getRecord());
            buf.writeInteger(listedItem.getRecord());
            try {
                final byte[] createdData = SerializationUtil.objectToBytes(listedItem.getCreated());
                buf.writeInteger(createdData.length);
                buf.writeBytes(createdData);
            } catch (IOException e) {
                e.printStackTrace();
                continue;
            }
            ByteBufUtil.writeBigDecimal((ByteBuf) buf, listedItem.getPrice());
        }
    }
    buf.writeInteger(this.lastKnownPriceItems == null ? 0 : this.lastKnownPriceItems.size());
    if (this.lastKnownPriceItems != null) {
        for (final ListItem delistedItem : this.lastKnownPriceItems) {
            delistedItem.getLastKnownPrice().ifPresent(lastKnownPrice -> {
                buf.writeInteger(delistedItem.getRecord());
                ByteBufUtil.writeBigDecimal((ByteBuf) buf, lastKnownPrice);
            });
        }
    }
}
Also used : ForSaleItem(com.almuradev.almura.feature.exchange.listing.ForSaleItem) IOException(java.io.IOException) ListItem(com.almuradev.almura.feature.exchange.listing.ListItem)

Aggregations

ForSaleItem (com.almuradev.almura.feature.exchange.listing.ForSaleItem)16 ListItem (com.almuradev.almura.feature.exchange.listing.ListItem)15 BasicForSaleItem (com.almuradev.almura.feature.exchange.basic.listing.BasicForSaleItem)11 BasicListItem (com.almuradev.almura.feature.exchange.basic.listing.BasicListItem)11 ClientboundForSaleFilterRequestPacket (com.almuradev.almura.feature.exchange.network.ClientboundForSaleFilterRequestPacket)8 ClientboundListItemsResponsePacket (com.almuradev.almura.feature.exchange.network.ClientboundListItemsResponsePacket)8 ClientboundListItemsSaleStatusPacket (com.almuradev.almura.feature.exchange.network.ClientboundListItemsSaleStatusPacket)8 AxsForSaleItem (com.almuradev.generated.axs.tables.AxsForSaleItem)8 AxsListItem (com.almuradev.generated.axs.tables.AxsListItem)8 BigDecimal (java.math.BigDecimal)8 List (java.util.List)7 BasicExchange (com.almuradev.almura.feature.exchange.basic.BasicExchange)6 SQLException (java.sql.SQLException)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 UUID (java.util.UUID)6 DSLContext (org.jooq.DSLContext)6 ClientboundExchangeGuiResponsePacket (com.almuradev.almura.feature.exchange.network.ClientboundExchangeGuiResponsePacket)5 ClientboundTransactionCompletePacket (com.almuradev.almura.feature.exchange.network.ClientboundTransactionCompletePacket)5