Solved Is it possible to get a section containing a string and back to know the section of the string?

Discussion in 'Plugin Development' started by hashing, Sep 26, 2019.

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

    hashing


    well, I have a problem, I want to get into a section like this GetString("list item" + ". Sworld_Edit" + ". Name") well, this is in a very large list section list item, my problem is going back to Sworld_Edit after checking the name and knowing that this name is from this sub section, well if I described it very badly warn that I edit

    exemple
    -----------------------

    ] List-Item [
    ] Sworld_Edit [
    ] name [
    ] [

    ---------------------
    well after getting the name I would like to go back to Sworld_Edit as it would be possible or is it possible?
     
    Last edited: Sep 26, 2019
  2. Online

    timtower Administrator Administrator Moderator

    @hashing You could make a function that loops over the keys of list item, then checks the value of name in that section, if it finds something then it returns the name of the key.
     
  3. Offline

    hashing

    hi thanks for help would you have anything basic how i could do this
     
  4. Online

    timtower Administrator Administrator Moderator

    @hashing Can't explain it better then how I already did.
     
  5. Offline

    hashing

    @timtower (getString ("list_item" + "item" + ". name")) / return getString ("list_item.item") /)

    would be something like that well anyway thanks i understand what you said so i don't know how to implement
     
  6. Online

    timtower Administrator Administrator Moderator

    @hashing You need a loop, using getKeys(false) you can get all the keys of a configurationsection.
     
  7. Offline

    hashing

    I tried something like that
    public void Returnameitem(Player player, String itemname) {
    Set<String> keys = Home.getPlugin().Config.getConfig().getConfigurationSection("list-item").getKeys(false);
    for(String key : keys)
    {
    player.sendMessage(key);
    if(player.getItemInHand().getItemMeta().getDisplayName() == key) {
    itemname = key;
    }
    if(player.getItemInHand().getItemMeta().getDisplayName().equals(itemname)) {

    }
    }
    }
     
  8. Online

    timtower Administrator Administrator Moderator

    @hashing The key here is Sworld_Edit, not the name of the item.
     
  9. Offline

    hashing

    Code:
    public void Returnameitem(Player player, String itemname) {
            Set<String> keys = Home.getPlugin().Config.getConfig().getConfigurationSection("list-item").getKeys(false);
            for(String key : keys)
            {
                player.sendMessage(key);
                if(player.getItemInHand().getItemMeta().getDisplayName() == Home.getPlugin().getConfig().getString("list-item."+key+".nome")) {
                    itemname = key;
                }
                if(player.getItemInHand().getItemMeta().getDisplayName().equals(itemname)) {
                   
                }
            }
        }
    updated the code well i wanted to check if the item name is equal to key and get the item key using this
     
  10. Online

    timtower Administrator Administrator Moderator

    @hashing 1. You misspelled name.
    2. You can't compare strings with ==
    3. You probably want to check if the player has an item in his hand and that it has a displayname.
     
    Sir_Jonn likes this.
  11. Offline

    hashing

    I want to do just that, but I want to create a crawl for the item just by its key, so I can identify it with the key, because the names will be like §4Edit edited sword §4Strength 1
    so by the key would give me more freedom since it would be (sword-edit)

    @timtower sorted out and thanks for all the help

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Sep 28, 2019
Thread Status:
Not open for further replies.

Share This Page