Retrieving Items

Discussion in 'Plugin Development' started by DoggyCode™, Sep 7, 2015.

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

    DoggyCode™

    Anyone has a good way to retrieve items into a inventory from a configuration file? Like, after the ID? For example:

    - 322:1
    - 32
    - 522:3

    etc... this would place these items into the player's inventory (or some other custom inventory).
     
  2. 1. What have you tried so far?
    2. You need to parse it yourself with string.split(...) and string.substring(..)
     
  3. Offline

    DoggyCode™

    I haven't tried anything, just a curious question if somebody has a good method and would like to share.
     
  4. How I would go about doing this:

    Format: 'item:amount'

    String item = split at the ":" and get the number on the left hand side
    int amount = ^ on the right hand side

    *insert some checks here*

    players inventory . addItem(new ItemStack(Material.valueOf("item".toUpperCase()), amount));

    I remember reading somewhere that ID's will eventually be replaced completely by names, (Pretty sure it was a tweet from dinnerbone, don't quote though) that's why I'm using material names instead.
     
  5. Offline

    Eos

    @DoggyCode™

    It's going to be a bit more complicated because you have colons
    You need to first check if a stringlist contains a :

    The code below will work but it doesn't support colons
    Code:
    for (String s: getConfig().getStringList("path")) {
        p.getInventory().addItem(new ItemStack(Integer.parseInt(s.split(" ")[0])));
    
    }
    This code supports colons it might work never tested it.
    Code:
     if ( s.contains(":") )
                {
                    for (String s: getConfig().getStringList("path")) {
                        p.getInventory().addItem(new ItemStack(Integer.parseInt(s.split(" ")[0]), 1, (byte) Integer.parseInt(s.split(":")[1]) ));
    
                    }
                }
     
  6. Offline

    DoggyCode™

    I'll try that @Eos
     
Thread Status:
Not open for further replies.

Share This Page