Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Add overloads to UnsafeValues#loadAdvancement

Open Strokkur424 opened this issue 11 months ago • 1 comments

This PR adds two new methods to UnsafeValues to improve the workflow of working with Advancements:

  • loadAdvancement(NamespacedKey key, String advancement, boolean persist)
  • loadAdvancements(Map<Key, String> advancements, boolean persist)

The first method just adds a new overload to the existing loadAdvancement method, which allows for disabling the printing into the Bukkit datapack. From my testing, this doesn't actually persist the Advancement anyways, so I am not even entirely certain what the point of storing it in the Bukkit datapack is, but that's probably a bug and it was intended to work that way.

The second method allows for bulk-registering advancements.

Example of registering two enchantments using the new `loadAdvancements` method
final boolean persist = false;
Bukkit.getUnsafe().loadAdvancements(Map.of(
        new NamespacedKey("cool_plugin", "cool/root"), """
            {
                "display": {
                  "announce_to_chat": false,
                  "show_toast": false,
                  "background": "minecraft:gui/advancements/backgrounds/adventure",
                  "icon": { "id": "diamond_sword" },
                  "title": { "color": "blue", "text": "Cool Advancements" },
                  "description": { "color": "aqua", "text": "Only for the coolest of all!" },
                  "frame": "challenge"
                },
                "criteria": { "impossible": {"trigger": "minecraft:impossible"} },
                "requirements": [ ["impossible"] ]
            }
            """,
        new NamespacedKey("cool_plugin", "cool/unlocked"), """
            {
                "parent": "cool_plugin:cool/root",
                "display": {
                  "announce_to_chat": true,
                  "show_toast": true,
                  "icon": { "id": "netherite_sword" },
                  "title": { "color": "dark_red", "text": "You are cool!" },
                  "description": { "color": "red", "text": "If you have this advancement, it means you are cool!!" },
                  "frame": "challenge",
                  "hidden": true
                },
                "criteria": { "impossible": {"trigger": "minecraft:impossible"} },
                "requirements": [ ["impossible"] ]
            }
            """),
    persist
);

Testing the Advancements, they work as intended even if registered in bulk.

image

image

Strokkur424 avatar May 16 '25 20:05 Strokkur424

Rebased to 1.21.6

Strokkur424 avatar Jun 17 '25 17:06 Strokkur424

Rebased to 1.21.7

Strokkur424 avatar Jul 12 '25 12:07 Strokkur424

I've addressed all requested changes now.

Strokkur424 avatar Jul 12 '25 12:07 Strokkur424

Rebased to 1.21.8

Strokkur424 avatar Jul 17 '25 17:07 Strokkur424