use of com.almuradev.almura.feature.exchange.network.ClientboundForSaleFilterRequestPacket in project Almura by AlmuraDev.
the class ServerExchangeManager method handleAdjustPriceForSaleItem.
public void handleAdjustPriceForSaleItem(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 adjust a price for a list item for exchange '{}' but the server has no knowledge of it. " + "Syncing exchange registry...", player.getName(), id);
this.syncExchangeRegistryTo(player);
return;
}
final List<ListItem> listItems = axs.getListItemsFor(player.getUniqueId()).orElse(null);
if (listItems == 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 adjust the price for list item '{}' for exchange '{}' but the server has no knowledge " + "of any list items for them. Syncing list items...", player.getName(), listItemRecNo, id);
this.network.sendTo(player, new ClientboundListItemsResponsePacket(axs.getId(), null));
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 adjust the price for list item '{}' for exchange '{}' but the server has no knowledge " + "of it. Syncing list items...", player.getName(), listItemRecNo, id);
this.network.sendTo(player, new ClientboundListItemsResponsePacket(axs.getId(), listItems));
return;
}
final ForSaleItem forSaleItem = found.getForSaleItem().orElse(null);
if (forSaleItem == 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 adjust the price for list item '{}' for exchange '{}' but the server has no knowledge " + "of it being for sale. Syncing list items...", player.getName(), listItemRecNo, id);
this.network.sendTo(player, new ClientboundListItemsResponsePacket(axs.getId(), listItems));
this.network.sendTo(player, new ClientboundListItemsSaleStatusPacket(axs.getId(), axs.getForSaleItemsFor(player.getUniqueId()).orElse(null), null));
return;
}
this.scheduler.createTaskBuilder().async().execute(() -> {
try (final DSLContext context = this.databaseManager.createContext(true)) {
final int result = ExchangeQueries.createUpdateForSaleItemPrice(forSaleItem.getRecord(), price).build(context).execute();
if (result == 0) {
this.logger.error("Player '{}' attempted to adjust the price for list item '{}' for exchange '{}' to the database but it " + "failed. Discarding changes...", player.getName(), listItemRecNo, id);
return;
}
ExchangeQueries.createUpdateListItemLastKnownPrice(found.getRecord(), forSaleItem.getPrice()).build(context).execute();
this.scheduler.createTaskBuilder().execute(() -> {
found.setLastKnownPrice(forSaleItem.getPrice());
((BasicForSaleItem) forSaleItem).setPrice(price);
this.network.sendTo(player, new ClientboundListItemsSaleStatusPacket(axs.getId(), axs.getForSaleItemsFor(player.getUniqueId()).orElse(null), Lists.newArrayList(found)));
this.network.sendToAll(new ClientboundForSaleFilterRequestPacket(axs.getId()));
}).submit(this.container);
} catch (SQLException e) {
e.printStackTrace();
}
}).submit(this.container);
}
use of com.almuradev.almura.feature.exchange.network.ClientboundForSaleFilterRequestPacket in project Almura by AlmuraDev.
the class ServerExchangeManager method openExchangeSpecific.
void openExchangeSpecific(final Player player, final Exchange axs) {
checkNotNull(player);
checkNotNull(axs);
if (!player.hasPermission(axs.getPermission())) {
this.notificationManager.sendPopupNotification(player, Text.of(TextColors.RED, "Exchange"), Text.of("You do not have permission " + "to open this exchange!"), 5);
return;
}
this.network.sendTo(player, new ClientboundExchangeGuiResponsePacket(ExchangeGuiType.SPECIFIC, axs.getId(), this.getListingsLimit(player)));
if (!axs.isLoaded()) {
this.playerSpecificInitiatorIds.add(player.getUniqueId());
this.databaseManager.getQueue().queue(DatabaseQueue.ActionType.FETCH_IGNORE_DUPLICATES, axs.getId(), () -> {
this.loadListItems(axs);
this.loadForSaleItems(axs);
this.scheduler.createTaskBuilder().execute(() -> {
axs.setLoaded(true);
final Iterator<UUID> iter = this.playerSpecificInitiatorIds.iterator();
while (iter.hasNext()) {
final UUID uniqueId = iter.next();
iter.remove();
final Player p = Sponge.getServer().getPlayer(uniqueId).orElse(null);
if (p != null && p.isOnline() && !p.isRemoved()) {
final List<ListItem> listItems = axs.getListItemsFor(p.getUniqueId()).orElse(null);
this.network.sendTo(p, new ClientboundListItemsResponsePacket(axs.getId(), listItems));
if (listItems != null && !listItems.isEmpty()) {
final List<ForSaleItem> forSaleItems = axs.getForSaleItemsFor(p.getUniqueId()).orElse(null);
if (forSaleItems != null && !forSaleItems.isEmpty()) {
this.network.sendTo(p, new ClientboundListItemsSaleStatusPacket(axs.getId(), forSaleItems, null));
}
}
this.network.sendTo(p, new ClientboundForSaleFilterRequestPacket(axs.getId()));
}
}
}).submit(this.container);
});
} else {
final List<ListItem> listItems = axs.getListItemsFor(player.getUniqueId()).orElse(null);
this.network.sendTo(player, new ClientboundListItemsResponsePacket(axs.getId(), listItems));
if (listItems != null && !listItems.isEmpty()) {
final List<ForSaleItem> forSaleItems = axs.getForSaleItemsFor(player.getUniqueId()).orElse(null);
if (forSaleItems != null && !forSaleItems.isEmpty()) {
this.network.sendTo(player, new ClientboundListItemsSaleStatusPacket(axs.getId(), forSaleItems, null));
}
}
this.network.sendTo(player, new ClientboundForSaleFilterRequestPacket(axs.getId()));
}
}
use of com.almuradev.almura.feature.exchange.network.ClientboundForSaleFilterRequestPacket in project Almura by AlmuraDev.
the class ServerExchangeManager method handleModifyListItems.
public void handleModifyListItems(final Player player, final String id, final List<InventoryAction> actions) {
checkNotNull(player);
checkNotNull(id);
checkNotNull(actions);
checkState(!actions.isEmpty());
final Exchange axs = this.getExchange(id).orElse(null);
if (axs == null) {
this.logger.error("Player '{}' attempted to list items for exchange '{}' but the server has no knowledge of it. Syncing exchange " + "registry...", player.getName(), id);
this.syncExchangeRegistryTo(player);
return;
}
final UUID seller = player.getUniqueId();
final EntityPlayerMP serverPlayer = (EntityPlayerMP) player;
final IItemHandler simulatedInventory = serverPlayer.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
// Inventory -> Listing
final List<InventoryAction> toListingActions = actions.stream().filter(a -> a.getDirection() == InventoryAction.Direction.TO_LISTING).collect(Collectors.toList());
final List<VanillaStack> toListingStacks = new ArrayList<>();
final List<VanillaStack> unknownInventoryStacks = new ArrayList<>();
final List<VanillaStack> leftoverToListingStacks = new ArrayList<>();
for (InventoryAction toListingAction : toListingActions) {
final VanillaStack stack = toListingAction.getStack();
int amountLeft = stack.getQuantity();
boolean matched = false;
for (int j = 0; j < simulatedInventory.getSlots(); j++) {
final ItemStack slotStack = simulatedInventory.getStackInSlot(j);
if (ItemHandlerHelper.canItemStacksStack(slotStack, stack.asRealStack())) {
amountLeft -= simulatedInventory.extractItem(j, amountLeft, false).getCount();
matched = true;
}
if (amountLeft <= 0) {
break;
}
}
if (!matched) {
unknownInventoryStacks.add(stack);
} else {
if (amountLeft > 0) {
final VanillaStack copyStack = stack.copy();
copyStack.setQuantity(amountLeft);
leftoverToListingStacks.add(copyStack);
}
final VanillaStack copyStack = stack.copy();
copyStack.setQuantity(stack.getQuantity() - amountLeft);
if (copyStack.getQuantity() != 0) {
toListingStacks.add(copyStack);
}
}
}
// Listing -> Inventory
final List<InventoryAction> toInventoryActions = actions.stream().filter(a -> a.getDirection() == InventoryAction.Direction.TO_INVENTORY).collect(Collectors.toList());
final List<VanillaStack> listingNotFoundStacks = new ArrayList<>();
final List<ListItem> desyncToInventoryStacks = new ArrayList<>();
final List<ListItem> toInventoryStacks = new ArrayList<>();
final List<ListItem> partialToInventoryStacks = new ArrayList<>();
final List<ListItem> currentListItems = axs.getListItemsFor(player.getUniqueId()).orElse(null);
if (!toInventoryActions.isEmpty()) {
if (currentListItems == null || currentListItems.isEmpty()) {
this.logger.error("Player '{}' attempted to move listings back to the inventory for exchange '{}' but the server knows of no " + "listings for them. This could be a de-sync or an exploit. Printing stacks...", player.getName(), axs.getId());
this.network.sendTo(player, new ClientboundListItemsResponsePacket(axs.getId(), null));
this.printStacksToConsole(toInventoryActions.stream().map(InventoryAction::getStack).collect(Collectors.toList()));
} else {
for (final InventoryAction action : toInventoryActions) {
final VanillaStack stack = action.getStack();
ListItem found = null;
for (final ListItem listItem : currentListItems) {
if (ItemHandlerHelper.canItemStacksStack(stack.asRealStack(), listItem.asRealStack())) {
found = listItem;
break;
}
}
// Unknown listing
if (found == null) {
listingNotFoundStacks.add(stack);
continue;
}
ListItem toRemove = found.copy();
// Listing quantity mismatch (tracking this to let the user know)
if (found.getQuantity() < stack.getQuantity()) {
desyncToInventoryStacks.add(found);
toRemove.setQuantity(found.getQuantity());
} else {
toRemove.setQuantity(stack.getQuantity());
}
final ItemStack resultStack = ItemHandlerHelper.insertItemStacked(simulatedInventory, toRemove.asRealStack(), true);
// Simulated a partial stack insertion
if (!resultStack.isEmpty()) {
final ListItem copyStack = toRemove.copy();
copyStack.setQuantity(resultStack.getCount());
partialToInventoryStacks.add(copyStack);
}
final ListItem copyStack = toRemove.copy();
copyStack.setQuantity(toRemove.getQuantity() - resultStack.getCount());
toInventoryStacks.add(copyStack);
}
}
}
// This may seem quite weird but we need to clear out the listing items reference for this player across the board to await what the results
// are from the database to ensure we're 1:1 in sync. Otherwise, the Exchange would keep selling..
axs.putListItemsFor(seller, null);
axs.putForSaleItemsFor(seller, null);
Sponge.getServer().getOnlinePlayers().stream().filter(p -> p.getUniqueId() != seller).forEach(p -> this.network.sendTo(p, new ClientboundForSaleFilterRequestPacket(axs.getId())));
this.scheduler.createTaskBuilder().async().execute(() -> {
try (final DSLContext context = this.databaseManager.createContext(true)) {
final Iterator<VanillaStack> listingIter = toListingStacks.iterator();
int index = 0;
// New listing
while (listingIter.hasNext()) {
final VanillaStack stack = listingIter.next();
final ItemStack realStack = stack.asRealStack();
ListItem found = null;
if (currentListItems != null) {
found = currentListItems.stream().filter(item -> ItemHandlerHelper.canItemStacksStack(realStack, item.asRealStack())).findAny().orElse(null);
}
if (found == null) {
final AxsListItemRecord itemRecord = ExchangeQueries.createInsertListItem(axs.getId(), Instant.now(), seller, realStack.getItem(), stack.getQuantity(), realStack.getMetadata(), index).build(context).fetchOne();
if (itemRecord == null) {
this.notificationManager.sendWindowMessage(player, Text.of("Exchange"), Text.of("Critical error encountered, check the server console for more details!"));
this.logger.error("Player '{}' submitted a new list item for exchange '{}' 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) {
continue;
}
final AxsListItemDataRecord dataRecord = ExchangeQueries.createInsertItemData(itemRecord.getRecNo(), compound).build(context).fetchOne();
if (dataRecord == null) {
this.notificationManager.sendWindowMessage(player, Text.of("Exchange"), Text.of("Critical error encountered, check the server console for more details!"));
this.logger.error("Player '{}' submitted data for item record '{}' for exchange '{}' but it failed. " + "Discarding changes...", player.getName(), itemRecord.getRecNo(), id);
ExchangeQueries.createDeleteListItem(itemRecord.getRecNo()).build(context).execute();
}
} else {
final int result = ExchangeQueries.createUpdateListItem(found.getRecord(), stack.getQuantity() + found.getQuantity(), index).build(context).execute();
if (result == 0) {
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 add quantity to list item '{}' for exchange '{}' but it failed. " + "Discarding changes...", player.getName(), found.getRecord(), id);
listingIter.remove();
}
}
index++;
}
for (final ListItem next : toInventoryStacks) {
ListItem existingStack = null;
for (final ListItem stack : currentListItems) {
if (next.getRecord() == stack.getRecord()) {
existingStack = stack;
break;
}
}
final int diff = existingStack.getQuantity() - next.getQuantity();
if (diff == 0) {
final int result = ExchangeQueries.createUpdateListItemIsHidden(next.getRecord(), true).build(context).execute();
if (result == 0) {
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 remove list item '{}' for exchange '{}' but it failed. Discarding " + "changes...", player.getName(), next.getRecord(), id);
}
// Update partial listings
} else {
final int result = ExchangeQueries.createUpdateListItem(next.getRecord(), diff, next.getIndex()).build(context).execute();
if (result == 0) {
this.notificationManager.sendWindowMessage(player, Text.of("Exchange"), Text.of("Critical error encountered, check the server console for more details!"));
this.logger.error("Player '{}' removed quantity from list item '{}' for exchange '{}' to the database but it " + "failed. Discarding changes...", player.getName(), next.getRecord(), id);
}
}
}
final Results listItemResults = ExchangeQueries.createFetchListItemsAndDataFor(seller, false).build(context).keepStatement(false).fetchMany();
final Results forSaleItemResults = ExchangeQueries.createFetchForSaleItemsFor(seller, false).build(context).keepStatement(false).fetchMany();
this.scheduler.createTaskBuilder().execute(() -> {
final Player sellerPlayer = Sponge.getServer().getPlayer(seller).orElse(null);
if (sellerPlayer != null) {
final IItemHandler inventory = ((EntityPlayerMP) sellerPlayer).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
// Add stacks from listings
for (final ListItem stack : toInventoryStacks) {
final ItemStack resultStack = ItemHandlerHelper.insertItemStacked(inventory, stack.asRealStack(), false);
if (!resultStack.isEmpty()) {
// TODO Their inventory changed since simulation. Best case scenario we toss it on the ground
}
}
} else {
// TODO They went offline on us. It is a very rare off-case. Half tempted to print what they should have got and let
// TODO an admin deal with it
}
final List<ListItem> listItems = new ArrayList<>();
listItemResults.forEach(result -> listItems.addAll(this.parseListItemsFrom(result)));
final List<ForSaleItem> forSaleItems = new ArrayList<>();
forSaleItemResults.forEach(result -> forSaleItems.addAll(this.parseForSaleItemsFrom(listItems, result)));
// TODO Build a notification that says...
// TODO - Stacks requested to go to a listing but inventory can't fulfill it
// TODO - Stacks requested to go to the inventory but listings aren't found
// TODO - Stacks requested to go to the inventory but the listing couldn't fulfill it so we took what we could
axs.putListItemsFor(seller, listItems);
axs.putForSaleItemsFor(seller, forSaleItems);
if (sellerPlayer != null) {
this.network.sendTo(sellerPlayer, new ClientboundListItemsResponsePacket(axs.getId(), listItems));
this.network.sendTo(sellerPlayer, new ClientboundListItemsSaleStatusPacket(axs.getId(), forSaleItems, null));
}
Sponge.getServer().getOnlinePlayers().forEach(p -> this.network.sendTo(p, new ClientboundForSaleFilterRequestPacket(axs.getId())));
}).submit(this.container);
} catch (SQLException | IOException e) {
e.printStackTrace();
}
}).submit(this.container);
}
use of com.almuradev.almura.feature.exchange.network.ClientboundForSaleFilterRequestPacket 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);
}
use of com.almuradev.almura.feature.exchange.network.ClientboundForSaleFilterRequestPacket in project Almura by AlmuraDev.
the class ServerExchangeManager method handleDelistForSaleItem.
public void handleDelistForSaleItem(final Player player, final String id, final int listItemRecNo) {
checkNotNull(player);
checkNotNull(id);
checkState(listItemRecNo >= 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 de-list list item '{}' for exchange '{}' but the server has no knowledge of it. 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 de-list list item '{}' 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 de-list list item '{}' 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 ForSaleItem forSaleItem = found.getForSaleItem().orElse(null);
final List<ForSaleItem> forSaleItems = axs.getForSaleItemsFor(player.getUniqueId()).orElse(null);
if (forSaleItem == 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 de-list list item '{}' for exchange '{}' but the server doesn't have 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) {
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 de-list list item '{}' for exchange '{}' but the server has no record of any listings for " + "that player. Syncing list items sale status...", player.getName(), listItemRecNo, id);
this.network.sendTo(player, new ClientboundListItemsSaleStatusPacket(id, null, null));
return;
}
this.scheduler.createTaskBuilder().async().execute(() -> {
try (final DSLContext context = this.databaseManager.createContext(true)) {
final int result = ExchangeQueries.createUpdateForSaleItemIsHidden(forSaleItem.getRecord(), true).build(context).keepStatement(false).execute();
if (result == 0) {
this.logger.error("Player '{}' attempted to de-list list item '{}' for exchange '{}' to the database but it failed. " + "Discarding changes...", player.getName(), listItemRecNo, id);
return;
}
ExchangeQueries.createUpdateListItemLastKnownPrice(listItemRecNo, forSaleItem.getPrice()).build(context).execute();
this.scheduler.createTaskBuilder().execute(() -> {
found.setLastKnownPrice(forSaleItem.getPrice());
forSaleItems.remove(forSaleItem);
found.setForSaleItem(null);
this.network.sendTo(player, new ClientboundListItemsSaleStatusPacket(axs.getId(), forSaleItems, Lists.newArrayList(found)));
this.network.sendToAll(new ClientboundForSaleFilterRequestPacket(axs.getId()));
}).submit(this.container);
} catch (SQLException e) {
e.printStackTrace();
}
}).submit(this.container);
}
Aggregations