-
Notifications
You must be signed in to change notification settings - Fork 0
Developer API
This guide explains how to compile against and integrate with the peyajAuth API and custom events.
Since peyajAuth is obfuscated for security, we explicitly protect the API package and event classes from name scrambling. You can compile your custom plugins against it by using your compiled peyajAuth.jar as a local project dependency.
Place the peyajAuth.jar into your project's libs directory and configure your build tool:
repositories {
flatDir {
dirs("libs")
}
}
dependencies {
compileOnly(files("libs/peyajAuth.jar"))
}<dependency>
<groupId>me.peyaj</groupId>
<artifactId>peyajauth</artifactId>
<version>1.4</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/peyajAuth.jar</systemPath>
</dependency>To ensure your plugin loads after peyajAuth, add the following to your plugin.yml:
depend: [peyajAuth]All interactions are coordinated through the PeyajAuthAPI interface. You can fetch the singleton provider instance at runtime using:
import me.peyaj.peyajauth.api.PeyajAuthAPI;
PeyajAuthAPI api = PeyajAuthAPI.getInstance();- Description: Checks if a player has successfully completed the login/registration process.
-
Return Type:
boolean - Example:
if (!api.isAuthenticated(player)) {
player.sendMessage("You must log in first!");
}- Description: Checks if the player has been authenticated as a verified premium Mojang/Xbox Live account (Java premium auto-login or Bedrock Floodgate bypass).
-
Return Type:
boolean - Example:
if (api.isPremium(player)) {
player.sendMessage("Welcome verified premium player!");
}- Description: Force-authenticates a player, bypassing any password entry prompts and clearing their restrictions.
-
Return Type:
void - Example:
api.login(player); // Player is now marked as authenticated- Description: De-authenticates an active player session and places them back into the restricted state (prompting for login).
-
Return Type:
void - Example:
api.logout(player);- Description: Registers a new account for the player with the specified password, automatically logging them in.
-
Return Type:
void - Example:
api.register(player, "mySecurePassword123");- Description: Deletes the player's registration account from the database and logs them out.
-
Return Type:
void - Example:
api.unregister(player);You can listen to state changes by creating a standard Bukkit listener for peyajAuth's custom events. All custom events inherit from org.bukkit.event.player.PlayerEvent.
| Event Class | Description |
|---|---|
PlayerAuthenticateEvent |
Fired when a player is successfully authenticated (logs in). |
PlayerFailedLoginEvent |
Fired when a player inputs an incorrect password. |
PlayerRegisterEvent |
Fired when a player registers a new account successfully. |
PlayerLogoutEvent |
Fired when a player logs out of their session. |
PlayerPasswordChangeEvent |
Fired when a player successfully changes their password. |
PlayerPremiumLoginEvent |
Fired when a premium Java/Bedrock player auto-authenticates. |
Here is a full example of a custom Bukkit listener implementing the events:
import me.peyaj.peyajauth.event.PlayerAuthenticateEvent;
import me.peyaj.peyajauth.event.PlayerFailedLoginEvent;
import me.peyaj.peyajauth.event.PlayerRegisterEvent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class AuthListener implements Listener {
@EventHandler
public void onPlayerLogin(PlayerAuthenticateEvent event) {
Player player = event.getPlayer();
Bukkit.getLogger().info(player.getName() + " has completed login!");
}
@EventHandler
public void onPlayerFailed(PlayerFailedLoginEvent event) {
Player player = event.getPlayer();
Bukkit.getLogger().warning(player.getName() + " failed a login attempt!");
}
@EventHandler
public void onPlayerRegister(PlayerRegisterEvent event) {
Player player = event.getPlayer();
player.sendMessage("Thank you for registering on our server!");
}
}