mirror of
https://github.com/lucko/LuckPerms.git
synced 2025-08-31 01:59:48 +02:00
Fix login configuration phase on NeoForge (#3961)
This commit is contained in:
@@ -80,9 +80,12 @@ public class ForgeConnectionListener extends AbstractConnectionListener {
|
|||||||
this.plugin.getLogger().info("Processing pre-login (sync phase) for " + uniqueId + " - " + username);
|
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(() -> {
|
AsyncConfigurationTask task = new AsyncConfigurationTask(
|
||||||
onPlayerNegotiationAsync(ctx.getConnection(), uniqueId, username);
|
this.plugin,
|
||||||
}, this.plugin.getBootstrap().getScheduler().async())));
|
USER_LOGIN_TASK_TYPE,
|
||||||
|
() -> onPlayerNegotiationAsync(event.getConnection(), uniqueId, username)
|
||||||
|
);
|
||||||
|
event.addTask(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onPlayerNegotiationAsync(Connection connection, UUID uniqueId, String username) {
|
private void onPlayerNegotiationAsync(Connection connection, UUID uniqueId, String username) {
|
||||||
|
@@ -38,27 +38,23 @@ import java.util.function.Supplier;
|
|||||||
public class AsyncConfigurationTask implements ConfigurationTask {
|
public class AsyncConfigurationTask implements ConfigurationTask {
|
||||||
private final LPForgePlugin plugin;
|
private final LPForgePlugin plugin;
|
||||||
private final Type type;
|
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.plugin = plugin;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.task = task;
|
this.task = task;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AsyncConfigurationTask(LPForgePlugin plugin, Type type, Supplier<CompletableFuture<?>> task) {
|
|
||||||
this(plugin, type, c -> task.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(ConfigurationTaskContext ctx) {
|
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) -> {
|
future.whenCompleteAsync((o, e) -> {
|
||||||
if (e != null) {
|
if (e != null) {
|
||||||
this.plugin.getLogger().warn("Configuration task threw an exception", e);
|
this.plugin.getLogger().warn("Configuration task threw an exception", e);
|
||||||
}
|
}
|
||||||
ctx.finish(type());
|
ctx.finish(this.type);
|
||||||
}, this.plugin.getBootstrap().getScheduler().sync()); // do we need to call this sync?
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -79,9 +79,13 @@ public class NeoForgeConnectionListener extends AbstractConnectionListener {
|
|||||||
this.plugin.getLogger().info("Processing pre-login (sync phase) for " + uniqueId + " - " + username);
|
this.plugin.getLogger().info("Processing pre-login (sync phase) for " + uniqueId + " - " + username);
|
||||||
}
|
}
|
||||||
|
|
||||||
event.register(new AsyncConfigurationTask(this.plugin, USER_LOGIN_TASK_TYPE, () -> CompletableFuture.runAsync(() -> {
|
AsyncConfigurationTask task = new AsyncConfigurationTask(
|
||||||
onPlayerNegotiationAsync(event.getListener().getConnection(), uniqueId, username);
|
this.plugin,
|
||||||
}, this.plugin.getBootstrap().getScheduler().async())));
|
USER_LOGIN_TASK_TYPE,
|
||||||
|
() -> onPlayerNegotiationAsync(event.getListener().getConnection(), uniqueId, username),
|
||||||
|
event.getListener()
|
||||||
|
);
|
||||||
|
event.register(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onPlayerNegotiationAsync(Connection connection, UUID uniqueId, String username) {
|
private void onPlayerNegotiationAsync(Connection connection, UUID uniqueId, String username) {
|
||||||
|
@@ -27,6 +27,7 @@ package me.lucko.luckperms.neoforge.util;
|
|||||||
|
|
||||||
import me.lucko.luckperms.neoforge.LPNeoForgePlugin;
|
import me.lucko.luckperms.neoforge.LPNeoForgePlugin;
|
||||||
import net.minecraft.network.protocol.Packet;
|
import net.minecraft.network.protocol.Packet;
|
||||||
|
import net.minecraft.network.protocol.configuration.ServerConfigurationPacketListener;
|
||||||
import net.minecraft.server.network.ConfigurationTask;
|
import net.minecraft.server.network.ConfigurationTask;
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
@@ -36,22 +37,25 @@ import java.util.function.Supplier;
|
|||||||
public class AsyncConfigurationTask implements ConfigurationTask {
|
public class AsyncConfigurationTask implements ConfigurationTask {
|
||||||
private final LPNeoForgePlugin plugin;
|
private final LPNeoForgePlugin plugin;
|
||||||
private final Type type;
|
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.plugin = plugin;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.task = task;
|
this.task = task;
|
||||||
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Consumer<Packet<?>> send) {
|
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) -> {
|
future.whenCompleteAsync((o, e) -> {
|
||||||
if (e != null) {
|
if (e != null) {
|
||||||
this.plugin.getLogger().warn("Configuration task threw an exception", e);
|
this.plugin.getLogger().warn("Configuration task threw an exception", e);
|
||||||
}
|
}
|
||||||
}).join();
|
this.listener.finishCurrentTask(this.type);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user