# API

## Methods

You can check all methods with the **EpicCraftingsAPI** class.

## Events

```java
// Event called when player is trying to craft an item.
@EventHandler
public void preCraftEvent(EpicCraftingsPreCraftEvent event){
  Player player = event.getPlayer();
  Crafting crafting = event.getCrafting();
}
```

```java
// Event called when successfully crafted an item and materials are removed 
// from players inventory.
@EventHandler
public void craftEvent(EpicCraftingsCraftEvent event){
  Player player = event.getPlayer();
  Crafting crafting = event.getCrafting();
}
```

## Creating Inventory Providers

If you have another plugin that manages player inventories, virtual chests or additional inventories, you can allow EpicCraftingsPlus to check for required items when crafting in those inventories as well.

First you need to create your inventory provider.

```java
// Create your inventory provider. Must extend EpicCraftingsInventoryProvider
public class CustomInventoryProvider extends EpicCraftingsInventoryProvider {

    public CustomInventoryProvider () {
        // Name of the inventory provider
        super("custom_inventory_provider");
    }

    @Override
    public int getTotalItems(Player player, CraftingItem craftingItem, CheckItemProperties checkItemProperties)
        // Must return the amount of items on this inventory 
        // You can use EpicCraftingsAPI.getPlugin().getCraftingItemManager().isTheSameItem(craftingItem, item, checkItemProperties)
        // to compare items.
    }

    @Override
    public int removeItems(Player player,CraftingItem craftingItem,CheckItemProperties checkItemProperties,int amountToRemove);
        // Must return the amount of items that were removed from this inventory
        // You can use EpicCraftingsAPI.getPlugin().getCraftingItemManager().isTheSameItem(craftingItem, item, checkItemProperties)
        // to compare items.
    }
}
```

Then you must register the new provider when enabling your plugin.

```java
public void onEnable(){
    EpicCraftingsAPI.registerInventoryProviders(this,new CustomInventoryProvider());
}
```

Now, when player tries to craft something, the required items will be searched in the player inventory and the additional inventory you are registering.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ajneb97.gitbook.io/epiccraftingsplus/api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
