# API Hook-up

{% hint style="info" %}
Ask for the API .jar file from [**here**](https://discord.gg/8yDm538BhU).
{% endhint %}

### Registering the API in your project

{% hint style="warning" %}
First you need to create a folder in the main path of your project and store the .jar file there.
{% endhint %}

#### Maven&#x20;

Replace `libs` with the name of the directory where the .jar file is stored and replace `API.jar` with the name of the .jar file.

{% code lineNumbers="true" %}

```atom
<dependency>
  <groupId>com.reussy.development.quests</groupId>
  <artifactId>api</artifactId>
  <version>4.0.0-BETA</version> 
  <scope>system</scope>
  <systemPath>${project.basedir}\libs\API.jar</systemPath>
</dependency>
```

{% endcode %}

#### Gradle

Replace `libs` with the name of the directory where the .jar file is stored and replace `API.jar` with the name of the .jar file.

```yaml
implementation fileTree(include: ['API.jar'], dir: 'libs')
```

### Obtaining and using the API

To obtain the API class we make use of the service provided by Bukkit to register a class and retrieve it using `#getRegistration` method.

#### Retrieving the service

```java
QuestsAPI questsAPI = Bukkit.getServicesManager().getRegistration(QuestsAPI.class).getProvider();
```

#### Manipulating a registered user in the cache

```java
UUID uuid = player.getUniqueID();
IUser user = questsAPI.getUserUtil().getUser(uuid);
        
user.setRemainingChallenges(5);
user.getPlayer().sendMessage("The remaining challenges has been set to 5.");
```

#### Manipulating the progress of a quest or challenge

```java
UUID uuid = player.getUniqueID();
IUser user = questsAPI.getUserUtil().getUser(uuid);

user.getUserQuestsProgress("first_win").setProgress(10); // Set the progress to 10.
user.getUserQuestsProgress("first_win").setStatus(QuestStatus.COMPLETED); // Set the status to completed.
user.getPlayer().sendMessage("§aQuests §8» §7Quest §aFirst Win §7completed!");
```

#### Start a quest for a user

```java
UUID uuid = UUID.randomUUID();
IUser user = questsAPI.getUserUtil().getUser(uuid);
IQuest quest = questsAPI.getQuestUtil().getQuest("first_win");

 questsAPI.getQuestUtil().startQuest(user, quest);
```


---

# 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://huh-docs.gitbook.io/quests-add-on/developer-api/api-hook-up.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.
