TextGUI
You want the player to input a single line of text, but chat is either too busy or not an interesting medium. How about through an Anvil interface? Creating one is simple - you may either instantiate a TextGUI object or extend the class, but with the added step of calling the #build
method.
Option 1: Object
Quick and easy, this method is ideal for infrequent use of your GUI:
// Create the object with title, size is ignored
TextGUI tg = new TextGUI(new GUI("Submit answer", Rows.ONE));
// Only first slot can set configured
tg.setItem(0, new Item(Material.BOOK));
// Pass settings to builder
tg.build(null, true, false);
// Open the inventory for a Player
tg.openInventory(player);
Option 2: Extended Class
This method is preferred if you intend to reuse your GUI frequently and/or show it to multiple players at once. For example:
public class MyCustomGUI extends TextGUI {
public MyCustomGUI(Player player) {
super(new GUI("Submit answer"), Rows.ONE);
setItem(0, new Item(Material.BOOK));
final int id = this.getId();
final boolean preventClose = false;
build(new BukkitRunnable() {
final TextGUI tg = (TextGUI)MilkGUI.INSTANCE.getGUI(id);
@Override
public void run() {
final String output = tg.getOutput().trim();
player.sendMessage("You wrote " + output);
}
}, preventClose);
}
}
// Call #openInventory from another class or listener
Last updated
Was this helpful?