Skip to content

AnvilAPI

ElieTGM edited this page Feb 9, 2017 · 4 revisions

AnvilGUI

Easily use anvil guis to get a user's input.

This api/module was made since their is no easy way to do this with the Spigot / Bukkit APIs. It requires interaction with NMS and that is a pain of doing in your plugin development.

Requirements

As previously said in the Requirements page, all apis/modules that you might use need to be built on a Java 8 and a 1_8_3 spigot version.

How To Use

After you successfully add OctopusCore to your project library by downloading it from the Releases page, here's what you have to do the following:

Prompting a user for input

new AnvilGUI(myPluginInstance, myPlayer, "What is the meaning of life?", (player, reply) -> {
    if (reply.equalsIgnoreCase("you")) {
        player.sendMessage("You have magical powers!");
        return null;
    }
    return "Incorrect.";
});

The AnvilGUI takes in a parameter of your plugin, the player that the GUI should open for, a prompt, and the BiFunction. The first two parameters are quite obvious, and the third for example would be a question, just like what is shown above.

Handling their answer

(player, reply) -> {
    if (reply.equalsIgnoreCase("you")) {
        player.sendMessage("You have magical powers!");
        return null;
    }
    return "Incorrect.";
}

The above code is what is inside your BiFunction. The parameters of the function are also obvious, the player who answered and their reply. The function also returns a String. This string is to be used if the user is wrong, etc, and it will show in the dialogue box in the GUI what is supplied. If you return null, the inventory will close.

Questions?

If you have any questions regarding the AnvilGUI api, please PM ElieTGM/JosephGP over at Skype or ask in the #development section of the staff chat.

Clone this wiki locally