Problem whit inventory

Discussion in 'Plugin Development' started by XFarwar, Aug 1, 2014.

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


    Hi, I'm going to create an plugin that introduces missions.
    I've create this:
    1. public boolean onCommand(CommandSender sender, Command cmd, String commandlabel, String[] args){
    2. Player player = (Player)sender;
    3. if(cmd.getName().equalsIgnoreCase("m-miniera")){
    4. if(player.getInventory().contains(new ItemStack(Material.COBBLESTONE, 80))){
    5. player.getInventory().addItem(new ItemStack(Material.DIAMOND, 1));
    6. }
    7. }
    8. return false;
    9. }

    If player has 80 cobblestone, it receive 1 diamond using m-miniera. But, it doesn't works.. Where is the problem?
  2. Offline


    First of all, you're casting sender to player without checking if the sender is a player.
    Secondly, there is no such thing as a stack of 80 cobblestone, hence the inventory will never contain it. You should check if the total contents of the inventory contains a total value of 80 cobblestone.
  3. Offline


    XFarwar As TheMcScavenger said, you'll need to do something like looping through the players inventory, counting how many cobblestone the player has, store it in a variable, or some sort of storing component, and check if that component is greater or equal to 80.
  4. Offline


    How can i define how many cobblestone need for get diamond? I would that player get a diamond if has 80 piece of cobblestone..

    Help me please.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page