Skip to content

Commit

Permalink
perf: Changed all Velocity events to use asynchronous tasks
Browse files Browse the repository at this point in the history
Except PlayerSettingsChangedEvent event

The change to asynchronous tasks has no significant change at the moment, since Velocity already handles all asynchronous events (unless specified), but in future releases this will change
  • Loading branch information
4drian3d committed Feb 16, 2023
1 parent 07ac81e commit 9f99f5f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
Expand Up @@ -15,6 +15,7 @@

package me.xneox.epicguard.velocity.listener;

import com.velocitypowered.api.event.Continuation;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.player.PlayerSettingsChangedEvent;
import me.xneox.epicguard.core.EpicGuard;
Expand All @@ -26,7 +27,8 @@ public PlayerSettingsListener(EpicGuard epicGuard) {
}

@Subscribe
public void onPostLogin(PlayerSettingsChangedEvent event) {
public void onPostLogin(PlayerSettingsChangedEvent event, Continuation continuation) {
this.onSettingsChanged(event.getPlayer().getUniqueId());
continuation.resume();
}
}
Expand Up @@ -15,6 +15,7 @@

package me.xneox.epicguard.velocity.listener;

import com.velocitypowered.api.event.EventTask;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.connection.PostLoginEvent;
import me.xneox.epicguard.core.EpicGuard;
Expand All @@ -26,8 +27,10 @@ public PostLoginListener(EpicGuard epicGuard) {
}

@Subscribe
public void onPostLogin(PostLoginEvent event) {
var player = event.getPlayer();
this.onPostLogin(player.getUniqueId(), player.getRemoteAddress().getAddress().getHostAddress());
public EventTask onPostLogin(PostLoginEvent event) {
return EventTask.async(() -> {
var player = event.getPlayer();
this.onPostLogin(player.getUniqueId(), player.getRemoteAddress().getAddress().getHostAddress());
});
}
}
Expand Up @@ -29,8 +29,8 @@ public PreLoginListener(EpicGuard epicGuard) {

@Subscribe(order = PostOrder.FIRST)
public EventTask onPreLogin(PreLoginEvent event) {
String address = event.getConnection().getRemoteAddress().getAddress().getHostAddress();
String nickname = event.getUsername();
final String address = event.getConnection().getRemoteAddress().getAddress().getHostAddress();
final String nickname = event.getUsername();

return EventTask.async(() ->
this.onPreLogin(address, nickname).ifPresent(result -> event.setResult(PreLoginEvent.PreLoginComponentResult.denied(result))));
Expand Down
Expand Up @@ -15,6 +15,7 @@

package me.xneox.epicguard.velocity.listener;

import com.velocitypowered.api.event.EventTask;
import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyPingEvent;
Expand All @@ -27,7 +28,8 @@ public ServerPingListener(EpicGuard epicGuard) {
}

@Subscribe(order = PostOrder.FIRST)
public void onPing(ProxyPingEvent event) {
this.onPing(event.getConnection().getRemoteAddress().getAddress().getHostAddress());
public EventTask onPing(ProxyPingEvent event) {
return EventTask.async(() ->
this.onPing(event.getConnection().getRemoteAddress().getAddress().getHostAddress()));
}
}

0 comments on commit 9f99f5f

Please sign in to comment.