use of com.almuradev.almura.feature.exchange.basic.listing.BasicListItem in project Almura by AlmuraDev.
the class ClientboundForSaleItemsResponsePacket method readFrom.
@Override
public void readFrom(final ChannelBuf buf) {
this.id = buf.readString();
final int count = buf.readInteger();
if (count > 0) {
this.forSaleItems = new ArrayList<>();
for (int i = 0; i < count; i++) {
final int listItemRecNo = buf.readInteger();
final ResourceLocation location = new ResourceLocation(buf.readString(), buf.readString());
final Item item = ForgeRegistries.ITEMS.getValue(location);
if (item == null) {
new IOException("Unknown item id when receiving for sale item! Id [" + location + "]. Skipping...").printStackTrace();
continue;
}
final int quantity = buf.readInteger();
final int metadata = buf.readInteger();
final Instant listItemCreated;
try {
listItemCreated = SerializationUtil.bytesToObject(buf.readBytes(buf.readInteger()));
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
continue;
}
final UUID seller = buf.readUniqueId();
final String sellerName = buf.readBoolean() ? buf.readString() : null;
final int index = buf.readInteger();
BigDecimal lastKnownPrice = null;
if (buf.readBoolean()) {
lastKnownPrice = ByteBufUtil.readBigDecimal((ByteBuf) buf);
}
final int compoundDataLength = buf.readInteger();
NBTTagCompound compound = null;
if (compoundDataLength > 0) {
try {
compound = SerializationUtil.compoundFromBytes(buf.readBytes(compoundDataLength));
} catch (IOException e) {
e.printStackTrace();
continue;
}
}
final BasicListItem basicListItem = new BasicListItem(listItemRecNo, listItemCreated, seller, item, quantity, metadata, index, lastKnownPrice, compound);
if (Sponge.getPlatform().getExecutionType().isClient()) {
basicListItem.setSellerName(sellerName);
}
final int forSaleItemRecNo = buf.readInteger();
// ForSaleItem
final Instant forSaleItemCreated;
try {
forSaleItemCreated = SerializationUtil.bytesToObject(buf.readBytes(buf.readInteger()));
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
continue;
}
final BigDecimal price = ByteBufUtil.readBigDecimal((ByteBuf) buf);
final BasicForSaleItem basicForSaleItem = new BasicForSaleItem(basicListItem, forSaleItemRecNo, forSaleItemCreated, price);
this.forSaleItems.add(basicForSaleItem);
}
}
this.preLimitCount = buf.readInteger();
}
Aggregations