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> <groupId>com.glyart.authmevelocity</groupId>
<artifactId>parent</artifactId> <artifactId>parent</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>
<version>1.2.0</version> <version>1.3.0</version>
<properties> <properties>
<maven.compiler.source>16</maven.compiler.source> <maven.compiler.source>16</maven.compiler.source>

View File

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

View File

@ -31,12 +31,11 @@ public class AuthmeVelocityAPI {
/** /**
* Removes a player from the list of logged-in players * Removes a player from the list of logged-in players
* @param player the unlogged player * @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(); final UUID playerUUID = player.getUniqueId();
if(AuthmeVelocityAPI.isLogged(player)){ return AuthMeVelocityPlugin.loggedPlayers.remove(playerUUID);
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.config.AuthMeConfig;
import com.glyart.authmevelocity.proxy.event.ProxyLoginEvent; import com.glyart.authmevelocity.proxy.event.ProxyLoginEvent;
import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataInput;
import com.velocitypowered.api.event.EventTask;
import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.command.CommandExecuteEvent; import com.velocitypowered.api.event.command.CommandExecuteEvent;
import com.velocitypowered.api.event.connection.DisconnectEvent; import com.velocitypowered.api.event.connection.DisconnectEvent;
@ -121,10 +122,11 @@ public class ProxyListener {
} }
@Subscribe @Subscribe
public void onTabComplete(TabCompleteEvent event){ public EventTask onTabComplete(TabCompleteEvent event){
final Player player = event.getPlayer(); final Player player = event.getPlayer();
if (!AuthmeVelocityAPI.isLogged(player)){ if (!AuthmeVelocityAPI.isLogged(player)){
event.getSuggestions().clear(); return EventTask.async(() -> event.getSuggestions().clear());
} }
return null;
} }
} }

View File

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

View File

@ -5,17 +5,18 @@ import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
public class AuthMeVelocityPlugin extends JavaPlugin { public class AuthMeVelocityPlugin extends JavaPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
getServer().getMessenger().registerOutgoingPluginChannel(this, "authmevelocity:main"); this.getServer().getMessenger().registerOutgoingPluginChannel(this, "authmevelocity:main");
getServer().getPluginManager().registerEvents(new AuthMeListener(this), this); 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(); ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("LOGIN"); out.writeUTF("LOGIN");
out.writeUTF(player.getUniqueId().toString()); 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 static final HandlerList HANDLERS = new HandlerList();
private boolean isCancelled; private boolean isCancelled;
public PreSendLoginEvent(@NotNull Player player) { public PreSendLoginEvent(@NotNull final Player player, boolean async) {
super(player); super(player, async);
} }
@Override @Override

View File

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