# Developer API

#### Maven / Gradle Dependency

```
<!-- pom.xml -->
<dependency>
    <groupId>in.twocube</groupId>
    <artifactId>TwoCubeCore</artifactId>
    <version>1.0.0</version>
    <scope>provided</scope>
</dependency>
```

```
// build.gradle (Groovy)
compileOnly 'in.twocube:TwoCubeCore:1.0.0'
```

#### plugin.yml

```
depend: [TwoCubeCore]        # hard â€” plugin won't load without TwoCubeCore
# OR
softdepend: [TwoCubeCore]    # soft â€” always null-check the API before use
```

#### Obtaining the API

```
import in.twocube.twocubecore.api.TwoCubeAPI;
import in.twocube.twocubecore.api.TwoCubeEconomyAPI;

TwoCubeEconomyAPI economy = TwoCubeAPI.getEconomy();
if (economy == null) return; // TwoCubeCore not loaded
```

#### Money Methods

| Method                      | Returns   | Description                                                            |
| --------------------------- | --------- | ---------------------------------------------------------------------- |
| `getMoney(UUID)`            | `double`  | Current money balance (0 if not cached)                                |
| `hasMoney(UUID, double)`    | `boolean` | true if balance â‰¥ amount                                             |
| `addMoney(UUID, double)`    | `void`    | Add to money balance                                                   |
| `removeMoney(UUID, double)` | `boolean` | Deduct money â€” returns **false** if insufficient (balance unchanged) |
| `setMoney(UUID, double)`    | `void`    | Set balance directly (clamped â‰¥ 0)                                   |

#### Shard Methods

| Method                       | Returns   | Description                                         |
| ---------------------------- | --------- | --------------------------------------------------- |
| `getShards(UUID)`            | `double`  | Current shard balance (0 if not cached)             |
| `hasShards(UUID, double)`    | `boolean` | true if shards â‰¥ amount                           |
| `addShards(UUID, double)`    | `void`    | Add to shard balance                                |
| `removeShards(UUID, double)` | `boolean` | Deduct shards â€” returns **false** if insufficient |
| `setShards(UUID, double)`    | `void`    | Set shard balance directly (clamped â‰¥ 0)          |

#### Full Example

```
import in.twocube.twocubecore.api.TwoCubeAPI;
import in.twocube.twocubecore.api.TwoCubeEconomyAPI;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

public class MyPlugin extends JavaPlugin {

    private TwoCubeEconomyAPI economy;

    @Override
    public void onEnable() {
        economy = TwoCubeAPI.getEconomy();
        if (economy == null) {
            getLogger().severe("TwoCubeCore not found! Disabling.");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }
        getLogger().info("Hooked into TwoCubeCore economy.");
    }

    // Give money reward
    public void reward(Player player, double amount) {
        economy.addMoney(player.getUniqueId(), amount);
        player.sendMessage("Â§aYou received Â§2$" + amount + "Â§a!");
    }

    // Charge money â€” returns false if player can't afford it
    public boolean charge(Player player, double cost) {
        if (!economy.removeMoney(player.getUniqueId(), cost)) {
            player.sendMessage("Â§cInsufficient balance! Need Â§4$" + cost);
            return false;
        }
        return true;
    }

    // Charge shards
    public boolean chargeShards(Player player, int cost) {
        return economy.removeShards(player.getUniqueId(), cost);
    }
}
```

{% hint style="info" %}
Important:- The player must be online (or recently loaded) for their data to be in memory cache. Operations on UUIDs that were never loaded return 0 / false.
{% endhint %}

#### Bukkit ServicesManager (alternative)

```
import org.bukkit.plugin.RegisteredServiceProvider;

RegisteredServiceProvider<TwoCubeEconomyAPI> rsp =
    Bukkit.getServicesManager().getRegistration(TwoCubeEconomyAPI.class);

if (rsp != null) {
    TwoCubeEconomyAPI eco = rsp.getProvider();
}
```

### LuckPerms Integration


---

# 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://docs.twocube.in/plugins/twocubecore-plugin/developer-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.
