SQLPerms API - Historical

Applied By john01dav: Jan 25, 2015 at 7:39 PM

SQLPerms (API)

This page is part of a series of SQLPerms documentation pages
SQLPerms has an API to allow other plugins to interact with it in various ways. Below is the documentation on each part of the API.

Getting the SQLPerms instance:
To use the SQLPerms API in your plugin, you first need to get an instance of the main class like so:
Code (Text):

for(Plugin plugin : Bukkit.getServer().getPluginManager().getPlugins()){
    if(plugin instanceof SQLPerms){
        sqlPerms = ((SQLPerms) plugin); break;
You should run this code in your onEnable method, and store the sqlPerms variable for later use.

Getting a player's rank:
To get a player's rank, you need the channel that you wish to check. Once you have this, get a player's rank like so:
Code (Text):
String rank = sqlPerms.getDataStore().getRank(player.getUniqueId(), "channel");
Each rank is represented in a String which is the name of the rank. There is no "Rank" or similar object in SQLPerms.

Setting a player's rank:
To set a player's rank, you need the channel in which you want to set their rank, and the name of the rank you would like to set. The first step in setting a player's rank is to call the following DataStore method:
Code (Text):
sqlPerms.getDataStore().setRank(player.getUniqueId(), "channel", "rank");
Then, if the player is online, run the following code to trigger an event to make the rest of the plugin update that players rank (prefix, permissions, etc.):
Code (Text):

PlayerChangeRankEvent playerChangeRankEvent = new PlayerChangeRankEvent(player, newRank, previousRank);Bukkit.getServer().getPluginManager().callEvent(playerChangeRankEvent);
If the player is not online at the time of the rank change, you do not need to call this event.

When setting or getting a player's rank you can pass in a UUID that represents a currently offline player. To get a UUID from a name (online or offline) run the following code:
Code (Text):
UUID uuid = sqlPerms.getUtil().getUUID("john01dav");