player.openInventory help

Discussion in 'Plugin Development' started by epicmeanscookies, Jun 18, 2014.

Thread Status:
Not open for further replies.
  1. ok first of i am new to java + bukkit. when i was making a command to open my custom inventory it just gives me a error on
    heres the rest of the code

    package com.epicmeanscookies.magewars.inv;
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.HumanEntity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    public class Kitinv {
        public static Inventory kits = Bukkit.createInventory(null, 9, "Kit Selector");
        static {
            kits.setItem(0, new ItemStack(Material.STICK, 1));
            kits.setItem(3, new ItemStack(Material.BOW, 1));
        public void onInventoryClick(InventoryClickEvent event) {
            Player player = (Player) event.getWhoClicked();
            ItemStack clicked = event.getCurrentItem();
            Inventory inventory = event.getInventory();
            if (inventory.getName().equals(kits.getName())) {
                if (clicked.getType() == Material.STICK);
                player.getInventory().addItem(new ItemStack(Material.STICK, 1));
                public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
                    if(cmd.getName().equalsIgnoreCase("kit")) {
                        return true;
  2. Offline


    Is that your entire code? Theres no where in that code that is actually making the inventory "kits"

    In your onCommand you need
    Player player = (Player) sender; so that it knows player.openInventory is referring to the player who sent the command.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 8, 2016
  3. Offline


    PM me if you have anymore issues. I like working with inventory's! :D
  4. Offline


    Nothing there needs to be static. Do not use the static keyword unless you actually know what it's for and how to use it.
Thread Status:
Not open for further replies.

Share This Page