InventoryClickEvent not working in certain inventory!

Discussion in 'Plugin Development' started by JPG2000, Sep 19, 2013.

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


    Pre-Note: My whole plugin is working, my listeners are registered and so on. Everything in the events class (this class with the inventory click event) is working as it should, except the the pieces of code Im about to show you. My navigator inventory is also working, so its not there code that does stuff when the back page is clicked.

    My first inventory, is working fine. Everything is fine, untill I select the BackPageItem, and nothing happens. No errors. I've been looking at this for a few days, and I really can't figure out the problem Any help will be appreciated. I am going to give you snippets of code, and not my whole class (read the pre note).

    Here is my onHelpClick method:
    1. @EventHandler
    2. public void onHelpInventoryClick(InventoryClickEvent event) {
    3. if (event.getWhoClicked() instanceof Player) {
    4. Player player = (Player) event.getWhoClicked();
    5. Inventory inventory = event.getInventory();
    6. ItemStack clicked = event.getCurrentItem();
    8. if (inventory.getName().equals(HelpInventory.HelperInventory.getName())) {
    9. if (clicked.equals(HelpInventoryItems.BackPageItem)) {
    10. player.openInventory(NavigatorInventory.NavigatorInventory);
    11. //The open inventory thing above isn't a issue, any code there won't work
    12. }
    13. }
    14. }
    15. }

    Here is my HelpInventory class:
    1. package me.JPG.GameonHubCore.Inventorys;
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.inventory.Inventory;
    7. /**
    8. *
    9. * @Author Jake
    10. */
    11. public class HelpInventory {
    13. public static Inventory HelperInventory = Bukkit.createInventory(null, 18, ChatColor.BOLD.toString() + "Resources and Guides");
    15. static {
    16. HelperInventory.setItem(17, HelpInventoryItems.BackPageItem);
    17. }
    19. }

    And my help inventory items class:
    1. package me.JPG.GameonHubCore.Inventorys;
    3. import java.util.ArrayList;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Material;
    6. import org.bukkit.inventory.ItemStack;
    7. import org.bukkit.inventory.meta.ItemMeta;
    9. /**
    10.  *
    11.  * @Author Jake
    12.  */
    13. public class HelpInventoryItems {
    15. public static ItemStack BackPageItem = new ItemStack(Material.ENDER_PEARL, 1);
    17. static {
    18. ItemMeta BackPageItemMeta = BackPageItem.getItemMeta();
    19. BackPageItemMeta.setDisplayName(ChatColor.DARK_PURPLE + "Back Page");
    20. ArrayList<String> BackPageItemLore = new ArrayList<String>();
    21. BackPageItemLore.add(ChatColor.BLUE + "Go back to the main Navigator inventory!");
    22. BackPageItemMeta.setLore(BackPageItemLore);
    23. BackPageItem.setItemMeta(BackPageItemMeta);
    25. }
    27. }

    I hope you can help, I really can't find any issues; if you need more classes/code feel free to ask!
    - Jake
  2. Offline


    I don't know much about inventories, but maybe you could try closing the help inventory before opening the navigating inventory.
  3. Offline


    DrTURTLE2 I tried. But like I said, it doesnt matter what code I write in that part, the code just wont work.
  4. Offline


    Try adding a message sentto the player between line 9 and line 10 in your onHelpInventoryClicked() method.
  5. Offline


    Janmm14 I did, I added a debug message on every line, its not working. Every other one in that class is though...its very wierd.
  6. Offline


    Try using event.getInventory().getHolder() to check against a player and get the player from.
  7. Offline


    JPG2000 Try adding some debug code that is executed whenever InventoryClickEvent is fired(such as sending a message) to make sure that it isn't just an issue with your if-statements. Also, you shouldn't open a new inventory from InventoryClickEvent. See

    EDIT: I just saw you've already tried this. If you paste your entire plugin code, I'll look over it and test it tonight to see what the issue is.
    1 person likes this.
  8. Offline


    evilmidget38 Thank you so much. With even furthur messing around I found 0 errors, yet it isn't working. I'll message you the plugin.
Thread Status:
Not open for further replies.

Share This Page