Solved Access a custom inventory across class

Discussion in 'Spigot Plugin Development' started by Ohwnead, May 20, 2018.

  1. Hey,
    I try to create an custom inventory per class, and in one class (EventClick class) open it for a player.
    I already have my inventory,
    Code (Java):
    Menu = Bukkit.createInventory(null, InventoryType.HOPPER, "§6Menu");
    but I can't acces it in another class
    I'hve try to import class, cast it as class, ... but nothing work, I don't know if I fail, or if I miss something like public variable :s

    On other forum code is very old and don't work now.
    thanks for help
  2. [​IMG]

    Yeah. Sorry. Had to put that there.
    • Agree Agree x 1
  3. You would have to pass the created inventory or the class instance containing it to the listener class where you want to use it, through the constructor or maybe by creating a new instance of your custom gui class right in the listener.
    If that sentence doesn't help and seems cryptical to you... You should follow the advice @tassu gave you. Please learn the Java basics before you start with Spigot programming.
  4. Ok it's good, it's seem cryptical for me just because you'r english x)
    but I know what I'hve miss (I'think so I don't close the post)
  5. It's good thanks

    I'know Java, but the method is use is deprecated, and not best, I use now :
    Code (Text):
    Inventory inventory = Menu.InvMenu();

        public void onInventoryClick(InventoryClickEvent e)

    Code (Java):
    public static Inventory InvMenu()
            Inventory Menu = Bukkit.createInventory(null, InventoryType.HOPPER, "§6Menu§f, " + /*PlayerCFG.getString("Info.Player.Argent") +*/ " Or");
            createDisplay(Material.ARMOR_STAND, Menu, 0, "§6Personnage", "§7Augmentez vos §fcaractéristique §7et §fsorts");
            createDisplay(Material.BOOK, Menu, 1, "§6Quêtes", "§7Affiches vos §fquêtes");
            createDisplay(Material.DRAGONS_BREATH, Menu, 2, "§6Potion de téléportation", "§7Vous §ftéléporte§7 à la §fdernière ville §fvisité");
            createDisplay(Material.NAME_TAG, Menu, 3, "§6Paramètres", "§7Ouvre vos §fParamètres");
            createDisplay(Material.BARRIER, Menu, 4, "§6Fermer", "§fFerme le menu §7actuel");
            return Menu;