Solved Command not working?

Discussion in 'Plugin Development' started by iClipse, Dec 23, 2016.

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

    iClipse

    So I finally got my plugin to load, but now we have a problem. I wanna make a command to open a shop, right? Well, there is a command... but it does nothing. Here is the code: (Also, it appears in the list when I do /help FactionShop)


    Also, I hovered over the command parameter stuff and it said "The method onCommand(CommandSender, String, Command, String[]) from the type shop is never used locally"

    what ever the *** that means....
    Code:
    private boolean onCommand(CommandSender  theSender, String commandLabel, String []args, Command command)
    {
            Player player = (Player) theSender;
      
            if(commandLabel.equalsIgnoreCase("Shop"));
        {
        Inventory inv = Bukkit.createInventory(null, 18, ChatColor.GOLD
                + "General Shop");
        ItemStack building = new ItemStack(Material.STONE);
        ItemMeta buildingMeta = building.getItemMeta();
        ItemStack crafting = new ItemStack(Material.WORKBENCH);
        ItemMeta craftingMeta = crafting.getItemMeta();
        ItemStack tools = new ItemStack(Material.STONE_AXE);
        ItemMeta toolsMeta = tools.getItemMeta();
        ItemStack battle = new ItemStack(Material.IRON_SWORD);
        ItemMeta battleMeta = battle.getItemMeta();
        ItemStack smelting = new ItemStack(Material.BURNING_FURNACE);
        ItemMeta smeltingMeta = smelting.getItemMeta();
        ItemStack organics = new ItemStack(Material.APPLE);
        ItemMeta organicsMeta = organics.getItemMeta();
        ItemStack brewing = new ItemStack(Material.BREWING_STAND);
        ItemMeta brewingMeta = brewing.getItemMeta();
        ItemStack redstone = new ItemStack(Material.REDSTONE);
        ItemMeta redstoneMeta = redstone.getItemMeta();
        ItemStack enchanting = new ItemStack(Material.ENCHANTMENT_TABLE);
        ItemMeta enchantingMeta = enchanting.getItemMeta();
      
        buildingMeta.setDisplayName(ChatColor.DARK_RED + "Building");
        building.setItemMeta(buildingMeta);
        craftingMeta.setDisplayName(ChatColor.BLUE + "Crafting");
        crafting.setItemMeta(craftingMeta);
        toolsMeta.setDisplayName(ChatColor.GRAY + "Tools");
        tools.setItemMeta(toolsMeta);
        battleMeta.setDisplayName(ChatColor.LIGHT_PURPLE + "Battle");
        battle.setItemMeta(battleMeta);
        smeltingMeta.setDisplayName(ChatColor.GOLD + "Smelting");
        smelting.setItemMeta(smeltingMeta);
        organicsMeta.setDisplayName(ChatColor.GREEN + "Organics");
        organics.setItemMeta(organicsMeta);
        brewingMeta.setDisplayName(ChatColor.DARK_PURPLE + "Brewing");
        brewing.setItemMeta(brewingMeta);
        redstoneMeta.setDisplayName(ChatColor.RED + "Redstone");
        redstone.setItemMeta(redstoneMeta);
        enchantingMeta.setDisplayName(ChatColor.DARK_BLUE + "Enchanting");
        enchanting.setItemMeta(enchantingMeta);
      
        inv.setItem(1, building);
        inv.setItem(2, crafting);
        inv.setItem(3, tools);
        inv.setItem(4, battle);
        inv.setItem(5, smelting);
        inv.setItem(6, organics);
        inv.setItem(7, brewing);
        inv.setItem(8, redstone);
        inv.setItem(9, enchanting);
      
        player.openInventory(inv);
      
        }
        return true;
    }}
    
    I am using Bukkit 1.11 R1 and Java 8 just incase that info matters
     
    Last edited: Dec 24, 2016
  2. Offline

    Zombie_Striker

    @iClipse
    You can't just ignore bits of the parameter. You need to add the Command and args requirements as well.
     
  3. Offline

    iClipse

    I mean, I thought I can because adding ",command cmd" to my parameter adds nothing to the table, atleast what I thought. Lemma try

    I added the 2 parameters, does nothing. Did I miss anything?
    private boolean onCommand(CommandSender theSender, String commandLabel, String [] args, Command cmd)

    Also, I hovered over the command parameter stuff and it said "The method onCommand(CommandSender, String, Command, String[]) from the type shop is never used locally"

    what ever the *** that means....
     
    Last edited: Dec 24, 2016
  4. Offline

    Zombie_Striker

    @iClipse
    The order is important. It MUST be ...
    Code:
    onCommand(CommandSender, Command, String, String[])
    The reason why is because bukkit looks for a method called "onCommand" with those exact parameters in that exact order. If it find a command with the wrong name/ incorrect order for pameters, It ignores that method.

    Because bukkit does not look for that incorrect method, and because you never call onCommand locally, it is never used. That is why you are getting that error.
     
  5. Offline

    iClipse

    I have no idea what it means by "locally". I re arranged it, and now it is underlined in red rather than yellow .-.

    Wait nvm. Changed it to a public boolean and were all good.
     
  6. Offline

    Zombie_Striker

    @iClipse
    If your problem has been solved, mark this thread as solved.
     
    iClipse likes this.
Thread Status:
Not open for further replies.

Share This Page