Solved Inventorys

Discussion in 'Plugin Development' started by PhilDEV_Acc, Jan 6, 2020.

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


    Hello probably @timtower ,;)

    I want to create a Compass so when you right click it it opens a Menu. My question is how can I create an own Inventory for the compass?

    I got the Rightclick event signed.
  2. Offline


    @PhilDEV_Acc You should create an inventory like this:
    1. InventoryHolder holder = null; // The owner of the inventory, this can just be null.
    2. int rows = 6; // The amount of rows in the inventory (can be 1 to 6). We're doing it like this because it has to be a multiple of 9
    3. String title = "Menu Title"; // This is the name of the inventory (the text at the top left).
    4. Inventory inventory = Bukkit.createInventory(holder, 9 * rows, title);

    Then you just open that inventory with this:
    1. Player player = ...; // Your player
    2. player.openInventory(inventory); // "inventory" being the variable we made before

    You then use the InventoryClickEvent to listen for the clicks in the inventory.
  3. Offline


    Ok I coded the Inventory but it doesnt work. Here code:
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.InventoryHolder;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    public class RechtklickListner implements Listener {
        public void onEvent(PlayerInteractEvent event) {
            Player spieler = event.getPlayer();
            Action rechtcklick = event.getAction();
            if(rechtcklick == Action.RIGHT_CLICK_AIR || rechtcklick == Action.RIGHT_CLICK_BLOCK) {
            ItemStack gegenstand = event.getItem();
            ItemMeta metaData = gegenstand.getItemMeta();
                if(metaData.getDisplayName().equals(ChatColor.MAGIC + "a" + ChatColor.DARK_BLUE + "Lobby Teleporter" + ChatColor.WHITE + ChatColor.MAGIC + "a")) {
                    InventoryHolder holder = null;
                    int rows = 20;
                    String title = "Lobby Menu";
                    Inventory inv = Bukkit.createInventory(holder, rows, title);
                    //Clan Lounge
                    ItemStack ClanLounge = new ItemStack(Material.RED_BANNER);
                    ItemMeta metaData2 = ClanLounge.getItemMeta();
                    metaData.setDisplayName(ChatColor.DARK_RED + "Clan Lounge " + ChatColor.GRAY + "(Rechtklick)");
                    //Clan Lounge Ende
                    inv.setItem(0, ClanLounge);
    The Inventory doesnt even Open

    oh I just realized 6 is not a multiple of 9

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
  4. Offline


    Haha, that's why i recommended multiplying the amount of rows you want (from 1 to 6) by 9.

    Did you get everything working?
  5. Offline


    Yes I did thanks for helping
    KarimAKL likes this.
Thread Status:
Not open for further replies.

Share This Page