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.
Maven
<repositories>
<repository>
<id>alessiodp-repo</id>
<url>https://repo.alessiodp.com/releases/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.alessiodp.lastloginapi</groupId>
<artifactId>lastloginapi-api</artifactId>
<version>1.7.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
Gradle
repositories {
maven {
name = 'alessiodp-repo'
url = 'https://repo.alessiodp.com/releases/'
}
}
dependencies {
compileOnly group: 'com.alessiodp.lastloginapi', name: 'lastloginapi-api', version: '1.7.4'
}
Usage
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
Events
There are some events that you can hook into, you can read more about them here.
Performance
This is a quick explanation about what LLAPI does on player method example above.
- The API
getPlayer()
tries to get the player from LLAPI instance- If the player is online (already cached), the loading time is almost zero
- If not, there will be a database request. This won't impact server main thread because is executed on a different thread
- The method
getName()
andgetLastLogin()
just return the value, every player data is fetched in the beginning - The method
setLastLogin(...)
set the last login attribute then execute an update request, the request is executed asynchronously on a different thread
JavaDoc
You can find the JavaDoc here.