use of com.almuradev.generated.store.tables.records.StoreSellingItemDataRecord in project Almura by AlmuraDev.
the class ServerStoreManager method handleListSellingItems.
public void handleListSellingItems(final Player player, final String id, final List<ServerboundListItemsRequestPacket.ListCandidate> candidates) {
checkNotNull(player);
checkNotNull(id);
if (!player.hasPermission(Almura.ID + ".store.admin")) {
this.notificationManager.sendPopupNotification(player, Text.of(TextColors.RED, "Store"), Text.of("You do not have permission " + "to list items!"), 5);
return;
}
final Store store = this.getStore(id).orElse(null);
if (store == null) {
this.logger.error("Player '{}' attempted to list selling items for store '{}' but the server has no knowledge of it. Syncing " + "store registry...", player.getName(), id);
this.syncStoreRegistryTo(player);
return;
}
this.scheduler.createTaskBuilder().async().execute(() -> {
try (final DSLContext context = this.databaseManager.createContext(true)) {
final Map<StoreSellingItemRecord, VanillaStack> inserted = new HashMap<>();
for (final ServerboundListItemsRequestPacket.ListCandidate candidate : candidates) {
final VanillaStack stack = candidate.stack;
final int index = candidate.index;
final BigDecimal price = candidate.price;
final StoreSellingItemRecord itemRecord = StoreQueries.createInsertSellingItem(store.getId(), Instant.now(), stack.getItem(), stack.getQuantity(), stack.getMetadata(), index, price).build(context).fetchOne();
if (itemRecord == null) {
this.notificationManager.sendWindowMessage(player, Text.of("Store"), Text.of("Critical error encountered, check the server console for more details!"));
this.logger.error("Player '{}' submitted a new selling item for store '{}' to the database but it failed. " + "Discarding changes and printing stack...", player.getName(), id);
this.printStacksToConsole(Lists.newArrayList(stack));
continue;
}
final NBTTagCompound compound = stack.getCompound();
if (compound != null) {
StoreSellingItemDataRecord dataRecord = null;
try {
dataRecord = StoreQueries.createInsertSellingItemData(itemRecord.getRecNo(), compound).build(context).fetchOne();
} catch (final IOException e) {
e.printStackTrace();
}
if (dataRecord == null) {
this.notificationManager.sendWindowMessage(player, Text.of("Store"), Text.of("Critical error encountered, check the server console for more details!"));
this.logger.error("Player '{}' submitted data for selling item record '{}' for store '{}' but it failed. " + "Discarding changes...", player.getName(), itemRecord.getRecNo(), id);
StoreQueries.createDeleteSellingItem(itemRecord.getRecNo()).build(context).execute();
}
}
inserted.put(itemRecord, stack);
}
this.scheduler.createTaskBuilder().execute(() -> {
for (final Map.Entry<StoreSellingItemRecord, VanillaStack> entry : inserted.entrySet()) {
final StoreSellingItemRecord record = entry.getKey();
final VanillaStack stack = entry.getValue();
final BasicSellingItem item = new BasicSellingItem(record.getRecNo(), record.getCreated().toInstant(), stack.getItem(), stack.getQuantity(), stack.getMetadata(), record.getPrice(), record.getIndex(), stack.getCompound());
store.getSellingItems().add(item);
}
this.network.sendToAll(new ClientboundListItemsResponsePacket(store.getId(), StoreItemSegmentType.SELLING, store.getSellingItems()));
}).submit(this.container);
} catch (final SQLException e) {
e.printStackTrace();
}
}).submit(this.container);
}
Aggregations