mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2026-11-19 10:49:20 +00:00
Call ConfigurationTask callback sync (#4272)
This commit is contained in:
5 files changed
+73
-44
No files matched your search
+5
-1
@@ -35,7 +35,11 @@ public class MinecraftSchedulerAdapter extends JavaSchedulerAdapter {
|
||||
|
||||
public MinecraftSchedulerAdapter(MinecraftLuckPermsBootstrap bootstrap) {
|
||||
super(bootstrap);
|
||||
this.syncExecutor = r -> bootstrap.getServer().orElseThrow(() -> new IllegalStateException("Server not ready")).executeBlocking(r);
|
||||
this.syncExecutor = r -> bootstrap.getServer().orElseThrow(() -> new IllegalStateException("Server not ready")).execute(r);
|
||||
}
|
||||
|
||||
public Executor sync() {
|
||||
return this.syncExecutor;
|
||||
}
|
||||
|
||||
public void executeSync(Runnable task) {
|
||||
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <[email protected]>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.minecraft.util;
|
||||
|
||||
import me.lucko.luckperms.common.minecraft.MinecraftLuckPermsPlugin;
|
||||
import net.minecraft.server.network.ConfigurationTask;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public abstract class AbstractAsyncConfigurationTask implements ConfigurationTask {
|
||||
private final MinecraftLuckPermsPlugin<?, ?> plugin;
|
||||
private final Type type;
|
||||
private final Runnable task;
|
||||
|
||||
public AbstractAsyncConfigurationTask(MinecraftLuckPermsPlugin<?, ?> plugin, Type type, Runnable task) {
|
||||
this.plugin = plugin;
|
||||
this.type = type;
|
||||
this.task = task;
|
||||
}
|
||||
|
||||
protected CompletableFuture<Void> start(Runnable completeCallback) {
|
||||
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);
|
||||
}
|
||||
completeCallback.run();
|
||||
}, this.plugin.getBootstrap().getScheduler().sync());
|
||||
return future;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type type() {
|
||||
return this.type;
|
||||
}
|
||||
}
|
||||
@@ -25,43 +25,25 @@
|
||||
|
||||
package me.lucko.luckperms.forge.util;
|
||||
|
||||
import me.lucko.luckperms.common.minecraft.util.AbstractAsyncConfigurationTask;
|
||||
import me.lucko.luckperms.forge.LPForgePlugin;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.server.network.ConfigurationTask;
|
||||
import net.minecraftforge.network.config.ConfigurationTaskContext;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class AsyncConfigurationTask implements ConfigurationTask {
|
||||
private final LPForgePlugin plugin;
|
||||
private final Type type;
|
||||
private final Runnable task;
|
||||
|
||||
public class AsyncConfigurationTask extends AbstractAsyncConfigurationTask {
|
||||
public AsyncConfigurationTask(LPForgePlugin plugin, Type type, Runnable task) {
|
||||
this.plugin = plugin;
|
||||
this.type = type;
|
||||
this.task = task;
|
||||
super(plugin, type, task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(ConfigurationTaskContext 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(this.type);
|
||||
});
|
||||
start(() -> ctx.finish(type()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Consumer<Packet<?>> send) {
|
||||
throw new IllegalStateException("This should never be called");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type type() {
|
||||
return this.type;
|
||||
}
|
||||
}
|
||||
@@ -159,6 +159,7 @@ public class HytalePlayerCalculator implements ContextCalculator<PlayerRef> {
|
||||
|
||||
private void onGameModeEvent(PlayerRef playerRef, ChangeGameModeEvent e) {
|
||||
this.playerGameModes.put(playerRef.getUuid(), e.getGameMode());
|
||||
this.plugin.getContextManager().signalContextUpdate(playerRef);
|
||||
}
|
||||
|
||||
private final class ChangeGameModeSystem extends EntityEventSystem<EntityStore, ChangeGameModeEvent> {
|
||||
|
||||
+4
-21
@@ -25,40 +25,23 @@
|
||||
|
||||
package me.lucko.luckperms.neoforge.util;
|
||||
|
||||
import me.lucko.luckperms.common.minecraft.util.AbstractAsyncConfigurationTask;
|
||||
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;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class AsyncConfigurationTask implements ConfigurationTask {
|
||||
private final LPNeoForgePlugin plugin;
|
||||
private final Type type;
|
||||
private final Runnable task;
|
||||
public class AsyncConfigurationTask extends AbstractAsyncConfigurationTask {
|
||||
private final ServerConfigurationPacketListener listener;
|
||||
|
||||
public AsyncConfigurationTask(LPNeoForgePlugin plugin, Type type, Runnable task, ServerConfigurationPacketListener listener) {
|
||||
this.plugin = plugin;
|
||||
this.type = type;
|
||||
this.task = task;
|
||||
super(plugin, type, task);
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Consumer<Packet<?>> send) {
|
||||
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);
|
||||
}
|
||||
this.listener.finishCurrentTask(this.type);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type type() {
|
||||
return this.type;
|
||||
start(() -> this.listener.finishCurrentTask(type()));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user