# 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.challenges</groupId>
  <artifactId>api</artifactId>
  <version>1.0.0-BETA</version> 
  <scope>system</scope>
  <systemPath>${project.basedir}\libs\Challenges-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: ['Challenges-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
ChallengesAPI challengesAPI = Bukkit.getServicesManager().getRegistration(ChallengesAPI.class).getProvider();
```

#### Change challenge wins

```java
UUID uuid = player.getUniqueId();
IUser user = challengesAPI.getUserUtil().getUser(uuid);
IChallenge challenge = challengesAPI.getChallengesUtil().getChallenge(@NotNull String id);
IChallengeUser challengeUser = challengesAPI.getChallengesUtil().getUserChallenge(user, challenge)

challengeUser.setChallengeWins(2);
```
