Performance improvements

- Use async event listener on velocity
This commit is contained in:
4drian3d 2021-11-14 20:15:36 -05:00
parent 5b32a71409
commit 914e15ff70
8 changed files with 21 additions and 19 deletions

View File

@ -7,7 +7,7 @@
<groupId>com.glyart.authmevelocity</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.2.0</version>
<version>1.3.0</version>
<properties>
<maven.compiler.source>16</maven.compiler.source>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>com.glyart.authmevelocity</groupId>
<version>1.2.0</version>
<version>1.3.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -31,12 +31,11 @@ public class AuthmeVelocityAPI {
/**
* Removes a player from the list of logged-in players
* @param player the unlogged player
* @return if the player was succesfully removed
*/
public static void removePlayer(@NotNull Player player){
public static boolean removePlayer(@NotNull Player player){
final UUID playerUUID = player.getUniqueId();
if(AuthmeVelocityAPI.isLogged(player)){
AuthMeVelocityPlugin.loggedPlayers.remove(playerUUID);
}
return AuthMeVelocityPlugin.loggedPlayers.remove(playerUUID);
}
/**

View File

@ -4,6 +4,7 @@ import com.glyart.authmevelocity.proxy.AuthmeVelocityAPI;
import com.glyart.authmevelocity.proxy.config.AuthMeConfig;
import com.glyart.authmevelocity.proxy.event.ProxyLoginEvent;
import com.google.common.io.ByteArrayDataInput;
import com.velocitypowered.api.event.EventTask;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.command.CommandExecuteEvent;
import com.velocitypowered.api.event.connection.DisconnectEvent;
@ -121,10 +122,11 @@ public class ProxyListener {
}
@Subscribe
public void onTabComplete(TabCompleteEvent event){
public EventTask onTabComplete(TabCompleteEvent event){
final Player player = event.getPlayer();
if (!AuthmeVelocityAPI.isLogged(player)){
event.getSuggestions().clear();
return EventTask.async(() -> event.getSuggestions().clear());
}
return null;
}
}

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>com.glyart.authmevelocity</groupId>
<version>1.2.0</version>
<version>1.3.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,17 +5,18 @@ import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
public class AuthMeVelocityPlugin extends JavaPlugin {
@Override
public void onEnable() {
getServer().getMessenger().registerOutgoingPluginChannel(this, "authmevelocity:main");
getServer().getPluginManager().registerEvents(new AuthMeListener(this), this);
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "authmevelocity:main");
this.getServer().getPluginManager().registerEvents(new AuthMeListener(this), this);
getLogger().info("AuthMeVelocity enabled.");
this.getLogger().info("AuthMeVelocity enabled.");
}
public void sendLoginToProxy(Player player) {
public void sendLoginToProxy(@NotNull final Player player) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("LOGIN");
out.writeUTF(player.getUniqueId().toString());

View File

@ -10,8 +10,8 @@ public class PreSendLoginEvent extends PlayerEvent implements Cancellable {
private static final HandlerList HANDLERS = new HandlerList();
private boolean isCancelled;
public PreSendLoginEvent(@NotNull Player player) {
super(player);
public PreSendLoginEvent(@NotNull final Player player, boolean async) {
super(player, async);
}
@Override

View File

@ -19,10 +19,10 @@ public class AuthMeListener implements Listener {
@EventHandler
public void onLogin(LoginEvent event) {
Player player = event.getPlayer();
PreSendLoginEvent sendloginevent = new PreSendLoginEvent(player);
Bukkit.getPluginManager().callEvent(sendloginevent);
if(!sendloginevent.isCancelled()){
final Player player = event.getPlayer();
PreSendLoginEvent preSendLoginEvent = new PreSendLoginEvent(player, false);
Bukkit.getPluginManager().callEvent(preSendLoginEvent);
if(!preSendLoginEvent.isCancelled()){
plugin.sendLoginToProxy(player);
}
}