PyvesB / advanced-achievements

:fireworks: Popular plugin that adds unique and challenging achievements to Minecraft servers.
https://www.spigotmc.org/resources/83466
GNU General Public License v3.0
199 stars 214 forks source link

trying to create another tab #594

Closed pluttotv closed 4 years ago

pluttotv commented 4 years ago

hey im trying to make another tab beside the one ur plugin make, so i created the same method of registerAdvancements() like in AdvancementManager. set: ADVANCED_ACHIEVEMENTS_PARENT = "advanced_test_parent"; along side with a copy config and gui yml i setup to hook with the copied method of urs.

so i tried to run it, the code worked - no errors but the tab doesn't shows up. tried to catch it with a debuger to understand where i went wrong.. but im not familiar with this area, and unsafeValues is new to me.

would u add a support to get an extra tab in the advencment with seperated achivments? if not any chance to hint me or tell me what im doing wrong?

Thanks for ur time and support. i love this plugin, and u should consider adding api options so plugin developers can create there own separate Advencment tab and aach list for there things, it can be epic.

PyvesB commented 4 years ago

Hello @pluttotv,

Is configHideAdvancements set to false in the config? Are you calling the code from a different plugin (i.e. is a different NamespacedKey used?). Can you find the generated JSON files on the server itself?

Cheers,

Pyves

pluttotv commented 4 years ago

ya HideAdvancements is set to false, im using 14.4, and i saw the generated JSON

im trying to create another advancments in a new plugin using ur source, and what basically i do ya i run on a new NamespacedKey and modify cleanupOldAchievementAdvancements(); registerParentAdvancement(); registerOtherAdvancements(); to baiscly read and make another advancment and control all it stuff in the new plugin (listeners etc etc): here is the full code onEnable() when plugin starts:

`//add AdvancedAchievements to create a new separete advanced achievments if(Bukkit.getPluginManager().isPluginEnabled("AdvancedAchievements")) { Bukkit.getConsoleSender().sendMessage("hooked with AdvancedAchievements"); //aach = (AdvancedAchievements) Bukkit.getServer().getPluginManager().getPlugin("AdvancedAchievements"); //achievementsAPI = AdvancedAchievementsAPIFetcher.fetchInstance(); unsafeValues = Bukkit.getUnsafe();

        // CREATE THE test data base
        File aachbf = new File(getDataFolder() + File.separator + "configadvancment.yml");
        if (!aachbf.exists()) {
            try {
                reloadAACHData();
                saveAACHData();
                this.getLogger().info("Generated configadvancment.yml succesfully!");
            } catch (Exception e) {
                this.getLogger().info("Failed to generate configadvancment.yml!");
            }
        }
        // CREATE THE gui data base
        File aacGUIhbf = new File(getDataFolder() + File.separator + "gui.yml");
        if (!aacGUIhbf.exists()) {
            try {
                reloadAACHGUIData();
                saveAACHGUIData();
                this.getLogger().info("Generated gui.yml succesfully!");
            } catch (Exception e) {
                this.getLogger().info("Failed to generate gui.yml!");
            }
        }

        cleanupOldAchievementAdvancements();
        registerParentAdvancement();
        registerOtherAdvancements();
    }

` those are

` private void cleanupOldAchievementAdvancements() { parseDisabledCategories(); parseEnabledCategoriesWithSubcategories(); parseAchievements();

    int achievementsCleaned = 0;
    Iterator<Advancement> advancements = Bukkit.advancementIterator();
    while (advancements.hasNext()) {
        NamespacedKey namespacedKey2 = advancements.next().getKey();
        if ("test".equals(namespacedKey2.getNamespace())) {
            ++achievementsCleaned;
            unsafeValues.removeAdvancement(namespacedKey2);
        }
    }
    Bukkit.reloadData();
    System.out.println("Cleaned " + achievementsCleaned + " old advancements.");
}

private void registerParentAdvancement() {
    NamespacedKey namespacedKey = new NamespacedKey(this, "advanced_test_parent");
    if (Bukkit.getAdvancement(namespacedKey) == null) {
        System.out.println("creating an advancements test!");
        AchievementAdvancement.AchievementAdvancementBuilder builder = new AchievementAdvancement.AchievementAdvancementBuilder()
                .iconItem("minecraft:ender_eye")
                .title("test")
                .description("")
                .background("minecraft:textures/item/ender_eye.png")
                .type(AdvancementType.GOAL);

        AchievementAdvancement aa = builder.build();
        unsafeValues.loadAdvancement(namespacedKey, AdvancementJsonHelper.toJson(aa));
    }
}

private void registerOtherAdvancements() {
    generatedAdvancements = 1; // Already generated 1 for parent.
    if (!disabledCategories.contains(CommandAchievements.COMMANDS)) {
        String parentKey = "advanced_test_parent";
        for (String ach : getAACHData2().getShallowKeys(CommandAchievements.COMMANDS.toString())) {
            parentKey = registerAdvancement(CommandAchievements.COMMANDS, CommandAchievements.COMMANDS + "." + ach,
                    parentKey, true);
            System.out.println("REGISTER registerAdvancement in OtherAdvcanments: " + ach);
        }
    }

    for (NormalAchievements category : NormalAchievements.values()) {
        registerCategoryAdvancements(category, "");
    }

    for (MultipleAchievements category : MultipleAchievements.values()) {
        for (String section : getAACHData2().getShallowKeys(category.toString())) {
            registerCategoryAdvancements(category, "." + section);
        }
    }
    Bukkit.reloadData();
    System.out.println("Generated " + generatedAdvancements + " new advancements.");
}

`

closing up the last modify idid:

` private String registerAdvancement(Category category, String configAchievement, String parentKey, boolean lastAchievement) { String achName = getAACHData2().getString(configAchievement + ".Name", ""); String achDisplayName = getAACHData2().getString(configAchievement + ".DisplayName", ""); if (StringUtils.isEmpty(achDisplayName)) { achDisplayName = achName; } // Strip colours as the advancements interface does not support them. achDisplayName = StringHelper.removeFormattingCodes(achDisplayName); String achKey = getKey(achName); NamespacedKey namespacedKey = new NamespacedKey(this, achKey); int metadata = getAACHGUIData2().getInt(category + ".Metadata", 0); String description = ""; //if (configRegisterAdvancementDescriptions) { // Give priority to the goal to stick with Vanilla naming of advancements. description = getAACHData2().getString(configAchievement + ".Goal", ""); if (!StringUtils.isNotBlank(description)) { description = getAACHData2().getString(configAchievement + ".Message", ""); } description = StringHelper.removeFormattingCodes(description); //}

    String path = category + ".Item";
    Material material = materialHelper.matchMaterial(getAACHGUIData2().getString(path), Material.BOOK, "gui.yml (" + path + ")");
    String icon = material.name().toLowerCase();
    AchievementAdvancement.AchievementAdvancementBuilder builder = new AchievementAdvancement.AchievementAdvancementBuilder()
            .iconItem(icon)
            .title(achDisplayName)
            .description(description)
            .parent("test:" + parentKey)
            .type(lastAchievement ? AdvancementType.CHALLENGE : AdvancementType.TASK);

    AchievementAdvancement aa = builder.build();
    unsafeValues.loadAdvancement(namespacedKey, AdvancementJsonHelper.toJson(aa));
    ++generatedAdvancements;
    return achKey;
}

`

pluttotv commented 4 years ago

sorry github messed it up. at the end - i see those events in the achievments load and also i see them generated good like when u do the generate command, yet i can't see them in Advancement tab.

tried both HideAdvancements true and false.

PyvesB commented 4 years ago

Had a quick read through the code, nothing obviously wrong stood out. Have you tried awarding one of those advancements? I seem to recall that the tab only appears when you've received at least one of them.

PyvesB commented 4 years ago

No news for over two weeks, closing.