Making GUI Shop

Discussion in 'Plugin Development' started by jay275475, Sep 5, 2013.

Thread Status:
Not open for further replies.
  1. Offline


    Hey I need Help Make a GUI Shop Can anyone help Me?
  2. Offline


    What do you need help with? Use vault and an inventory?
  3. Offline


    I'm Working on A GUI Shop where you can buy things Ik the Vault Part But I well need Help With the GUI itself
  4. Offline


  5. Offline


    first google result:

    private Menu menu;


    public void onPlayerInteract(PlayerInteractEvent event) {

    if (event.getAction() == Action.RIGHT_CLICK_AIR
    || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    Player p = event.getPlayer();
    if (p.getItemInHand().getType().equals(Material.PAPER)) {
    menu = new Menu(this, p);;

    public class Menu implements Listener {

    private Inventory inv;

    public Menu(Plugin p, Player pl) {
    inv = Bukkit.getServer().createInventory(
    ChatColor.GOLD+ "Shop");

    Bukkit.getServer().getPluginManager().registerEvents(this, p);

    watch the video

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 4, 2016
    PogoStick29 likes this.
  6. Offline


    jay275475 On my server I do it like this. I have two HashMaps, one for items which are buyable and their price and another for items which are sellable and their price and where they're sold.
    public static HashMap<String, Integer> buyPrice = new HashMap<String, Integer>();
        public static HashMap<String, SellItem> sellPrice = new HashMap<String, SellItem>();
    You'll notice that I don't store an integer as the value of sellPrice. Instead I store a constructor

    public class SellItem {
        public int sell_cost;
        public String alternate_name;
        public ItemType type; 
    public SellItem(int sell_cost, ItemType type) {
            this.sell_cost = sell_cost;
            this.type = type;
        public int getSellCost() {
            return this.sell_cost;
        public String getAlternate() {
            return this.alternate_name;
        public ItemType getType() {
            return this.type;
    The ItemType is just an enumeration of all the shops I have which in my case goes like this

        public enum ItemType {
    The reason why I use a constructor in the sellPrice map and not in the buyPrice map is so that people can't sell their items at any shop, they have to be at the correct one. If they're not at the correct shop, it says that the item which they're trying to sell is sold at <item_shop_here>.
    As for creating the inventories MercilessPvP has posted all you need.
  7. Offline


    Thank You guys!

    I have another Question
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent e) {
    3. if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;

    How would I make it a Certain Block Besides Any block?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 4, 2016
  8. Offline


    jay275475 What do you mean? Like this?
    if(event.getClickedBlock().getType() != Material.YOUR_BLOCK)
  9. Offline


    Why Do You Write Like This? It makes it very difficult to read
    Loogeh likes this.
  10. Offline

    CeramicTitan Retired Staff

  11. Offline


  12. Offline


    It's simple. When they interact with an item, cancel the event and create & open a new inventory. Then listen to the InventoryClickEvent and if the inventory has the same name as the inventory you just created, cancel the event, check the item and item's name. If the item and item name are the ones you want, do something in it.
    I've used this in a few of my plugins, and it shouldn't be too hard to make.
  13. Offline


    jay275475 Like kreashenz said its SOOO simple! (PS sorry for not using Java format, on Ipad D:)

    To create:
    Inventory customInv = bukkit.createInventory(null, 9, "My Custom Inv Name!");
    //NOTE: The 9 represents the # of slots, must be a multiple of 9.

    To set items in the Inv:
    customInv.setItem(0, new ItemStack(Material.ENDER_PEARL, 1));
    //NOTE: The 0 represents the slot that the item goes to

    The inv click event:
    public void onClick(InventoryClickEvent event) {
    if (event.getInventory().getName().equalsIgnoreCase(CustomInv.getName()) {
    //Makes it so the code will only work if its in the CustomInv inventory
    ItemStack clicked = event.getCurrentItem();
    //The item that was clicked
    if (clicked.getType() == Material.ENDER_PEARL) {
    //Stops the player from taking the item,

    Thats basicly it. The ony hard part is the inv click event. Remember to show the player first:
  14. Offline


    I always set the display names of items before adding them to the inventory GUI
    And when a player clicks on the item I check to see what the display name is
    Depending on what the display name is, I do.. whatever I want to have happen afterwards
Thread Status:
Not open for further replies.

Share This Page