# 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);
```
