Solved Get Name of Advancement

Discussion in 'Plugin Development' started by zjuventus14, Aug 27, 2017.

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

    zjuventus14

    I'm currently updating a plugin from achievements to advancements, which gives players rewards for achievements. The problem is that this relies on a config file that was previously structured as
    Code:
    ACHIEVEMENT_NAME_REWARD_ITEM: ITEM_REWARD
    However, with the introduction of advancements, this no longer works, since in order to get all advancements, as far as I know, I have to do this:
    Code:
    Iterator<Advancement> it = plugin.getServer().advancementIterator();
    while(it.hasNext()) {
                Advancement a = it.next();
                config.addDefault(a.toString() + "_REWARD_ITEM", "");
    }
    
    However, the advancement "a" has no method to get it's name, and instead seems to be CraftBukkitAdvancement@memory_address, with memory_address changing every time. Is there any way to get the name of an advancement? If not, are there any other ideas on how to reference advancements in my configuration file? Any help is appreciated :)
     
  2. @zjuventus14
    The Advancement interface extends Keyed which has a method 'getKey'. This essentially returns its name (it also allows you to get the namespace, IE minecraft or something else if any custom advancements have been added). So this would get the name of an Advancement:
    Code:java
    1. Advancement advancement = ...
    2. String name = advancement.getKey().getKey()
     
  3. Offline

    zjuventus14

    Exactly what I was looking for! Thanks.
     
Thread Status:
Not open for further replies.

Share This Page