From 9bf30fc8391ed5227760547be05aa00063c57a88 Mon Sep 17 00:00:00 2001 From: 3TUSK Date: Tue, 20 Aug 2024 16:51:18 -0700 Subject: [PATCH] Fix login configuration phase on NeoForge (#3961) --- .../forge/listeners/ForgeConnectionListener.java | 9 ++++++--- .../forge/util/AsyncConfigurationTask.java | 14 +++++--------- .../listeners/NeoForgeConnectionListener.java | 10 +++++++--- .../neoforge/util/AsyncConfigurationTask.java | 12 ++++++++---- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/forge/src/main/java/me/lucko/luckperms/forge/listeners/ForgeConnectionListener.java b/forge/src/main/java/me/lucko/luckperms/forge/listeners/ForgeConnectionListener.java index 95e9bd0d7..9efef7cb6 100644 --- a/forge/src/main/java/me/lucko/luckperms/forge/listeners/ForgeConnectionListener.java +++ b/forge/src/main/java/me/lucko/luckperms/forge/listeners/ForgeConnectionListener.java @@ -80,9 +80,12 @@ public class ForgeConnectionListener extends AbstractConnectionListener { this.plugin.getLogger().info("Processing pre-login (sync phase) for " + uniqueId + " - " + username); } - event.addTask(new AsyncConfigurationTask(this.plugin, USER_LOGIN_TASK_TYPE, ctx -> CompletableFuture.runAsync(() -> { - onPlayerNegotiationAsync(ctx.getConnection(), uniqueId, username); - }, this.plugin.getBootstrap().getScheduler().async()))); + AsyncConfigurationTask task = new AsyncConfigurationTask( + this.plugin, + USER_LOGIN_TASK_TYPE, + () -> onPlayerNegotiationAsync(event.getConnection(), uniqueId, username) + ); + event.addTask(task); } private void onPlayerNegotiationAsync(Connection connection, UUID uniqueId, String username) { diff --git a/forge/src/main/java/me/lucko/luckperms/forge/util/AsyncConfigurationTask.java b/forge/src/main/java/me/lucko/luckperms/forge/util/AsyncConfigurationTask.java index e740c9af8..48294016c 100644 --- a/forge/src/main/java/me/lucko/luckperms/forge/util/AsyncConfigurationTask.java +++ b/forge/src/main/java/me/lucko/luckperms/forge/util/AsyncConfigurationTask.java @@ -38,27 +38,23 @@ import java.util.function.Supplier; public class AsyncConfigurationTask implements ConfigurationTask { private final LPForgePlugin plugin; private final Type type; - private final Function> task; + private final Runnable task; - public AsyncConfigurationTask(LPForgePlugin plugin, Type type, Function> task) { + public AsyncConfigurationTask(LPForgePlugin plugin, Type type, Runnable task) { this.plugin = plugin; this.type = type; this.task = task; } - public AsyncConfigurationTask(LPForgePlugin plugin, Type type, Supplier> task) { - this(plugin, type, c -> task.get()); - } - @Override public void start(ConfigurationTaskContext ctx) { - CompletableFuture future = this.task.apply(ctx); + CompletableFuture future = CompletableFuture.runAsync(this.task, this.plugin.getBootstrap().getScheduler().async()); future.whenCompleteAsync((o, e) -> { if (e != null) { this.plugin.getLogger().warn("Configuration task threw an exception", e); } - ctx.finish(type()); - }, this.plugin.getBootstrap().getScheduler().sync()); // do we need to call this sync? + ctx.finish(this.type); + }); } @Override diff --git a/neoforge/src/main/java/me/lucko/luckperms/neoforge/listeners/NeoForgeConnectionListener.java b/neoforge/src/main/java/me/lucko/luckperms/neoforge/listeners/NeoForgeConnectionListener.java index c4a91e165..18b848f78 100644 --- a/neoforge/src/main/java/me/lucko/luckperms/neoforge/listeners/NeoForgeConnectionListener.java +++ b/neoforge/src/main/java/me/lucko/luckperms/neoforge/listeners/NeoForgeConnectionListener.java @@ -79,9 +79,13 @@ public class NeoForgeConnectionListener extends AbstractConnectionListener { this.plugin.getLogger().info("Processing pre-login (sync phase) for " + uniqueId + " - " + username); } - event.register(new AsyncConfigurationTask(this.plugin, USER_LOGIN_TASK_TYPE, () -> CompletableFuture.runAsync(() -> { - onPlayerNegotiationAsync(event.getListener().getConnection(), uniqueId, username); - }, this.plugin.getBootstrap().getScheduler().async()))); + AsyncConfigurationTask task = new AsyncConfigurationTask( + this.plugin, + USER_LOGIN_TASK_TYPE, + () -> onPlayerNegotiationAsync(event.getListener().getConnection(), uniqueId, username), + event.getListener() + ); + event.register(task); } private void onPlayerNegotiationAsync(Connection connection, UUID uniqueId, String username) { diff --git a/neoforge/src/main/java/me/lucko/luckperms/neoforge/util/AsyncConfigurationTask.java b/neoforge/src/main/java/me/lucko/luckperms/neoforge/util/AsyncConfigurationTask.java index 748ba9fe2..f7c34d794 100644 --- a/neoforge/src/main/java/me/lucko/luckperms/neoforge/util/AsyncConfigurationTask.java +++ b/neoforge/src/main/java/me/lucko/luckperms/neoforge/util/AsyncConfigurationTask.java @@ -27,6 +27,7 @@ package me.lucko.luckperms.neoforge.util; import me.lucko.luckperms.neoforge.LPNeoForgePlugin; import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.configuration.ServerConfigurationPacketListener; import net.minecraft.server.network.ConfigurationTask; import java.util.concurrent.CompletableFuture; @@ -36,22 +37,25 @@ import java.util.function.Supplier; public class AsyncConfigurationTask implements ConfigurationTask { private final LPNeoForgePlugin plugin; private final Type type; - private final Supplier> task; + private final Runnable task; + private final ServerConfigurationPacketListener listener; - public AsyncConfigurationTask(LPNeoForgePlugin plugin, Type type, Supplier> task) { + public AsyncConfigurationTask(LPNeoForgePlugin plugin, Type type, Runnable task, ServerConfigurationPacketListener listener) { this.plugin = plugin; this.type = type; this.task = task; + this.listener = listener; } @Override public void start(Consumer> send) { - CompletableFuture future = this.task.get(); + CompletableFuture future = CompletableFuture.runAsync(this.task, this.plugin.getBootstrap().getScheduler().async()); future.whenCompleteAsync((o, e) -> { if (e != null) { this.plugin.getLogger().warn("Configuration task threw an exception", e); } - }).join(); + this.listener.finishCurrentTask(this.type); + }); } @Override