Help :| - Inventory

Discussion in 'Plugin Development' started by BitaSmietana, Feb 28, 2015.

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

    BitaSmietana

    I'm new in Writting plugins :p
    I have this code:

    Show Spoiler
    Code:
        public Inventory inv;
        @Override
        public boolean onCommand(CommandSender player, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("vip")){
                player.sendMessage("Otwieram testowe inventory ;)");
               inv = Bukkit.createInventory(null, 9, "Funny Menu");
               inv.setItem(0, new ItemStack(Material.DIAMOND));
                sender.openInventory(inv);
                return true;
            }
         
     
            return false;
        }
    

    "sender cannot be resolved" [line 29: sender.openInventory(inv);]
    What should i do ?

    and sorry for my English if i did some mistakes :)
     
  2. BitaSmietana likes this.
  3. Offline

    BitaSmietana

    @bwfcwalshy
    Ok, sorry
    now
    "Method openInventory(inventory) is undefined for the type CommandSender"
    same line
    Code:
    Show Spoiler
    Code:
        public Inventory inv;
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("vip")){
                sender.sendMessage("Test Inventory opened ;)");
               inv = Bukkit.createInventory(null, 9, "Funny Menu");
               inv.setItem(0, new ItemStack(Material.DIAMOND));
                sender.openInventory(inv);
                return true;
            }
          
      
            return false;
        }
    
     
  4. Offline

    Kassestral

    @BitaSmietana
    Like @bwfcwalshy has said, the variable does not exist, however you should also consider checking the sender has an instance of a Player, otherwise the command will also be executable from console.

    @BitaSmietana

    You must cast your sender variable as a player
    Code:
    Player player = (Player) sender;
     
    BitaSmietana likes this.
  5. Offline

    BitaSmietana

    @Kassestral
    So how i can create this variable, sorry this is my second plugin (if i can name it plugin ^^)

    @edit
    Ok thanks
     
  6. @BitaSmietana In the method arguments change the "CommandSender player" to "CommandSender sender" then check if sender is an instance of a Player and do the cast.
     
Thread Status:
Not open for further replies.

Share This Page