📡API

API Setup

To use the API, you should begin by compiling it. Follow these steps:

  • Clone the repository with git clone https://github.com/Smooth-Plugins/SmoothUsersAPI.git.

  • Compile it with Maven using mvn clean install.

Setup with Maven

To integrate the API using Maven, add the following code to your pom.xml file:

<dependencies>
    <dependency>
        <groupId>net.smoothplugins</groupId>
        <artifactId>SmoothUsersAPI</artifactId>
        <version>%POM-VERSION%</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

Setup with Gradle

If you're using Gradle, add the following code to your build.gradle file:

dependencies {
    compileOnly 'net.smoothplugins:SmoothUsersAPI:%POM-VERSION%'
}

Replace %POM-VERSION% with the appropriate version of the API.

Final step

To complete the setup, include SmoothUsers as a dependency (or softdepend) in your plugin.yml:

name: MyPlugin
version: 1.0
main: net.smoothplugins.myplugin.MyPlugin
author: Author
depend:
  - SmoothUsers

Getting the API

Now, you can get the SmoothUsersAPI to interact with SmoothUsers within your plugin's code:

@Override
public void onEnable() {
    SmoothUsersAPI smoothUsersAPI = getSmoothUsersAPI();
}

private SmoothUsersAPI getSmoothUsersAPI() {
    if (Bukkit.getPluginManager().getPlugin("SmoothUsers") != null) {
        RegisteredServiceProvider<SmoothUsersAPI> rsp = Bukkit.getServicesManager().getRegistration(SmoothUsersAPI.class);
        return rsp.getProvider();
    }

    return null;
}

Interact with the API

Get a UUID by the player username

To retrieve a UUID based on a player's username, follow this example:

import net.smoothplugins.smoothusersapi.SmoothUsersAPI;
import net.smoothplugins.smoothusersapi.user.User;

import java.util.UUID;

public class Example {
    
    private final SmoothUsersAPI smoothUsersAPI;

    public Example(SmoothUsersAPI smoothUsersAPI) {
        this.smoothUsersAPI = smoothUsersAPI;
    }
    
    public UUID getUUIDByUsername(String username) {
        User user = smoothUsersAPI.getUserService().getUserByUsername(username).orElse(null);
        if (user == null) return null;
        
        return user.getUuid();
    }
}

Last updated