1
0
mirror of https://github.com/lucko/LuckPerms.git synced 2025-08-30 17:49:48 +02:00

Fix login configuration phase on NeoForge (#3961)

This commit is contained in:
3TUSK
2024-08-20 16:51:18 -07:00
committed by Luck
parent 136a4859f3
commit 9bf30fc839
4 changed files with 26 additions and 19 deletions

View File

@@ -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) {

View File

@@ -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<ConfigurationTaskContext, CompletableFuture<?>> task;
private final Runnable task;
public AsyncConfigurationTask(LPForgePlugin plugin, Type type, Function<ConfigurationTaskContext, CompletableFuture<?>> 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<CompletableFuture<?>> task) {
this(plugin, type, c -> task.get());
}
@Override
public void start(ConfigurationTaskContext ctx) {
CompletableFuture<?> future = this.task.apply(ctx);
CompletableFuture<Void> 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

View File

@@ -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) {

View File

@@ -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<CompletableFuture<?>> task;
private final Runnable task;
private final ServerConfigurationPacketListener listener;
public AsyncConfigurationTask(LPNeoForgePlugin plugin, Type type, Supplier<CompletableFuture<?>> 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<Packet<?>> send) {
CompletableFuture<?> future = this.task.get();
CompletableFuture<Void> 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