1.16.5 Merchant Trade Inventory Click Event

Discussion in 'Spigot Plugin Development' started by Zinc813, Jul 19, 2021 at 6:51 PM.

  1. I made a custom merchant trade inventory.
    How to get which recipe that I selected?
    I already tried InventoryClickEvent#getSlot() but it couldn't get what recipe that I selected.
    Please DONT suggest me about that.

    I also use ProtocolLib for my other plugins, so you can suggest code with it if needed.

    Code (Java):
    Merchant merchant = Bukkit.createMerchant("Shop");
    List<MerchantRecipe> merchantRecipes = new ArrayList<MerchantRecipe>();
    MerchantRecipe recipe = new MerchantRecipe(new ItemStack(Material.DIAMOND_HELMET, 1), 10000);
    recipe.setExperienceReward(false);
    recipe.addIngredient(new ItemStack(Material.EMERALD, 1));
    merchantRecipes.add(recipe);
           
    merchant.setRecipes(merchantRecipes);
           
    player.openMerchant(merchant, true);
     
    #1 Zinc813, Jul 19, 2021 at 6:51 PM
    Last edited: Jul 19, 2021 at 10:21 PM
  2. Get the inventory from the event, cast it to MerchantInventory (if needed, maybe not), then use #getSelectedRecipe to get the recipe the player chose.
     
  3. Thanks for the advice, one more question.

    Then which event that I have to check when I select recipe?

    ex)
    Code (Text):
    recipe1 :
        Emerald x 1 -> Diamond Helmet
    recipe2 :
        Diamond x 1 -> Iron Hemet
    how to check if I chose recipe2?
    not inventoryclickevent, want recipe click event.
     
  4. Thank you for your prompt advice.