/** * Buys a item from the store. * * @param player The player. * @param item The item to buy. */ public void buyItem(Player player, SlottedItem item) { if (player.getInventory().freeSlots() >= item.getItem().getAmount()) { if (payment.buyItem(player, item)) { player.getInventory().add(item.getItem()); player.send(new UpdateItemsEvent(3823, player.getInventory().getItems())); if (!type.equals(ShopType.UNLIMITED_BUY_ONLY)) { items.remove(item.getItem()); } } } else { player.getInventory().forceCapacityExceeded(); } }
/** * Sells a item to the store. * * @param player The player that is selling this item. * @param slot The item slot. * @param item The item. */ public void sellItem(Player player, Item item) { if (type.equals(ShopType.BUY_AND_SELL)) { if (player.getInventory().contains(item)) { if (payment.sellItem(player, item)) { player.getInventory().remove(item); player.send(new UpdateItemsEvent(3823, player.getInventory().getItems())); items.add(item); } } } else { player.sendMessage("You cannot sell items in this shop."); } }
/** * Adds a bulk item to the store. * * @param item The item to add to the store. */ protected void addItem(Item item) { items.add(item); }
/** * Create a new shop. * * @param name The shop name. * @param type The shop type. */ public Shop(String name, ShopType type) { this.name = name; this.type = type; items.addListener(new ShopAmountChangedListener(this)); }
/** Refresh the shop for all viewers. */ public void refresh() { for (Player player : players) { player.send(new UpdateItemsEvent(3900, items.getItems())); } }