Skip to content

upperlevel/anvil-gui

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AnvilGUI

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

This project 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 in a non-private plugin where users will have lots of different versions of the server running.

Requirements

Java 8 and Bukkit / Spigot. Most server versions in the Spigot Repository are supported.

My version isn't supported

If you are a developer, submit a pull request adding a wrapper class for your version. Otherwise, please create an issue on the issues tab.

How to use

As a dependency

<dependencies>
    <dependency>
        <groupId>xyz.upperlevel.spigot.anvilgui</groupId>
        <artifactId>spigot-anvil-gui</artifactId>
        <version>1.3</version>
    </dependency>
    ...
</dependencies>

In your plugin

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.

Compilation

Build with mvn clean install. Do note that you will need maven installed

License

This project is licensed under the MIT License.

About

Easy to use anvil GUI API to get user input.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%