Solved Inventorys

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

Thread Status:
Not open for further replies.
  1. 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

    KarimAKL

    @PhilDEV_Acc You should create an inventory like this:
    Code:Java
    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:
    Code:Java
    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. Ok I coded the Inventory but it doesnt work. Here code:
    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 {
    
    
        @EventHandler
        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)");
                    ClanLounge.setItemMeta(metaData2);
                    //Clan Lounge Ende
                    inv.setItem(0, ClanLounge);
                    spieler.openInventory(inv);
                }
            }
        }
    }
    
    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

    KarimAKL

    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. Yes I did thanks for helping
     
    KarimAKL likes this.
Thread Status:
Not open for further replies.

Share This Page