Minigame Shop!

Discussion in 'Plugin Development' started by AlcedoApps, Nov 11, 2018.

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

    AlcedoApps

    Hello, I'm making my own minigame, and I would like to know how to make a shop: When you right-click-air the nether star, the shop will appear (inventory), where you can buy some things for coins (int coins).
    Please help.
     
  2. @AlcedoApps

    You will need to listen for the PlayerInteractEvent and check if the item in the main hand of the player is a nether star and if the event.getAction() will return Action.RIGHT_CLICK_AIR.
    If so, you need to create an inventory menu.
    I will show example code since this is more about Bukkit knowledge than java knowledge:
    Code:
    // null because it has no 'owner'
    // the number (in this case 18) is the number of slots of the menu, must be a multiple of 9
    Inventory menu = Bukkit.createInventory(null, 18, YOUR_INVENTORY_NAME);
    // set the first slot of the menu to a barrier
    menu.setItem(0, new ItemStack(Material.BARRIER));
    // TODO set more items
    player.openInventory(menu);
    
    Then listen to the InventoryClickEvent and check if event.getInventory().getName().equals(YOUR_INVENTORY_NAME)
    Then check event.getCurrentItem() to get the item the player clicked on. If the material is BARRIER, you close the menu.
    You should just check the material the player clicked on and use that to determine what action should happen.
     
Thread Status:
Not open for further replies.

Share This Page