Search in sources :

Example 1 with ClientboundExchangeGuiResponsePacket

use of com.almuradev.almura.feature.exchange.network.ClientboundExchangeGuiResponsePacket 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()));
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) BasicForSaleItem(com.almuradev.almura.feature.exchange.basic.listing.BasicForSaleItem) AxsForSaleItem(com.almuradev.generated.axs.tables.AxsForSaleItem) ForSaleItem(com.almuradev.almura.feature.exchange.listing.ForSaleItem) ClientboundExchangeGuiResponsePacket(com.almuradev.almura.feature.exchange.network.ClientboundExchangeGuiResponsePacket) Iterator(java.util.Iterator) ClientboundForSaleFilterRequestPacket(com.almuradev.almura.feature.exchange.network.ClientboundForSaleFilterRequestPacket) ClientboundListItemsResponsePacket(com.almuradev.almura.feature.exchange.network.ClientboundListItemsResponsePacket) ClientboundListItemsSaleStatusPacket(com.almuradev.almura.feature.exchange.network.ClientboundListItemsSaleStatusPacket) List(java.util.List) ArrayList(java.util.ArrayList) AxsListItem(com.almuradev.generated.axs.tables.AxsListItem) BasicListItem(com.almuradev.almura.feature.exchange.basic.listing.BasicListItem) ListItem(com.almuradev.almura.feature.exchange.listing.ListItem) UUID(java.util.UUID)

Example 2 with ClientboundExchangeGuiResponsePacket

use of com.almuradev.almura.feature.exchange.network.ClientboundExchangeGuiResponsePacket in project Almura by AlmuraDev.

the class ServerExchangeManager method handleExchangeSpecificOffer.

public void handleExchangeSpecificOffer(final Player player, final String id) {
    checkNotNull(player);
    checkNotNull(id);
    final Exchange axs = this.getExchange(id).orElse(null);
    if (axs == null) {
        this.logger.error("Player '{}' attempted to open an offer screen for exchange '{}' but the server has no knowledge of it. Syncing " + "exchange registry...", player.getName(), id);
        this.syncExchangeRegistryTo(player);
        return;
    }
    this.network.sendTo(player, new ClientboundExchangeGuiResponsePacket(ExchangeGuiType.SPECIFIC_OFFER, id));
}
Also used : BasicExchange(com.almuradev.almura.feature.exchange.basic.BasicExchange) ClientboundExchangeGuiResponsePacket(com.almuradev.almura.feature.exchange.network.ClientboundExchangeGuiResponsePacket)

Example 3 with ClientboundExchangeGuiResponsePacket

use of com.almuradev.almura.feature.exchange.network.ClientboundExchangeGuiResponsePacket in project Almura by AlmuraDev.

the class ServerExchangeManager method openExchangeManage.

void openExchangeManage(final Player player) {
    checkNotNull(player);
    if (!player.hasPermission(Almura.ID + ".exchange.admin")) {
        this.notificationManager.sendPopupNotification(player, Text.of(TextColors.RED, "Exchange"), Text.of("You do not have permission " + "to manage exchanges!"), 5);
        return;
    }
    this.network.sendTo(player, new ClientboundExchangeGuiResponsePacket(ExchangeGuiType.MANAGE));
}
Also used : ClientboundExchangeGuiResponsePacket(com.almuradev.almura.feature.exchange.network.ClientboundExchangeGuiResponsePacket)

Aggregations

ClientboundExchangeGuiResponsePacket (com.almuradev.almura.feature.exchange.network.ClientboundExchangeGuiResponsePacket)3 BasicExchange (com.almuradev.almura.feature.exchange.basic.BasicExchange)1 BasicForSaleItem (com.almuradev.almura.feature.exchange.basic.listing.BasicForSaleItem)1 BasicListItem (com.almuradev.almura.feature.exchange.basic.listing.BasicListItem)1 ForSaleItem (com.almuradev.almura.feature.exchange.listing.ForSaleItem)1 ListItem (com.almuradev.almura.feature.exchange.listing.ListItem)1 ClientboundForSaleFilterRequestPacket (com.almuradev.almura.feature.exchange.network.ClientboundForSaleFilterRequestPacket)1 ClientboundListItemsResponsePacket (com.almuradev.almura.feature.exchange.network.ClientboundListItemsResponsePacket)1 ClientboundListItemsSaleStatusPacket (com.almuradev.almura.feature.exchange.network.ClientboundListItemsSaleStatusPacket)1 AxsForSaleItem (com.almuradev.generated.axs.tables.AxsForSaleItem)1 AxsListItem (com.almuradev.generated.axs.tables.AxsListItem)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 UUID (java.util.UUID)1 Player (org.spongepowered.api.entity.living.player.Player)1