# API Examples

## Step 1. Add the SimpleClans API to your plugin

There are two ways to do this: via Maven or locally. \
We strongly **recommend** doing this via Maven.

### Maven

Add the following lines to `pom.xml`:

```markup
<repositories>
    <repository>
        <id>roinujnosde-repo</id>
        <url>https://repo.roinujnosde.me/releases/</url>
    </repository>
</repositories>
```

```markup
<dependencies>
    <dependency>
        <groupId>net.sacredlabyrinth.phaed.simpleclans</groupId>
        <artifactId>SimpleClans</artifactId>
        <version>2.19.2</version> 
        <!-- You can find out the latest available version in the note below -->
        <scope>provided</scope>
    </dependency>
</dependencies>
```

{% hint style="info" %}
**Note**\
The latest version can be found here: [link](https://github.com/RoinujNosde/SimpleClans/releases)
{% endhint %}

### Locally

In this example, we will use the IntelliJ IDEA, but the following actions also work in other IDEs.

1. Open the structure of your project (`F4`)
2. Select Libraries, click on the cross, select "New Project Library -> Java" in the window that appears and add SimpleClans.

![](https://3147254304-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MDzSURjf29qvGnoWu7Z%2F-MdwTNsxIlqZzSOmzk7E%2F-MdwUWt3zBLiI4pamGtX%2F%D0%B8%D0%B7%D0%BE%D0%B1%D1%80%D0%B0%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5.png?alt=media\&token=fe2d8204-f901-4f0b-8c90-8eef95c6a088)

Return to the project structure, then go to Project Settings - > Modules, set the compilation mode to "Provided".

![](https://3147254304-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MDzSURjf29qvGnoWu7Z%2F-MdwTNsxIlqZzSOmzk7E%2F-MdwUjSRzRAXP7fqoQD7%2F%D0%B8%D0%B7%D0%BE%D0%B1%D1%80%D0%B0%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5.png?alt=media\&token=0868d6ba-8f4a-46e1-828c-6d0247576078)

* [x] Congratulations, you have added the SimpleClans API to your project. 😃

## Step 2. Use the SimpleClans API

#### What do you need to know?

* [**ClanPlayer**](https://ci.roinujnosde.me/job/SimpleClans/Javadoc/net/sacredlabyrinth/phaed/simpleclans/ClanPlayer.html) is a class that represents a player object. This class contains information about the player, his clan, etc.
* [**Clan**](https://ci.roinujnosde.me/job/SimpleClans/Javadoc/net/sacredlabyrinth/phaed/simpleclans/Clan.html) is a class that presents a clan object. It has methods for getting clan players, clan tag, allies, leaders, etc.
* [**ClanManager**](https://ci.roinujnosde.me/job/SimpleClans/Javadoc/net/sacredlabyrinth/phaed/simpleclans/managers/ClanManager.html) is a class that allows you to retrieve **Clan** and **ClanPlayer**.

#### Example of using SimpleClans API

You can hook into SimpleClans plugin like so:

{% tabs %}
{% tab title="MyPlugin.class" %}

```java
public class MyPlugin extends JavaPlugin {
    private static MyPlugin instance;
    private SimpleClans sc;
     
    @Override   
    public void onEnable() {
      instance = this;
      
      Plugin plug = getServer().getPluginManager().getPlugin("SimpleClans");
      if (plug != null) {
          sc = (SimpleClans) plug;
      }
    }
    
    public SimpleClans getSCPlugin() {
        return sc;
    }
    
    public static getInstance() {
        return instance;
    }
}
```

{% endtab %}

{% tab title="Example.class" %}

```java
public class Example {

    public void doClanStuff(Player player) {
        UUID playerUuid = player.getUniqueId();
        
        // Get a ClanManager object
        ClanManager cm = MyPlugin.getInstance().getSCPlugin().getClanManager();
        
        // Get a ClanPlayer object
        ClanPlayer cp = cm.getClanPlayer(playerUuid);
            
        if (cp != null) {
            Clan clan = cp.getClan();
        } else {
            // Player is not in a clan
        }
    
        // Get a clan from a clan tag
        Clan clan = cm.getClan("staff");
    
        if (clan != null) {
            // Clan exists
        }
    }
}
```

{% endtab %}
{% endtabs %}

If you don't want to specify a check for the presence of SimpleClans, you can always specify a dependency in `plugin.yml`:

{% tabs %}
{% tab title="plugin.yml" %}

```yaml
depend:
    - SimpleClans
```

{% endtab %}
{% endtabs %}

## Step 3. Continue your learning

Don't stop in your beginnings, feel free to learn our API: [javadocs](https://ci.roinujnosde.me/job/SimpleClans/Javadoc/).
