/chest (Virtual Chest Command)

Discussion in 'Plugin Development' started by BaconStripzMan, Oct 27, 2015.

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

    BaconStripzMan

    Hello!

    My name is Jordan and I'm coding a virtual chest command for my server.

    It works fine other than the fact that obviously the HashMap resets after reload/stop of the server.

    Would I have to save the Virtual Chests in a config.yml or is there an easier/better/another way?

    Post if you need code ^_^
     
  2. Yes, you need to save it in a yml file. I'ts really easy because you can directly save items to it and get them with .getItemStack("path");
     
  3. Offline

    BaconStripzMan

    That's what I meant. Alright thank you for your help!

    @FisheyLP I'm trying to figure out how i could itterate through a list of strings in the config and change them to items?
    and how would I get the amount?

    ETC..

    for(code i need) {
    chestcommand.get(p).addItem(item);
    }

    Config:

    BaconStripsMan:

    chest:
    - apple

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 29, 2015
  4. Offline

    Scimiguy

    @BaconStripzMan
    config.getStringList()

    new ItemStack(Material, Amount)

    list.size()
     
  5. Offline

    Zombie_Striker

    Not needed.
    It's always best to assume we need that.

    Now, there are two ways we can save the chest; We can save it by using the whole inventory instance or just the contents. If you want to save the whole inventory, it's simpler but it takes up slightly more space. You would use the following:
    SAVING
    Code:
    getConfig().set("Path.To.Where.You.Want.To.Save.It",The Inventory instance);
    saveConfig();
    LOADING
    Code:
    Inventory inv = (Inventory)getConfig().get("That.Same.Path");
    If you want to use the contents,
    SAVING
    Code:
    getConfig().set("Path.To.Where.You.Want.To.Save.It",The Inventory Contents instance);
    saveConfig();
    LOADING
    Code:
    ItemStack[] itemstack = getConfig().get("That.Same.Path");
    Inventory inv;
    for(int i = 0; i < 36; i++){
    if(itemstack[i] != null){
    inv.setItem(i,itemstack[i]);
    }
    }
     
Thread Status:
Not open for further replies.

Share This Page