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.
Java 8 and Bukkit / Spigot. Most server versions in the Spigot Repository are 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.
<dependencies>
<dependency>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui</artifactId>
<version>1.2.1-SNAPSHOT</version>
</dependency>
...
</dependencies>
<repositories>
<repository>
<id>wesjd-repo</id>
<url>https://nexus.wesjd.net/repository/thirdparty/</url>
</repository>
...
</repositories>
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.
(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.
Build with mvn clean install
. Do note that you will need the spigot jars in this repo to be installed on your
local repository. To make this easier, you can use this shell script.
This project is licensed under the MIT License.