Skip to content

Plugin API

Adrian edited this page Feb 7, 2023 · 14 revisions

Using the API

Gradle

repositories {
  maven("https://jitpack.io")
}

dependencies {
  // API Velocity
  compileOnly("com.github.4drian3d.AuthMeVelocity:api-velocity:3.0.6")
  
  // API Paper
  compileOnly("com.github.4drian3d.AuthMeVelocity:api-paper:3.0.6")
}

Available events

Velocity API

Javadocs

ProxyRegisterEvent

Event executed in case the player has register itself

@Subscribe
public void onRegister(ProxyRegisterEvent event){
  Player player = event.player();
}

ProxyLoginEvent

Event executed when a player logs in correctly.

@Subscribe
public void onLoginInProxy(ProxyLoginEvent event){
  Player player = event.player();
  RegisteredServer server = event.server();
}

PreSendOnLoginEvent (Cancellable)

Event executed just before sending a player to another server after logging in. You can cancel this event.

@Subscribe
public void onPlayerPreSend(PreSendOnLoginEvent event){
  RegisteredServer actualServer = event.actualServer();
  // Actual calculed server
  RegisteredServer toSendServer = event.getResult().getServer();
  Player player = event.player();
  // You can set the server to send
  event.setResult(ServerResult.allowed(customServer));
}

ProxyLogoutEvent

Event executed in case the player has logout from the network

@Subscribe
public void onPlayerLogout(ProxyLogoutEvent event){
  Player player = event.getPlayer();
}

ProxyUnregisterEvent

Event executed in case the player has unregistered itself

@Subscribe
public void onPlayerUnregister(ProxyUnregisterEvent event){
  Player player = event.player();
}

ProxyForcedUnregisterEvent

Event executed in case a player is forced unregister by a server operator

@Subscribe
public void onForcedUnregister(ProxyForcedUnregisterEvent event){
  Player player = event.player();
}

Paper API

Javadocs

PreSendLoginEvent (Cancellable)

@EventHandler
public void onPreSend(PreSendLoginEvent event){
  Player player = event.getPlayer();
  boolean cancelled = event.isCancelled();
  event.setCancelled(true);
}

LoginByProxyEvent

Event to be executed in case a player who has already logged into a previously configured server enters the server.

@EventHandler
public void onPreSend(LoginByProxyEvent event){
  Player player = event.getPlayer();
}

Available Methods (Velocity)

// Random Player
Player player = event.getPlayer();

// Example predicate 
Predicate<Player> predicatePlayer = (player) -> player.getUsername().equals("4drian3d");

// Velocity plugin manager https://jd.papermc.io/velocity/3.0.0/com/velocitypowered/api/plugin/PluginManager.html
PluginManager pluginManager = proxy.getPluginManager();

// AuthmeVelocity API instance
AuthMeVelocityAPI api = pluginManager.getPlugin("authmevelocity")
    .flatMap(Optional::get)
    // You need to check if the AuthMeVelocity instance is available, here we use a direct method to make the explanation simpler
    .get();

// Check if the player is logged
boolean isPlayerLogged = api.isLogged(player);

// Check if the player was not logged
boolean isPlayerNotLogger = api.isNotLogged(player);

// Adds a player to logged players
// May return false if is already logged
boolean succesfullyAdded = api.addPlayer(player);

// Removes a player from logged players
// May return false if is not present
boolean succesfullyRemoved = api.removePlayer(player);

// Removes a player based on a condition
api.removePlayerIf(predicatePlayer);

// Check if the player is in auth server
boolean isInAuthServer = api.isInAuthServer(player)
Clone this wiki locally