Kit plugin

Discussion in 'Plugin Development' started by Epixel, May 3, 2016.

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

    Epixel

    I get an error saying : The method addItem(ItemStack[]) in the type Inventory is not applicable for the arguments (ItemStack, ItemStack)

    The error comes from the word "addItem" which I made in a big font so you can see.

    When I try to make a kit plugin. This is what it looks like (currently) :

    Code:
    
    public class pvp implements CommandExecutor {
    
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
                String[] args) {
            if (!(sender instanceof Player)) {
                sender.sendMessage("You need to be a player to execute this command");
                return false;
                }
           
            if(commandLabel.equalsIgnoreCase("pvp")){
           
            Player player = (Player) sender;
            PlayerInventory inv = player.getInventory();
           
            inv.clear();
           
            ItemStack diamondSword = new ItemStack(Material.DIAMOND_SWORD, 1);
            ItemStack ironboots = new ItemStack(Material.IRON_BOOTS, 1);
            ItemStack ironchestplate = new ItemStack(Material.IRON_CHESTPLATE, 1);
            ItemStack ironleggings = new ItemStack(Material.IRON_LEGGINGS, 1);
            ItemStack ironhelmet = new ItemStack(Material.IRON_HELMET, 1);
            ItemStack soup = new ItemStack(Material.MUSHROOM_SOUP, 35);
           
            inv.[SIZE=5][COLOR=#ff0000][U][B]addItem[/B][/U][/COLOR][/SIZE](diamondSword, soup);
           
            player.sendMessage(ChatColor.GREEN + "You have successfully equipped the PvP class!");
           
       
        }
     
    Last edited by a moderator: May 3, 2016
  2. Offline

    XxTimexX

    @Epixel
    Please follow Java coventions, class names should start with upprrcase letter.

    You could either make
    inv.add(item) for every item or you could store all of items in Array (never tried, so idk will it work like expected).
    Btw use if cmd#getName() instead of commandLabel
     
  3. Offline

    I Al Istannen

    @XxTimexX
    From the Javadoc he should be able to do what he wants. See here. It has "(ItemStack... items)".
    @Epixel
    Are you sure you imported the Bukkit itemstack (org.bukkit.inventory.ItemStack)? Show your imports please.

    And also retun true in the first if, as you don't want to show the usage message from the plugin.yml.
    And make sure to return something at the end. Preferably true.
    You also never close the if, which leads me to the assumption this isn't your whole method. So you may do this later. Intendation will help though. In eclipse it is CTRL+SHIFT+F.
     
  4. Offline

    Epixel

    Imports :
    Code:
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    
    By the way, as you can clearly see I'm very new to coding, so don't become frustrated if I make some really dumb mistakes xD

    @I Al Istannen

    I think it's something wrong with this part:

    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
    String[] args) {

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

    I Al Istannen

    @Epixel
    Well, this is odd. This works for me:
    Code:
            ItemStack item = new ItemStack(Material.ACACIA_DOOR);
            ItemStack item2 = new ItemStack(Material.ACACIA_DOOR);
            e.getPlayer().getInventory().addItem(item, item2);
    So yours should work too :confused: I am probably overlooking something dumb.
    Alternatively you can use "new ItemStack[] {soup, diamondSword,...}" to convert it to an array directly. But it should work the way you did it too.

    This isn't your whole onCommand, is it? If yes, you should get some more errors.

    To your question. The onCommand method is defined in the CommandExecutor interface. Just add "@Override" above the "onCommand..." and your IDE will scream at you if you mess the parameters or name up.
     
  6. Offline

    WolfMage1

    you're forced to implement any methods within an interface (unless the class is abstract) with the exact same parameters.

    Can you post your onEnable and plugin.yml please @Epixel
     
  7. Offline

    I Al Istannen

    @WolfMage1
    True that. Not the same with extends (except it is an abstract class and method) though. I would still place it there, but thanks for the reminder.
     
  8. Offline

    Epixel

    @I Al Istannen

    Any suggestions on what I should do? I've probably forgot something, this is the WHOLE thing:
    Code:
    package com.epixel.plugin3.commands;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    
    public class Pvp implements CommandExecutor {
    
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
                String[] args) {
            if (!(sender instanceof Player)) {
                sender.sendMessage("You need to be a player to execute this command");
                return false;
                }
           
            if(commandLabel.equalsIgnoreCase("Pvp")){
                return true;
            }
           
            Player player = (Player) sender;
            PlayerInventory inv = player.getInventory();
           
            inv.clear();
           
            ItemStack diamondSword = new ItemStack(Material.DIAMOND_SWORD, 1);
            ItemStack ironboots = new ItemStack(Material.IRON_BOOTS, 1);
            ItemStack ironchestplate = new ItemStack(Material.IRON_CHESTPLATE, 1);
            ItemStack ironleggings = new ItemStack(Material.IRON_LEGGINGS, 1);
            ItemStack ironhelmet = new ItemStack(Material.IRON_HELMET, 1);
            ItemStack soup = new ItemStack(Material.MUSHROOM_SOUP, 35);
           
            inv.addItem(diamondSword, soup);
           
            player.sendMessage(ChatColor.GREEN + "You have successfully equipped the PvP class!");
           
       
        }
     
    Last edited by a moderator: May 4, 2016
  9. Offline

    Epixel

  10. Offline

    I Al Istannen

    @Epixel
    You are missing a return statement. But apart from that it compiles fine for me. No error, no warning.
    Could you show me a picture of your Build path (Project -> Right click -> Properties -> Build Path on the left -> Libraries Tab)?
     
Thread Status:
Not open for further replies.

Share This Page