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 {
        OfflinePlayer player;

        public GUIHolder(OfflinePlayer player) {
            this.player = player;

        public Inventory getInventory() {
            return null;

        public OfflinePlayer getPlayer() {
            return player;

    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 player = ((Player) e.getWhoClicked());
                        OfflinePlayer target = ((GUIHolder) e.getInventory().getHolder()).getPlayer();
    #2 MrWouter, Jul 3, 2017
    Last edited: Jun 28, 2019
    • Like Like x 2
    • 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