use of com.almuradev.almura.feature.exchange.Exchange in project Almura by AlmuraDev.
the class ClientExchangeManager method handleListItemsSaleStatus.
public void handleListItemsSaleStatus(final String id, @Nullable final List<ClientboundListItemsSaleStatusPacket.ListedItemUpdate> itemCandidates, @Nullable final List<ClientboundListItemsSaleStatusPacket.LastKnownPriceUpdate> lastKnowPriceItemCandidates) {
checkNotNull(id);
final Exchange axs = this.getExchange(id);
if (axs == null) {
return;
}
final List<ListItem> listItems = axs.getListItemsFor(Minecraft.getMinecraft().player.getUniqueID()).orElse(null);
if (listItems == null || listItems.isEmpty()) {
return;
}
// Null out all for sale items, our candidates will have what we currently have
listItems.forEach(item -> item.setForSaleItem(null));
if (itemCandidates != null) {
for (final ClientboundListItemsSaleStatusPacket.ListedItemUpdate itemCandidate : itemCandidates) {
listItems.stream().filter(item -> item.getRecord() == itemCandidate.listItemRecNo).findAny().ifPresent(listItem -> listItem.setForSaleItem(new BasicForSaleItem((BasicListItem) listItem, itemCandidate.forSaleItemRecNo, itemCandidate.created, itemCandidate.price)));
}
}
if (lastKnowPriceItemCandidates != null) {
for (final ClientboundListItemsSaleStatusPacket.LastKnownPriceUpdate lastKnownPriceItemCandidate : lastKnowPriceItemCandidates) {
listItems.stream().filter(item -> item.getRecord() == lastKnownPriceItemCandidate.listItemRecNo).findAny().ifPresent(listItem -> listItem.setLastKnownPrice(lastKnownPriceItemCandidate.lastKnownPrice));
}
}
}
use of com.almuradev.almura.feature.exchange.Exchange in project Almura by AlmuraDev.
the class ClientExchangeManager method handleExchangeSpecificOffer.
public void handleExchangeSpecificOffer(final String id) {
checkNotNull(id);
final GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen;
if (!(currentScreen instanceof ExchangeScreen)) {
return;
}
final Exchange axs = this.getExchange(id);
if (axs == null) {
((ExchangeScreen) currentScreen).close();
return;
}
final ExchangeScreen axsScreen = (ExchangeScreen) currentScreen;
new ExchangeOfferScreen(axsScreen, axs, axsScreen.listItemList.getItems().stream().filter(item -> !item.getForSaleItem().isPresent()).map(item -> new BasicVanillaStack(item.asRealStack())).collect(Collectors.toList()), axsScreen.limit).display();
}
use of com.almuradev.almura.feature.exchange.Exchange in project Almura by AlmuraDev.
the class ClientExchangeManager method handleForSaleItems.
public void handleForSaleItems(final String id, @Nullable final List<ForSaleItem> forSaleItems, int preLimitCount) {
checkNotNull(id);
final Exchange axs = this.getExchange(id);
if (axs == null) {
return;
}
final GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen;
if (currentScreen instanceof ExchangeScreen) {
if (axs != ((ExchangeScreen) currentScreen).getExchange()) {
return;
}
if (forSaleItems == null) {
axs.putForSaleItems(null);
} else {
axs.putForSaleItems(forSaleItems.stream().collect(Collectors.groupingBy(k -> k.getListItem().getSeller(), ConcurrentHashMap::new, Collectors.toCollection(ArrayList::new))));
}
((ExchangeScreen) currentScreen).refreshForSaleItemResults(forSaleItems, preLimitCount);
}
}
use of com.almuradev.almura.feature.exchange.Exchange in project Almura by AlmuraDev.
the class ClientboundExchangeRegistryPacket method writeTo.
@Override
public void writeTo(final ChannelBuf buf) {
buf.writeInteger(this.exchanges == null ? 0 : this.exchanges.size());
if (this.exchanges != null) {
for (final Exchange axs : this.exchanges) {
buf.writeString(axs.getId());
buf.writeString(axs.getName());
try {
final byte[] createdData = SerializationUtil.objectToBytes(axs.getCreated());
buf.writeInteger(createdData.length);
buf.writeBytes(createdData);
} catch (IOException e) {
e.printStackTrace();
continue;
}
final byte[] creatorData = SerializationUtil.toBytes(axs.getCreator());
buf.writeInteger(creatorData.length);
buf.writeBytes(creatorData);
final String creatorName = axs.getCreatorName().orElse(null);
buf.writeBoolean(creatorName != null);
if (creatorName != null) {
buf.writeString(creatorName);
}
buf.writeString(axs.getPermission());
buf.writeBoolean(axs.isHidden());
}
}
}
use of com.almuradev.almura.feature.exchange.Exchange in project Almura by AlmuraDev.
the class ClientExchangeManager method handleExchangeSpecific.
public void handleExchangeSpecific(final String id, final int limit) {
checkState(limit >= FeatureConstants.UNLIMITED);
final Exchange axs = this.getExchange(id);
if (axs != null) {
this.clearFilterCache();
new ExchangeScreen(axs, limit).display();
}
}
Aggregations