> For the complete documentation index, see [llms.txt](https://notnaxito.gitbook.io/notnaxito-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notnaxito.gitbook.io/notnaxito-docs/api.md).

# API

Si programas plugins y quieres integrar tus desarrollos con **CMRankups**, puedes engancharte directamente a su instancia usando Java de forma muy sencilla.

***

## Dependencia

Agrega el jar de **CMRankups** en las dependencias de tu proyecto de Maven/Gradle e indícalo en el archivo `plugin.yml` de tu plugin para asegurar que cargue después:

```yaml
softdepend: [CMRankups]
```

***

## Acceso a la Instancia Principal

Para comunicarte con el plugin, obtén la instancia usando su método estático:

```java
import com.cm.rankups.CMRankups;

CMRankups api = CMRankups.getInstance();
```

Desde esta instancia puedes acceder a todas las funciones y hooks del plugin:

***

## Ejemplos de uso

### 1. Saber el rango de un jugador (api.getRankupManager())

Este gestor tiene todo lo necesario para calcular las progresiones y consultar rangos:

* **Buscar un rango por su ID:**

  ```java
  import com.cm.rankups.models.Rankup;

  Rankup rank = api.getRankupManager().getRankup("B");
  if (rank != null) {
      String nombreColoreado = rank.getName(); // Te da el nombre del rango con colores listos
      int slot = rank.getSlot();
  }
  ```
* **Saber cuál es el siguiente rango al que puede subir un jugador:**

  ```java
  org.bukkit.entity.Player player = ...;
  Rankup nextRank = api.getRankupManager().getNextRankup(player);
  if (nextRank != null) {
      player.sendMessage("Tu próximo rango es: " + nextRank.getName());
  } else {
      player.sendMessage("¡Ya estás en el rango máximo!");
  }
  ```
* **Comprobar si el jugador ya tiene o superó cierto rango:**

  ```java
  boolean tieneRango = api.getRankupManager().hasRankup(player, "B");
  ```

***

### 2. Mensajes del plugin (api.getConfigManager())

Si quieres mandar mensajes del plugin con su prefijo y colores aplicados:

* **Obtener un mensaje como String con colores clásicos:**

  ```java
  String msg = api.getConfigManager().getMessage("rankup_failed");
  ```
* **Obtener el mensaje como Component de Adventure (MiniMessage):**

  ```java
  net.kyori.adventure.text.Component component = api.getConfigManager().getMessageComponent("rankup_success");
  ```

***

### 3. Hooks de Economía y Permisos

Si necesitas consultar de forma segura los plugins externos a través del puente que usa el plugin:

* **Consultar saldo o cobrar dinero con Vault:**

  ```java
  double balance = api.getVaultHook().getBalance(player);
  api.getVaultHook().withdraw(player, 100.0);
  ```
* **Añadir a un jugador a un grupo de LuckPerms:**

  ```java
  api.getLuckPermsHook().addPlayerToGroup(player, "rango_a");
  ```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://notnaxito.gitbook.io/notnaxito-docs/api.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
