keeping players and their armor inside a file

Discussion in 'Plugin Development' started by amitlin14, Dec 5, 2012.

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

    amitlin14

    How do i make a file and keep a player name, and their armor, inside of it, and then read it when i need to?
     
  2. Offline

    boardinggamer

    You can use a HashMap if its only temporary storage.

    Code:
    public HashMap<Player, ItemStack[]> playerarmor = new HashMap<Player, ItemStack[]>;
    playerarmor.put(player, player.getInventory().getArmorContents()); 
     
  3. Offline

    amitlin14

    boardinggamer no i need it to be saved even after restart, also, how do i keep the durability of it saved too?
     
  4. Offline

    Ivan

    He said he wanted to keep it in a file.
    amitlin14 if you want to save the item data with it, I think its the easiest to use a serializable object.
    http://forums.bukkit.org/threads/cardboard-serializable-itemstack-with-enchantments.75768/
    I think cardboard can do this but I doubt it saved data for books and skulls.
     
  5. Offline

    boardinggamer

    amitlin14
    You can try using a .yml file

    then set it up like
    Code:
    playername:
      slot1: id,damage
      slot2: id,damage
      slot3: id,damage
      slot4: id,damage
    then when you need it split the string by the "," for the values and make a new ItemStack useing those values and set it to the player
     
  6. Offline

    amitlin14

    Ivan could u explain a bit more about what it is, and how i can use it?
    boardinggamer i could, havnt thought of it, but wouldnt it reach gigantic sizes?
     
  7. Offline

    boardinggamer

    amitlin14
    4 slots per player
    assuming the max players on the server is about 50 that's 5 lines per players so its only 250 lines. unless you set it up so it only stores the used slots then it can be as low as 100 lines if EVERYONE has at least one piece of armor on

    If set up right, the chances are that it wont have more then 50 lines at a time
     
  8. Offline

    Ivan

    Basically what is does is it reads the essential data (Enchantments, Durability, Item Type, etc...) and saves it to a file (unreadable by us, but a computer program can easily read this file). Later on you can recall the file and reload the data into your plugin. In the thread (if you scroll down a bit) you can find a serializable inventory, which contains the armor too ;). The only downside is that (as far as I know) it doesn't save NBT Tags yet, which stores information for eg. Mob Skulls, readable books etc.
     
  9. Offline

    amitlin14

    boardinggamer i have a question, i want to make a list inside a list, like this:

    Armors:
    - player1:
    -- slot1: id, damage, enchant
    -- slot2: id, damage, enchant
    -- slot3: id, damage, enchant
    -- slot4: id, damage, enchant
    - player2:
    -- slot1: id, damage, enchant
    -- slot2: id, damage, enchant
    -- slot3: id, damage, enchant
    -- slot4: id, damage, enchant
    - player3:
    -- slot1: id, damage, enchant
    -- slot2: id, damage, enchant
    -- slot3: id, damage, enchant
    -- slot4: id, damage, enchant


    How do i do this? i know how to make a list(i think), but how do i make a list inside a list?
     
  10. Offline

    Ivan

    Add dots :p . If you save a value to a yml file with path armor.player1.slot1 you get what boardinggamer gave you
     
  11. Offline

    amitlin14

    Ivan im quite confused about ymls, if i do:
    Code:
    config.addDefault("Example.list.path", Arrays.asList("rules"));
    it will make a new list, called example, but what are the .list and .path r for?
     
  12. Offline

    boardinggamer

    Code:
    Player player = e.getPlayer();
    String name = player.getName();
    armorconf.set(name + ".slot1", //id and stuff here);
    armorconf.set(name + ".slot2", //id and stuff here);
    armorconf.set(name + ".slot3", //id and stuff here);
    armorconf.set(name + ".slot4", //id and stuff here);
    armorconf.options.copyDefaults(true);
    try{ armorconf.save(File); } catch (exception e2){}
    also to make a list inside a list you can do
    List<List<String>> = new ArrayList<List<String>>; (I think)
     
  13. Offline

    tommycake50

    im no expert but shouldn't it be
    Code:
    config.set(path, value);
    eg
    Code:
    config.set(playername.helmet, <item id>);
    config.set(playername.helmet.damage, <item damage>);
    etc,
     
  14. Offline

    amitlin14

    but i first need to make a list for that player, how do i do that, thats what im struggling with xD
     
  15. Offline

    boardinggamer

    name + ".slot1" = name.slot1 = the path
    a list of what? just make a string for each slot
    Code:
    String slot1 = "" + player.getHelmet().getTypeID() + "," + player.getHelmet().getDamage();
    String slot2 = "" + player.getBody().getTypeID() + "," + player.getBody().getDamage();
    //and so on
     
  16. Offline

    tommycake50

    you mean the actual yaml file?
    well to save time you can just allow it to be called config.yml.
    so first you need to add a file called config.yml to your project.
    in your onenable call the saveDefaultConfig(); method
    then presuming you have a public variable called config do config = getConfig();
    then you can do stuff with it from other classes.
    eg, the stuff that boardingggamer said.
     
  17. Offline

    amitlin14

  18. Offline

    boardinggamer

    amitlin14
    Once you get used to using them you realize just how useful they are. I love using .yml files.
     
Thread Status:
Not open for further replies.

Share This Page