-
-
Notifications
You must be signed in to change notification settings - Fork 15
Plugin API
Adrian edited this page Jun 25, 2023
·
14 revisions
repositories {
// For releases
mavenCentral()
// For snapshots
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
dependencies {
// API Velocity
compileOnly("io.github.4drian3d:authmevelocity-api-velocity:4.0.2")
// API Paper
compileOnly("io.github.4drian3d:authMevelocity-api-paper:4.0.2")
}
Event executed in case the player has register itself
@Subscribe
public void onRegister(ProxyRegisterEvent event){
Player player = event.player();
}
Event executed when a player logs in correctly.
@Subscribe
public void onLoginInProxy(ProxyLoginEvent event){
Player player = event.player();
RegisteredServer server = event.server();
}
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));
}
Event executed in case the player has logout from the network
@Subscribe
public void onPlayerLogout(ProxyLogoutEvent event){
Player player = event.getPlayer();
}
Event executed in case the player has unregistered itself
@Subscribe
public void onPlayerUnregister(ProxyUnregisterEvent event){
Player player = event.player();
}
Event executed in case a player is forced unregister by a server operator
@Subscribe
public void onForcedUnregister(ProxyForcedUnregisterEvent event){
Player player = event.player();
}
@EventHandler
public void onPreSend(PreSendLoginEvent event){
Player player = event.getPlayer();
boolean cancelled = event.isCancelled();
event.setCancelled(true);
}
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();
}
// 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)