Inventories

Discussion in 'Plugin Development' started by ewrs, Oct 8, 2018.

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

    ewrs

    Hey. I have a question for you. How can I split inventories between modes?

    That is, when a player in GameMode 1, he has 1 inventory, if he is a GameMode 0, then he has 2 inventory. At the same time, after restarting the server, things should be saved.

    Please tell me how to do it with SQL? And how to do it at all
     
  2. Offline

    timtower Administrator Administrator Moderator

    @ewrs I would suggest YML storage for this over SQL, as there is a ConfigurationSection#getItemStack, you don't have that for SQL.
    You need 3 things:
    • A way to save the inventory.
    • A way to load the inventory.
    • A way to switch inventories.
    My suggestion is to start with saving.
     
  3. Offline

    ewrs

    Thanks for the advice, but how do I save?
     
  4. Offline

    timtower Administrator Administrator Moderator

    Depends on what you want to use.
    What storage method are you gonna use?
     
  5. Offline

    new-ewrs728

  6. Offline

    timtower Administrator Administrator Moderator

    @new-ewrs728 Then you can just use config.set(path,itemstack)
     
  7. Offline

    new-ewrs728

    All the time to save and delete?
     
  8. Offline

    timtower Administrator Administrator Moderator

    Pretty much
     
  9. Offline

    new-ewrs728

    And how do I get ALL things in the player's inventory and I drop them into the config
     
  10. Offline

    timtower Administrator Administrator Moderator

    @new-ewrs728 Inventory has a fixed size, you can loop over it with an int counter.
     
  11. Offline

    new-ewrs728

    It seems there was a method with getting things? If not, please show your solution.
     
  12. Offline

    timtower Administrator Administrator Moderator

  13. Offline

    new-ewrs728

    I know about him. But I will need to get all the charms, the number of things, etc. Show how to put them in the config ...
     
  14. Offline

    timtower Administrator Administrator Moderator

  15. Offline

    new-ewrs728

    I understood the principle, but did not understand how to do it in code
     
  16. Offline

    timtower Administrator Administrator Moderator

  17. Offline

    new-ewrs728

    GameModeChangeEvent only for 1.13, yea?
     
  18. Offline

    timtower Administrator Administrator Moderator

    Make a method that just saves the inventory, regardless of what calls it.
     
  19. Offline

    new-ewrs728

    I'm generally confused ...
    I made a cycle, what to check in it ...
     
  20. Offline

    timtower Administrator Administrator Moderator

    @new-ewrs728 Post your code.
    And please use the "Tahg user" or "Reply" button so the other people get notifications.
     
  21. Offline

    new-ewrs728

    I made a simple loop in which there is nothing, for I am confused.
     
  22. Offline

    timtower Administrator Administrator Moderator

    Then please post your code.
     
  23. Offline

    new-ewrs728

    I figured it out a bit, but there are questions. Let's solve with a little java question.

    wait

    My code XD

    for(int x = 0; x < p.getInventory().getSize(); x++) {
    }

    And yet, I saw a lot about getArmorContents (), is it also needed?
     
  24. Offline

    timtower Administrator Administrator Moderator

    @new-ewrs728 Remove the \\, those should be File.separator, because that line won't work on linux.
    Use UUID's instead of names
    Make sure to make a directory first.
    How big is that inventory? Does it not already contain the armor?
     
  25. Offline

    new-ewrs728

    Folder again...
    new File(this.getDataFolder() + File.separator + "Inventories" + File.separator + "Inventories_" + p.getUniqueId() + File.separator + "creative.yml");

    That is player inventory...
     
  26. Offline

    timtower Administrator Administrator Moderator

  27. Offline

    new-ewrs728

    How about file?
     
  28. Offline

    timtower Administrator Administrator Moderator

  29. Offline

    new-ewrs728

  30. Offline

    timtower Administrator Administrator Moderator

    You want to write YML, how do you want to write to the File?
     
Thread Status:
Not open for further replies.

Share This Page