private ItemStack[] getIcons() { ItemStack[] icons = new ItemStack[InventoryType.CHEST.getDefaultSize()]; for (PlayerShopOffer offer : shop.getOffers().values()) { icons[offer.getSlot()] = getIcon(offer); } return icons; }
@Override public void onClose(Player player, Inventory inventory) { getSession().end(); PlayerShopsManager.FutureShop futureShop = getSession().getHandler().getShopsManager().release(getSession().getLocation()); if (futureShop != null) { try { PlayerShop shop = futureShop.getShop(); shop.getLock().lock(); try { if (inventory.getViewers().size() < 2) inventory.clear(); } finally { shop.getLock().unlock(); } } catch (ShopDataException e) { e.printStackTrace(); } } else { inventory.clear(); } }
@Override public void onClick(Player player, InventoryClickEvent event) { if (event.getCurrentItem() != null && !event.getCurrentItem().getType().equals(Material.AIR)) { if (event.getRawSlot() <= event.getSlot()) { int slot = event.getSlot(); PlayerShopOffer offer = shop.getOffers().get(slot); if (offer != null) { if (event.isLeftClick()) { if (player.getName().equalsIgnoreCase(shop.getOwnerName())) { handleOfferEdit(player, event, offer); } else { handleTrade(player, event, offer); } } else if (event.isRightClick()) { if (getSession().getPermissionsProvider().has(player, ASPermissionKey.MANAGER)) { handleOfferEdit(player, event, offer); } } } } } }
private ItemStack getSellIcon(PlayerShopOffer offer) { ItemStack icon = new ItemStack(offer.getItem().getItemStack()); icon.setAmount(1); String priceLine = ChatColor.GRAY + getSession().getTranslator().$(ASMessageKey.SHOP_INV_ICON_SELL) + ChatColor.RED + " " + OffersUtils.getFormatedPrice(offer.getPrice()); String amountLine = ChatColor.GRAY + "x" + offer.getItem().getAmount(); String ownerLine = ChatColor.GRAY + shop.getOwnerName(); InventoryUtils.appendLore(icon, priceLine, amountLine, ownerLine); return icon; }
public void updateIcon(int slot) { PlayerShopOffer offer = shop.getOffers().get(slot); if (offer != null) for (PlayerShopOffer o : offer.getItem().getOffers()) inventory.setItem(o.getSlot(), getIcon(o)); }