ItemStack error

Discussion in 'Plugin Development' started by Macklan, Aug 5, 2022.

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

    Macklan

    Hi, I am new and need your help please.
    I wanted to read a Material from a String and use it to add the Item/Material to the users Iventory.
    It seems I am doing something wrong here, but I am not sure what exactly.


    Code:
      //mymat causes error on new ItemStack(mymat, myamount);
      String matval= "Material.DIAMOND";
      int myamount = 5;
    
      Material mymat = Material.getMaterial(matval);
    
      ItemStack mystack = new ItemStack(mymat, myamount);
      inventory.addItem(mystack);
    
    
      //not taking it from a string works
    
      int myamount = 5;
    
      ItemStack mystack = new ItemStack(Material.DIAMOND, myamount);
      inventory.addItem(mystack);
     
  2. Online

    timtower Administrator Administrator Moderator

    @Macklan Why do you want to do it from a string?
    And the matval should not contain "Material"
     
Thread Status:
Not open for further replies.

Share This Page