<commit_before># AnvilGUI
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](https://hub.spigotmc.org/nexus/) 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](https://jitpack.io/#WesJD/AnvilGUI)
### In your plugin
```java
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
    .item(new ItemStack(Material.GOLD_BLOCK)) //use a custom item for the first slot
    .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
```

### [Javadocs](http://docs.wesjd.net/AnvilGUI/)

## Compilation
Build with `mvn clean install`.

## License
This project is licensed under the [MIT License](LICENSE).<commit_msg>add better method descriptions to readme<commit_after># AnvilGUI
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](https://hub.spigotmc.org/nexus/) 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

AnvilGUI requires the usage of Maven or a Maven compatible build system. 
You can find the repository and dependency information [here](https://jitpack.io/#WesJD/AnvilGUI).

### 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](http://docs.wesjd.net/AnvilGUI/).

#### `onClose(Consumer<Player>)` 
Takes a `Consumer<Player>` argument that is called when a player closes the anvil gui.
```java                                             
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()` or `text(String)`. Returning `close()` will close the inventory; returning `text(String)` will keep
the inventory open and put the supplied String in the renaming field.           
```java                                                
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.                                      
```java                     
builder.preventClose();     
```                         
     
#### `text(String)`
Takes a `String` that contains what the initial text in the renaming field should be set to.
```java                                           
builder.text("What is the meaning of life?");     
```  

#### `item(ItemStack)`
Takes a custom `ItemStack` to be placed in the input slot.
```java                                              
ItemStack stack = new ItemStack(Material.GOLD_BLOCK);
ItemMeta meta = stack.getItemMeta();                 
meta.setLore(Arrays.asList("Hi there"));             
stack.setItemMeta(meta); builder.item(stack);        
```                                                  

#### `title(String)`
Takes a `String` that will be used as the inventory title. Only displayed in Minecraft 1.14 and above.
```java                            
builder.title("Enter your answer");
```                                
                 
#### `plugin(Plugin)`
Takes the `Plugin` object that is making this anvil gui. It is needed to register listeners.
```java                                         
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.                                                                                            
```java              
builder.open(player);
```                  

### A full example combining all methods
```java
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
    .item(new ItemStack(Material.GOLD_BLOCK)) //use a custom item for the first slot
    .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](LICENSE).
{'fraction_non_alphanumeric': 0.08797385620915033, 'fraction_numerical': 0.001437908496732026, 'mean_word_length': 1.7660882140274765, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 38, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3330142', 'n_tokens_mistral': 1821, 'n_tokens_neox': 1748, 'n_words': 729}