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!
    Website: https://AdvancementAPI.com/
    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 https://github.com/AdvancementAPI. 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 https://pluginwiki.io/AdvancementAPI 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 https://github.com/Ste3et/AdvancementMessage

    [​IMG]


    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

    Supporter

    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 org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:499) [spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:484) [spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at net.minecraft.server.v1_12_R1.PlayerList.onPlayerJoin(PlayerList.java:342) [spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at net.minecraft.server.v1_12_R1.PlayerList.a(PlayerList.java:162) [spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at net.minecraft.server.v1_12_R1.LoginListener.b(LoginListener.java:147) [spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at net.minecraft.server.v1_12_R1.LoginListener.e(LoginListener.java:57) [spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at net.minecraft.server.v1_12_R1.NetworkManager.a(NetworkManager.java:233) [spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at net.minecraft.server.v1_12_R1.ServerConnection.c(ServerConnection.java:140) [spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:842) [spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:405) [spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:678) [spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:576) [spigot-1.12-pre2-SNAPSHOT.jar:git-Spigot-429b0e3-5195487]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_121]
    Caused by: java.lang.NullPointerException
        at com.SamB440.Kingdoms.AdvancementAPI.save(AdvancementAPI.java:136) ~[?:?]
        at com.SamB440.Kingdoms.Main.onPlayerJoin(Main.java:647) ~[?:?]
        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 org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[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.setTitle("Test!");
            api.setIcon("minecraft:golden_apple");
            api.setTrigger("minecraft:impossible");
            api.setDescription("Granted an impossible advancement!");
            api.setBackground("minecraft:textures/gui/advancements/backgrounds/stone.png");
            api.addItem(new ItemStack(Material.APPLE, 1));
            api.save(p.getWorld().toString());
            Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "advancement grant " + p.getName() + " minecraft:story test");
     
  7. Choco

    Moderator

    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(
                Bukkit.getWorld(world).getWorldFolder().getAbsolutePath()
                    + File.separator + "data"
                    + File.separator + "advancements"
                    + File.separator + "minecraft"
            + File.separator + "story");
            FileWriter fileWriter;
            try {
                fileWriter = new FileWriter(f.getAbsolutePath() + File.separator + getID() + ".json");

                fileWriter.write(getJSON());
                fileWriter.close();

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

            } catch (IOException e) {
                e.printStackTrace();
            }

        }
     
    #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?
    2017-05-15_17.03.50.png

    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?

    Thanks!
     
  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")
            .withTitle("Dregora")
            .withDescription("And so your journey began...")
            .withIcon("minecraft:book")
            .withTrigger("minecraft:impossible")
            .withBackground("minecraft:textures/gui/advancements/backgrounds/stone.png")
            .withItem(new ItemStack(Material.PAPER, 1));
            AdvancementAPI api2 = new AdvancementAPI("themessage")
            .withTitle("Delivered!")
            .withDescription("Deliver the message to the soldiers at the beacon!")
            .withIcon("minecraft:book")
            .withTrigger("minecraft:impossible")
            .withBackground("minecraft:textures/gui/advancements/backgrounds/stone.png")
            .withParent("dregora")
            .withItem(new ItemStack(Material.PAPER, 1));
            api.save(Bukkit.getWorld("EaglesRealm").getName());
            api2.save(Bukkit.getWorld("EaglesRealm").getName());
    Error:
    [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.