All Projects β†’ WesJD β†’ Anvilgui

WesJD / Anvilgui

Licence: mit
Easily use anvil guis to get a user's input

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Anvilgui

Lagmonitor
Monitor performance of your Minecraft server. Similar to VisualVM and Java Mission Control.
Stars: ✭ 147 (-24.23%)
Mutual labels:  minecraft, spigot, bukkit
Advanced Achievements
πŸŽ† Popular plugin that adds unique and challenging achievements to Minecraft servers.
Stars: ✭ 151 (-22.16%)
Mutual labels:  minecraft, spigot, bukkit
Glowstone
A fast, customizable and compatible open source server for Minecraft: Java Edition
Stars: ✭ 1,364 (+603.09%)
Mutual labels:  minecraft, spigot, bukkit
Worldedit
πŸ—ΊοΈ Minecraft map editor and mod
Stars: ✭ 2,288 (+1079.38%)
Mutual labels:  minecraft, spigot, bukkit
Holographicdisplays
Create modern looking holograms in Minecraft.
Stars: ✭ 175 (-9.79%)
Mutual labels:  minecraft, spigot, bukkit
Viabackwards
Allows the connection of older clients to newer server versions for Minecraft servers.
Stars: ✭ 135 (-30.41%)
Mutual labels:  minecraft, spigot, bukkit
Chestshop 3
ChestShop - the chest & sign shop plugin for Minecraft Servers running Bukkit/Spigot/Paper
Stars: ✭ 158 (-18.56%)
Mutual labels:  minecraft, spigot, bukkit
Plugman
Plugin manager for Bukkit servers.
Stars: ✭ 80 (-58.76%)
Mutual labels:  minecraft, spigot, bukkit
Geyser
A bridge/proxy allowing you to connect to Minecraft: Java Edition servers with Minecraft: Bedrock Edition.
Stars: ✭ 2,851 (+1369.59%)
Mutual labels:  minecraft, spigot, bukkit
Slime World Manager
A Spigot plugin that implements the Slime Region Format.
Stars: ✭ 118 (-39.18%)
Mutual labels:  minecraft, spigot, bukkit
Commandbook
General and administrative commands
Stars: ✭ 139 (-28.35%)
Mutual labels:  minecraft, spigot, bukkit
Serverlistplus
A flexible Minecraft plugin to customize the appearance of your server in the server list
Stars: ✭ 127 (-34.54%)
Mutual labels:  minecraft, spigot, bukkit
Bstats
bStats collects data for plugin authors. It's free and easy to use!
Stars: ✭ 99 (-48.97%)
Mutual labels:  minecraft, spigot, bukkit
Mobarena
MobArena plugin for Minecraft
Stars: ✭ 147 (-24.23%)
Mutual labels:  minecraft, spigot, bukkit
Savagefactions
The Ultimate Competitve Factions Plugin. Switches focus from casual factions and introduces new features for competitive factions.
Stars: ✭ 99 (-48.97%)
Mutual labels:  minecraft, spigot, bukkit
Bedwarsrel
Bedwars Reloaded - The Minecraft Bedwars Plugin!
Stars: ✭ 108 (-44.33%)
Mutual labels:  minecraft, spigot, bukkit
Chestcommands
An intuitive and powerful plugin to create graphical user interfaces in Minecraft.
Stars: ✭ 62 (-68.04%)
Mutual labels:  minecraft, spigot, bukkit
Guilds
Adding RPG to your server has never been more fun and action-packed!
Stars: ✭ 66 (-65.98%)
Mutual labels:  minecraft, spigot, bukkit
Xseries
Library for cross-version Minecraft Bukkit support and various efficient API methods.
Stars: ✭ 109 (-43.81%)
Mutual labels:  minecraft, spigot, bukkit
Betonquest
An advanced and powerful quest scripting plugin for Minecraft. Features built-in RPG style conversations and integration for over 25 other plugins.
Stars: ✭ 121 (-37.63%)
Mutual labels:  minecraft, spigot, bukkit

AnvilGUI Build Status

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

This project was made since there is no way to prompt users with an anvil input with the Spigot / Bukkit API. It requires interaction with NMS and that is a pain in plugins where users have 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 module for your version. Otherwise, please create an issue on the issues tab.

Usage

As a dependency

AnvilGUI requires the usage of Maven or a Maven compatible build system.

<dependency>
    <groupId>net.wesjd</groupId>
    <artifactId>anvilgui</artifactId>
    <version>1.5.0-SNAPSHOT</version>
</dependency>

<repository>
    <id>codemc-snapshots</id>
    <url>https://repo.codemc.io/repository/maven-snapshots/</url>
</repository>

In your plugin

The AnvilGUI.Builder class is how you build an AnvilGUI. The following methods allow you to modify various parts of the displayed GUI. Javadocs are available here.

onClose(Consumer<Player>)

Takes a Consumer<Player> argument that is called when a player closes the anvil gui.

builder.onClose(player -> {                         
    player.sendMessage("You closed the inventory.");
});                                                 

onComplete(BiFunction<Player, String, AnvilGUI.Response>)

Takes a BiFunction<Player, String, AnvilGUI.Response> argument. The BiFunction is called when a player clicks the output slot. The supplied string is what the player has inputted in the renaming field of the anvil gui. You must return an AnvilGUI.Response, which can either be close(), text(String), or openInventory(Inventory). Returning close() will close the inventory; returning text(String) will keep the inventory open and put the supplied String in the renaming field; returning openInventory(Inventory) will open the provided inventory, which is useful for when a user has finished their input in GUI menus.

builder.onComplete((player, text) -> {                 
    if(text.equalsIgnoreCase("you")) {                 
        player.sendMessage("You have magical powers!");
        return AnvilGUI.Response.close();              
    } else {                                           
        return AnvilGUI.Response.text("Incorrect.");   
    }                                                  
});                                                    

preventClose()

Tells the AnvilGUI to prevent the user from pressing escape to close the inventory. Useful for situations like password input to play.

builder.preventClose();     

text(String)

Takes a String that contains what the initial text in the renaming field should be set to.

builder.text("What is the meaning of life?");     

itemLeft(ItemStack)

Takes a custom ItemStack to be placed in the left input slot.

ItemStack stack = new ItemStack(Material.IRON_SWORD);
ItemMeta meta = stack.getItemMeta();                 
meta.setLore(Arrays.asList("Sharp iron sword"));             
stack.setItemMeta(meta); 
builder.itemLeft(stack);        

onLeftInputClick(Consumer<Player>)

Takes a Consumer<Player> to be executed when the item in the left input slot is clicked.

builder.onLeftInputClick(player -> {
    player.sendMessage("You clicked the left input slot!");
});        

itemRight(ItemStack)

Takes a custom ItemStack to be placed in the right input slot.

ItemStack stack = new ItemStack(Material.IRON_INGOT);
ItemMeta meta = stack.getItemMeta();                 
meta.setLore(Arrays.asList("A piece of metal"));             
stack.setItemMeta(meta); 
builder.itemRight(stack);        

onRightInputClick(Consumer<Player>)

Takes a Consumer<Player> to be executed when the item in the right input slot is clicked.

builder.onRightInputClick(player -> {
    player.sendMessage("You clicked the right input slot!");
});        

title(String)

Takes a String that will be used as the inventory title. Only displayed in Minecraft 1.14 and above.

builder.title("Enter your answer");

plugin(Plugin)

Takes the Plugin object that is making this anvil gui. It is needed to register listeners.

builder.plugin(pluginInstance);                 

open(Player)

Takes a Player that the anvil gui should be opened for. This method can be called multiple times without needing to create a new AnvilGUI.Builder object.

builder.open(player);

A full example combining all methods

new AnvilGUI.Builder()
    .onClose(player -> {                                        //called when the inventory is closing
        player.sendMessage("You closed the inventory.");
    })
    .onComplete((player, text) -> {                             //called when the inventory output slot is clicked
        if(text.equalsIgnoreCase("you")) {
            player.sendMessage("You have magical powers!");
            return AnvilGUI.Response.close();
        } else {
            return AnvilGUI.Response.text("Incorrect.");
        }
    })
    .preventClose()                                             //prevents the inventory from being closed
    .text("What is the meaning of life?")                       //sets the text the GUI should start with
    .itemLeft(new ItemStack(Material.IRON_SWORD))               //use a custom item for the first slot
    .itemRight(new ItemStack(Material.IRON_INGOT))              //use a custom item for the second slot
    .onLeftInputClick(player -> player.sendMessage("sword"))    //called when the left input slot is clicked
    .onRightInputClick(player -> player.sendMessage("ingot"))   //called when the right input slot is clicked
    .title("Enter your answer.")                                //set the title of the GUI (only works in 1.14+)
    .plugin(myPluginInstance)                                   //set the plugin instance
    .open(myPlayer);                                            //opens the GUI for the player provided

Compilation

Build with mvn clean install.

License

This project is licensed under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].