Solved Overwriding stuff in the config?

Discussion in 'Plugin Development' started by ErzLegendZero, Dec 26, 2018.

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

    ErzLegendZero

    Hey ther I have a problem
    I'm creating a plugin(with quests...)
    I'm saving the quests in a config.
    Now I want do create a command to change the name of the quest
    but how can i do this?

    config (Example):

    Code:
    villagers:
      Villagername:     (NameToChange)
        X: 0.0
        Y: 0.0
        Z: 0.0
        Yaw: 0.0
        Pitch: 0.0
        World: world
        freeze: true
        rewads:
          coins: 100
          ...
        other stuff....
      OtherNames...
    ....
    How can I now change the name of the villager without creating a compledly new one?

    Sry for spelling mistake and thanks for supporte in advance!
     
  2. Offline

    MightyOne

    If the name of the villager is not a unique or final string than I would not use it as key in in the config.
    You could rather set it up like this:
    Code:
    villagers:
        villager1:
            custom-name: (easily changeable value)
            world: world
            ...
     
  3. Offline

    ErzLegendZero

    yes that is an good idea but the thing is I need to get them by there name

    so I wand to make a command like: /villager <villagername(customname)> <edit> <name/reward/quest>
    How can I make this?
    is there a way to search yust the custom name ?

    Example:
    Code:
    villagers:
    
      villager1:
        customname: Test123
        X: 0.0
        Y: 0.0
        Z: 0.0
        Yaw: 0.0
        Pitch: 0.0
        World: world
        freeze: true
        rewads:
          coins: 100
          ...
      villager2:
        customname: Test456
        X: 0.1
        Y: 3.4
        Z: 2.3
        ...
      villager3:
        customname: Test456124235aawawdawd
        X: 3.4
        Y: 1.2
        Z: 56.1
    ....
    So how can I now get the Location for example of the villager just by there custom names?
    Is that posible?

    Sry for spelling mistake!
     
  4. Offline

    ForbiddenSoul

    Use a HashMap,
    this can be sort of tricky to save in a config properly, so read this if you haven't already:
    https://bukkit.gamepedia.com/Configuration_API_Reference#HashMaps

    Easiest way would be to just make a HashMap<String, Quest>. (or what ever your "Quest" is called, it seems to already be serializing into your config so it should work.)
    Then you can simply use yourHashMap.get("yourVillager'sName");
    and that will get your quest by villager name.



    If it isn't letting you use quest as a value for some reason, alternatively you can simply make a HashMap<String, Integer>.
    The String will be the villagers name, and the int will be the index in your list (villager1 is at index 0)
    The you can do yourHashMap.get("yourVillagersName"), and then that will return a numbered index for you, then you can use that index to get a hold of the entire object you wish to operate on.

    villagers.get(yourHashMap.get("yourVillagersName"));
     
    Last edited: Dec 27, 2018
  5. Offline

    MightyOne

    Uuuuuhmmm... You can iterate through all villagers in the config and check which one has the fitting custom-name.
    With getConfig().getConfigurationSection("villagers").getKeys(false) you will get a list with the strings of all listed villagers. Like "villager3" and all the others.
    You can then go through these villager-"keys" and check if their custom-name equals your value.
     
  6. Offline

    ErzLegendZero

    That worked, thank you very much!
     
    MightyOne likes this.
Thread Status:
Not open for further replies.

Share This Page