use of com.almuradev.generated.axs.tables.records.AxsForSaleItemRecord in project Almura by AlmuraDev.
the class ServerExchangeManager method handleListForSaleItem.
public void handleListForSaleItem(final Player player, final String id, final int listItemRecNo, final BigDecimal price) {
checkNotNull(player);
checkNotNull(id);
checkState(listItemRecNo >= 0);
checkNotNull(price);
checkState(price.doubleValue() >= 0);
final Exchange axs = this.getExchange(id).orElse(null);
if (axs == null) {
this.notificationManager.sendWindowMessage(player, Text.of("Exchange"), Text.of("Critical error encountered, check the " + "server console for more details!"));
this.logger.error("Player '{}' attempted to mark list item '{}' for sale for exchange '{}' but the server has no knowledge of that " + "exchange. Syncing exchange registry...", player.getName(), listItemRecNo, id);
this.syncExchangeRegistryTo(player);
return;
}
final List<ListItem> listItems = axs.getListItemsFor(player.getUniqueId()).orElse(null);
if (listItems == null || listItems.isEmpty()) {
this.notificationManager.sendWindowMessage(player, Text.of("Exchange"), Text.of("Critical error encountered, check the " + "server console for more details!"));
this.logger.error("Player '{}' attempted to mark list item '{}' for sale for exchange '{}' but the server has no record of any list " + "items for that player. Syncing list items...", player.getName(), listItemRecNo, id);
this.network.sendTo(player, new ClientboundListItemsResponsePacket(id, listItems));
return;
}
final ListItem found = listItems.stream().filter(item -> item.getRecord() == listItemRecNo).findAny().orElse(null);
if (found == null) {
this.notificationManager.sendWindowMessage(player, Text.of("Exchange"), Text.of("Critical error encountered, check the " + "server console for more details!"));
this.logger.error("Player '{}' attempted to mark list item '{}' for sale for exchange '{}' but the server has no record of the listing. " + "Syncing list items...", player.getName(), listItemRecNo, id);
this.network.sendTo(player, new ClientboundListItemsResponsePacket(id, listItems));
return;
}
final List<ForSaleItem> forSaleItems = axs.getForSaleItemsFor(player.getUniqueId()).orElse(null);
if (found.getForSaleItem().isPresent()) {
this.notificationManager.sendWindowMessage(player, Text.of("Exchange"), Text.of("Critical error encountered, check the " + "server console for more details!"));
this.logger.error("Player '{}' attempted to mark list item '{}' for sale for exchange '{}' but the " + "server already has a listing for that item. Syncing list items sale status...", player.getName(), listItemRecNo, id);
this.network.sendTo(player, new ClientboundListItemsSaleStatusPacket(id, forSaleItems, null));
return;
}
if (forSaleItems != null && forSaleItems.size() + 1 > this.getListingsLimit(player)) {
this.notificationManager.sendWindowMessage(player, Text.of("Exchange"), Text.of("You have reached your listing limit."));
return;
}
this.scheduler.createTaskBuilder().async().execute(() -> {
try (final DSLContext context = this.databaseManager.createContext(true)) {
final Instant created = Instant.now();
final AxsForSaleItemRecord record = ExchangeQueries.createInsertForSaleItem(created, found.getRecord(), price).build(context).fetchOne();
if (record == null) {
this.logger.error("Player '{}' attempted to mark list item '{}' for sale for exchange '{}' to the database but it failed. " + "Discarding changes...", player.getName(), listItemRecNo, id);
return;
}
this.scheduler.createTaskBuilder().execute(() -> {
final BasicForSaleItem basicForSaleItem = new BasicForSaleItem((BasicListItem) found, record.getRecNo(), created, record.getPrice());
List<ForSaleItem> forSaleItemsRef = forSaleItems;
if (forSaleItemsRef == null) {
forSaleItemsRef = new ArrayList<>();
axs.putForSaleItemsFor(player.getUniqueId(), forSaleItemsRef);
}
forSaleItemsRef.add(basicForSaleItem);
this.network.sendTo(player, new ClientboundListItemsSaleStatusPacket(axs.getId(), forSaleItems, null));
this.network.sendToAll(new ClientboundForSaleFilterRequestPacket(axs.getId()));
}).submit(this.container);
} catch (SQLException e) {
e.printStackTrace();
}
}).submit(this.container);
}
Aggregations