Solved Items in Config

Discussion in 'Plugin Development' started by malikdbuseck, Jan 9, 2015.

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

    malikdbuseck

    So if in the config you wanted to give a player a bunch of items.

    Config:
    Items: 1/64, 5:1/64, 35:5/64

    How would you make it so it knows that the : is talking about item data and the / is talking about the amount?

    Im trying to make something kind of simple where in the config the server owner can set what items they get on join. So that way I dont have to create a ton of items stacks in my code. It will just be what ever is written like that.
     
  2. Offline

    adam753

    String#split is magical.
    Protip: don't use item IDs, they were deprecated years ago.
     
  3. Offline

    Skionz

    @malikdbuseck Split the ItemStack up into parts when you save it and re-assemble it when you grab it from the file.
     
  4. Offline

    Experminator

    Maybe is this better:
    Code:
    public void giveItemToPlayer(Player p){
         ItemStack i = new ItemStack(Material.valueOf(getConfig().get("material")).getId());
    ItemMeta im = i.getItemMeta();
    
    im.setAmount(getConfig().getInt("amount"));
    
    i.setItemMeta(im);
    
    p.getInventory().addItem(i);
    }
     
    adam753 likes this.
  5. Offline

    malikdbuseck

    So no matter what Im going to have to use ItemStacks? Im trying make it so they can just type the item id or material name in the config with commas to separate each material and / to separate amount

    what is valueof doing?

    EDIT by Timtower: merged double post
     
    Last edited by a moderator: Jan 9, 2015
  6. Offline

    xMakerx

    @malikdbuseck

    Yeah you should try Material names and just separate it with a comma if you want to write the config out yourself. Better yet, why don't you make an admin only command that takes your inventory and saves it to the config?
     
  7. Offline

    Experminator

    @malikdbuseck the method 'valueOf()' in this case 'Material.valueOf()' gets the specific material out a String or something. For example the configuration file.
     
  8. Offline

    malikdbuseck

    Im not trying to take a players inventory im trying to set one haha.

    I have ti setup right now when a player types /kits a InventoryGUI comes up with the kits and when they click say a bow it will look in the config and grab the items that are given to that kit:

    Items: BOW:1, ARROWS:64
     
  9. Offline

    Experminator

    @malikdbuseck You can use a Material array.
    EDIT: Even is it better to use a ItemStack array.
     
    malikdbuseck likes this.
Thread Status:
Not open for further replies.

Share This Page