how would i get this to work

Discussion in 'Plugin Development' started by kamakarzy, May 13, 2013.

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

    kamakarzy

    how would i make this command work.
    i want to give a player a list of items thats in the config integerlist test

    Code:
    event.getPlayer().getInventory().addItem(plugin.getConfig().getIntegerList("test"));
    thanks
     
  2. kamakarzy
    I'd suggest using the format <itemid>,<data>,<quantity>;

    Then read in your string from your config file. Split it by the semi colon the get the data of each item stack.

    Code:java
    1.  
    2. String in;
    3. String[] items = in.split(";");


    Then you can take each string from this array and split it by the comma into its constituent components to create an ItemStack.

    Code:java
    1.  
    2. for(String collection : items){
    3. String[] args = collection.split(",");
    4. int id, quantity;
    5. byte data;
    6. try{
    7. id = Integer.parseInt(args[0]);
    8. quantity = Integer.parseInt(args[2]);
    9. data= Byte.parseByte(args[1]);
    10. ItemStack is = new ItemStack(id, quantity, data);
    11. } catch (NumberFormatException ex){
    12. ex.printStackTrace();
    13. }
    14. }
    15.  
     
  3. Offline

    kamakarzy

    Adamki11s so how would i make it call
    Code:
    test: { 1, 2, 3, 4, 5, 6, 7,}
    in config im sorry i have never used the string code you have gave me befor
     
  4. kamakarzy
    For example, 10 stone and 5 grass:

    1,0,10;2,0,5
     
  5. Offline

    kamakarzy

    Adamki11s i ment how do i call it would it be
    Code:
    String in = plugin.getConfig().getIntegerList("test");
     
  6. kamakarzy
    Have a look for File I/O if you are not sure how to load/save text from files.
     
Thread Status:
Not open for further replies.

Share This Page