Hook into LastLoginAPI

LastLoginAPI offers a developer API to handle LLAPI data and information about players. Whenever something will change in the future it will be deprecated then deleted with future updates, so never use deprecated methods.

Importing LastLoginAPI

To add the API to your project you can use use Maven, Gradle or manual adding in classpath.





repositories {
    maven {
        name = 'alessiodp-repo'
        url = 'https://repo.alessiodp.com/releases/'

dependencies {
    compileOnly group: 'com.alessiodp.lastloginapi', name: 'lastloginapi-api', version: '1.4.3'


Your plugin must loaded after LastLoginAPI so you have to define this behavior in plugin.yml of your plugin by inserting LastLoginAPI as depend (or soft-depend):

depend: [LastLoginAPI]
soft-depend: [LastLoginAPI]

Before hook into it, be sure its enabled!

if (getServer().getPluginManager().getPlugin("LastLoginAPI") != null) {
    if (getServer().getPluginManager().getPlugin("LastLoginAPI").isEnabled()) {
        // LastLoginAPI is enabled

Then you can take the instance of LastLoginAPI:

LastLoginAPI api = LastLogin.getApi();

General API methods

LastLoginAPI offers a class called LastLoginAPI, you can use it to call general API methods. This is how you can use it:

LastLoginAPI api = LastLogin.getApi();
LastLoginPlayer player = api.getPlayer(simplePlayer.getUniqueId()); // Get the player
String name = player.getName(); // Get the name

Player methods

With LLPlayer class you can handle any data/information about the player, these are some examples of what you can do:

LastLoginPlayer player = api.getPlayer(simplePlayer.getUniqueId()); // Get the player
player.getName(); // Get the current name
player.getLastLogin(); // Get the last login timestamp
player.setLastLogin(...); // Set the last login timestamp and automatically save to database


There are some events that you can hook into, you can read more about them here.


This is a quick explanation about what LLAPI does on player method example above.

  1. The API getPlayer() tries to get the player from LLAPI instance
    1. If the player is online (already cached), the loading time is almost zero
    2. If not, there will be a database request. This won't impact server main thread because is executed on a different thread
  2. The method getName() and getLastLogin() just return the value, every player data is fetched in the beginning
  3. The method setLastLogin(...) set the last login attribute then execute an update request, the request is executed asynchronously on a different thread


You can find the JavaDoc here.

© AlessioDP 2015-2021