# Custom economy

With the zAuctionHouse API, you can create an infinite amount of AuctionEconomy! To do this, you need to create a class that implements the AuctionEconomy interface. Then, simply implement each method in the interface.

Here is an example of an economy with the level of the players:

```java
package fr.maxlego08.zauctionhouse.economy;

import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;

import fr.maxlego08.zauctionhouse.api.economy.AuctionEconomy;

public class LevelEconomy implements AuctionEconomy {

  @Override
  public long getMoney(OfflinePlayer offlinePlayer) {
    return offlinePlayer.isOnline() ? ((Player) offlinePlayer).getLevel() : 0;
  }

  @Override
  public boolean hasMoney(OfflinePlayer offlinePlayer, long price) {
    return getMoney(offlinePlayer) >= price;
  }

  @Override
  public void depositMoney(OfflinePlayer offlinePlayer, long value) {
    if (offlinePlayer.isOnline()) {
      int level = offlinePlayer.getPlayer().getLevel();
      offlinePlayer.getPlayer().setLevel((int) (level + value));
    }
  }

  @Override
  public void withdrawMoney(OfflinePlayer offlinePlayer, long value) {
    if (offlinePlayer.isOnline()) {
       int level = offlinePlayer.getPlayer().getLevel();
       offlinePlayer.getPlayer().setLevel((int) (level - value));
    }
  }

  @Override
  public String getCurrency() {
    return "%price%L";
  }

  @Override
  public String getFormat() {
    return "l";
  }

  @Override
  public boolean isEnable() {  
    return true;
  }

  @Override
  public String getName() {
    return "LEVEL";
  }
  
}
```

If you directly imported the jar of the plugin you can use the `DefaultEconomy` class like that:

```java
public class ExampleEconomy extends DefaultEconomy {

    public ExampleEconomy() {
        super("example", "%price%€", "You dont have enough money", "e");
    }

    @Override
    public long getMoney(OfflinePlayer offlinePlayer) {
        return 10000;
    }

    @Override
    public void depositMoney(OfflinePlayer offlinePlayer, long l) {
        // Do Your Stuff
    }

    @Override
    public void withdrawMoney(OfflinePlayer offlinePlayer, long l) {
        // Do Your Stuff
    }
}
```

Vous devez ajouter dans votre plugin.yml le loadBefore pour zAuctionHouse. Cela va indiquer a votre serveur que votre plugin doit charger avant zAuctionHouse.

```yaml
loadbefore:
  - zAuctionHouseV3
```

Then you need to create a listener for the event `AuctionLoadEconomyEvent`, this event will allow to retrieve the `EconomyManager` interface to register your economy.

```java
public class TestListener implements Listener {

    @EventHandler
    public void onLoad(AuctionLoadEconomyEvent event) {

        EconomyManager economyManager = event.getEconomyManager();
        economyManager.registerEconomy(new ExampleEconomy());
    }

}
```


---

# 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://zauctionhouse.groupez.dev/development-portal/custom-economy.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.
