Search in sources :

Example 1 with ClientboundStoreGuiResponsePacket

use of com.almuradev.almura.feature.store.network.ClientboundStoreGuiResponsePacket in project Almura by AlmuraDev.

the class ServerStoreManager method openStoreSpecific.

void openStoreSpecific(final Player player, final Store store) {
    checkNotNull(player);
    checkNotNull(store);
    if (!player.hasPermission(store.getPermission())) {
        this.notificationManager.sendPopupNotification(player, Text.of(TextColors.RED, "Store"), Text.of("You do not have permission " + "to open this store!"), 5);
        return;
    }
    this.network.sendTo(player, new ClientboundStoreGuiResponsePacket(StoreGuiType.SPECIFIC, store.getId(), player.hasPermission(Almura.ID + ".store.admin")));
    if (!store.isLoaded()) {
        this.playerSpecificInitiatorIds.add(player.getUniqueId());
        this.databaseManager.getQueue().queue(DatabaseQueue.ActionType.FETCH_IGNORE_DUPLICATES, store.getId(), () -> {
            this.loadSellingItems(store);
            this.loadBuyingItems(store);
            this.scheduler.createTaskBuilder().execute(() -> {
                store.setLoaded(true);
                final Iterator<UUID> iterator = this.playerSpecificInitiatorIds.iterator();
                while (iterator.hasNext()) {
                    final UUID uniqueId = iterator.next();
                    iterator.remove();
                    final Player p = Sponge.getServer().getPlayer(uniqueId).orElse(null);
                    if (p != null && p.isOnline() && !p.isRemoved()) {
                        this.network.sendTo(p, new ClientboundListItemsResponsePacket(store.getId(), StoreItemSegmentType.BUYING, store.getBuyingItems()));
                        this.network.sendTo(p, new ClientboundListItemsResponsePacket(store.getId(), StoreItemSegmentType.SELLING, store.getSellingItems()));
                    }
                }
            }).submit(this.container);
        });
    } else {
        this.network.sendTo(player, new ClientboundListItemsResponsePacket(store.getId(), StoreItemSegmentType.SELLING, store.getSellingItems()));
        this.network.sendTo(player, new ClientboundListItemsResponsePacket(store.getId(), StoreItemSegmentType.BUYING, store.getBuyingItems()));
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) Iterator(java.util.Iterator) ClientboundStoreGuiResponsePacket(com.almuradev.almura.feature.store.network.ClientboundStoreGuiResponsePacket) ClientboundListItemsResponsePacket(com.almuradev.almura.feature.store.network.ClientboundListItemsResponsePacket) UUID(java.util.UUID)

Example 2 with ClientboundStoreGuiResponsePacket

use of com.almuradev.almura.feature.store.network.ClientboundStoreGuiResponsePacket in project Almura by AlmuraDev.

the class ServerStoreManager method openStoreManage.

public void openStoreManage(final Player player) {
    checkNotNull(player);
    if (!player.hasPermission(Almura.ID + ".store.admin")) {
        this.notificationManager.sendPopupNotification(player, Text.of(TextColors.RED, "Store"), Text.of("You do not have permission " + "to manage stores!"), 5);
        return;
    }
    this.network.sendTo(player, new ClientboundStoreGuiResponsePacket(StoreGuiType.MANAGE));
}
Also used : ClientboundStoreGuiResponsePacket(com.almuradev.almura.feature.store.network.ClientboundStoreGuiResponsePacket)

Aggregations

ClientboundStoreGuiResponsePacket (com.almuradev.almura.feature.store.network.ClientboundStoreGuiResponsePacket)2 ClientboundListItemsResponsePacket (com.almuradev.almura.feature.store.network.ClientboundListItemsResponsePacket)1 Iterator (java.util.Iterator)1 UUID (java.util.UUID)1 Player (org.spongepowered.api.entity.living.player.Player)1