Skip to content

Commit

Permalink
fix: use AsyncPlayerConfgiurationEvent for permission checks on minestom
Browse files Browse the repository at this point in the history
### Motivation
Maintainance kicks on minestom kick the player after he has joined. This
causes join/leave messages for that player to be visible, even though he
was disallowed to join.

### Modification
I changed the event with the permission check from PlayerSpawnEvent to
AsyncPlayerConfigurationEvent.
Permission systems have time to load the permission data before that
time by using `AsyncPlayerPreLoginEvent`, and the player won't be in the
world yet. Perfect time for permission checks to deny login.

### Result
The player properly gets denied on "login", not kicked right after he
was able to join.
  • Loading branch information
DasBabyPixel authored Jan 20, 2025
1 parent cfdf19f commit 8bfd442
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.minestom.server.event.EventFilter;
import net.minestom.server.event.EventNode;
import net.minestom.server.event.GlobalEventHandler;
import net.minestom.server.event.player.AsyncPlayerConfigurationEvent;
import net.minestom.server.event.player.PlayerDisconnectEvent;
import net.minestom.server.event.player.PlayerSpawnEvent;

Expand All @@ -51,13 +52,13 @@ public MinestomPlayerManagementListener(
// listen on these events and redirect them into the methods
var node = EventNode.type("cloudnet-bridge", EventFilter.PLAYER);
eventHandler.addChild(node
.addListener(PlayerSpawnEvent.class, this::handleLogin)
.addListener(AsyncPlayerConfigurationEvent.class, this::handleLogin)
.addListener(PlayerSpawnEvent.class, this::handleJoin)
.addListener(PlayerDisconnectEvent.class, this::handleDisconnect));
}

private void handleLogin(@NonNull PlayerSpawnEvent event) {
if (!event.isFirstSpawn()) {
private void handleLogin(@NonNull AsyncPlayerConfigurationEvent event) {
if (!event.isFirstConfig()) {
return;
}

Expand Down

0 comments on commit 8bfd442

Please sign in to comment.