Example #1
0
 /**
  * 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();
   }
 }
Example #2
0
 /**
  * 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.");
   }
 }
Example #3
0
 /**
  * Adds a bulk item to the store.
  *
  * @param item The item to add to the store.
  */
 protected void addItem(Item item) {
   items.add(item);
 }
Example #4
0
 /**
  * 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));
 }
Example #5
0
 /** Refresh the shop for all viewers. */
 public void refresh() {
   for (Player player : players) {
     player.send(new UpdateItemsEvent(3900, items.getItems()));
   }
 }