예제 #1
0
 private ItemStack[] getIcons() {
   ItemStack[] icons = new ItemStack[InventoryType.CHEST.getDefaultSize()];
   for (PlayerShopOffer offer : shop.getOffers().values()) {
     icons[offer.getSlot()] = getIcon(offer);
   }
   return icons;
 }
예제 #2
0
 @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();
   }
 }
예제 #3
0
 @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);
           }
         }
       }
     }
   }
 }
예제 #4
0
 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;
 }
예제 #5
0
 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));
 }