getStringList("Blabla") onto Material.getMaterial(plugin.getConfig()...)

Discussion in 'Plugin Development' started by adde, Jul 12, 2013.

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

    adde

    Hello.
    I am currently trying to add items to automaticly refill. I just noticed that when I want to add more than just one item with ItemStack, it won't work.

    Here's my code():
    Code:java
    1.  
    2. public void fillChest(Block block){
    3. List<String> items = plugin.getConfig().getStringList("Items");
    4.  
    5. Chest chest = (Chest)block.getState();
    6. ItemStack item = new ItemStack(Material.getMaterial(items));
    7.  
    8. if(block instanceof Chest){
    9. chest.getBlockInventory().addItem(item);
    10. }
    11. }
    12.  

    The error is on this line:
    Code:
          ItemStack item = new ItemStack(Material.getMaterial(items));
    
    And the error that appears in eclipse is:
    Code:
    The method getMaterial(int) in the type Material is not applicable for the arguments (List<String>)
    
    How would I fix this, should I use another method to add more than just one item into the chest?
     
  2. Offline

    kreashenz

    You need to split the List<String> into a String[]
    Code:java
    1. public void fillChest(Block block){
    2. for(String items : plugin.getConfig().getStringList("Items")){
    3. String[] item = items.split(":");
    4. if(block instanceof Chest){
    5. Chest chest = (Chest)block.getState();
    6. ItemStack item = new ItemStack(Material.getMaterial(item[0]));
    7. chest.getBlockInventory().addItem(item);
    8. }
    9. }

    Made that just then, no IDE.
     
  3. Offline

    adde

    Ooh, thank you. Didn't think of that in any way. Will try that.

    Edit:
    Now I got:

    The method getMaterial(String) is undefined for the type Material

    Never mind, silly me. Imported wrong. :p
     
Thread Status:
Not open for further replies.

Share This Page