Note
The Maven repository for AnvilGUI has moved as of version 1.10.11-SNAPSHOT.
Replace:
<id>codemc-snapshotsid>
<url>https://repo.codemc.io/repository/maven-snapshots/url>
repository>
With:
<id>mvn-wesjd-netid>
<url>https://mvn.wesjd.net/url>
repository>
AnvilGUI
AnvilGUI is a Minecraft Java Edition library that supports capturing user input from an anvil inventory without touching version-specific code.
.onClose(stateSnapshot -> {
stateSnapshot.getPlayer().sendMessage("You closed the inventory.");
})
.onClick((slot, stateSnapshot) -> {
if(slot != AnvilGUI.Slot.OUTPUT) {
return Collections.emptyList();
}
if(stateSnapshot.getText().equalsIgnoreCase("you")) {
stateSnapshot.getPlayer().sendMessage("You have magical powers!");
return Arrays.asList(AnvilGUI.ResponseAction.close());
} else {
return Arrays.asList(AnvilGUI.ResponseAction.replaceInputText("Try again"));
}
})
.preventClose()
.text("What is the meaning of life?")
.title("Enter your answer")
.plugin(plugin)
.open(player);
More usage information is available in USAGE.md
Installation
Add the repository and dependency to your POM:
<id>mvn-wesjd-netid>
<url>https://mvn.wesjd.net/url>
repository>
<dependency>
<groupId>net.wesjdgroupId>
<artifactId>anvilguiartifactId>
<version>1.10.11-SNAPSHOTversion>
<scope>compilescope>
dependency>
Since AnvilGUI is a library, it must be shaded into your plugin. Follow the example shade config below to ensure that:
- You avoid classpath conflicts with other plugins
- You do not break the library when minimizing your JAR
<plugins>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-shade-pluginartifactId>
<version>${shade.version}version>
<executions>
<execution>
<phase>packagephase>
<goals>
<goal>shadegoal>
goals>
<configuration>
<relocations>
<relocation>
<pattern>net.wesjd.anvilguipattern>
<shadedPattern>[YOUR_PLUGIN_PACKAGE].anvilguishadedPattern>
relocation>
relocation>
<filters>
<filter>
<artifact>*:*artifact>
<excludeDefaults>falseexcludeDefaults>
<includes>
<include>net/wesjd/anvilgui/**include>
includes>
filter>
filters>
configuration>
execution>
executions>
plugin>
plugins>
build>
Requirements
- Java 8+
- Bukkit / Spigot / Paper for Minecraft 1.7+
- Spigot mappings
Ensuring you are using Spigot mappings
AnvilGUI is compiled against Spigot mappings. Mojang mappings are not supported at runtime. You can still develop using Mojang mappings when using Paperweight. See below.
Bukkit Plugin
Your plugin is a Bukkit plugin if it contains a plugin.yml and does not contain a paper-plugin.yml.
Bukkit plugins use Spigot mappings by default.
Note that you can still use the Paper API even if your plugin is a Bukkit plugin. The Paper plugin system provides some additional features on top of the Paper API, but is not needed in order to use the Paper API.
Paper Plugin
Your plugin is a Paper plugin if it contains a paper-plugin.yml (even if plugin.yml is also present).
Paper plugins do not use Spigot mappings by default. You must explicitly enable them via your manifest.
If you are accessing server internals in your paper plugin, you need to reobfuscate your plugin to Spigot mappings. Assuming you are using the Paperweight Userdev toolchain, enable Spigot mappings via the reobfArtifactConfiguration option.