SQLTokens - API

Jan 28, 2015
SQLTokens - API
  • Getting a SQLTokens instance:
    In order to use the SQLTokens API, you must first get the instance of the plugin. To do so, run the following code in onEnable() while making neccessary changes to fit your plugin:
    Code (Text):

    for(Plugin plugin : Bukkit.getServer().getPluginManager().getPlugins()){
       if(plugin instanceof SQLTokens){
         this.sqlTokens = ((SQlTokens) plugin);
         break;
       }
    }
    if(this.sqlTokens == null){
       //SQLTokens is not installed or had an error during startup (ie. bad MySQL credentials)
    }
     
    This code loops through all of the plugins on the server until it finds SQLTokens, once it does, it saves the instance.

    Checking a player's balance:
    To check a players' balance, execute the following code:
    Code (Text):
    double balance = sqlTokens.getDataStore().getBalance(OfflinePlayer player);
    Setting a player's balance:
    To set a players' balance, execute the following code:
    Code (Text):
    double balance = sqlTokens.getDataStore().setBalance(OfflinePlayer player, double balance);
    NOTE: SQLTokens will not store any balance with more than 2 decimal places. As such, getBalance() will always return no more than 2 decimal places, and setBalance() will round if you give it more than 2 decimal places.

    Adding to a player's balance
    To add to a player's balance, you must first get their current balance, then you need to add their current balance to the amount you want to add, then set their balance with the updated value. The following is some example code to do so:
    Code (Text):

    double balance = sqlTokens.getDataStore().getBalance(player);
    double newBalance = (balance + theAmountYouWantToAdd);
    sqlTokens.getDataStore().setBalance(player, newBalance);
     
  • Loading...
  • Loading...