Solved Custom InventoryHolders

Discussion in 'Spigot Plugin Development' started by TheMelvin, Jul 3, 2017.

  1. Hi,

    For my plugin I need to identify which inventory is clicked by the player, I can use inventory titles and check if the title equals the title I need. But because I have a lot of inventories with the same name, that's not an option. So I thought about custom InventoryHolders, but how can I make them? I then want to access them with for example:
    Code (Text):
    Inventory inv = Bukkit.createInventory(InvHolders.MyCustomInvHolder, 27, "Inventory Title");
  2. Code (Text):

    package me.wouter.ResetGUI;

    import org.bukkit.OfflinePlayer;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.InventoryHolder;

    public class GUIHolder implements InventoryHolder {

        Inventory inv;
        OfflinePlayer p;

        public GUIHolder(OfflinePlayer target) {
            this.p = target;

        public Inventory getInventory() {
            return inv;

        public OfflinePlayer getPlayer() {
            return p;

    This is the code i'm using to save an offlineplayer as inventoryholder. Example how I use it.
    Code (Text):
            Inventory inv = Bukkit.createInventory(new GUIHolder(target), 9, "§3Reset menu van " + target.getName());
    Code (Text):

                    if (e.getInventory().getHolder() != null && e.getInventory().getHolder() instanceof GUIHolder) {
                        Player p = ((Player) e.getWhoClicked());
                        OfflinePlayer p2 = ((GUIHolder) e.getInventory().getHolder()).getPlayer();
    • Like Like x 1
    • Agree Agree x 1
  3. Thanks it works now! But I changed one thing, instead of using OfflinePlayers to identify the inventory I used enums.
  4. Yeah sure, this is my code i used for using offlineplayers as inventoryholders ^-^

    Mark the thread as solved :p
  5. This help me a lot thanks
    • Winner Winner x 1

Share This Page