Save in config more Slots

Discussion in 'Plugin Development' started by Sempych, Nov 22, 2023.

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

    Sempych

    Hi
    I created a gui where there are items, I need to put the slot number of the item that the user clicked on in the config, and then use these values to replace the same items when opening this menu. My problem is that I do not know how to add more than 1 slot


    event clik code:
    Player p = (Player) e.getWhoClicked();
    String uuid = p.getUniqueId().toString();

    if (e.getCurrentItem().getType() == Material.EMERALD_BLOCK) {
    SkillMenu(p);
    int slot = RPGPROFILE.getData().getConfig().getInt("ItemSave." + p.getName() + "." + uuid + ".slot");
    SkillMenu(p).setItem(slot, SkillResearched);
    }




    if (e.getInventory().getName().equalsIgnoreCase("skillmenu")) {
    e.setCancelled(true);


    if (e.getCurrentItem().getType() == Material.NETHER_STAR) {
    p.sendMessage(ChatColor.GREEN + "Навык разрез изучен!");
    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "clear " + p.getName() + " diamond " + 2);
    SkillMenu(p).setItem(9, SkillResearched);
    RPGPROFILE.getData().getConfig().set("ItemSave." + p.getName() +"."+ uuid + ".slot", e.getSlot());
    RPGPROFILE.getData().save();


    }

    if (e.getCurrentItem().getType() == Material.DIAMOND_SWORD) {
    p.sendMessage(ChatColor.GREEN + "Навык рассечение изучен!");
    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "clear " + p.getName() + " diamond " + 5);

    SkillMenu(p).setItem(11, SkillResearched);


    RPGPROFILE.getData().getConfig().set("ItemSave." + p.getName() +"."+ uuid + ".slot", e.getSlot());
    RPGPROFILE.getData().save();

    }
    }

    pls help guys
     
  2. Online

    timtower Administrator Administrator Moderator

  3. Offline

    Sempych

    Slot numbers are given, the problem is that I can't add more than 1 slot

    Config:

    Code:
    name: RPGPROFILE
    version: 1.0-SNAPSHOT
    main: org.example.rpgprofile.rpgprofile.RPGPROFILE
    commands:
      profile:
        description: Открывает профиль
        usage: /<command
    Code:
    ItemSave:
      Senpa1ka:
        23f0455d-1069-342a-8da4-c772c26a64bc:
          slot: 9

    If I want to add a slot, for example 11, then it just replaces the previous one, that is, 9 just changes to 11
     
  4. Online

    timtower Administrator Administrator Moderator

    @Sempych Then make it a list of slots?
     
  5. Offline

    Sempych

    I tried to do it, but it didn't work out, I think I did something wrong
    can you give me a hint?
     
  6. Online

    timtower Administrator Administrator Moderator

    What code did you use?
     
  7. Offline

    Sempych

    I don't have this code anymore since it didn't work, I deleted it, but I remember why it didn't work correctly He added the same slots many times and I had problems getting these slots out of the config to replace the item
     
  8. Online

    timtower Administrator Administrator Moderator

    @Sempych Then check if it is in the list already?
     
  9. Offline

    Sempych

    I didn't do it...
    now I'll try to do it

    if (!RPGPROFILE.getData().getConfig().getList(p.getUniqueId().toString() + ".Slots").equals(String.valueOf(SlotToInventory))) {
    SlotToSave.add(String.valueOf(SlotToInventory));
    RPGPROFILE.getData().getConfig().set(p.getUniqueId().toString() + ".Slots", SlotToSave);
    RPGPROFILE.getData().save();
    }

    I tried to make a check, but I had a problem how to call the first element of the list from the config that I passed to it

    the mistake is that I can't compare String and List

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 23, 2023
  10. Online

    timtower Administrator Administrator Moderator

    @Sempych What is slotToInventory then?
     
  11. Offline

    Sempych

    int SlotToInventory = e.getSlot();
    List<String> SlotToSave = new ArrayList<String>();


    if (!RPGPROFILE.getData().getConfig().getList(p.getUniqueId().toString() + ".Slots").get(1).equals(String.valueOf(SlotToInventory))) {
    SlotToSave.add(String.valueOf(SlotToInventory));
    RPGPROFILE.getData().getConfig().set(p.getUniqueId().toString() + ".Slots", SlotToSave);
    RPGPROFILE.getData().save();
    }

    I have solved my problem
     
  12. Online

    timtower Administrator Administrator Moderator

    @Sempych Why is it a string list?
    Why not a SlotToSave.contains(SlotToInventory) ?
     
  13. Offline

    Sempych

    Can you give an example of how it should look in my code ?
    I don't fully understand
     
  14. Online

    timtower Administrator Administrator Moderator

    @Sempych Not gonna spoonfeed you.
    Why is the list for strings? And not for ints, which represent the slots.
     
  15. Offline

    Sempych

    Code:
    if (e.getInventory().getName().equalsIgnoreCase("skillmenu")) {
    e.setCancelled(true);
    int SlotToInventory = e.getSlot();
    List<Integer> SlotToSave = new ArrayList<Integer>();
    if (e.getCurrentItem().getType() == Material.NETHER_STAR) {
    p.sendMessage(ChatColor.GREEN + "Навык разрез изучен!");
    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "clear " + p.getName() + " diamond " + 2);
    SkillMenu(p).setItem(9, SkillResearched);
    
    
    if (RPGPROFILE.getData().getConfig().getIntegerList(p.getUniqueId() + ".Slots").contains(SlotToInventory)) {
    p.closeInventory();
    }
    else {
    p.sendMessage("Work");
    SlotToSave.add(SlotToInventory);
    RPGPROFILE.getData().getConfig().set(p.getUniqueId() + ".Slots", SlotToSave);
    RPGPROFILE.getData().save();
    }
    }
    
    if (e.getCurrentItem().getType() == Material.DIAMOND_SWORD) {
    p.sendMessage(ChatColor.GREEN + "Навык рассечение изучен!");
    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "clear " + p.getName() + " diamond " + 5);
    SkillMenu(p).setItem(11, SkillResearched);
    
    if (RPGPROFILE.getData().getConfig().getIntegerList(p.getUniqueId() + ".Slots").contains(SlotToInventory)) {
    p.closeInventory();
    }
    else {
    p.sendMessage("Work");
    SlotToSave.add(SlotToInventory-2);
    SlotToSave.add(SlotToInventory);
    RPGPROFILE.getData().getConfig().set(p.getUniqueId() + ".Slots", SlotToSave);
    RPGPROFILE.getData().save();
    }
    }
    }
    It work!
    Thank
    but I have another problem, when I open the menu, only the last item in the list is replaced

    Code:
    Code:
    if (e.getCurrentItem().getType() == Material.EMERALD_BLOCK) {
    SkillMenu(p);
    int size = RPGPROFILE.getData().getConfig().getIntegerList(p.getUniqueId() + ".Slots").size();
    for (int j = 0; j <= size; j++) {
    int slot = RPGPROFILE.getData().getConfig().getIntegerList(p.getUniqueId() + ".Slots").get(j);
    SkillMenu(p).setItem(slot, SkillResearched);
    }
    SkillMenu(p);
    }
    Config:
    Code:
    name: RPGPROFILE
    version: 1.0-SNAPSHOT
    main: org.example.rpgprofile.rpgprofile.RPGPROFILE
    commands:
      profile:
        description: Открывает профиль
        usage: /<command
    23f0455d-1069-342a-8da4-c772c26a64bc:
      Slots:
      - 9
      - 11
     
    Last edited by a moderator: Nov 23, 2023
  16. Online

    timtower Administrator Administrator Moderator

  17. Offline

    Sempych

    this did not help to solve the problem
     
Thread Status:
Not open for further replies.

Share This Page