Skip to content

Example: Making shop with SimpleInventories

Misat11 edited this page May 30, 2020 · 2 revisions

Making shop with pure SimpleInventories plugin (Groovy only)

If you want to create a custom shop, there are lot of methods that could help you with it. For this you will need groovy format, because in YAML you can't write any code blocks. Then you will need SimpleInventories-Plugin.

Open your config.yml and put here these informations:

inventories:
  # .. there could be another shops
  shop:
    file: shop.groovy # the file name
    options:
        genericShop: true # this will enable shop callbacks for our inventory
        genericShopPriceTypeRequired: true # this will disable calling shop callback if price type is not specified
/* First we will import needed bukkit API */
import org.bukkit.inventory.ItemStack;
import org.bukkit.Material;

inventory {
    /* Then we will create global buy callback, so all items with price will use it */
    buy {
        /* 
           Inside this callback we can use hasPlayerInInventory, buyStack and sellStack,
           this will help us making an shop
         */
        def currency = new ItemStack(Material.getMaterial(getType()), getPrice())
        if (hasPlayerInInventory(currency)) {
            sellStack(currency)
            buyStack()
        }
    }

    /* Now we can just simply create items with prices */
    item('STONE;2 for 1 DIRT')
    item('IRON_ORE;4 for 5 DIRT')
}
Clone this wiki locally