AdvancementAPI - Create 1.12 Advancements!

Discussion in 'Spigot Plugin Development' started by 24763, May 14, 2017.

Thread Status:
Not open for further replies.
  1. [​IMG]

    Create 1.12 Advancements with a breeze!
    Helpful Links:
    About the Project:
    From 1.12 being released to us, only soon after did I feel the determination to find an easier way for developers (like myself) to build and create advancements without having to touch or even tamper with a JSON file to succeed. This is where the idea of AdvancementAPI comes from, the API is in its stages and has been developing the minute it had been released (which I wish to thank the Github Contributors for).

    If you wish to help with the production of the API, you are more than welcome to submit a Pull Request over at This will then be looked into before merging will proceed, and all PR's will be taken into consideration to ensure they benefit the project and those who are using it. We also have a Wiki page over at which we would love for you to help by signing up and adding / contributing to the page as a whole. This will then help current and future users of this project.

    Community Showcase
    » Thank you @Ste3et_C0st for submitting this :)

    » The source for that can be seen at


    Thank you for all the support, it really means a lot and I hope that one way or another this has benefitted the community as a whole. If you liked the resource, a rating on this post would be awesome. Feedback would also be AWESOME!
    #1 24763, May 14, 2017
    Last edited: May 13, 2018
    • Like Like x 17
    • Useful Useful x 12
    • Winner Winner x 8
    • Informative Informative x 1
  2. konsolas


    Nice job. This looks like a prime candidate for the builder pattern, to ensure that the advancement is immutable.
    • Agree Agree x 8
    • Like Like x 2
    • Friendly Friendly x 1
  3. Thank you! You are welcome to edit the code with a pull request and I'll edit the post here :p

    Edit: I'll look into that!
    • Informative Informative x 1
    • Like Like x 1
  4. Pull Request merge by @Gianluca :
    • Changed ArrayList import to Guava
    • Changed to the Builder Pattern
    • Fixed setBackground being assigned to itself
    • Code beautification
    • Like Like x 1
  5. Gianluca

    Gianluca Retired Resource Staff
    Retired Patron

    Be sure to check it. I said all was untested, and I did it early in the morning on a Sunday, so xD
  6. I have an error :(
    Code (Text):
    [12:54:18] [Server thread/ERROR]: Could not pass event PlayerJoinEvent to IEKingdoms v1.2.0
    org.bukkit.event.EventException: null
        at$1.execute( ~[spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at org.bukkit.plugin.RegisteredListener.callEvent( ~[spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at org.bukkit.plugin.SimplePluginManager.fireEvent( [spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at org.bukkit.plugin.SimplePluginManager.callEvent( [spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at net.minecraft.server.v1_12_R1.PlayerList.onPlayerJoin( [spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at net.minecraft.server.v1_12_R1.PlayerList.a( [spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at net.minecraft.server.v1_12_R1.LoginListener.b( [spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at net.minecraft.server.v1_12_R1.LoginListener.e( [spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at net.minecraft.server.v1_12_R1.NetworkManager.a( [spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at net.minecraft.server.v1_12_R1.ServerConnection.c( [spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at net.minecraft.server.v1_12_R1.MinecraftServer.D( [spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at net.minecraft.server.v1_12_R1.DedicatedServer.D( [spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at net.minecraft.server.v1_12_R1.MinecraftServer.C( [spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at [spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at Source) [?:1.8.0_121]
    Caused by: java.lang.NullPointerException
        at ~[?:?]
        at com.SamB440.Kingdoms.Main.onPlayerJoin( ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_121]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_121]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_121]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_121]
        at$1.execute( ~[spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        ... 14 more
    This is my code:
    Code (Text):
            final Player p = pje.getPlayer();
            AdvancementAPI api = new AdvancementAPI("test");
            api.setDescription("Granted an impossible advancement!");
            api.addItem(new ItemStack(Material.APPLE, 1));
            Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "advancement grant " + p.getName() + " minecraft:story test");
  7. Choco


    Pretty sure you want World#getName(), and not World#toString(). That prints out a lot more than just the name of the world.

    @OP You may be better off passing a World object to that method rather than an undocumented String. A bit more null safe in case someone passes a World name that doesn't exist
  8. I actually added some code to his API, which allows me to input a custom world, he was just getting 'world' before.

    Edit: Thanks, it worked @2008Choco . The only issue I'm having is granting a player an achievement. How would I accomplish this?

    Edit2: Nvm! I got it working! Command: /advancement grant SamB440 only minecraft:story/test Also, how does the setBackground work? I would like to set a custom background

    And if you're interested, this is the new 'save' code in the API I made:
    Code (Text):
        public void save(String world) {
            File f = new File(
                    + File.separator + "data"
                    + File.separator + "advancements"
                    + File.separator + "minecraft"
            + File.separator + "story");
            FileWriter fileWriter;
            try {
                fileWriter = new FileWriter(f.getAbsolutePath() + File.separator + getID() + ".json");


                Bukkit.getLogger().info("[AdvancementAPI] Created " + getID() + ".json.");

            } catch (IOException e) {

    #10 SamB440, May 15, 2017
    Last edited: May 15, 2017
  9. I'll update the code later :)
  10. I've updated the main post now, shows the latest (working) version directly from GitHub.

    @konsolas API now uses the builder pattern :) (thanks to @Gianluca)
  11. How would I make advancements like this?

    Example, I want a tree of advancements like shown in the above picture. The dirt block has the category 'minecraft' when you hover over it.. how can I do this?

  12. If I remember rightly, set the parent to minecraft:story (not 100% certain).

    Advancement JSON System is still currently new to me :p

    I'll look into it however
    • Like Like x 1
  13. Yus :p :D
    • Like Like x 1
  14. One last issue (not sure if this is related to you, but oh well..)

    Minecraft can't find the json file.
    My code:
    Code (Text):
            AdvancementAPI api = new AdvancementAPI("dregora")
            .withDescription("And so your journey began...")
            .withItem(new ItemStack(Material.PAPER, 1));
            AdvancementAPI api2 = new AdvancementAPI("themessage")
            .withDescription("Deliver the message to the soldiers at the beacon!")
            .withItem(new ItemStack(Material.PAPER, 1));
    [18:42:12] [Client thread/INFO]: [CHAT] [Server: No advancement was found by the name 'minecraft:story/dregora']
    [18:42:12] [Client thread/INFO]: [CHAT] [Server: No advancement was found by the name 'minecraft:story/themessage']

    Thanks once again!
  15. Strange o.0
    Did it save the file correctly?
Thread Status:
Not open for further replies.